2 * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2004, EdelKey Project. All Rights Reserved.
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
10 * Originally written by Christophe Renou and Peter Sylvester,
11 * for the EdelKey project.
17 #include <openssl/opensslconf.h>
19 #ifndef OPENSSL_NO_SRP
22 # include <openssl/safestack.h>
23 # include <openssl/bn.h>
24 # include <openssl/crypto.h>
30 typedef struct SRP_gN_cache_st {
36 DEFINE_STACK_OF(SRP_gN_cache)
38 typedef struct SRP_user_pwd_st {
43 /* Not owned by us. */
50 void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
52 DEFINE_STACK_OF(SRP_user_pwd)
54 typedef struct SRP_VBASE_st {
55 STACK_OF(SRP_user_pwd) *users_pwd;
56 STACK_OF(SRP_gN_cache) *gN_cache;
57 /* to simulate a user */
59 const BIGNUM *default_g;
60 const BIGNUM *default_N;
64 * Internal structure storing N and g pair
66 typedef struct SRP_gN_st {
72 DEFINE_STACK_OF(SRP_gN)
74 SRP_VBASE *SRP_VBASE_new(char *seed_key);
75 void SRP_VBASE_free(SRP_VBASE *vb);
76 int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file);
78 int SRP_VBASE_add0_user(SRP_VBASE *vb, SRP_user_pwd *user_pwd);
79 /* This method ignores the configured seed and fails for an unknown user. */
80 DEPRECATEDIN_1_1_0(SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username))
81 /* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/
82 SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);
84 char *SRP_create_verifier(const char *user, const char *pass, char **salt,
85 char **verifier, const char *N, const char *g);
86 int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
87 BIGNUM **verifier, const BIGNUM *N,
90 # define SRP_NO_ERROR 0
91 # define SRP_ERR_VBASE_INCOMPLETE_FILE 1
92 # define SRP_ERR_VBASE_BN_LIB 2
93 # define SRP_ERR_OPEN_FILE 3
94 # define SRP_ERR_MEMORY 4
97 # define DB_srpverifier 1
101 # define DB_srpinfo 5
105 # define DB_SRP_INDEX 'I'
106 # define DB_SRP_VALID 'V'
107 # define DB_SRP_REVOKED 'R'
108 # define DB_SRP_MODIF 'v'
111 char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N);
112 SRP_gN *SRP_get_default_gN(const char *id);
114 /* server side .... */
115 BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
116 const BIGNUM *b, const BIGNUM *N);
117 BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
119 int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N);
120 BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N);
122 /* client side .... */
123 BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass);
124 BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g);
125 BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
126 const BIGNUM *x, const BIGNUM *a, const BIGNUM *u);
127 int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N);
129 # define SRP_MINIMAL_N 1024