1/* 2 * Copyright 2016-2020 The OpenSSL Project Authors. All Rights Reserved. 3 * 4 * Licensed under the Apache License 2.0 (the "License"). You may not use 5 * this file except in compliance with the License. You can obtain a copy 6 * in the file LICENSE in the source distribution or at 7 * https://www.openssl.org/source/license.html 8 */ 9 10/* 11 * DSA low level APIs are deprecated for public use, but still ok for 12 * internal use. 13 */ 14#include "internal/deprecated.h" 15 16#include "dsa_local.h" 17#include <string.h> 18#include <openssl/err.h> 19 20#ifndef OPENSSL_NO_DEPRECATED_3_0 21DSA_METHOD *DSA_meth_new(const char *name, int flags) 22{ 23 DSA_METHOD *dsam = OPENSSL_zalloc(sizeof(*dsam)); 24 25 if (dsam != NULL) { 26 dsam->flags = flags; 27 28 dsam->name = OPENSSL_strdup(name); 29 if (dsam->name != NULL) 30 return dsam; 31 32 OPENSSL_free(dsam); 33 } 34 35 ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); 36 return NULL; 37} 38 39void DSA_meth_free(DSA_METHOD *dsam) 40{ 41 if (dsam != NULL) { 42 OPENSSL_free(dsam->name); 43 OPENSSL_free(dsam); 44 } 45} 46 47DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam) 48{ 49 DSA_METHOD *ret = OPENSSL_malloc(sizeof(*ret)); 50 51 if (ret != NULL) { 52 memcpy(ret, dsam, sizeof(*dsam)); 53 54 ret->name = OPENSSL_strdup(dsam->name); 55 if (ret->name != NULL) 56 return ret; 57 58 OPENSSL_free(ret); 59 } 60 61 ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); 62 return NULL; 63} 64 65const char *DSA_meth_get0_name(const DSA_METHOD *dsam) 66{ 67 return dsam->name; 68} 69 70int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name) 71{ 72 char *tmpname = OPENSSL_strdup(name); 73 74 if (tmpname == NULL) { 75 ERR_raise(ERR_LIB_DSA, ERR_R_MALLOC_FAILURE); 76 return 0; 77 } 78 79 OPENSSL_free(dsam->name); 80 dsam->name = tmpname; 81 82 return 1; 83} 84 85int DSA_meth_get_flags(const DSA_METHOD *dsam) 86{ 87 return dsam->flags; 88} 89 90int DSA_meth_set_flags(DSA_METHOD *dsam, int flags) 91{ 92 dsam->flags = flags; 93 return 1; 94} 95 96void *DSA_meth_get0_app_data(const DSA_METHOD *dsam) 97{ 98 return dsam->app_data; 99} 100 101int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data) 102{ 103 dsam->app_data = app_data; 104 return 1; 105} 106 107DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam)) 108 (const unsigned char *, int, DSA *) 109{ 110 return dsam->dsa_do_sign; 111} 112 113int DSA_meth_set_sign(DSA_METHOD *dsam, 114 DSA_SIG *(*sign) (const unsigned char *, int, DSA *)) 115{ 116 dsam->dsa_do_sign = sign; 117 return 1; 118} 119 120int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam)) 121 (DSA *, BN_CTX *, BIGNUM **, BIGNUM **) 122{ 123 return dsam->dsa_sign_setup; 124} 125 126int DSA_meth_set_sign_setup(DSA_METHOD *dsam, 127 int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **)) 128{ 129 dsam->dsa_sign_setup = sign_setup; 130 return 1; 131} 132 133int (*DSA_meth_get_verify(const DSA_METHOD *dsam)) 134 (const unsigned char *, int, DSA_SIG *, DSA *) 135{ 136 return dsam->dsa_do_verify; 137} 138 139int DSA_meth_set_verify(DSA_METHOD *dsam, 140 int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *)) 141{ 142 dsam->dsa_do_verify = verify; 143 return 1; 144} 145 146int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam)) 147 (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, 148 const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *) 149{ 150 return dsam->dsa_mod_exp; 151} 152 153int DSA_meth_set_mod_exp(DSA_METHOD *dsam, 154 int (*mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, 155 const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *, 156 BN_MONT_CTX *)) 157{ 158 dsam->dsa_mod_exp = mod_exp; 159 return 1; 160} 161 162int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam)) 163 (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *, 164 BN_MONT_CTX *) 165{ 166 return dsam->bn_mod_exp; 167} 168 169int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam, 170 int (*bn_mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, 171 const BIGNUM *, BN_CTX *, BN_MONT_CTX *)) 172{ 173 dsam->bn_mod_exp = bn_mod_exp; 174 return 1; 175} 176 177int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *) 178{ 179 return dsam->init; 180} 181 182int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *)) 183{ 184 dsam->init = init; 185 return 1; 186} 187 188int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *) 189{ 190 return dsam->finish; 191} 192 193int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *)) 194{ 195 dsam->finish = finish; 196 return 1; 197} 198 199int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam)) 200 (DSA *, int, const unsigned char *, int, int *, unsigned long *, 201 BN_GENCB *) 202{ 203 return dsam->dsa_paramgen; 204} 205 206int DSA_meth_set_paramgen(DSA_METHOD *dsam, 207 int (*paramgen) (DSA *, int, const unsigned char *, int, int *, 208 unsigned long *, BN_GENCB *)) 209{ 210 dsam->dsa_paramgen = paramgen; 211 return 1; 212} 213 214int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *) 215{ 216 return dsam->dsa_keygen; 217} 218 219int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *)) 220{ 221 dsam->dsa_keygen = keygen; 222 return 1; 223} 224#endif 225