dsa_meth.c 5.0 KB

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