]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Namespace-protect SHA-256 symbols. Build SHA-256 code independently of
authorGreg Hudson <ghudson@mit.edu>
Fri, 25 Feb 2011 19:53:04 +0000 (19:53 +0000)
committerGreg Hudson <ghudson@mit.edu>
Fri, 25 Feb 2011 19:53:04 +0000 (19:53 +0000)
whether Fortuna was selected.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24666 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/crypto/builtin/sha2/sha2.h
src/lib/crypto/builtin/sha2/sha256.c
src/lib/crypto/builtin/sha2/t_sha256.c
src/lib/crypto/krb/prng_fortuna.c
src/lib/crypto/libk5crypto.exports
src/lib/crypto/nss/stubs.c
src/lib/crypto/openssl/sha2/sha2.h
src/lib/crypto/openssl/stubs.c

index 0cff88f4a9b43bb88d8b522104ed644a3b8c239b..6c743e1226301182d8a35cf89f64d18f367f9e91 100644 (file)
@@ -1,4 +1,5 @@
 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
+/* lib/crypto/builtin/sha2/sha2.h - SHA-256 declarations */
 /*
  * Copyright (c) 1995 - 2001 Kungliga Tekniska Högskolan
  * (Royal Institute of Technology, Stockholm, Sweden).
  * SUCH DAMAGE.
  */
 
-/* $Id$ */
-
-#ifndef HEIM_SHA_H
-#define HEIM_SHA_H 1
+#ifndef SHA2_H
+#define SHA2_H 1
 
 #include <k5-int.h>
-/*
-#include <stdlib.h>
-#include <string.h>
-#include <stddef.h>
-#ifdef KRB5
-#include <krb5-types.h>
-#endif
-*/
-#ifndef min
-#define min(a,b) (((a)>(b))?(b):(a))
-#endif
-
-/* Vector Crays doesn't have a good 32-bit type, or more precisely,
- * int32_t as defined by <bind/bitypes.h> isn't 32 bits, and we don't
- * want to depend in being able to redefine this type.  To cope with
- * this we have to clamp the result in some places to [0,2^32); no
- * need to do this on other machines.  Did I say this was a mess?
- */
-
-#ifdef _CRAY
-#define CRAYFIX(X) ((X) & 0xffffffff)
-#else
-#define CRAYFIX(X) (X)
-#endif
-
-static inline uint32_t
-cshift (uint32_t x, unsigned int n)
-{
-    x = CRAYFIX(x);
-    return CRAYFIX((x << n) | (x >> (32 - n)));
-}
-
-/*
- * SHA-2 256
- */
 
 #define SHA256_DIGEST_LENGTH 32
 
