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