srp.h.in 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /*
  2. * {- join("\n * ", @autowarntext) -}
  3. *
  4. * Copyright 2004-2021 The OpenSSL Project Authors. All Rights Reserved.
  5. * Copyright (c) 2004, EdelKey Project. All Rights Reserved.
  6. *
  7. * Licensed under the Apache License 2.0 (the "License"). You may not use
  8. * this file except in compliance with the License. You can obtain a copy
  9. * in the file LICENSE in the source distribution or at
  10. * https://www.openssl.org/source/license.html
  11. *
  12. * Originally written by Christophe Renou and Peter Sylvester,
  13. * for the EdelKey project.
  14. */
  15. {-
  16. use OpenSSL::stackhash qw(generate_stack_macros);
  17. -}
  18. #ifndef OPENSSL_SRP_H
  19. # define OPENSSL_SRP_H
  20. # pragma once
  21. # include <openssl/macros.h>
  22. # ifndef OPENSSL_NO_DEPRECATED_3_0
  23. # define HEADER_SRP_H
  24. # endif
  25. #include <openssl/opensslconf.h>
  26. #ifndef OPENSSL_NO_SRP
  27. # include <stdio.h>
  28. # include <string.h>
  29. # include <openssl/safestack.h>
  30. # include <openssl/bn.h>
  31. # include <openssl/crypto.h>
  32. # ifdef __cplusplus
  33. extern "C" {
  34. # endif
  35. # ifndef OPENSSL_NO_DEPRECATED_3_0
  36. typedef struct SRP_gN_cache_st {
  37. char *b64_bn;
  38. BIGNUM *bn;
  39. } SRP_gN_cache;
  40. {-
  41. generate_stack_macros("SRP_gN_cache");
  42. -}
  43. typedef struct SRP_user_pwd_st {
  44. /* Owned by us. */
  45. char *id;
  46. BIGNUM *s;
  47. BIGNUM *v;
  48. /* Not owned by us. */
  49. const BIGNUM *g;
  50. const BIGNUM *N;
  51. /* Owned by us. */
  52. char *info;
  53. } SRP_user_pwd;
  54. {-
  55. generate_stack_macros("SRP_user_pwd");
  56. -}
  57. OSSL_DEPRECATEDIN_3_0
  58. SRP_user_pwd *SRP_user_pwd_new(void);
  59. OSSL_DEPRECATEDIN_3_0
  60. void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
  61. OSSL_DEPRECATEDIN_3_0
  62. void SRP_user_pwd_set_gN(SRP_user_pwd *user_pwd, const BIGNUM *g,
  63. const BIGNUM *N);
  64. OSSL_DEPRECATEDIN_3_0
  65. int SRP_user_pwd_set1_ids(SRP_user_pwd *user_pwd, const char *id,
  66. const char *info);
  67. OSSL_DEPRECATEDIN_3_0
  68. int SRP_user_pwd_set0_sv(SRP_user_pwd *user_pwd, BIGNUM *s, BIGNUM *v);
  69. typedef struct SRP_VBASE_st {
  70. STACK_OF(SRP_user_pwd) *users_pwd;
  71. STACK_OF(SRP_gN_cache) *gN_cache;
  72. /* to simulate a user */
  73. char *seed_key;
  74. const BIGNUM *default_g;
  75. const BIGNUM *default_N;
  76. } SRP_VBASE;
  77. /*
  78. * Internal structure storing N and g pair
  79. */
  80. typedef struct SRP_gN_st {
  81. char *id;
  82. const BIGNUM *g;
  83. const BIGNUM *N;
  84. } SRP_gN;
  85. {-
  86. generate_stack_macros("SRP_gN");
  87. -}
  88. OSSL_DEPRECATEDIN_3_0
  89. SRP_VBASE *SRP_VBASE_new(char *seed_key);
  90. OSSL_DEPRECATEDIN_3_0
  91. void SRP_VBASE_free(SRP_VBASE *vb);
  92. OSSL_DEPRECATEDIN_3_0
  93. int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file);
  94. OSSL_DEPRECATEDIN_3_0
  95. int SRP_VBASE_add0_user(SRP_VBASE *vb, SRP_user_pwd *user_pwd);
  96. /* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/
  97. OSSL_DEPRECATEDIN_3_0
  98. SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);
  99. OSSL_DEPRECATEDIN_3_0
  100. char *SRP_create_verifier_ex(const char *user, const char *pass, char **salt,
  101. char **verifier, const char *N, const char *g,
  102. OSSL_LIB_CTX *libctx, const char *propq);
  103. OSSL_DEPRECATEDIN_3_0
  104. char *SRP_create_verifier(const char *user, const char *pass, char **salt,
  105. char **verifier, const char *N, const char *g);
  106. OSSL_DEPRECATEDIN_3_0
  107. int SRP_create_verifier_BN_ex(const char *user, const char *pass, BIGNUM **salt,
  108. BIGNUM **verifier, const BIGNUM *N,
  109. const BIGNUM *g, OSSL_LIB_CTX *libctx,
  110. const char *propq);
  111. OSSL_DEPRECATEDIN_3_0
  112. int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
  113. BIGNUM **verifier, const BIGNUM *N,
  114. const BIGNUM *g);
  115. # define SRP_NO_ERROR 0
  116. # define SRP_ERR_VBASE_INCOMPLETE_FILE 1
  117. # define SRP_ERR_VBASE_BN_LIB 2
  118. # define SRP_ERR_OPEN_FILE 3
  119. # define SRP_ERR_MEMORY 4
  120. # define DB_srptype 0
  121. # define DB_srpverifier 1
  122. # define DB_srpsalt 2
  123. # define DB_srpid 3
  124. # define DB_srpgN 4
  125. # define DB_srpinfo 5
  126. # undef DB_NUMBER
  127. # define DB_NUMBER 6
  128. # define DB_SRP_INDEX 'I'
  129. # define DB_SRP_VALID 'V'
  130. # define DB_SRP_REVOKED 'R'
  131. # define DB_SRP_MODIF 'v'
  132. /* see srp.c */
  133. OSSL_DEPRECATEDIN_3_0
  134. char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N);
  135. OSSL_DEPRECATEDIN_3_0
  136. SRP_gN *SRP_get_default_gN(const char *id);
  137. /* server side .... */
  138. OSSL_DEPRECATEDIN_3_0
  139. BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
  140. const BIGNUM *b, const BIGNUM *N);
  141. OSSL_DEPRECATEDIN_3_0
  142. BIGNUM *SRP_Calc_B_ex(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
  143. const BIGNUM *v, OSSL_LIB_CTX *libctx, const char *propq);
  144. OSSL_DEPRECATEDIN_3_0
  145. BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
  146. const BIGNUM *v);
  147. OSSL_DEPRECATEDIN_3_0
  148. int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N);
  149. OSSL_DEPRECATEDIN_3_0
  150. BIGNUM *SRP_Calc_u_ex(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N,
  151. OSSL_LIB_CTX *libctx, const char *propq);
  152. OSSL_DEPRECATEDIN_3_0
  153. BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N);
  154. /* client side .... */
  155. OSSL_DEPRECATEDIN_3_0
  156. BIGNUM *SRP_Calc_x_ex(const BIGNUM *s, const char *user, const char *pass,
  157. OSSL_LIB_CTX *libctx, const char *propq);
  158. OSSL_DEPRECATEDIN_3_0
  159. BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass);
  160. OSSL_DEPRECATEDIN_3_0
  161. BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g);
  162. OSSL_DEPRECATEDIN_3_0
  163. BIGNUM *SRP_Calc_client_key_ex(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
  164. const BIGNUM *x, const BIGNUM *a, const BIGNUM *u,
  165. OSSL_LIB_CTX *libctx, const char *propq);
  166. OSSL_DEPRECATEDIN_3_0
  167. BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
  168. const BIGNUM *x, const BIGNUM *a, const BIGNUM *u);
  169. OSSL_DEPRECATEDIN_3_0
  170. int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N);
  171. # define SRP_MINIMAL_N 1024
  172. # endif /* OPENSSL_NO_DEPRECATED_3_0 */
  173. /* This method ignores the configured seed and fails for an unknown user. */
  174. # ifndef OPENSSL_NO_DEPRECATED_1_1_0
  175. OSSL_DEPRECATEDIN_1_1_0
  176. SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username);
  177. # endif
  178. # ifdef __cplusplus
  179. }
  180. # endif
  181. # endif
  182. #endif