dsa_meth.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. * Licensed under the Apache License 2.0 (the "License");
  11. * you may not use this file except in compliance with the License.
  12. * You may obtain a copy of the License at
  13. * https://www.openssl.org/source/license.html
  14. * or in the file LICENSE in the source distribution.
  15. */
  16. #include "dsa_local.h"
  17. #include <string.h>
  18. #include <openssl/err.h>
  19. #ifndef OPENSSL_NO_DEPRECATED_3_0
  20. DSA_METHOD *DSA_meth_new(const char *name, int flags)
  21. {
  22. DSA_METHOD *dsam = OPENSSL_zalloc(sizeof(*dsam));
  23. if (dsam != NULL) {
  24. dsam->flags = flags;
  25. dsam->name = OPENSSL_strdup(name);
  26. if (dsam->name != NULL)
  27. return dsam;
  28. OPENSSL_free(dsam);
  29. }
  30. DSAerr(DSA_F_DSA_METH_NEW, ERR_R_MALLOC_FAILURE);
  31. return NULL;
  32. }
  33. void DSA_meth_free(DSA_METHOD *dsam)
  34. {
  35. if (dsam != NULL) {
  36. OPENSSL_free(dsam->name);
  37. OPENSSL_free(dsam);
  38. }
  39. }
  40. DSA_METHOD *DSA_meth_dup(const DSA_METHOD *dsam)
  41. {
  42. DSA_METHOD *ret = OPENSSL_malloc(sizeof(*ret));
  43. if (ret != NULL) {
  44. memcpy(ret, dsam, sizeof(*dsam));
  45. ret->name = OPENSSL_strdup(dsam->name);
  46. if (ret->name != NULL)
  47. return ret;
  48. OPENSSL_free(ret);
  49. }
  50. DSAerr(DSA_F_DSA_METH_DUP, ERR_R_MALLOC_FAILURE);
  51. return NULL;
  52. }
  53. const char *DSA_meth_get0_name(const DSA_METHOD *dsam)
  54. {
  55. return dsam->name;
  56. }
  57. int DSA_meth_set1_name(DSA_METHOD *dsam, const char *name)
  58. {
  59. char *tmpname = OPENSSL_strdup(name);
  60. if (tmpname == NULL) {
  61. DSAerr(DSA_F_DSA_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
  62. return 0;
  63. }
  64. OPENSSL_free(dsam->name);
  65. dsam->name = tmpname;
  66. return 1;
  67. }
  68. int DSA_meth_get_flags(const DSA_METHOD *dsam)
  69. {
  70. return dsam->flags;
  71. }
  72. int DSA_meth_set_flags(DSA_METHOD *dsam, int flags)
  73. {
  74. dsam->flags = flags;
  75. return 1;
  76. }
  77. void *DSA_meth_get0_app_data(const DSA_METHOD *dsam)
  78. {
  79. return dsam->app_data;
  80. }
  81. int DSA_meth_set0_app_data(DSA_METHOD *dsam, void *app_data)
  82. {
  83. dsam->app_data = app_data;
  84. return 1;
  85. }
  86. DSA_SIG *(*DSA_meth_get_sign(const DSA_METHOD *dsam))
  87. (const unsigned char *, int, DSA *)
  88. {
  89. return dsam->dsa_do_sign;
  90. }
  91. int DSA_meth_set_sign(DSA_METHOD *dsam,
  92. DSA_SIG *(*sign) (const unsigned char *, int, DSA *))
  93. {
  94. dsam->dsa_do_sign = sign;
  95. return 1;
  96. }
  97. int (*DSA_meth_get_sign_setup(const DSA_METHOD *dsam))
  98. (DSA *, BN_CTX *, BIGNUM **, BIGNUM **)
  99. {
  100. return dsam->dsa_sign_setup;
  101. }
  102. int DSA_meth_set_sign_setup(DSA_METHOD *dsam,
  103. int (*sign_setup) (DSA *, BN_CTX *, BIGNUM **, BIGNUM **))
  104. {
  105. dsam->dsa_sign_setup = sign_setup;
  106. return 1;
  107. }
  108. int (*DSA_meth_get_verify(const DSA_METHOD *dsam))
  109. (const unsigned char *, int, DSA_SIG *, DSA *)
  110. {
  111. return dsam->dsa_do_verify;
  112. }
  113. int DSA_meth_set_verify(DSA_METHOD *dsam,
  114. int (*verify) (const unsigned char *, int, DSA_SIG *, DSA *))
  115. {
  116. dsam->dsa_do_verify = verify;
  117. return 1;
  118. }
  119. int (*DSA_meth_get_mod_exp(const DSA_METHOD *dsam))
  120. (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
  121. const BIGNUM *, const BIGNUM *, BN_CTX *, BN_MONT_CTX *)
  122. {
  123. return dsam->dsa_mod_exp;
  124. }
  125. int DSA_meth_set_mod_exp(DSA_METHOD *dsam,
  126. int (*mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
  127. const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
  128. BN_MONT_CTX *))
  129. {
  130. dsam->dsa_mod_exp = mod_exp;
  131. return 1;
  132. }
  133. int (*DSA_meth_get_bn_mod_exp(const DSA_METHOD *dsam))
  134. (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *, BN_CTX *,
  135. BN_MONT_CTX *)
  136. {
  137. return dsam->bn_mod_exp;
  138. }
  139. int DSA_meth_set_bn_mod_exp(DSA_METHOD *dsam,
  140. int (*bn_mod_exp) (DSA *, BIGNUM *, const BIGNUM *, const BIGNUM *,
  141. const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
  142. {
  143. dsam->bn_mod_exp = bn_mod_exp;
  144. return 1;
  145. }
  146. int (*DSA_meth_get_init(const DSA_METHOD *dsam))(DSA *)
  147. {
  148. return dsam->init;
  149. }
  150. int DSA_meth_set_init(DSA_METHOD *dsam, int (*init)(DSA *))
  151. {
  152. dsam->init = init;
  153. return 1;
  154. }
  155. int (*DSA_meth_get_finish(const DSA_METHOD *dsam)) (DSA *)
  156. {
  157. return dsam->finish;
  158. }
  159. int DSA_meth_set_finish(DSA_METHOD *dsam, int (*finish) (DSA *))
  160. {
  161. dsam->finish = finish;
  162. return 1;
  163. }
  164. int (*DSA_meth_get_paramgen(const DSA_METHOD *dsam))
  165. (DSA *, int, const unsigned char *, int, int *, unsigned long *,
  166. BN_GENCB *)
  167. {
  168. return dsam->dsa_paramgen;
  169. }
  170. int DSA_meth_set_paramgen(DSA_METHOD *dsam,
  171. int (*paramgen) (DSA *, int, const unsigned char *, int, int *,
  172. unsigned long *, BN_GENCB *))
  173. {
  174. dsam->dsa_paramgen = paramgen;
  175. return 1;
  176. }
  177. int (*DSA_meth_get_keygen(const DSA_METHOD *dsam)) (DSA *)
  178. {
  179. return dsam->dsa_keygen;
  180. }
  181. int DSA_meth_set_keygen(DSA_METHOD *dsam, int (*keygen) (DSA *))
  182. {
  183. dsam->dsa_keygen = keygen;
  184. return 1;
  185. }
  186. #endif