svn rev #24666: trunk/src/lib/crypto/ builtin/sha2/ krb/ nss/ openssl/ openssl/sha2/
ghudson@MIT.EDU
ghudson at MIT.EDU
Fri Feb 25 14:53:04 EST 2011
http://src.mit.edu/fisheye/changelog/krb5/?cs=24666
Commit By: ghudson
Log Message:
Namespace-protect SHA-256 symbols. Build SHA-256 code independently of
whether Fortuna was selected.
Changed Files:
U trunk/src/lib/crypto/builtin/sha2/sha2.h
U trunk/src/lib/crypto/builtin/sha2/sha256.c
U trunk/src/lib/crypto/builtin/sha2/t_sha256.c
U trunk/src/lib/crypto/krb/prng_fortuna.c
U trunk/src/lib/crypto/libk5crypto.exports
U trunk/src/lib/crypto/nss/stubs.c
U trunk/src/lib/crypto/openssl/sha2/sha2.h
U trunk/src/lib/crypto/openssl/stubs.c
Modified: trunk/src/lib/crypto/builtin/sha2/sha2.h
===================================================================
--- trunk/src/lib/crypto/builtin/sha2/sha2.h 2011-02-25 19:51:44 UTC (rev 24665)
+++ trunk/src/lib/crypto/builtin/sha2/sha2.h 2011-02-25 19:53:04 UTC (rev 24666)
@@ -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).
@@ -32,48 +33,11 @@
* SUCH DAMAGE.
*/
-/* $Id$ */
+#ifndef SHA2_H
+#define SHA2_H 1
-#ifndef HEIM_SHA_H
-#define HEIM_SHA_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
struct sha256state {
@@ -84,8 +48,8 @@
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 */
Modified: trunk/src/lib/crypto/builtin/sha2/sha256.c
===================================================================
--- trunk/src/lib/crypto/builtin/sha2/sha256.c 2011-02-25 19:51:44 UTC (rev 24665)
+++ trunk/src/lib/crypto/builtin/sha2/sha256.c 2011-02-25 19:53:04 UTC (rev 24666)
@@ -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).
@@ -36,8 +36,30 @@
#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 @@
};
void
-sha2Init (SHA256_CTX *m)
+k5_sha256_init(SHA256_CTX *m)
{
m->sz[0] = 0;
m->sz[1] = 0;
@@ -92,7 +114,7 @@
}
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 @@
#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 @@
}
#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 @@
}
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 @@
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 @@
}
}
}
-#endif /* FORTUNA */
Modified: trunk/src/lib/crypto/builtin/sha2/t_sha256.c
===================================================================
--- trunk/src/lib/crypto/builtin/sha2/t_sha256.c 2011-02-25 19:51:44 UTC (rev 24665)
+++ trunk/src/lib/crypto/builtin/sha2/t_sha256.c 2011-02-25 19:53:04 UTC (rev 24666)
@@ -36,15 +36,6 @@
#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 @@
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 @@
printf ("success\n");
return 0;
}
-#endif /* FORTUNA */
+
Modified: trunk/src/lib/crypto/krb/prng_fortuna.c
===================================================================
--- trunk/src/lib/crypto/krb/prng_fortuna.c 2011-02-25 19:51:44 UTC (rev 24665)
+++ trunk/src/lib/crypto/krb/prng_fortuna.c 2011-02-25 19:53:04 UTC (rev 24666)
@@ -135,25 +135,25 @@
/* 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. */
Modified: trunk/src/lib/crypto/libk5crypto.exports
===================================================================
--- trunk/src/lib/crypto/libk5crypto.exports 2011-02-25 19:51:44 UTC (rev 24665)
+++ trunk/src/lib/crypto/libk5crypto.exports 2011-02-25 19:53:04 UTC (rev 24666)
@@ -102,8 +102,8 @@
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
Modified: trunk/src/lib/crypto/nss/stubs.c
===================================================================
--- trunk/src/lib/crypto/nss/stubs.c 2011-02-25 19:51:44 UTC (rev 24665)
+++ trunk/src/lib/crypto/nss/stubs.c 2011-02-25 19:53:04 UTC (rev 24666)
@@ -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 @@
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();
}
Modified: trunk/src/lib/crypto/openssl/sha2/sha2.h
===================================================================
--- trunk/src/lib/crypto/openssl/sha2/sha2.h 2011-02-25 19:51:44 UTC (rev 24665)
+++ trunk/src/lib/crypto/openssl/sha2/sha2.h 2011-02-25 19:53:04 UTC (rev 24666)
@@ -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 */
Modified: trunk/src/lib/crypto/openssl/stubs.c
===================================================================
--- trunk/src/lib/crypto/openssl/stubs.c 2011-02-25 19:51:44 UTC (rev 24665)
+++ trunk/src/lib/crypto/openssl/stubs.c 2011-02-25 19:53:04 UTC (rev 24666)
@@ -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 @@
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();
}
More information about the cvs-krb5
mailing list