From c3266dc0d85ed519ff40d1738aadf7b1280af3ba Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Wed, 19 Sep 2007 20:37:48 +0000 Subject: * crypt/Makefile (libcrypt-routines): Add sha256-crypt, sha256, sha512-crypt, and sha512. (tests): Add sha256test, sha256c-test, sha512test, and sha512c-test. (distribute): Add sha256.h and sha512.h. * crypt/crypt-entry.c (crypt): Recognize the new $5$ and $6$ prefixes and call the appropriate code. * crypt/sha256-crypt.c: New file. * crypt/sha256.c: New file. * crypt/sha256.h: New file. * crypt/sha256c-test.c: New file. * crypt/sha256test.c: New file. * crypt/sha512-crypt.c: New file. * crypt/sha512.c: New file. * crypt/sha512.h: New file. * crypt/sha512c-test.c: New file. * crypt/sha512test.c: New file. * sysdeps/unix/sysv/linux/sparc/sparc32/clone.S (__thread_start): Likewise. * sysdeps/unix/sysv/linux/sparc/sparc64/clone.S (__thread_start): Likewise. --- crypt/crypt-entry.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'crypt/crypt-entry.c') diff --git a/crypt/crypt-entry.c b/crypt/crypt-entry.c index ca219bb..fdddad2 100644 --- a/crypt/crypt-entry.c +++ b/crypt/crypt-entry.c @@ -1,7 +1,7 @@ /* * UFC-crypt: ultra fast crypt(3) implementation * - * Copyright (C) 1991, 1992, 1993, 1996, 1997 Free Software Foundation, Inc. + * Copyright (C) 1991,1992,1993,1996,1997,2007 Free Software Foundation, Inc. * * The GNU C Library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public @@ -55,6 +55,12 @@ void _ufc_clearmem (char *start, int cnt); extern char *__md5_crypt_r (const char *key, const char *salt, char *buffer, int buflen); extern char *__md5_crypt (const char *key, const char *salt); +extern char *__sha256_crypt_r (const char *key, const char *salt, + char *buffer, int buflen); +extern char *__sha256_crypt (const char *key, const char *salt); +extern char *__sha512_crypt_r (const char *key, const char *salt, + char *buffer, int buflen); +extern char *__sha512_crypt (const char *key, const char *salt); #endif /* Define our magic string to mark salt for MD5 encryption @@ -62,6 +68,12 @@ extern char *__md5_crypt (const char *key, const char *salt); encryption implementations. */ static const char md5_salt_prefix[] = "$1$"; +/* Magic string for SHA256 encryption. */ +static const char sha256_salt_prefix[] = "$5$"; + +/* Magic string for SHA512 encryption. */ +static const char sha512_salt_prefix[] = "$6$"; + /* For use by the old, non-reentrant routines (crypt/encrypt/setkey) */ extern struct crypt_data _ufc_foobar; @@ -84,6 +96,16 @@ __crypt_r (key, salt, data) if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0) return __md5_crypt_r (key, salt, (char *) data, sizeof (struct crypt_data)); + + /* Try to find out whether we have to use SHA256 encryption replacement. */ + if (strncmp (sha256_salt_prefix, salt, sizeof (sha256_salt_prefix) - 1) == 0) + return __sha256_crypt_r (key, salt, (char *) data, + sizeof (struct crypt_data)); + + /* Try to find out whether we have to use SHA512 encryption replacement. */ + if (strncmp (sha512_salt_prefix, salt, sizeof (sha512_salt_prefix) - 1) == 0) + return __sha512_crypt_r (key, salt, (char *) data, + sizeof (struct crypt_data)); #endif /* @@ -126,6 +148,14 @@ crypt (key, salt) /* Try to find out whether we have to use MD5 encryption replacement. */ if (strncmp (md5_salt_prefix, salt, sizeof (md5_salt_prefix) - 1) == 0) return __md5_crypt (key, salt); + + /* Try to find out whether we have to use SHA256 encryption replacement. */ + if (strncmp (sha256_salt_prefix, salt, sizeof (sha256_salt_prefix) - 1) == 0) + return __sha256_crypt (key, salt); + + /* Try to find out whether we have to use SHA512 encryption replacement. */ + if (strncmp (sha512_salt_prefix, salt, sizeof (sha512_salt_prefix) - 1) == 0) + return __sha512_crypt (key, salt); #endif return __crypt_r (key, salt, &_ufc_foobar); -- cgit v1.1