dsa_meth.c 4.9 KB

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