summaryrefslogtreecommitdiffstats
path: root/src/lib/crypto/sha/hmac_sha.c
diff options
context:
space:
mode:
authorTom Yu <tlyu@mit.edu>1997-10-28 21:39:36 +0000
committerTom Yu <tlyu@mit.edu>1997-10-28 21:39:36 +0000
commit052d558202badc4e9e81641058c89d17f656e2f5 (patch)
tree8ac55df2c8c65c178ed7aa6c17d6da3a6acabaae /src/lib/crypto/sha/hmac_sha.c
parent653084c4714f8f996fd2b8ac261909038d57331c (diff)
downloadkrb5-052d558202badc4e9e81641058c89d17f656e2f5.tar.gz
krb5-052d558202badc4e9e81641058c89d17f656e2f5.tar.xz
krb5-052d558202badc4e9e81641058c89d17f656e2f5.zip
* shs.c, sha_glue.c, hmac_sha.c: Fix to deal with LONG wider than
32 bits. * t_shs.c: Print out the actual and expected values on error. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@10258 dc483132-0cff-0310-8789-dd5450dbe970
Diffstat (limited to 'src/lib/crypto/sha/hmac_sha.c')
-rw-r--r--src/lib/crypto/sha/hmac_sha.c31
1 files changed, 27 insertions, 4 deletions
diff --git a/src/lib/crypto/sha/hmac_sha.c b/src/lib/crypto/sha/hmac_sha.c
index 01b00899e..d57092e69 100644
--- a/src/lib/crypto/sha/hmac_sha.c
+++ b/src/lib/crypto/sha/hmac_sha.c
@@ -16,19 +16,28 @@ hmac_sha(text, text_len, key, key_len, digest)
krb5_octet k_ipad[PAD_SZ]; /* inner padding - key XORd with ipad */
krb5_octet k_opad[PAD_SZ]; /* outer padding - key XORd with opad */
int i;
+ krb5_octet *cp;
+ LONG *lp;
/* sanity check parameters */
if (!text || !key || !digest)
/* most heinous, probably should log something */
return EINVAL;
- /* if key is longer than 64 bytes reset it to key=MD5(key) */
+ /* if key is longer than 64 bytes reset it to key=SHA(key) */
if (key_len > sizeof(k_ipad)) {
shsInit(&context);
shsUpdate(&context, key, key_len);
shsFinal(&context);
- memcpy(digest, context.digest, SHS_DIGESTSIZE);
+ cp = digest;
+ lp = context.digest;
+ while (cp < digest + SHS_DIGESTSIZE) {
+ *cp++ = (*lp >> 24) & 0xff;
+ *cp++ = (*lp >> 16) & 0xff;
+ *cp++ = (*lp >> 8) & 0xff;
+ *cp++ = *lp++ & 0xff;
+ }
key = digest;
key_len = SHS_DIGESTSIZE;
}
@@ -62,7 +71,14 @@ hmac_sha(text, text_len, key, key_len, digest)
shsUpdate(&context, text, text_len);
shsFinal(&context);
- memcpy(digest, context.digest, SHS_DIGESTSIZE);
+ cp = digest;
+ lp = context.digest;
+ while (cp < digest + SHS_DIGESTSIZE) {
+ *cp++ = (*lp >> 24) & 0xff;
+ *cp++ = (*lp >> 16) & 0xff;
+ *cp++ = (*lp >> 8) & 0xff;
+ *cp++ = *lp++ & 0xff;
+ }
/*
* perform outer SHA
@@ -72,7 +88,14 @@ hmac_sha(text, text_len, key, key_len, digest)
shsUpdate(&context, digest, SHS_DIGESTSIZE);
shsFinal(&context);
- memcpy(digest, context.digest, SHS_DIGESTSIZE);
+ cp = digest;
+ lp = context.digest;
+ while (cp < digest + SHS_DIGESTSIZE) {
+ *cp++ = (*lp >> 24) & 0xff;
+ *cp++ = (*lp >> 16) & 0xff;
+ *cp++ = (*lp >> 8) & 0xff;
+ *cp++ = *lp++ & 0xff;
+ }
return 0;
}