A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

225 lines
5.1 KiB

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