diff options
Diffstat (limited to 'sbin/isakmpd/hash.c')
-rw-r--r-- | sbin/isakmpd/hash.c | 112 |
1 files changed, 57 insertions, 55 deletions
diff --git a/sbin/isakmpd/hash.c b/sbin/isakmpd/hash.c index 978857eaba9..bf77af07836 100644 --- a/sbin/isakmpd/hash.c +++ b/sbin/isakmpd/hash.c @@ -1,5 +1,5 @@ -/* $OpenBSD: hash.c,v 1.14 2004/03/31 10:54:46 ho Exp $ */ -/* $EOM: hash.c,v 1.10 1999/04/17 23:20:34 niklas Exp $ */ +/* $OpenBSD: hash.c,v 1.15 2004/04/15 18:39:25 deraadt Exp $ */ +/* $EOM: hash.c,v 1.10 1999/04/17 23:20:34 niklas Exp $ */ /* * Copyright (c) 1998 Niels Provos. All rights reserved. @@ -38,20 +38,20 @@ #else #include <md5.h> #include <sha1.h> -#endif /* __APPLE__ */ +#endif /* __APPLE__ */ #include "sysdep.h" #include "hash.h" #include "log.h" -void hmac_init (struct hash *, unsigned char *, unsigned int); -void hmac_final (unsigned char *, struct hash *); +void hmac_init(struct hash *, unsigned char *, unsigned int); +void hmac_final(unsigned char *, struct hash *); /* Temporary hash contexts. */ static union { - MD5_CTX md5ctx; - SHA1_CTX sha1ctx; + MD5_CTX md5ctx; + SHA1_CTX sha1ctx; } Ctx, Ctx2; /* Temporary hash digest. */ @@ -60,32 +60,37 @@ static unsigned char digest[HASH_MAX]; /* Encapsulation of hash functions. */ static struct hash hashes[] = { - { HASH_MD5, 5, MD5_SIZE, (void *)&Ctx.md5ctx, digest, - sizeof (MD5_CTX), (void *)&Ctx2.md5ctx, - (void (*) (void *))MD5Init, - (void (*) (void *, unsigned char *, unsigned int))MD5Update, - (void (*) (unsigned char *, void *))MD5Final, - hmac_init, hmac_final }, - { HASH_SHA1, 6, SHA1_SIZE, (void *)&Ctx.sha1ctx, digest, - sizeof (SHA1_CTX), (void *)&Ctx2.sha1ctx, - (void (*) (void *))SHA1Init, - (void (*) (void *, unsigned char *, unsigned int))SHA1Update, - (void (*) (unsigned char *, void *))SHA1Final, - hmac_init, hmac_final }, + { + HASH_MD5, 5, MD5_SIZE, (void *) &Ctx.md5ctx, digest, + sizeof(MD5_CTX), (void *) &Ctx2.md5ctx, + (void (*) (void *)) MD5Init, + (void (*) (void *, unsigned char *, unsigned int)) MD5Update, + (void (*) (unsigned char *, void *)) MD5Final, + hmac_init, + hmac_final + }, { + HASH_SHA1, 6, SHA1_SIZE, (void *) &Ctx.sha1ctx, digest, + sizeof(SHA1_CTX), (void *) &Ctx2.sha1ctx, + (void (*) (void *)) SHA1Init, + (void (*) (void *, unsigned char *, unsigned int)) SHA1Update, + (void (*) (unsigned char *, void *)) SHA1Final, + hmac_init, + hmac_final + }, }; struct hash * -hash_get (enum hashes hashtype) +hash_get(enum hashes hashtype) { - size_t i; + size_t i; - LOG_DBG ((LOG_CRYPTO, 60, "hash_get: requested algorithm %d", hashtype)); + LOG_DBG((LOG_CRYPTO, 60, "hash_get: requested algorithm %d", hashtype)); - for (i = 0; i < sizeof hashes / sizeof hashes[0]; i++) - if (hashtype == hashes[i].type) - return &hashes[i]; + for (i = 0; i < sizeof hashes / sizeof hashes[0]; i++) + if (hashtype == hashes[i].type) + return &hashes[i]; - return 0; + return 0; } /* @@ -95,38 +100,35 @@ hash_get (enum hashes hashtype) */ void -hmac_init (struct hash *hash, unsigned char *okey, unsigned int len) +hmac_init(struct hash *hash, unsigned char *okey, unsigned int len) { - unsigned int i, blocklen = HMAC_BLOCKLEN; - unsigned char key[HMAC_BLOCKLEN]; + unsigned int i, blocklen = HMAC_BLOCKLEN; + unsigned char key[HMAC_BLOCKLEN]; - memset (key, 0, blocklen); - if (len > blocklen) - { - /* Truncate key down to blocklen */ - hash->Init (hash->ctx); - hash->Update (hash->ctx, okey, len); - hash->Final (key, hash->ctx); - } - else - { - memcpy (key, okey, len); - } + memset(key, 0, blocklen); + if (len > blocklen) { + /* Truncate key down to blocklen */ + hash->Init(hash->ctx); + hash->Update(hash->ctx, okey, len); + hash->Final(key, hash->ctx); + } else { + memcpy(key, okey, len); + } - /* HMAC I and O pad computation */ - for (i = 0; i < blocklen; i++) - key[i] ^= HMAC_IPAD_VAL; + /* HMAC I and O pad computation */ + for (i = 0; i < blocklen; i++) + key[i] ^= HMAC_IPAD_VAL; - hash->Init (hash->ctx); - hash->Update (hash->ctx, key, blocklen); + hash->Init(hash->ctx); + hash->Update(hash->ctx, key, blocklen); - for (i = 0; i < blocklen; i++) - key[i] ^= (HMAC_IPAD_VAL ^ HMAC_OPAD_VAL); + for (i = 0; i < blocklen; i++) + key[i] ^= (HMAC_IPAD_VAL ^ HMAC_OPAD_VAL); - hash->Init (hash->ctx2); - hash->Update (hash->ctx2, key, blocklen); + hash->Init(hash->ctx2); + hash->Update(hash->ctx2, key, blocklen); - memset (key, 0, blocklen); + memset(key, 0, blocklen); } /* @@ -134,9 +136,9 @@ hmac_init (struct hash *hash, unsigned char *okey, unsigned int len) */ void -hmac_final (unsigned char *dgst, struct hash *hash) +hmac_final(unsigned char *dgst, struct hash *hash) { - hash->Final (dgst, hash->ctx); - hash->Update (hash->ctx2, dgst, hash->hashsize); - hash->Final (dgst, hash->ctx2); + hash->Final(dgst, hash->ctx); + hash->Update(hash->ctx2, dgst, hash->hashsize); + hash->Final(dgst, hash->ctx2); } |