diff options
author | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-05-03 09:44:17 +0000 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2001-05-03 09:44:17 +0000 |
commit | 936728c607c1ad0c2b13f733417264104a98bdd5 (patch) | |
tree | 09126d19f9d225b45659f34ad02d1f2400c7e09c /src/crypt.c | |
parent | c8af7ee9674d5c8f91c63bab4653f7d8de3727f6 (diff) | |
download | gnutls-936728c607c1ad0c2b13f733417264104a98bdd5.tar.gz |
Changes in random number handling. Added bcrypt (for use with SRP).
Added test program crypt for creating bcrypt passwd files.
Diffstat (limited to 'src/crypt.c')
-rw-r--r-- | src/crypt.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/src/crypt.c b/src/crypt.c new file mode 100644 index 0000000000..d86752a8d3 --- /dev/null +++ b/src/crypt.c @@ -0,0 +1,84 @@ +/* + * Copyright (C) 2001 Nikos Mavroyanopoulos + * + * This file is part of GNUTLS. + * + * GNUTLS is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * GNUTLS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> +#include "../lib/gnutls.h" +#include "gaa.h" + +int verify_passwd(char *file, char* username, char* passwd) { + FILE* fd; + char line[513]; + int i; + + fd = fopen( file, "r"); + if (fd==NULL) { + fprintf(stderr, "Cannot open file '%s'\n", file); + return -1; + } + + while( fgets( line, sizeof(line), fd) != NULL) { + /* move to first ':' */ + i=0; + while( (line[i]!=':') && (line[i]!='\0') && (i < sizeof(line)) ) { + i++; + } + if (strncmp( username, line, i) == 0) { + if (gnutls_crypt_vrfy( username, passwd, &line[++i]) == 0) { + fprintf(stderr, "Password verified\n"); + } else { + fprintf(stderr, "Password does NOT match\n"); + } + return 0; + } + } + + fclose(fd); + return -1; + +} + +int main(int argc, char** argv) { +gaainfo info; +char* passwd; +char* cr=NULL; + + if ( gaa(argc, argv, &info) != -1) { + fprintf(stderr, "Error in the arguments.\n"); + return -1; + } + + passwd = getpass("Enter password: "); + + if (info.passwd != NULL) { + verify_passwd( info.passwd, info.username, passwd); + free(cr); + return 0; + } + + cr = gnutls_crypt( info.username, passwd, BLOWFISH_CRYPT); + printf("%s:%s\n", info.username, cr); + free(cr); + return 0; + + +}
\ No newline at end of file |