srp.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. /*
  2. * Copyright 2011-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. #ifndef HEADER_SRP_H
  10. # define HEADER_SRP_H
  11. #include <openssl/opensslconf.h>
  12. #ifndef OPENSSL_NO_SRP
  13. # include <stdio.h>
  14. # include <string.h>
  15. # include <openssl/safestack.h>
  16. # include <openssl/bn.h>
  17. # include <openssl/crypto.h>
  18. # ifdef __cplusplus
  19. extern "C" {
  20. # endif
  21. typedef struct SRP_gN_cache_st {
  22. char *b64_bn;
  23. BIGNUM *bn;
  24. } SRP_gN_cache;
  25. DEFINE_STACK_OF(SRP_gN_cache)
  26. typedef struct SRP_user_pwd_st {
  27. /* Owned by us. */
  28. char *id;
  29. BIGNUM *s;
  30. BIGNUM *v;
  31. /* Not owned by us. */
  32. const BIGNUM *g;
  33. const BIGNUM *N;
  34. /* Owned by us. */
  35. char *info;
  36. } SRP_user_pwd;
  37. void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
  38. DEFINE_STACK_OF(SRP_user_pwd)
  39. typedef struct SRP_VBASE_st {
  40. STACK_OF(SRP_user_pwd) *users_pwd;
  41. STACK_OF(SRP_gN_cache) *gN_cache;
  42. /* to simulate a user */
  43. char *seed_key;
  44. const BIGNUM *default_g;
  45. const BIGNUM *default_N;
  46. } SRP_VBASE;
  47. /*
  48. * Internal structure storing N and g pair
  49. */
  50. typedef struct SRP_gN_st {
  51. char *id;
  52. const BIGNUM *g;
  53. const BIGNUM *N;
  54. } SRP_gN;
  55. DEFINE_STACK_OF(SRP_gN)
  56. SRP_VBASE *SRP_VBASE_new(char *seed_key);
  57. void SRP_VBASE_free(SRP_VBASE *vb);
  58. int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file);
  59. /* This method ignores the configured seed and fails for an unknown user. */
  60. DEPRECATEDIN_1_1_0(SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username))
  61. /* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/
  62. SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);
  63. char *SRP_create_verifier(const char *user, const char *pass, char **salt,
  64. char **verifier, const char *N, const char *g);
  65. int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
  66. BIGNUM **verifier, const BIGNUM *N,
  67. const BIGNUM *g);
  68. # define SRP_NO_ERROR 0
  69. # define SRP_ERR_VBASE_INCOMPLETE_FILE 1
  70. # define SRP_ERR_VBASE_BN_LIB 2
  71. # define SRP_ERR_OPEN_FILE 3
  72. # define SRP_ERR_MEMORY 4
  73. # define DB_srptype 0
  74. # define DB_srpverifier 1
  75. # define DB_srpsalt 2
  76. # define DB_srpid 3
  77. # define DB_srpgN 4
  78. # define DB_srpinfo 5
  79. # undef DB_NUMBER
  80. # define DB_NUMBER 6
  81. # define DB_SRP_INDEX 'I'
  82. # define DB_SRP_VALID 'V'
  83. # define DB_SRP_REVOKED 'R'
  84. # define DB_SRP_MODIF 'v'
  85. /* see srp.c */
  86. char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N);
  87. SRP_gN *SRP_get_default_gN(const char *id);
  88. /* server side .... */
  89. BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
  90. const BIGNUM *b, const BIGNUM *N);
  91. BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
  92. const BIGNUM *v);
  93. int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N);
  94. BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N);
  95. /* client side .... */
  96. BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass);
  97. BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g);
  98. BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
  99. const BIGNUM *x, const BIGNUM *a, const BIGNUM *u);
  100. int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N);
  101. # define SRP_MINIMAL_N 1024
  102. # ifdef __cplusplus
  103. }
  104. # endif
  105. # endif
  106. #endif