diff options
author | Damien Miller <djm@cvs.openbsd.org> | 2008-09-06 22:23:22 +0000 |
---|---|---|
committer | Damien Miller <djm@cvs.openbsd.org> | 2008-09-06 22:23:22 +0000 |
commit | 75d891f82396fa10292e82f1a4ce69cef2360761 (patch) | |
tree | 2437ba02f7be4e77a040afbb23a4adfdd653b4ed | |
parent | 3963bcc1a4f62e323d92a8f8d75cf5dce429627d (diff) |
match libc sha2(3) API changes for kernel; ok millert@
-rw-r--r-- | sys/crypto/hmac.c | 24 | ||||
-rw-r--r-- | sys/crypto/hmac.h | 4 | ||||
-rw-r--r-- | sys/crypto/sha2.c | 234 | ||||
-rw-r--r-- | sys/crypto/sha2.h | 38 | ||||
-rw-r--r-- | sys/crypto/xform.c | 38 | ||||
-rw-r--r-- | sys/crypto/xform.h | 6 |
6 files changed, 172 insertions, 172 deletions
diff --git a/sys/crypto/hmac.c b/sys/crypto/hmac.c index 00aa18bc8de..0922af34b79 100644 --- a/sys/crypto/hmac.c +++ b/sys/crypto/hmac.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hmac.c,v 1.1 2008/08/12 15:43:00 damien Exp $ */ +/* $OpenBSD: hmac.c,v 1.2 2008/09/06 22:23:20 djm Exp $ */ /*- * Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr> @@ -144,9 +144,9 @@ HMAC_SHA256_Init(HMAC_SHA256_CTX *ctx, const u_int8_t *key, u_int key_len) int i; if (key_len > SHA256_BLOCK_LENGTH) { - SHA256_Init(&ctx->ctx); - SHA256_Update(&ctx->ctx, key, key_len); - SHA256_Final(ctx->key, &ctx->ctx); + SHA256Init(&ctx->ctx); + SHA256Update(&ctx->ctx, key, key_len); + SHA256Final(ctx->key, &ctx->ctx); ctx->key_len = SHA256_DIGEST_LENGTH; } else { bcopy(key, ctx->key, key_len); @@ -158,8 +158,8 @@ HMAC_SHA256_Init(HMAC_SHA256_CTX *ctx, const u_int8_t *key, u_int key_len) for (i = 0; i < SHA256_BLOCK_LENGTH; i++) k_ipad[i] ^= 0x36; - SHA256_Init(&ctx->ctx); - SHA256_Update(&ctx->ctx, k_ipad, SHA256_BLOCK_LENGTH); + SHA256Init(&ctx->ctx); + SHA256Update(&ctx->ctx, k_ipad, SHA256_BLOCK_LENGTH); bzero(k_ipad, sizeof k_ipad); } @@ -167,7 +167,7 @@ HMAC_SHA256_Init(HMAC_SHA256_CTX *ctx, const u_int8_t *key, u_int key_len) void HMAC_SHA256_Update(HMAC_SHA256_CTX *ctx, const u_int8_t *data, u_int len) { - SHA256_Update(&ctx->ctx, data, len); + SHA256Update(&ctx->ctx, data, len); } void @@ -176,17 +176,17 @@ HMAC_SHA256_Final(u_int8_t digest[SHA256_DIGEST_LENGTH], HMAC_SHA256_CTX *ctx) u_int8_t k_opad[SHA256_BLOCK_LENGTH]; int i; - SHA256_Final(digest, &ctx->ctx); + SHA256Final(digest, &ctx->ctx); bzero(k_opad, SHA256_BLOCK_LENGTH); bcopy(ctx->key, k_opad, ctx->key_len); for (i = 0; i < SHA256_BLOCK_LENGTH; i++) k_opad[i] ^= 0x5c; - SHA256_Init(&ctx->ctx); - SHA256_Update(&ctx->ctx, k_opad, SHA256_BLOCK_LENGTH); - SHA256_Update(&ctx->ctx, digest, SHA256_DIGEST_LENGTH); - SHA256_Final(digest, &ctx->ctx); + SHA256Init(&ctx->ctx); + SHA256Update(&ctx->ctx, k_opad, SHA256_BLOCK_LENGTH); + SHA256Update(&ctx->ctx, digest, SHA256_DIGEST_LENGTH); + SHA256Final(digest, &ctx->ctx); bzero(k_opad, sizeof k_opad); } diff --git a/sys/crypto/hmac.h b/sys/crypto/hmac.h index 677f9d4598b..99b1dd63b99 100644 --- a/sys/crypto/hmac.h +++ b/sys/crypto/hmac.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hmac.h,v 1.1 2008/08/12 15:43:00 damien Exp $ */ +/* $OpenBSD: hmac.h,v 1.2 2008/09/06 22:23:20 djm Exp $ */ /*- * Copyright (c) 2008 Damien Bergamini <damien.bergamini@free.fr> @@ -32,7 +32,7 @@ typedef struct _HMAC_SHA1_CTX { } HMAC_SHA1_CTX; typedef struct _HMAC_SHA256_CTX { - SHA256_CTX ctx; + SHA2_CTX ctx; u_int8_t key[SHA256_BLOCK_LENGTH]; u_int key_len; } HMAC_SHA256_CTX; diff --git a/sys/crypto/sha2.c b/sys/crypto/sha2.c index 79b42b94afb..bca331f1e64 100644 --- a/sys/crypto/sha2.c +++ b/sys/crypto/sha2.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sha2.c,v 1.6 2004/05/03 02:57:36 millert Exp $ */ +/* $OpenBSD: sha2.c,v 1.7 2008/09/06 22:23:20 djm Exp $ */ /* * FILE: sha2.c @@ -160,9 +160,9 @@ * library -- they are intended for private internal visibility/use * only. */ -void SHA512_Last(SHA512_CTX *); -void SHA256_Transform(SHA256_CTX *, const u_int8_t *); -void SHA512_Transform(SHA512_CTX *, const u_int8_t *); +void SHA512Last(SHA2_CTX *); +void SHA256Transform(SHA2_CTX *, const u_int8_t *); +void SHA512Transform(SHA2_CTX *, const u_int8_t *); /*** SHA-XYZ INITIAL HASH VALUES AND CONSTANTS ************************/ @@ -269,13 +269,14 @@ const static u_int64_t sha512_initial_hash_value[8] = { /*** SHA-256: *********************************************************/ void -SHA256_Init(SHA256_CTX *context) +SHA256Init(SHA2_CTX *context) { if (context == NULL) return; - bcopy(sha256_initial_hash_value, context->state, SHA256_DIGEST_LENGTH); + bcopy(sha256_initial_hash_value, context->state.st32, + SHA256_DIGEST_LENGTH); bzero(context->buffer, SHA256_BLOCK_LENGTH); - context->bitcount = 0; + context->bitcount[0] = 0; } #ifdef SHA2_UNROLL_TRANSFORM @@ -305,7 +306,7 @@ SHA256_Init(SHA256_CTX *context) } while(0) void -SHA256_Transform(SHA256_CTX *context, const u_int8_t *data) +SHA256Transform(SHA2_CTX *context, const u_int8_t *data) { u_int32_t a, b, c, d, e, f, g, h, s0, s1; u_int32_t T1, *W256; @@ -314,14 +315,14 @@ SHA256_Transform(SHA256_CTX *context, const u_int8_t *data) W256 = (u_int32_t *)context->buffer; /* Initialize registers with the prev. intermediate value */ - a = context->state[0]; - b = context->state[1]; - c = context->state[2]; - d = context->state[3]; - e = context->state[4]; - f = context->state[5]; - g = context->state[6]; - h = context->state[7]; + a = context->state.st32[0]; + b = context->state.st32[1]; + c = context->state.st32[2]; + d = context->state.st32[3]; + e = context->state.st32[4]; + f = context->state.st32[5]; + g = context->state.st32[6]; + h = context->state.st32[7]; j = 0; do { @@ -349,14 +350,14 @@ SHA256_Transform(SHA256_CTX *context, const u_int8_t *data) } while (j < 64); /* Compute the current intermediate hash value */ - context->state[0] += a; - context->state[1] += b; - context->state[2] += c; - context->state[3] += d; - context->state[4] += e; - context->state[5] += f; - context->state[6] += g; - context->state[7] += h; + context->state.st32[0] += a; + context->state.st32[1] += b; + context->state.st32[2] += c; + context->state.st32[3] += d; + context->state.st32[4] += e; + context->state.st32[5] += f; + context->state.st32[6] += g; + context->state.st32[7] += h; /* Clean up */ a = b = c = d = e = f = g = h = T1 = 0; @@ -365,7 +366,7 @@ SHA256_Transform(SHA256_CTX *context, const u_int8_t *data) #else /* SHA2_UNROLL_TRANSFORM */ void -SHA256_Transform(SHA256_CTX *context, const u_int8_t *data) +SHA256Transform(SHA2_CTX *context, const u_int8_t *data) { u_int32_t a, b, c, d, e, f, g, h, s0, s1; u_int32_t T1, T2, *W256; @@ -374,14 +375,14 @@ SHA256_Transform(SHA256_CTX *context, const u_int8_t *data) W256 = (u_int32_t *)context->buffer; /* Initialize registers with the prev. intermediate value */ - a = context->state[0]; - b = context->state[1]; - c = context->state[2]; - d = context->state[3]; - e = context->state[4]; - f = context->state[5]; - g = context->state[6]; - h = context->state[7]; + a = context->state.st32[0]; + b = context->state.st32[1]; + c = context->state.st32[2]; + d = context->state.st32[3]; + e = context->state.st32[4]; + f = context->state.st32[5]; + g = context->state.st32[6]; + h = context->state.st32[7]; j = 0; do { @@ -427,14 +428,14 @@ SHA256_Transform(SHA256_CTX *context, const u_int8_t *data) } while (j < 64); /* Compute the current intermediate hash value */ - context->state[0] += a; - context->state[1] += b; - context->state[2] += c; - context->state[3] += d; - context->state[4] += e; - context->state[5] += f; - context->state[6] += g; - context->state[7] += h; + context->state.st32[0] += a; + context->state.st32[1] += b; + context->state.st32[2] += c; + context->state.st32[3] += d; + context->state.st32[4] += e; + context->state.st32[5] += f; + context->state.st32[6] += g; + context->state.st32[7] += h; /* Clean up */ a = b = c = d = e = f = g = h = T1 = T2 = 0; @@ -443,7 +444,7 @@ SHA256_Transform(SHA256_CTX *context, const u_int8_t *data) #endif /* SHA2_UNROLL_TRANSFORM */ void -SHA256_Update(SHA256_CTX *context, const u_int8_t *data, size_t len) +SHA256Update(SHA2_CTX *context, const u_int8_t *data, size_t len) { size_t freespace, usedspace; @@ -451,7 +452,7 @@ SHA256_Update(SHA256_CTX *context, const u_int8_t *data, size_t len) if (len == 0) return; - usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH; + usedspace = (context->bitcount[0] >> 3) % SHA256_BLOCK_LENGTH; if (usedspace > 0) { /* Calculate how much free space is available in the buffer */ freespace = SHA256_BLOCK_LENGTH - usedspace; @@ -459,14 +460,14 @@ SHA256_Update(SHA256_CTX *context, const u_int8_t *data, size_t len) if (len >= freespace) { /* Fill the buffer completely and process it */ bcopy(data, &context->buffer[usedspace], freespace); - context->bitcount += freespace << 3; + context->bitcount[0] += freespace << 3; len -= freespace; data += freespace; - SHA256_Transform(context, context->buffer); + SHA256Transform(context, context->buffer); } else { /* The buffer is not yet full */ bcopy(data, &context->buffer[usedspace], len); - context->bitcount += len << 3; + context->bitcount[0] += len << 3; /* Clean up: */ usedspace = freespace = 0; return; @@ -474,32 +475,32 @@ SHA256_Update(SHA256_CTX *context, const u_int8_t *data, size_t len) } while (len >= SHA256_BLOCK_LENGTH) { /* Process as many complete blocks as we can */ - SHA256_Transform(context, data); - context->bitcount += SHA256_BLOCK_LENGTH << 3; + SHA256Transform(context, data); + context->bitcount[0] += SHA256_BLOCK_LENGTH << 3; len -= SHA256_BLOCK_LENGTH; data += SHA256_BLOCK_LENGTH; } if (len > 0) { /* There's left-overs, so save 'em */ bcopy(data, context->buffer, len); - context->bitcount += len << 3; + context->bitcount[0] += len << 3; } /* Clean up: */ usedspace = freespace = 0; } void -SHA256_Final(u_int8_t digest[], SHA256_CTX *context) +SHA256Final(u_int8_t digest[], SHA2_CTX *context) { u_int32_t *d = (u_int32_t *)digest; unsigned int usedspace; /* If no digest buffer is passed, we don't bother doing this: */ if (digest != NULL) { - usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH; + usedspace = (context->bitcount[0] >> 3) % SHA256_BLOCK_LENGTH; #if BYTE_ORDER == LITTLE_ENDIAN /* Convert FROM host byte order */ - REVERSE64(context->bitcount,context->bitcount); + REVERSE64(context->bitcount[0], context->bitcount[0]); #endif if (usedspace > 0) { /* Begin padding with a 1 bit: */ @@ -513,7 +514,7 @@ SHA256_Final(u_int8_t digest[], SHA256_CTX *context) bzero(&context->buffer[usedspace], SHA256_BLOCK_LENGTH - usedspace); } /* Do second-to-last transform: */ - SHA256_Transform(context, context->buffer); + SHA256Transform(context, context->buffer); /* And set-up for the last transform: */ bzero(context->buffer, SHA256_SHORT_BLOCK_LENGTH); @@ -526,22 +527,23 @@ SHA256_Final(u_int8_t digest[], SHA256_CTX *context) *context->buffer = 0x80; } /* Set the bit count: */ - *(u_int64_t *)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount; + *(u_int64_t *)&context->buffer[SHA256_SHORT_BLOCK_LENGTH] = context->bitcount[0]; /* Final transform: */ - SHA256_Transform(context, context->buffer); + SHA256Transform(context, context->buffer); #if BYTE_ORDER == LITTLE_ENDIAN { /* Convert TO host byte order */ int j; for (j = 0; j < 8; j++) { - REVERSE32(context->state[j],context->state[j]); - *d++ = context->state[j]; + REVERSE32(context->state.st32[j], + context->state.st32[j]); + *d++ = context->state.st32[j]; } } #else - bcopy(context->state, d, SHA256_DIGEST_LENGTH); + bcopy(context->state.st32, d, SHA256_DIGEST_LENGTH); #endif } @@ -553,11 +555,12 @@ SHA256_Final(u_int8_t digest[], SHA256_CTX *context) /*** SHA-512: *********************************************************/ void -SHA512_Init(SHA512_CTX *context) +SHA512Init(SHA2_CTX *context) { if (context == NULL) return; - bcopy(sha512_initial_hash_value, context->state, SHA512_DIGEST_LENGTH); + bcopy(sha512_initial_hash_value, context->state.st64, + SHA512_DIGEST_LENGTH); bzero(context->buffer, SHA512_BLOCK_LENGTH); context->bitcount[0] = context->bitcount[1] = 0; } @@ -592,21 +595,21 @@ SHA512_Init(SHA512_CTX *context) } while(0) void -SHA512_Transform(SHA512_CTX *context, const u_int8_t *data) +SHA512Transform(SHA2_CTX *context, const u_int8_t *data) { u_int64_t a, b, c, d, e, f, g, h, s0, s1; u_int64_t T1, *W512 = (u_int64_t *)context->buffer; int j; /* Initialize registers with the prev. intermediate value */ - a = context->state[0]; - b = context->state[1]; - c = context->state[2]; - d = context->state[3]; - e = context->state[4]; - f = context->state[5]; - g = context->state[6]; - h = context->state[7]; + a = context->state.st64[0]; + b = context->state.st64[1]; + c = context->state.st64[2]; + d = context->state.st64[3]; + e = context->state.st64[4]; + f = context->state.st64[5]; + g = context->state.st64[6]; + h = context->state.st64[7]; j = 0; do { @@ -633,14 +636,14 @@ SHA512_Transform(SHA512_CTX *context, const u_int8_t *data) } while (j < 80); /* Compute the current intermediate hash value */ - context->state[0] += a; - context->state[1] += b; - context->state[2] += c; - context->state[3] += d; - context->state[4] += e; - context->state[5] += f; - context->state[6] += g; - context->state[7] += h; + context->state.st64[0] += a; + context->state.st64[1] += b; + context->state.st64[2] += c; + context->state.st64[3] += d; + context->state.st64[4] += e; + context->state.st64[5] += f; + context->state.st64[6] += g; + context->state.st64[7] += h; /* Clean up */ a = b = c = d = e = f = g = h = T1 = 0; @@ -649,21 +652,21 @@ SHA512_Transform(SHA512_CTX *context, const u_int8_t *data) #else /* SHA2_UNROLL_TRANSFORM */ void -SHA512_Transform(SHA512_CTX *context, const u_int8_t *data) +SHA512Transform(SHA2_CTX *context, const u_int8_t *data) { u_int64_t a, b, c, d, e, f, g, h, s0, s1; u_int64_t T1, T2, *W512 = (u_int64_t *)context->buffer; int j; /* Initialize registers with the prev. intermediate value */ - a = context->state[0]; - b = context->state[1]; - c = context->state[2]; - d = context->state[3]; - e = context->state[4]; - f = context->state[5]; - g = context->state[6]; - h = context->state[7]; + a = context->state.st64[0]; + b = context->state.st64[1]; + c = context->state.st64[2]; + d = context->state.st64[3]; + e = context->state.st64[4]; + f = context->state.st64[5]; + g = context->state.st64[6]; + h = context->state.st64[7]; j = 0; do { @@ -711,14 +714,14 @@ SHA512_Transform(SHA512_CTX *context, const u_int8_t *data) } while (j < 80); /* Compute the current intermediate hash value */ - context->state[0] += a; - context->state[1] += b; - context->state[2] += c; - context->state[3] += d; - context->state[4] += e; - context->state[5] += f; - context->state[6] += g; - context->state[7] += h; + context->state.st64[0] += a; + context->state.st64[1] += b; + context->state.st64[2] += c; + context->state.st64[3] += d; + context->state.st64[4] += e; + context->state.st64[5] += f; + context->state.st64[6] += g; + context->state.st64[7] += h; /* Clean up */ a = b = c = d = e = f = g = h = T1 = T2 = 0; @@ -727,7 +730,7 @@ SHA512_Transform(SHA512_CTX *context, const u_int8_t *data) #endif /* SHA2_UNROLL_TRANSFORM */ void -SHA512_Update(SHA512_CTX *context, const u_int8_t *data, size_t len) +SHA512Update(SHA2_CTX *context, const u_int8_t *data, size_t len) { size_t freespace, usedspace; @@ -746,7 +749,7 @@ SHA512_Update(SHA512_CTX *context, const u_int8_t *data, size_t len) ADDINC128(context->bitcount, freespace << 3); len -= freespace; data += freespace; - SHA512_Transform(context, context->buffer); + SHA512Transform(context, context->buffer); } else { /* The buffer is not yet full */ bcopy(data, &context->buffer[usedspace], len); @@ -758,7 +761,7 @@ SHA512_Update(SHA512_CTX *context, const u_int8_t *data, size_t len) } while (len >= SHA512_BLOCK_LENGTH) { /* Process as many complete blocks as we can */ - SHA512_Transform(context, data); + SHA512Transform(context, data); ADDINC128(context->bitcount, SHA512_BLOCK_LENGTH << 3); len -= SHA512_BLOCK_LENGTH; data += SHA512_BLOCK_LENGTH; @@ -773,7 +776,7 @@ SHA512_Update(SHA512_CTX *context, const u_int8_t *data, size_t len) } void -SHA512_Last(SHA512_CTX *context) +SHA512Last(SHA2_CTX *context) { unsigned int usedspace; @@ -795,7 +798,7 @@ SHA512_Last(SHA512_CTX *context) bzero(&context->buffer[usedspace], SHA512_BLOCK_LENGTH - usedspace); } /* Do second-to-last transform: */ - SHA512_Transform(context, context->buffer); + SHA512Transform(context, context->buffer); /* And set-up for the last transform: */ bzero(context->buffer, SHA512_BLOCK_LENGTH - 2); @@ -812,17 +815,17 @@ SHA512_Last(SHA512_CTX *context) *(u_int64_t *)&context->buffer[SHA512_SHORT_BLOCK_LENGTH+8] = context->bitcount[0]; /* Final transform: */ - SHA512_Transform(context, context->buffer); + SHA512Transform(context, context->buffer); } void -SHA512_Final(u_int8_t digest[], SHA512_CTX *context) +SHA512Final(u_int8_t digest[], SHA2_CTX *context) { u_int64_t *d = (u_int64_t *)digest; /* If no digest buffer is passed, we don't bother doing this: */ if (digest != NULL) { - SHA512_Last(context); + SHA512Last(context); /* Save the hash data for output: */ #if BYTE_ORDER == LITTLE_ENDIAN @@ -830,12 +833,13 @@ SHA512_Final(u_int8_t digest[], SHA512_CTX *context) /* Convert TO host byte order */ int j; for (j = 0; j < 8; j++) { - REVERSE64(context->state[j],context->state[j]); - *d++ = context->state[j]; + REVERSE64(context->state.st64[j], + context->state.st64[j]); + *d++ = context->state.st64[j]; } } #else - bcopy(context->state, d, SHA512_DIGEST_LENGTH); + bcopy(context->state.st64, d, SHA512_DIGEST_LENGTH); #endif } @@ -846,29 +850,30 @@ SHA512_Final(u_int8_t digest[], SHA512_CTX *context) /*** SHA-384: *********************************************************/ void -SHA384_Init(SHA384_CTX *context) +SHA384Init(SHA2_CTX *context) { if (context == NULL) return; - bcopy(sha384_initial_hash_value, context->state, SHA512_DIGEST_LENGTH); + bcopy(sha384_initial_hash_value, context->state.st64, + SHA512_DIGEST_LENGTH); bzero(context->buffer, SHA384_BLOCK_LENGTH); context->bitcount[0] = context->bitcount[1] = 0; } void -SHA384_Update(SHA384_CTX *context, const u_int8_t *data, size_t len) +SHA384Update(SHA2_CTX *context, const u_int8_t *data, size_t len) { - SHA512_Update((SHA512_CTX *)context, data, len); + SHA512Update((SHA2_CTX *)context, data, len); } void -SHA384_Final(u_int8_t digest[], SHA384_CTX *context) +SHA384Final(u_int8_t digest[], SHA2_CTX *context) { u_int64_t *d = (u_int64_t *)digest; /* If no digest buffer is passed, we don't bother doing this: */ if (digest != NULL) { - SHA512_Last((SHA512_CTX *)context); + SHA512Last((SHA2_CTX *)context); /* Save the hash data for output: */ #if BYTE_ORDER == LITTLE_ENDIAN @@ -876,12 +881,13 @@ SHA384_Final(u_int8_t digest[], SHA384_CTX *context) /* Convert TO host byte order */ int j; for (j = 0; j < 6; j++) { - REVERSE64(context->state[j],context->state[j]); - *d++ = context->state[j]; + REVERSE64(context->state.st64[j], + context->state.st64[j]); + *d++ = context->state.st64[j]; } } #else - bcopy(context->state, d, SHA384_DIGEST_LENGTH); + bcopy(context->state.st64, d, SHA384_DIGEST_LENGTH); #endif } diff --git a/sys/crypto/sha2.h b/sys/crypto/sha2.h index 45894a1fd80..c9e7500821f 100644 --- a/sys/crypto/sha2.h +++ b/sys/crypto/sha2.h @@ -1,4 +1,4 @@ -/* $OpenBSD: sha2.h,v 1.2 2004/04/28 23:11:57 millert Exp $ */ +/* $OpenBSD: sha2.h,v 1.3 2008/09/06 22:23:20 djm Exp $ */ /* * FILE: sha2.h @@ -50,39 +50,35 @@ #define SHA512_DIGEST_STRING_LENGTH (SHA512_DIGEST_LENGTH * 2 + 1) -/*** SHA-256/384/512 Context Structures *******************************/ -typedef struct _SHA256_CTX { - u_int32_t state[8]; - u_int64_t bitcount; - u_int8_t buffer[SHA256_BLOCK_LENGTH]; -} SHA256_CTX; -typedef struct _SHA512_CTX { - u_int64_t state[8]; +/*** SHA-256/384/512 Context Structure *******************************/ +typedef struct _SHA2_CTX { + union { + u_int32_t st32[8]; + u_int64_t st64[8]; + } state; u_int64_t bitcount[2]; u_int8_t buffer[SHA512_BLOCK_LENGTH]; -} SHA512_CTX; - -typedef SHA512_CTX SHA384_CTX; +} SHA2_CTX; #include <sys/cdefs.h> __BEGIN_DECLS -void SHA256_Init(SHA256_CTX *); -void SHA256_Update(SHA256_CTX *, const u_int8_t *, size_t) +void SHA256Init(SHA2_CTX *); +void SHA256Update(SHA2_CTX *, const u_int8_t *, size_t) __attribute__((__bounded__(__string__,2,3))); -void SHA256_Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA256_CTX *) +void SHA256Final(u_int8_t[SHA256_DIGEST_LENGTH], SHA2_CTX *) __attribute__((__bounded__(__minbytes__,1,SHA256_DIGEST_LENGTH))); -void SHA384_Init(SHA384_CTX *); -void SHA384_Update(SHA384_CTX *, const u_int8_t *, size_t) +void SHA384Init(SHA2_CTX *); +void SHA384Update(SHA2_CTX *, const u_int8_t *, size_t) __attribute__((__bounded__(__string__,2,3))); -void SHA384_Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA384_CTX *) +void SHA384Final(u_int8_t[SHA384_DIGEST_LENGTH], SHA2_CTX *) __attribute__((__bounded__(__minbytes__,1,SHA384_DIGEST_LENGTH))); -void SHA512_Init(SHA512_CTX *); -void SHA512_Update(SHA512_CTX *, const u_int8_t *, size_t) +void SHA512Init(SHA2_CTX *); +void SHA512Update(SHA2_CTX *, const u_int8_t *, size_t) __attribute__((__bounded__(__string__,2,3))); -void SHA512_Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA512_CTX *) +void SHA512Final(u_int8_t[SHA512_DIGEST_LENGTH], SHA2_CTX *) __attribute__((__bounded__(__minbytes__,1,SHA512_DIGEST_LENGTH))); __END_DECLS diff --git a/sys/crypto/xform.c b/sys/crypto/xform.c index 12e99c638ca..900b993ee3e 100644 --- a/sys/crypto/xform.c +++ b/sys/crypto/xform.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xform.c,v 1.35 2008/06/09 16:11:36 djm Exp $ */ +/* $OpenBSD: xform.c,v 1.36 2008/09/06 22:23:21 djm Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr), @@ -112,9 +112,9 @@ void aes_xts_reinit(caddr_t, u_int8_t *); int MD5Update_int(void *, const u_int8_t *, u_int16_t); int SHA1Update_int(void *, const u_int8_t *, u_int16_t); int RMD160Update_int(void *, const u_int8_t *, u_int16_t); -int SHA256_Update_int(void *, const u_int8_t *, u_int16_t); -int SHA384_Update_int(void *, const u_int8_t *, u_int16_t); -int SHA512_Update_int(void *, const u_int8_t *, u_int16_t); +int SHA256Update_int(void *, const u_int8_t *, u_int16_t); +int SHA384Update_int(void *, const u_int8_t *, u_int16_t); +int SHA512Update_int(void *, const u_int8_t *, u_int16_t); u_int32_t deflate_compress(u_int8_t *, u_int32_t, u_int8_t **); u_int32_t deflate_decompress(u_int8_t *, u_int32_t, u_int8_t **); @@ -249,23 +249,23 @@ struct auth_hash auth_hash_hmac_ripemd_160_96 = { struct auth_hash auth_hash_hmac_sha2_256_96 = { CRYPTO_SHA2_256_HMAC, "HMAC-SHA2-256", - 32, 32, 12, sizeof(SHA256_CTX), - (void (*)(void *)) SHA256_Init, SHA256_Update_int, - (void (*)(u_int8_t *, void *)) SHA256_Final + 32, 32, 12, sizeof(SHA2_CTX), + (void (*)(void *)) SHA256Init, SHA256Update_int, + (void (*)(u_int8_t *, void *)) SHA256Final }; struct auth_hash auth_hash_hmac_sha2_384_96 = { CRYPTO_SHA2_384_HMAC, "HMAC-SHA2-384", - 48, 48, 12, sizeof(SHA384_CTX), - (void (*)(void *)) SHA384_Init, SHA384_Update_int, - (void (*)(u_int8_t *, void *)) SHA384_Final + 48, 48, 12, sizeof(SHA2_CTX), + (void (*)(void *)) SHA384Init, SHA384Update_int, + (void (*)(u_int8_t *, void *)) SHA384Final }; struct auth_hash auth_hash_hmac_sha2_512_96 = { CRYPTO_SHA2_512_HMAC, "HMAC-SHA2-512", - 64, 64, 12, sizeof(SHA512_CTX), - (void (*)(void *)) SHA512_Init, SHA512_Update_int, - (void (*)(u_int8_t *, void *)) SHA512_Final + 64, 64, 12, sizeof(SHA2_CTX), + (void (*)(void *)) SHA512Init, SHA512Update_int, + (void (*)(u_int8_t *, void *)) SHA512Final }; struct auth_hash auth_hash_key_md5 = { @@ -725,23 +725,23 @@ SHA1Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) } int -SHA256_Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) +SHA256Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) { - SHA256_Update(ctx, buf, len); + SHA256Update(ctx, buf, len); return 0; } int -SHA384_Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) +SHA384Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) { - SHA384_Update(ctx, buf, len); + SHA384Update(ctx, buf, len); return 0; } int -SHA512_Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) +SHA512Update_int(void *ctx, const u_int8_t *buf, u_int16_t len) { - SHA512_Update(ctx, buf, len); + SHA512Update(ctx, buf, len); return 0; } diff --git a/sys/crypto/xform.h b/sys/crypto/xform.h index 55321bef960..aed3ec6678c 100644 --- a/sys/crypto/xform.h +++ b/sys/crypto/xform.h @@ -1,4 +1,4 @@ -/* $OpenBSD: xform.h,v 1.18 2008/06/09 16:07:00 djm Exp $ */ +/* $OpenBSD: xform.h,v 1.19 2008/09/06 22:23:21 djm Exp $ */ /* * The author of this code is Angelos D. Keromytis (angelos@cis.upenn.edu) @@ -66,9 +66,7 @@ union authctx { MD5_CTX md5ctx; SHA1_CTX sha1ctx; RMD160_CTX rmd160ctx; - SHA256_CTX sha2_256ctx; - SHA384_CTX sha2_384ctx; - SHA512_CTX sha2_512ctx; + SHA2_CTX sha2_ctx; }; extern struct enc_xform enc_xform_des; |