about summary refs log tree commit diff
path: root/crypt/crypt-entry.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2007-09-19 20:37:48 +0000
committerUlrich Drepper <drepper@redhat.com>2007-09-19 20:37:48 +0000
commitc3266dc0d85ed519ff40d1738aadf7b1280af3ba (patch)
tree8ce7e3317452a3e606529b18fd83674dc30af6b1 /crypt/crypt-entry.c
parent9425cb9eea6a62fc21d99aafe8a60f752b934b05 (diff)
downloadglibc-c3266dc0d85ed519ff40d1738aadf7b1280af3ba.tar.gz
glibc-c3266dc0d85ed519ff40d1738aadf7b1280af3ba.tar.xz
glibc-c3266dc0d85ed519ff40d1738aadf7b1280af3ba.zip
* 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.
Diffstat (limited to 'crypt/crypt-entry.c')
-rw-r--r--crypt/crypt-entry.c32
1 files changed, 31 insertions, 1 deletions
diff --git a/crypt/crypt-entry.c b/crypt/crypt-entry.c
index ca219bb69c..fdddad2c55 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);