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.

175 lines
3.6 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. #include "dh_locl.h"
  10. #include <string.h>
  11. #include <openssl/err.h>
  12. DH_METHOD *DH_meth_new(const char *name, int flags)
  13. {
  14. DH_METHOD *dhm = OPENSSL_zalloc(sizeof(DH_METHOD));
  15. if (dhm != NULL) {
  16. dhm->name = OPENSSL_strdup(name);
  17. if (dhm->name == NULL) {
  18. OPENSSL_free(dhm);
  19. DHerr(DH_F_DH_METH_NEW, ERR_R_MALLOC_FAILURE);
  20. return NULL;
  21. }
  22. dhm->flags = flags;
  23. }
  24. return dhm;
  25. }
  26. void DH_meth_free(DH_METHOD *dhm)
  27. {
  28. if (dhm != NULL) {
  29. if (dhm->name != NULL)
  30. OPENSSL_free(dhm->name);
  31. OPENSSL_free(dhm);
  32. }
  33. }
  34. DH_METHOD *DH_meth_dup(const DH_METHOD *dhm)
  35. {
  36. DH_METHOD *ret;
  37. ret = OPENSSL_malloc(sizeof(DH_METHOD));
  38. if (ret != NULL) {
  39. memcpy(ret, dhm, sizeof(*dhm));
  40. ret->name = OPENSSL_strdup(dhm->name);
  41. if (ret->name == NULL) {
  42. OPENSSL_free(ret);
  43. DHerr(DH_F_DH_METH_DUP, ERR_R_MALLOC_FAILURE);
  44. return NULL;
  45. }
  46. }
  47. return ret;
  48. }
  49. const char *DH_meth_get0_name(const DH_METHOD *dhm)
  50. {
  51. return dhm->name;
  52. }
  53. int DH_meth_set1_name(DH_METHOD *dhm, const char *name)
  54. {
  55. char *tmpname;
  56. tmpname = OPENSSL_strdup(name);
  57. if (tmpname == NULL) {
  58. DHerr(DH_F_DH_METH_SET1_NAME, ERR_R_MALLOC_FAILURE);
  59. return 0;
  60. }
  61. OPENSSL_free(dhm->name);
  62. dhm->name = tmpname;
  63. return 1;
  64. }
  65. int DH_meth_get_flags(DH_METHOD *dhm)
  66. {
  67. return dhm->flags;
  68. }
  69. int DH_meth_set_flags(DH_METHOD *dhm, int flags)
  70. {
  71. dhm->flags = flags;
  72. return 1;
  73. }
  74. void *DH_meth_get0_app_data(const DH_METHOD *dhm)
  75. {
  76. return dhm->app_data;
  77. }
  78. int DH_meth_set0_app_data(DH_METHOD *dhm, void *app_data)
  79. {
  80. dhm->app_data = app_data;
  81. return 1;
  82. }
  83. int (*DH_meth_get_generate_key(const DH_METHOD *dhm)) (DH *)
  84. {
  85. return dhm->generate_key;
  86. }
  87. int DH_meth_set_generate_key(DH_METHOD *dhm, int (*generate_key) (DH *))
  88. {
  89. dhm->generate_key = generate_key;
  90. return 1;
  91. }
  92. int (*DH_meth_get_compute_key(const DH_METHOD *dhm))
  93. (unsigned char *key, const BIGNUM *pub_key, DH *dh)
  94. {
  95. return dhm->compute_key;
  96. }
  97. int DH_meth_set_compute_key(DH_METHOD *dhm,
  98. int (*compute_key) (unsigned char *key, const BIGNUM *pub_key, DH *dh))
  99. {
  100. dhm->compute_key = compute_key;
  101. return 1;
  102. }
  103. int (*DH_meth_get_bn_mod_exp(const DH_METHOD *dhm))
  104. (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *, const BIGNUM *,
  105. BN_CTX *, BN_MONT_CTX *)
  106. {
  107. return dhm->bn_mod_exp;
  108. }
  109. int DH_meth_set_bn_mod_exp(DH_METHOD *dhm,
  110. int (*bn_mod_exp) (const DH *, BIGNUM *, const BIGNUM *, const BIGNUM *,
  111. const BIGNUM *, BN_CTX *, BN_MONT_CTX *))
  112. {
  113. dhm->bn_mod_exp = bn_mod_exp;
  114. return 1;
  115. }
  116. int (*DH_meth_get_init(const DH_METHOD *dhm))(DH *)
  117. {
  118. return dhm->init;
  119. }
  120. int DH_meth_set_init(DH_METHOD *dhm, int (*init)(DH *))
  121. {
  122. dhm->init = init;
  123. return 1;
  124. }
  125. int (*DH_meth_get_finish(const DH_METHOD *dhm)) (DH *)
  126. {
  127. return dhm->finish;
  128. }
  129. int DH_meth_set_finish(DH_METHOD *dhm, int (*finish) (DH *))
  130. {
  131. dhm->finish = finish;
  132. return 1;
  133. }
  134. int (*DH_meth_get_generate_params(const DH_METHOD *dhm))
  135. (DH *, int, int, BN_GENCB *)
  136. {
  137. return dhm->generate_params;
  138. }
  139. int DH_meth_set_generate_params(DH_METHOD *dhm,
  140. int (*generate_params) (DH *, int, int, BN_GENCB *))
  141. {
  142. dhm->generate_params = generate_params;
  143. return 1;
  144. }