summaryrefslogtreecommitdiffstats
path: root/src/lib/crypto/builtin
diff options
context:
space:
mode:
authorGreg Hudson <ghudson@mit.edu>2011-02-25 19:53:04 +0000
committerGreg Hudson <ghudson@mit.edu>2011-02-25 19:53:04 +0000
commit259a07f169b9a1188c3a9efb3a5fb1fb67b4b04d (patch)
treefdfbd5bf84ef9d78c19f02685e3cca54c023449d /src/lib/crypto/builtin
parentab0c0b3179d9d9e6e6a3c56a169109af1548eeed (diff)
downloadkrb5-259a07f169b9a1188c3a9efb3a5fb1fb67b4b04d.tar.gz
krb5-259a07f169b9a1188c3a9efb3a5fb1fb67b4b04d.tar.xz
krb5-259a07f169b9a1188c3a9efb3a5fb1fb67b4b04d.zip
Namespace-protect SHA-256 symbols. Build SHA-256 code independently of
whether Fortuna was selected. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@24666 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/crypto/builtin')
-rw-r--r--src/lib/crypto/builtin/sha2/sha2.h50
-rw-r--r--src/lib/crypto/builtin/sha2/sha256.c41
-rw-r--r--src/lib/crypto/builtin/sha2/t_sha256.c19
3 files changed, 43 insertions, 67 deletions
diff --git a/src/lib/crypto/builtin/sha2/sha2.h b/src/lib/crypto/builtin/sha2/sha2.h
index 0cff88f4a..6c743e122 100644
--- a/src/lib/crypto/builtin/sha2/sha2.h
+++ b/src/lib/crypto/builtin/sha2/sha2.h
@@ -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,47 +33,10 @@
* 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 */
diff --git a/src/lib/crypto/builtin/sha2/sha256.c b/src/lib/crypto/builtin/sha2/sha256.c
index fb66bff70..23b1a26c0 100644
--- a/src/lib/crypto/builtin/sha2/sha256.c
+++ b/src/lib/crypto/builtin/sha2/sha256.c
@@ -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,7 +36,29 @@
#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 */
diff --git a/src/lib/crypto/builtin/sha2/t_sha256.c b/src/lib/crypto/builtin/sha2/t_sha256.c
index bcad91093..4facb0f31 100644
--- a/src/lib/crypto/builtin/sha2/t_sha256.c
+++ b/src/lib/crypto/builtin/sha2/t_sha256.c
@@ -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 @@ 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 */
+