2 * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2004, EdelKey Project. All Rights Reserved.
5 * Licensed under the Apache License 2.0 (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.
15 # define OPENSSL_SRP_H
18 # include <openssl/macros.h>
19 # ifndef OPENSSL_NO_DEPRECATED_3_0
23 #include <openssl/opensslconf.h>
25 #ifndef OPENSSL_NO_SRP
28 # include <openssl/safestack.h>
29 # include <openssl/bn.h>
30 # include <openssl/crypto.h>
36 typedef struct SRP_gN_cache_st {
42 DEFINE_STACK_OF(SRP_gN_cache)
44 typedef struct SRP_user_pwd_st {
49 /* Not owned by us. */
56 SRP_user_pwd *SRP_user_pwd_new(void);
57 void SRP_user_pwd_free(SRP_user_pwd *user_pwd);
59 void SRP_user_pwd_set_gN(SRP_user_pwd *user_pwd, const BIGNUM *g, const BIGNUM *N);
60 int SRP_user_pwd_set1_ids(SRP_user_pwd *user_pwd, const char *id, const char *info);
61 int SRP_user_pwd_set0_sv(SRP_user_pwd *user_pwd, BIGNUM *s, BIGNUM *v);
63 DEFINE_STACK_OF(SRP_user_pwd)
65 typedef struct SRP_VBASE_st {
66 STACK_OF(SRP_user_pwd) *users_pwd;
67 STACK_OF(SRP_gN_cache) *gN_cache;
68 /* to simulate a user */
70 const BIGNUM *default_g;
71 const BIGNUM *default_N;
75 * Internal structure storing N and g pair
77 typedef struct SRP_gN_st {
83 DEFINE_STACK_OF(SRP_gN)
85 SRP_VBASE *SRP_VBASE_new(char *seed_key);
86 void SRP_VBASE_free(SRP_VBASE *vb);
87 int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file);
89 int SRP_VBASE_add0_user(SRP_VBASE *vb, SRP_user_pwd *user_pwd);
90 /* This method ignores the configured seed and fails for an unknown user. */
91 DEPRECATEDIN_1_1_0(SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username))
92 /* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/
93 SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username);
95 char *SRP_create_verifier_ex(const char *user, const char *pass, char **salt,
96 char **verifier, const char *N, const char *g,
97 OPENSSL_CTX *libctx, const char *propq);
98 char *SRP_create_verifier(const char *user, const char *pass, char **salt,
99 char **verifier, const char *N, const char *g);
100 int SRP_create_verifier_BN_ex(const char *user, const char *pass, BIGNUM **salt,
101 BIGNUM **verifier, const BIGNUM *N,
102 const BIGNUM *g, OPENSSL_CTX *libctx,
104 int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
105 BIGNUM **verifier, const BIGNUM *N,
108 # define SRP_NO_ERROR 0
109 # define SRP_ERR_VBASE_INCOMPLETE_FILE 1
110 # define SRP_ERR_VBASE_BN_LIB 2
111 # define SRP_ERR_OPEN_FILE 3
112 # define SRP_ERR_MEMORY 4
114 # define DB_srptype 0
115 # define DB_srpverifier 1
116 # define DB_srpsalt 2
119 # define DB_srpinfo 5
123 # define DB_SRP_INDEX 'I'
124 # define DB_SRP_VALID 'V'
125 # define DB_SRP_REVOKED 'R'
126 # define DB_SRP_MODIF 'v'
129 char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N);
130 SRP_gN *SRP_get_default_gN(const char *id);
132 /* server side .... */
133 BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u,
134 const BIGNUM *b, const BIGNUM *N);
135 BIGNUM *SRP_Calc_B_ex(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
136 const BIGNUM *v, OPENSSL_CTX *libctx, const char *propq);
137 BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g,
139 int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N);
140 BIGNUM *SRP_Calc_u_ex(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N,
141 OPENSSL_CTX *libctx, const char *propq);
142 BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N);
144 /* client side .... */
145 BIGNUM *SRP_Calc_x_ex(const BIGNUM *s, const char *user, const char *pass,
146 OPENSSL_CTX *libctx, const char *propq);
147 BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass);
148 BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g);
149 BIGNUM *SRP_Calc_client_key_ex(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
150 const BIGNUM *x, const BIGNUM *a, const BIGNUM *u,
151 OPENSSL_CTX *libctx, const char *propq);
152 BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g,
153 const BIGNUM *x, const BIGNUM *a, const BIGNUM *u);
154 int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N);
156 # define SRP_MINIMAL_N 1024