*** empty log message ***
[gnutls.git] / libextra / crypt.c
blobd4f9a21719e637e705f9ed6f50d814f7e9b9cf05
1 /*
2 * Copyright (C) 2000,2001 Nikos Mavroyanopoulos
4 * This file is part of GNUTLS.
6 * GNUTLS-EXTRA is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GNUTLS-EXTRA is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #include "gnutls_int.h"
23 #ifdef ENABLE_SRP
25 #include "crypt_bcrypt.h"
26 #include "crypt_srpsha1.h"
27 #include "gnutls_random.h"
29 char * gnutls_crypt(const char* username, const char *passwd, crypt_algo algo, int salt, GNUTLS_MPI g, GNUTLS_MPI n) {
31 switch(algo) {
32 case BLOWFISH_CRYPT: /* bcrypt */
33 /* salt in bcrypt is actually the cost */
34 return crypt_bcrypt_wrapper(username, passwd, salt, g, n);
35 case SRPSHA1_CRYPT: /* bcrypt */
36 /* salt in bcrypt is the salt size */
37 return crypt_srpsha1_wrapper(username, passwd, salt, g, n);
39 return NULL;
42 int gnutls_crypt_vrfy(const char* username, const char *passwd, char* salt, GNUTLS_MPI g, GNUTLS_MPI n) {
43 char* cr;
45 switch(salt[0]) {
46 case '$':
47 switch(salt[1]) {
48 case '2':
49 cr = crypt_bcrypt(username, passwd, salt, g, n);
50 if (cr==NULL) return 1;
51 if (strncmp(cr, salt, strlen(cr))==0) return 0;
52 break;
54 default:
55 cr = crypt_srpsha1(username, passwd, salt, g, n);
56 if (cr==NULL) return 1;
57 if (strncmp(cr, salt, strlen(cr))==0) return 0;
58 break;
60 return 1;
63 #endif