jpayne@69: /* jpayne@69: * Copyright 2004-2018 The OpenSSL Project Authors. All Rights Reserved. jpayne@69: * Copyright (c) 2004, EdelKey Project. All Rights Reserved. jpayne@69: * jpayne@69: * Licensed under the OpenSSL license (the "License"). You may not use jpayne@69: * this file except in compliance with the License. You can obtain a copy jpayne@69: * in the file LICENSE in the source distribution or at jpayne@69: * https://www.openssl.org/source/license.html jpayne@69: * jpayne@69: * Originally written by Christophe Renou and Peter Sylvester, jpayne@69: * for the EdelKey project. jpayne@69: */ jpayne@69: jpayne@69: #ifndef HEADER_SRP_H jpayne@69: # define HEADER_SRP_H jpayne@69: jpayne@69: #include jpayne@69: jpayne@69: #ifndef OPENSSL_NO_SRP jpayne@69: # include jpayne@69: # include jpayne@69: # include jpayne@69: # include jpayne@69: # include jpayne@69: jpayne@69: # ifdef __cplusplus jpayne@69: extern "C" { jpayne@69: # endif jpayne@69: jpayne@69: typedef struct SRP_gN_cache_st { jpayne@69: char *b64_bn; jpayne@69: BIGNUM *bn; jpayne@69: } SRP_gN_cache; jpayne@69: jpayne@69: jpayne@69: DEFINE_STACK_OF(SRP_gN_cache) jpayne@69: jpayne@69: typedef struct SRP_user_pwd_st { jpayne@69: /* Owned by us. */ jpayne@69: char *id; jpayne@69: BIGNUM *s; jpayne@69: BIGNUM *v; jpayne@69: /* Not owned by us. */ jpayne@69: const BIGNUM *g; jpayne@69: const BIGNUM *N; jpayne@69: /* Owned by us. */ jpayne@69: char *info; jpayne@69: } SRP_user_pwd; jpayne@69: jpayne@69: void SRP_user_pwd_free(SRP_user_pwd *user_pwd); jpayne@69: jpayne@69: DEFINE_STACK_OF(SRP_user_pwd) jpayne@69: jpayne@69: typedef struct SRP_VBASE_st { jpayne@69: STACK_OF(SRP_user_pwd) *users_pwd; jpayne@69: STACK_OF(SRP_gN_cache) *gN_cache; jpayne@69: /* to simulate a user */ jpayne@69: char *seed_key; jpayne@69: const BIGNUM *default_g; jpayne@69: const BIGNUM *default_N; jpayne@69: } SRP_VBASE; jpayne@69: jpayne@69: /* jpayne@69: * Internal structure storing N and g pair jpayne@69: */ jpayne@69: typedef struct SRP_gN_st { jpayne@69: char *id; jpayne@69: const BIGNUM *g; jpayne@69: const BIGNUM *N; jpayne@69: } SRP_gN; jpayne@69: jpayne@69: DEFINE_STACK_OF(SRP_gN) jpayne@69: jpayne@69: SRP_VBASE *SRP_VBASE_new(char *seed_key); jpayne@69: void SRP_VBASE_free(SRP_VBASE *vb); jpayne@69: int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file); jpayne@69: jpayne@69: /* This method ignores the configured seed and fails for an unknown user. */ jpayne@69: DEPRECATEDIN_1_1_0(SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username)) jpayne@69: /* NOTE: unlike in SRP_VBASE_get_by_user, caller owns the returned pointer.*/ jpayne@69: SRP_user_pwd *SRP_VBASE_get1_by_user(SRP_VBASE *vb, char *username); jpayne@69: jpayne@69: char *SRP_create_verifier(const char *user, const char *pass, char **salt, jpayne@69: char **verifier, const char *N, const char *g); jpayne@69: int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, jpayne@69: BIGNUM **verifier, const BIGNUM *N, jpayne@69: const BIGNUM *g); jpayne@69: jpayne@69: # define SRP_NO_ERROR 0 jpayne@69: # define SRP_ERR_VBASE_INCOMPLETE_FILE 1 jpayne@69: # define SRP_ERR_VBASE_BN_LIB 2 jpayne@69: # define SRP_ERR_OPEN_FILE 3 jpayne@69: # define SRP_ERR_MEMORY 4 jpayne@69: jpayne@69: # define DB_srptype 0 jpayne@69: # define DB_srpverifier 1 jpayne@69: # define DB_srpsalt 2 jpayne@69: # define DB_srpid 3 jpayne@69: # define DB_srpgN 4 jpayne@69: # define DB_srpinfo 5 jpayne@69: # undef DB_NUMBER jpayne@69: # define DB_NUMBER 6 jpayne@69: jpayne@69: # define DB_SRP_INDEX 'I' jpayne@69: # define DB_SRP_VALID 'V' jpayne@69: # define DB_SRP_REVOKED 'R' jpayne@69: # define DB_SRP_MODIF 'v' jpayne@69: jpayne@69: /* see srp.c */ jpayne@69: char *SRP_check_known_gN_param(const BIGNUM *g, const BIGNUM *N); jpayne@69: SRP_gN *SRP_get_default_gN(const char *id); jpayne@69: jpayne@69: /* server side .... */ jpayne@69: BIGNUM *SRP_Calc_server_key(const BIGNUM *A, const BIGNUM *v, const BIGNUM *u, jpayne@69: const BIGNUM *b, const BIGNUM *N); jpayne@69: BIGNUM *SRP_Calc_B(const BIGNUM *b, const BIGNUM *N, const BIGNUM *g, jpayne@69: const BIGNUM *v); jpayne@69: int SRP_Verify_A_mod_N(const BIGNUM *A, const BIGNUM *N); jpayne@69: BIGNUM *SRP_Calc_u(const BIGNUM *A, const BIGNUM *B, const BIGNUM *N); jpayne@69: jpayne@69: /* client side .... */ jpayne@69: BIGNUM *SRP_Calc_x(const BIGNUM *s, const char *user, const char *pass); jpayne@69: BIGNUM *SRP_Calc_A(const BIGNUM *a, const BIGNUM *N, const BIGNUM *g); jpayne@69: BIGNUM *SRP_Calc_client_key(const BIGNUM *N, const BIGNUM *B, const BIGNUM *g, jpayne@69: const BIGNUM *x, const BIGNUM *a, const BIGNUM *u); jpayne@69: int SRP_Verify_B_mod_N(const BIGNUM *B, const BIGNUM *N); jpayne@69: jpayne@69: # define SRP_MINIMAL_N 1024 jpayne@69: jpayne@69: # ifdef __cplusplus jpayne@69: } jpayne@69: # endif jpayne@69: # endif jpayne@69: jpayne@69: #endif