LTKCPP-- LLRP Toolkit C Plus Plus Library
srp.h
00001 /* crypto/srp/srp.h */
00002 /*
00003  * Written by Christophe Renou (christophe.renou@edelweb.fr) with the
00004  * precious help of Peter Sylvester (peter.sylvester@edelweb.fr) for the
00005  * EdelKey project and contributed to the OpenSSL project 2004.
00006  */
00007 /* ====================================================================
00008  * Copyright (c) 2004 The OpenSSL Project.  All rights reserved.
00009  *
00010  * Redistribution and use in source and binary forms, with or without
00011  * modification, are permitted provided that the following conditions
00012  * are met:
00013  *
00014  * 1. Redistributions of source code must retain the above copyright
00015  *    notice, this list of conditions and the following disclaimer.
00016  *
00017  * 2. Redistributions in binary form must reproduce the above copyright
00018  *    notice, this list of conditions and the following disclaimer in
00019  *    the documentation and/or other materials provided with the
00020  *    distribution.
00021  *
00022  * 3. All advertising materials mentioning features or use of this
00023  *    software must display the following acknowledgment:
00024  *    "This product includes software developed by the OpenSSL Project
00025  *    for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
00026  *
00027  * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
00028  *    endorse or promote products derived from this software without
00029  *    prior written permission. For written permission, please contact
00030  *    licensing@OpenSSL.org.
00031  *
00032  * 5. Products derived from this software may not be called "OpenSSL"
00033  *    nor may "OpenSSL" appear in their names without prior written
00034  *    permission of the OpenSSL Project.
00035  *
00036  * 6. Redistributions of any form whatsoever must retain the following
00037  *    acknowledgment:
00038  *    "This product includes software developed by the OpenSSL Project
00039  *    for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
00040  *
00041  * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
00042  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00043  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00044  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE OpenSSL PROJECT OR
00045  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00046  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00047  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00048  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00049  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
00050  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00051  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
00052  * OF THE POSSIBILITY OF SUCH DAMAGE.
00053  * ====================================================================
00054  *
00055  * This product includes cryptographic software written by Eric Young
00056  * (eay@cryptsoft.com).  This product includes software written by Tim
00057  * Hudson (tjh@cryptsoft.com).
00058  *
00059  */
00060 #ifndef __SRP_H__
00061 # define __SRP_H__
00062 
00063 # ifndef OPENSSL_NO_SRP
00064 
00065 #  include <stdio.h>
00066 #  include <string.h>
00067 
00068 #ifdef  __cplusplus
00069 extern "C" {
00070 #endif
00071 
00072 #  include <openssl/safestack.h>
00073 #  include <openssl/bn.h>
00074 #  include <openssl/crypto.h>
00075 
00076 typedef struct SRP_gN_cache_st {
00077     char *b64_bn;
00078     BIGNUM *bn;
00079 } SRP_gN_cache;
00080 
00081 
00082 DECLARE_STACK_OF(SRP_gN_cache)
00083 
00084 typedef struct SRP_user_pwd_st {
00085     char *id;
00086     BIGNUM *s;
00087     BIGNUM *v;
00088     const BIGNUM *g;
00089     const BIGNUM *N;
00090     char *info;
00091 } SRP_user_pwd;
00092 
00093 DECLARE_STACK_OF(SRP_user_pwd)
00094 
00095 typedef struct SRP_VBASE_st {
00096     STACK_OF(SRP_user_pwd) *users_pwd;
00097     STACK_OF(SRP_gN_cache) *gN_cache;
00098 /* to simulate a user */
00099     char *seed_key;
00100     BIGNUM *default_g;
00101     BIGNUM *default_N;
00102 } SRP_VBASE;
00103 
00104 /*
00105  * Structure interne pour retenir les couples N et g
00106  */
00107 typedef struct SRP_gN_st {
00108     char *id;
00109     BIGNUM *g;
00110     BIGNUM *N;
00111 } SRP_gN;
00112 
00113 DECLARE_STACK_OF(SRP_gN)
00114 
00115 SRP_VBASE *SRP_VBASE_new(char *seed_key);
00116 int SRP_VBASE_free(SRP_VBASE *vb);
00117 int SRP_VBASE_init(SRP_VBASE *vb, char *verifier_file);
00118 SRP_user_pwd *SRP_VBASE_get_by_user(SRP_VBASE *vb, char *username);
00119 char *SRP_create_verifier(const char *user, const char *pass, char **salt,
00120                           char **verifier, const char *N, const char *g);
00121 int SRP_create_verifier_BN(const char *user, const char *pass, BIGNUM **salt,
00122                            BIGNUM **verifier, BIGNUM *N, BIGNUM *g);
00123 
00124 #  define SRP_NO_ERROR 0
00125 #  define SRP_ERR_VBASE_INCOMPLETE_FILE 1
00126 #  define SRP_ERR_VBASE_BN_LIB 2
00127 #  define SRP_ERR_OPEN_FILE 3
00128 #  define SRP_ERR_MEMORY 4
00129 
00130 #  define DB_srptype      0
00131 #  define DB_srpverifier  1
00132 #  define DB_srpsalt      2
00133 #  define DB_srpid        3
00134 #  define DB_srpgN        4
00135 #  define DB_srpinfo      5
00136 #  undef  DB_NUMBER
00137 #  define DB_NUMBER       6
00138 
00139 #  define DB_SRP_INDEX    'I'
00140 #  define DB_SRP_VALID    'V'
00141 #  define DB_SRP_REVOKED  'R'
00142 #  define DB_SRP_MODIF    'v'
00143 
00144 /* see srp.c */
00145 char *SRP_check_known_gN_param(BIGNUM *g, BIGNUM *N);
00146 SRP_gN *SRP_get_default_gN(const char *id);
00147 
00148 /* server side .... */
00149 BIGNUM *SRP_Calc_server_key(BIGNUM *A, BIGNUM *v, BIGNUM *u, BIGNUM *b,
00150                             BIGNUM *N);
00151 BIGNUM *SRP_Calc_B(BIGNUM *b, BIGNUM *N, BIGNUM *g, BIGNUM *v);
00152 int SRP_Verify_A_mod_N(BIGNUM *A, BIGNUM *N);
00153 BIGNUM *SRP_Calc_u(BIGNUM *A, BIGNUM *B, BIGNUM *N);
00154 
00155 /* client side .... */
00156 BIGNUM *SRP_Calc_x(BIGNUM *s, const char *user, const char *pass);
00157 BIGNUM *SRP_Calc_A(BIGNUM *a, BIGNUM *N, BIGNUM *g);
00158 BIGNUM *SRP_Calc_client_key(BIGNUM *N, BIGNUM *B, BIGNUM *g, BIGNUM *x,
00159                             BIGNUM *a, BIGNUM *u);
00160 int SRP_Verify_B_mod_N(BIGNUM *B, BIGNUM *N);
00161 
00162 #  define SRP_MINIMAL_N 1024
00163 
00164 #ifdef  __cplusplus
00165 }
00166 #endif
00167 
00168 # endif
00169 #endif