@@ -84,8 +48,8 @@ struct sha256state {
 
 typedef struct sha256state SHA256_CTX;
 
-void sha2Init (SHA256_CTX *);
-void sha2Update (SHA256_CTX *, const void *, size_t);
-void sha2Final (void *, SHA256_CTX *);
+void k5_sha256_init(SHA256_CTX *);
+void k5_sha256_update(SHA256_CTX *, const void *, size_t);
+void k5_sha256_final(void *, SHA256_CTX *);
 
-#endif /* HEIM_SHA_H */
+#endif /* SHA2_H */
index fb66bff706175e9f255917d7b6cb3f1b69bb9dd6..23b1a26c05857e58584791b0132b3db39887199a 100644 (file)
@@ -1,5 +1,5 @@
 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
-/* lib/crypto/builtin/sha256.c */
+/* lib/crypto/builtin/sha2/sha256.c - SHA-256 implementation */
 /*
  * Copyright (c) 2006 Kungliga Tekniska Högskolan
  * (Royal Institute of Technology, Stockholm, Sweden).
 #include <k5-int.h>
 #include "sha2.h"
 
-#ifdef FORTUNA
+#ifndef min
+#define min(a,b) (((a)>(b))?(b):(a))
+#endif
+
+/* Vector Crays doesn't have a good 32-bit type, or more precisely,
+ * int32_t as defined by <bind/bitypes.h> isn't 32 bits, and we don't
+ * want to depend in being able to redefine this type.  To cope with
+ * this we have to clamp the result in some places to [0,2^32); no
+ * need to do this on other machines.  Did I say this was a mess?
+ */
+
+#ifdef _CRAY
+#define CRAYFIX(X) ((X) & 0xffffffff)
+#else
+#define CRAYFIX(X) (X)
+#endif
+
+static inline uint32_t
+cshift (uint32_t x, unsigned int n)
+{
+    x = CRAYFIX(x);
+    return CRAYFIX((x << n) | (x >> (32 - n)));
+}
 
 #define Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z)))
 #define Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z)))
@@ -77,7 +99,7 @@ static const uint32_t constant_256[64] = {
 };
 
 void
-sha2Init (SHA256_CTX *m)
+k5_sha256_init(SHA256_CTX *m)
 {
     m->sz[0] = 0;
     m->sz[1] = 0;
@@ -92,7 +114,7 @@ sha2Init (SHA256_CTX *m)
 }
 
 static void
-calc (SHA256_CTX *m, uint32_t *in)
+calc(SHA256_CTX *m, uint32_t *in)
 {
     uint32_t AA, BB, CC, DD, EE, FF, GG, HH;
     uint32_t data[64];
@@ -145,7 +167,7 @@ calc (SHA256_CTX *m, uint32_t *in)
 
 #if !defined(WORDS_BIGENDIAN) || defined(_CRAY)
 static inline uint32_t
-swap_uint32_t (uint32_t t)
+swap_uint32_t(uint32_t t)
 {
 #define ROL(x,n) ((x)<<(n))|((x)>>(32-(n)))
     uint32_t temp1, temp2;
@@ -159,13 +181,13 @@ swap_uint32_t (uint32_t t)
 }
 #endif
 
-struct x32{
+struct x32 {
     unsigned int a:32;
     unsigned int b:32;
 };
 
 void
-sha2Update (SHA256_CTX *m, const void *v, size_t len)
+k5_sha256_update(SHA256_CTX *m, const void *v, size_t len)
 {
     const unsigned char *p = v;
     size_t old_sz = m->sz[0];
@@ -200,7 +222,7 @@ sha2Update (SHA256_CTX *m, const void *v, size_t len)
 }
 
 void
-sha2Final (void *res, SHA256_CTX *m)
+k5_sha256_final(void *res, SHA256_CTX *m)
 {
     unsigned char zeros[72];
     unsigned offset = (m->sz[0] / 8) % 64;
@@ -216,7 +238,7 @@ sha2Final (void *res, SHA256_CTX *m)
     zeros[dstart+2] = (m->sz[1] >> 8) & 0xff;
     zeros[dstart+1] = (m->sz[1] >> 16) & 0xff;
     zeros[dstart+0] = (m->sz[1] >> 24) & 0xff;
-    sha2Update (m, zeros, dstart + 8);
+    k5_sha256_update(m, zeros, dstart + 8);
     {
        int i;
        unsigned char *r = (unsigned char*)res;
@@ -229,4 +251,3 @@ sha2Final (void *res, SHA256_CTX *m)
        }
     }
 }
-#endif /* FORTUNA */
index bcad910937df339e76b03b062d354289cb623069..4facb0f31c3f7bbad942a36509400f6759d68eaa 100644 (file)
 #include <k5-int.h>
 #include "sha2.h"
 
-#ifndef FORTUNA
-int
-main (void)
-{
-    return 0;
-}
-
-#else
-
 #define ONE_MILLION_A "one million a's"
 
 struct test {
@@ -81,18 +72,18 @@ main (void)
 
     for (t = tests; t->str; ++t) {
     
-        sha2Init(ctx);
+        k5_sha256_init(ctx);
         if(strcmp(t->str, ONE_MILLION_A) == 0) {
             int i;
             memset(buf, 'a', sizeof(buf));
             for(i = 0; i < 1000; i++) {
-                sha2Update(ctx, buf, sizeof(buf));
+                k5_sha256_update(ctx, buf, sizeof(buf));
             }
         } else {
-            sha2Update(ctx, (unsigned char *)t->str, strlen(t->str));
+            k5_sha256_update(ctx, (unsigned char *)t->str, strlen(t->str));
         }
 
-        sha2Final(res, ctx);
+        k5_sha256_final(res, ctx);
         if (memcmp (res, t->hash, SHA256_DIGEST_LENGTH) != 0) {
             int i;
 
@@ -123,4 +114,4 @@ main (void)
     printf ("success\n");
     return 0;
 }
-#endif /* FORTUNA */
+
index 669a9163d28dae568f6c83a4d8c8b48174c81e76..3acf96b3a2cfc9195e31efe2cf0efc3449324d41 100644 (file)
@@ -135,25 +135,25 @@ shad256_init(SHA256_CTX *ctx)
 
     /* Initialize the inner SHA-256 context and update it with a zero block. */
     memset(zero, 0, sizeof(zero));
-    sha2Init(ctx);
-    sha2Update(ctx, zero, sizeof(zero));
+    k5_sha256_init(ctx);
+    k5_sha256_update(ctx, zero, sizeof(zero));
 }
 
 static void
 shad256_update(SHA256_CTX *ctx, const unsigned char *data, int len)
 {
     /* Feed the input to the inner SHA-256 context. */
-    sha2Update(ctx, data, len);
+    k5_sha256_update(ctx, data, len);
 }
 
 static void
 shad256_result(SHA256_CTX *ctx, unsigned char *dst)
 {
     /* Finalize the inner context, then feed the result back through SHA256. */
-    sha2Final(dst, ctx);
-    sha2Init(ctx);
-    sha2Update(ctx, dst, SHA256_HASHSIZE);
-    sha2Final(dst, ctx);
+    k5_sha256_final(dst, ctx);
+    k5_sha256_init(ctx);
+    k5_sha256_update(ctx, dst, SHA256_HASHSIZE);
+    k5_sha256_final(dst, ctx);
 }
 
 /* Initialize state. */
index 810c90df8efa3d3433dc1105ca253d6c3da08c03..6307303cf56f2f237c494ca254464b079ae71829 100644 (file)
@@ -102,8 +102,8 @@ krb5int_enc_aes256
 krb5int_enc_camellia128
 krb5int_enc_camellia256
 krb5int_derive_key
-sha2Final
-sha2Init
-sha2Update
 krb5int_aes_enc_blk
 krb5int_aes_enc_key
+k5_sha256_final
+k5_sha256_init
+k5_sha256_update
index 14ce874060ab1104d6c227f1d31deaef9f0338e9..034e7e6f03c7e8e37bf5a10d12346a9407c4f9b6 100644 (file)
@@ -38,9 +38,9 @@
  */
 void krb5int_aes_enc_blk(void);
 void krb5int_aes_enc_key(void);
-void sha2Final(void);
-void sha2Init(void);
-void sha2Update(void);
+void k5_sha256_final(void);
+void k5_sha256_init(void);
+void k5_sha256_update(void);
 
 void krb5int_aes_enc_blk(void)
 {
@@ -52,17 +52,17 @@ void krb5int_aes_enc_key(void)
     abort();
 }
 
-void sha2Final(void)
+void k5_sha256_final(void)
 {
     abort();
 }
 
-void sha2Init(void)
+void k5_sha256_init(void)
 {
     abort();
 }
 
-void sha2Update(void)
+void k5_sha256_update(void)
 {
     abort();
 }
index 0f61d5dc41ff8f2fba3a3610e6ffc17353a08802..afc1d46606a4b74aaa78619385717f0e34389ebd 100644 (file)
@@ -31,8 +31,8 @@
 
 #define _SHA2_DEFINED
 
-#define sha2Init SHA256_Init
-#define sha2Update SHA256_Update 
-#define sha2Final SHA256_Final
+#define k5_sha256_init SHA256_Init
+#define k5_sha256_update SHA256_Update
+#define k5_sha256_final SHA256_Final
 
 #endif /* _SHA2_DEFINED */
index 220df388ad06ffc850d9019c74addc5db1b906e2..1ee4d7b35f68d565b13bd25ce0bc012f23b6b13c 100644 (file)
@@ -39,9 +39,9 @@
  */
 void krb5int_aes_enc_blk(void);
 void krb5int_aes_enc_key(void);
-void sha2Final(void);
-void sha2Init(void);
-void sha2Update(void);
+void k5_sha256_final(void);
+void k5_sha256_init(void);
+void k5_sha256_update(void);
 
 void krb5int_aes_enc_blk(void)
 {
@@ -53,17 +53,17 @@ void krb5int_aes_enc_key(void)
     abort();
 }
 
-void sha2Final(void)
+void k5_sha256_final(void)
 {
     abort();
 }
 
-void sha2Init(void)
+void k5_sha256_init(void)
 {
     abort();
 }
 
-void sha2Update(void)
+void k5_sha256_update(void)
 {
     abort();
 }