srp.h 3.7 KB

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