srp.h revision 280304
1239268Sgonzo/* crypto/srp/srp.h */ 2244469Scognet/* 3239268Sgonzo * Written by Christophe Renou (christophe.renou@edelweb.fr) with the 4239268Sgonzo * precious help of Peter Sylvester (peter.sylvester@edelweb.fr) for the 5239268Sgonzo * EdelKey project and contributed to the OpenSSL project 2004. 6239268Sgonzo */ 7239268Sgonzo/* ==================================================================== 8239268Sgonzo * Copyright (c) 2004 The OpenSSL Project. All rights reserved. 9239268Sgonzo * 10239268Sgonzo * Redistribution and use in source and binary forms, with or without 11239268Sgonzo * modification, are permitted provided that the following conditions 12239268Sgonzo * are met: 13239268Sgonzo * 14239268Sgonzo * 1. Redistributions of source code must retain the above copyright 15239268Sgonzo * notice, this list of conditions and the following disclaimer. 16239268Sgonzo * 17239268Sgonzo * 2. Redistributions in binary form must reproduce the above copyright 18239268Sgonzo * notice, this list of conditions and the following disclaimer in 19239268Sgonzo * the documentation and/or other materials provided with the 20239268Sgonzo * distribution. 21239268Sgonzo * 22239268Sgonzo * 3. All advertising materials mentioning features or use of this 23239268Sgonzo * software must display the following acknowledgment: 24239268Sgonzo * "This product includes software developed by the OpenSSL Project 25239268Sgonzo * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" 26239268Sgonzo * 27239268Sgonzo * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to 28239268Sgonzo * endorse or promote products derived from this software without 29239268Sgonzo * prior written permission. For written permission, please contact 30239268Sgonzo * licensing@OpenSSL.org. 31239268Sgonzo * 32239268Sgonzo * 5. Products derived from this software may not be called "OpenSSL" 33239268Sgonzo * nor may "OpenSSL" appear in their names without prior written 34239268Sgonzo * permission of the OpenSSL Project. 35239268Sgonzo * 36239268Sgonzo * 6. Redistributions of any form whatsoever must retain the following 37239268Sgonzo * acknowledgment: 38239268Sgonzo * "This product includes software developed by the OpenSSL Project 39239268Sgonzo * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" 40239268Sgonzo * 41239268Sgonzo * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY 42239268Sgonzo * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 43239268Sgonzo * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 44244469Scognet * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR 45239268Sgonzo * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 46239268Sgonzo * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 47239268Sgonzo * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 48239268Sgonzo * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 49246713Skib * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 50239268Sgonzo * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 51239268Sgonzo * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 52246713Skib * OF THE POSSIBILITY OF SUCH DAMAGE. 53239268Sgonzo * ==================================================================== 54239268Sgonzo * 55239268Sgonzo * This product includes cryptographic software written by Eric Young 56239268Sgonzo * (eay@cryptsoft.com). This product includes software written by Tim 57239268Sgonzo * Hudson (tjh@cryptsoft.com). 58244469Scognet * 59244469Scognet */ 60239268Sgonzo#ifndef __SRP_H__ 61239268Sgonzo# define __SRP_H__ 62239268Sgonzo 63239268Sgonzo# ifndef OPENSSL_NO_SRP 64239268Sgonzo 65239268Sgonzo# include <stdio.h> 66239268Sgonzo# include <string.h> 67239268Sgonzo 68239268Sgonzo#ifdef __cplusplus 69239268Sgonzoextern "C" { 70239268Sgonzo#endif 71239268Sgonzo 72239268Sgonzo# include <openssl/safestack.h> 73239268Sgonzo# include <openssl/bn.h> 74239268Sgonzo# include <openssl/crypto.h> 75239268Sgonzo 76239268Sgonzotypedef struct SRP_gN_cache_st { 77239268Sgonzo char *b64_bn; 78239268Sgonzo BIGNUM *bn; 79239268Sgonzo} SRP_gN_cache; 80239268Sgonzo 81239268Sgonzo 82239268SgonzoDECLARE_STACK_OF(SRP_gN_cache) 83239268Sgonzo 84239268Sgonzotypedef struct SRP_user_pwd_st { 85239268Sgonzo char *id; 86239268Sgonzo BIGNUM *s; 87239268Sgonzo BIGNUM *v; 88239268Sgonzo const BIGNUM *g; 89239268Sgonzo const BIGNUM *N; 90239268Sgonzo char *info; 91239268Sgonzo} SRP_user_pwd; 92239268Sgonzo 93239268SgonzoDECLARE_STACK_OF(SRP_user_pwd) 94239268Sgonzo 95239268Sgonzotypedef struct SRP_VBASE_st { 96239268Sgonzo STACK_OF(SRP_user_pwd) *users_pwd; 97239268Sgonzo STACK_OF(SRP_gN_cache) *gN_cache; 98239268Sgonzo/* to simulate a user */ 99244469Scognet char *seed_key; 100244469Scognet BIGNUM *default_g; 101244469Scognet BIGNUM *default_N; 102244469Scognet} SRP_VBASE; 103244469Scognet 104244469Scognet/* 105244469Scognet * Structure interne pour retenir les couples N et g 106239268Sgonzo */ 107244469Scognettypedef struct SRP_gN_st { 108239268Sgonzo char *id; 109239268Sgonzo BIGNUM *g; 110239268Sgonzo BIGNUM *N; 111239268Sgonzo} SRP_gN; 112239268Sgonzo 113239268SgonzoDECLARE_STACK_OF(SRP_gN) 114246713Skib 115239268SgonzoSRP_VBASE *SRP_VBASE_new(char *seed_key); 116239268Sgonzoint SRP_VBASE_free(SRP_VBASE *vb); 117239268Sgonzoint SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file); 118239268SgonzoSRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username); 119239268Sgonzochar *SRP_create_verifier(const char *user, const char *pass, char **salt, 120239268Sgonzo char **verifier, const char *N, const char *g); 121239268Sgonzoint SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt, 122239268Sgonzo BIGNUM **verifier, BIGNUM *N, BIGNUM *g); 123239268Sgonzo 124239268Sgonzo# define SRP_NO_ERROR 0 125239268Sgonzo# define SRP_ERR_VBASE_INCOMPLETE_FILE 1 126239268Sgonzo# define SRP_ERR_VBASE_BN_LIB 2 127239268Sgonzo# define SRP_ERR_OPEN_FILE 3 128239268Sgonzo# define SRP_ERR_MEMORY 4 129239268Sgonzo 130239268Sgonzo# define DB_srptype 0 131239268Sgonzo# define DB_srpverifier 1 132239268Sgonzo# define DB_srpsalt 2 133239268Sgonzo# define DB_srpid 3 134239268Sgonzo# define DB_srpgN 4 135239268Sgonzo# define DB_srpinfo 5 136239268Sgonzo# undef DB_NUMBER 137239268Sgonzo# define DB_NUMBER 6 138239268Sgonzo 139239268Sgonzo# define DB_SRP_INDEX 'I' 140239268Sgonzo# define DB_SRP_VALID 'V' 141239268Sgonzo# define DB_SRP_REVOKED 'R' 142239268Sgonzo# define DB_SRP_MODIF 'v' 143239268Sgonzo 144239268Sgonzo/* see srp.c */ 145239268Sgonzochar *SRP_check_known_gN_param(BIGNUM *g, BIGNUM *N); 146239268SgonzoSRP_gN *SRP_get_default_gN(const char *id); 147239268Sgonzo 148239268Sgonzo/* server side .... */ 149239268SgonzoBIGNUM *SRP_Calc_server_key(BIGNUM *A, BIGNUM *v, BIGNUM *u, BIGNUM *b, 150239268Sgonzo BIGNUM *N); 151239268SgonzoBIGNUM *SRP_Calc_B(BIGNUM *b, BIGNUM *N, BIGNUM *g, BIGNUM *v); 152239268Sgonzoint SRP_Verify_A_mod_N(BIGNUM *A, BIGNUM *N); 153239268SgonzoBIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N); 154239268Sgonzo 155239268Sgonzo/* client side .... */ 156239268SgonzoBIGNUM *SRP_Calc_x(BIGNUM *s, const char *user, const char *pass); 157239268SgonzoBIGNUM *SRP_Calc_A(BIGNUM *a, BIGNUM *N, BIGNUM *g); 158239268SgonzoBIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x, 159246713Skib BIGNUM *a, BIGNUM *u); 160239268Sgonzoint SRP_Verify_B_mod_N(BIGNUM *B, BIGNUM *N); 161239268Sgonzo 162239268Sgonzo# define SRP_MINIMAL_N 1024 163244469Scognet 164244469Scognet#ifdef __cplusplus 165239268Sgonzo} 166246713Skib#endif 167246713Skib 168239268Sgonzo# endif 169239268Sgonzo#endif 170239268Sgonzo