diff options
author | jbj <devnull@localhost> | 2003-04-27 23:06:37 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 2003-04-27 23:06:37 +0000 |
commit | 6099f7ee0e858d8831726ff1e430e4f80d63ba62 (patch) | |
tree | 09991d97f99d5b8d68eadecf53bbb1dcc8107ff0 /beecrypt/hmac.c | |
parent | 18eea94d34737988ae6c8dfaa9aebd349236994c (diff) | |
download | librpm-tizen-6099f7ee0e858d8831726ff1e430e4f80d63ba62.tar.gz librpm-tizen-6099f7ee0e858d8831726ff1e430e4f80d63ba62.tar.bz2 librpm-tizen-6099f7ee0e858d8831726ff1e430e4f80d63ba62.zip |
beecrypt-3.0.0 merge: (mostly) grand renaming, mpw et al.
CVS patchset: 6782
CVS date: 2003/04/27 23:06:37
Diffstat (limited to 'beecrypt/hmac.c')
-rw-r--r-- | beecrypt/hmac.c | 92 |
1 files changed, 33 insertions, 59 deletions
diff --git a/beecrypt/hmac.c b/beecrypt/hmac.c index 3e2522a97..e0a4d9b3a 100644 --- a/beecrypt/hmac.c +++ b/beecrypt/hmac.c @@ -1,14 +1,6 @@ -/** \ingroup HMAC_m - * \file hmac.c - * - * HMAC message authentication code, code. - */ - /* * Copyright (c) 1999, 2000, 2002 Virtual Unlimited B.V. * - * Author: Bob Deblier <bob@virtualunlimited.com> - * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either @@ -25,6 +17,16 @@ * */ +/*!\file hmac.c + * HMAC algorithm. + * + * \see RFC2104 HMAC: Keyed-Hashing for Message Authentication. + * H. Krawczyk, M. Bellare, R. Canetti. + * + * \author Bob Deblier <bob.deblier@pandore.be> + * \ingroup HMAC_m + */ + #include "system.h" #include "hmac.h" #include "mp.h" @@ -35,105 +37,77 @@ #define HMAC_OPAD 0x5c /*@-boundswrite@*/ -int hmacSetup(hmacParam* hp, const hashFunction* hash, hashFunctionParam* param, const uint32* key, int keybits) +int hmacSetup(byte* kxi, byte* kxo, const hashFunction* hash, hashFunctionParam* param, const byte* key, size_t keybits) { register int i, rc; - int keywords = (((uint32)keybits + 31) >> 5); /* rounded up */ - int keybytes = (((uint32)keybits ) >> 3); + + size_t keybytes = (((uint32)keybits ) >> 3); /* if the key is too large, hash it first */ - if (keybytes > 64) + if (keybytes > hash->blocksize) { - uint32 keydigest[16]; - byte* tmp; - - /* if the hash digest is too large, this doesn't help */ - if (hash->digestsize > 64) + /* if the hash digest is too large, this doesn't help; this is really a sanity check */ + if (hash->digestsize > hash->blocksize) return -1; if (hash->reset(param)) return -1; - tmp = (byte*) malloc(keybytes); - - if (tmp == (byte*) 0) + if (hash->update(param, key, keybytes)) return -1; - /* before we can hash the key, we need to encode it! */ - (void) encodeIntsPartial(key, tmp, keybytes); - - rc = hash->update(param, tmp, keybytes); - free(tmp); - - if (rc) + if (hash->digest(param, kxi)) return -1; - memset(keydigest, 0, sizeof(keydigest)); - if (hash->digest(param, keydigest)) - return -1; - - keywords = hash->digestsize >> 2; - keybytes = hash->digestsize; - - (void) encodeInts(keydigest, hp->kxi, keybytes); - (void) encodeInts(keydigest, hp->kxo, keybytes); + memcpy(kxo, kxi, keybytes = hash->digestsize); } else if (keybytes > 0) { - (void) encodeIntsPartial(key, hp->kxi, keybytes); - (void) encodeIntsPartial(key, hp->kxo, keybytes); + memcpy(kxi, key, keybytes); + memcpy(kxo, key, keybytes); } else return -1; for (i = 0; i < keybytes; i++) { - hp->kxi[i] ^= HMAC_IPAD; - hp->kxo[i] ^= HMAC_OPAD; + kxi[i] ^= HMAC_IPAD; + kxo[i] ^= HMAC_OPAD; } - for (i = keybytes; i < 64; i++) + for (i = keybytes; i < hash->blocksize; i++) { - hp->kxi[i] = HMAC_IPAD; - hp->kxo[i] = HMAC_OPAD; + kxi[i] = HMAC_IPAD; + kxo[i] = HMAC_OPAD; } - return hmacReset(hp, hash, param); + return hmacReset(kxi, hash, param); } /*@=boundswrite@*/ -int hmacReset(hmacParam* hp, const hashFunction* hash, hashFunctionParam* param) +int hmacReset(const byte* kxi, const hashFunction* hash, hashFunctionParam* param) { if (hash->reset(param)) return -1; - - if (hash->update(param, hp->kxi, 64)) + if (hash->update(param, kxi, hash->blocksize)) return -1; return 0; } -int hmacUpdate(/*@unused@*/ hmacParam* hp, const hashFunction* hash, hashFunctionParam* param, const byte* data, int size) +int hmacUpdate(const hashFunction* hash, hashFunctionParam* param, const byte* data, size_t size) { return hash->update(param, data, size); } -int hmacDigest(hmacParam* hp, const hashFunction* hash, hashFunctionParam* param, uint32* data) +int hmacDigest(const byte* kxo, const hashFunction* hash, hashFunctionParam* param, byte* data) { if (hash->digest(param, data)) return -1; - - if (hash->update(param, hp->kxo, 64)) + if (hash->update(param, kxo, hash->blocksize)) return -1; - - /* digestsize is in bytes; divide by 4 to get the number of words */ - /*@-compdef@*/ /* FIX: *data undef ??? Code looks bogus ... */ - (void) encodeInts((const javaint*) data, (byte*) data, hash->digestsize >> 2); - /*@=compdef@*/ - - if (hash->update(param, (const byte*) data, hash->digestsize)) + if (hash->update(param, data, hash->digestsize)) return -1; - if (hash->digest(param, data)) return -1; |