2
0

dsa_meth.c 4.8 KB

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