diff options
author | 2015-11-07 17:46:07 +0000 | |
---|---|---|
committer | 2015-11-07 17:46:07 +0000 | |
commit | ef3fdbac49973e81bffb70e7e9ea323f3039dae5 (patch) | |
tree | c11b61890defcab25fa854fb2cbc7379c31c5074 /sys/crypto | |
parent | In private header files, __BEGIN_DECLS and __END_DECLS are pointless. (diff) | |
download | wireguard-openbsd-ef3fdbac49973e81bffb70e7e9ea323f3039dae5.tar.xz wireguard-openbsd-ef3fdbac49973e81bffb70e7e9ea323f3039dae5.zip |
Pass AES_GMAC context as a void pointer to cut down on casts in xform.c
Diffstat (limited to 'sys/crypto')
-rw-r--r-- | sys/crypto/gmac.c | 20 | ||||
-rw-r--r-- | sys/crypto/gmac.h | 12 | ||||
-rw-r--r-- | sys/crypto/xform.c | 23 |
3 files changed, 27 insertions, 28 deletions
diff --git a/sys/crypto/gmac.c b/sys/crypto/gmac.c index cff97e50be0..3a03599f70b 100644 --- a/sys/crypto/gmac.c +++ b/sys/crypto/gmac.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gmac.c,v 1.6 2015/11/07 01:37:26 naddy Exp $ */ +/* $OpenBSD: gmac.c,v 1.7 2015/11/07 17:46:07 mikeb Exp $ */ /* * Copyright (c) 2010 Mike Belopuhov <mike@vantronix.net> @@ -99,8 +99,10 @@ ghash_update_mi(GHASH_CTX *ctx, uint8_t *X, size_t len) #define AESCTR_NONCESIZE 4 void -AES_GMAC_Init(AES_GMAC_CTX *ctx) +AES_GMAC_Init(void *xctx) { + AES_GMAC_CTX *ctx = xctx; + bzero(ctx->ghash.H, GMAC_BLOCK_LEN); bzero(ctx->ghash.S, GMAC_BLOCK_LEN); bzero(ctx->ghash.Z, GMAC_BLOCK_LEN); @@ -108,8 +110,10 @@ AES_GMAC_Init(AES_GMAC_CTX *ctx) } void -AES_GMAC_Setkey(AES_GMAC_CTX *ctx, const uint8_t *key, uint16_t klen) +AES_GMAC_Setkey(void *xctx, const uint8_t *key, uint16_t klen) { + AES_GMAC_CTX *ctx = xctx; + ctx->rounds = rijndaelKeySetupEnc(ctx->K, (u_char *)key, (klen - AESCTR_NONCESIZE) * 8); /* copy out salt to the counter block */ @@ -119,15 +123,18 @@ AES_GMAC_Setkey(AES_GMAC_CTX *ctx, const uint8_t *key, uint16_t klen) } void -AES_GMAC_Reinit(AES_GMAC_CTX *ctx, const uint8_t *iv, uint16_t ivlen) +AES_GMAC_Reinit(void *xctx, const uint8_t *iv, uint16_t ivlen) { + AES_GMAC_CTX *ctx = xctx; + /* copy out IV to the counter block */ bcopy(iv, ctx->J + AESCTR_NONCESIZE, ivlen); } int -AES_GMAC_Update(AES_GMAC_CTX *ctx, const uint8_t *data, uint16_t len) +AES_GMAC_Update(void *xctx, const uint8_t *data, uint16_t len) { + AES_GMAC_CTX *ctx = xctx; uint32_t blk[4] = { 0, 0, 0, 0 }; int plen; @@ -147,8 +154,9 @@ AES_GMAC_Update(AES_GMAC_CTX *ctx, const uint8_t *data, uint16_t len) } void -AES_GMAC_Final(uint8_t digest[GMAC_DIGEST_LEN], AES_GMAC_CTX *ctx) +AES_GMAC_Final(uint8_t digest[GMAC_DIGEST_LEN], void *xctx) { + AES_GMAC_CTX *ctx = xctx; uint8_t keystream[GMAC_BLOCK_LEN]; int i; diff --git a/sys/crypto/gmac.h b/sys/crypto/gmac.h index 393b21d302d..07a4adb1a54 100644 --- a/sys/crypto/gmac.h +++ b/sys/crypto/gmac.h @@ -1,4 +1,4 @@ -/* $OpenBSD: gmac.h,v 1.3 2015/11/07 01:37:26 naddy Exp $ */ +/* $OpenBSD: gmac.h,v 1.4 2015/11/07 17:46:07 mikeb Exp $ */ /* * Copyright (c) 2010 Mike Belopuhov <mike@vantronix.net> @@ -40,11 +40,11 @@ typedef struct _AES_GMAC_CTX { __BEGIN_DECLS extern void (*ghash_update)(GHASH_CTX *, uint8_t *, size_t); -void AES_GMAC_Init(AES_GMAC_CTX *); -void AES_GMAC_Setkey(AES_GMAC_CTX *, const uint8_t *, uint16_t); -void AES_GMAC_Reinit(AES_GMAC_CTX *, const uint8_t *, uint16_t); -int AES_GMAC_Update(AES_GMAC_CTX *, const uint8_t *, uint16_t); -void AES_GMAC_Final(uint8_t [GMAC_DIGEST_LEN], AES_GMAC_CTX *); +void AES_GMAC_Init(void *); +void AES_GMAC_Setkey(void *, const uint8_t *, uint16_t); +void AES_GMAC_Reinit(void *, const uint8_t *, uint16_t); +int AES_GMAC_Update(void *, const uint8_t *, uint16_t); +void AES_GMAC_Final(uint8_t [GMAC_DIGEST_LEN], void *); __END_DECLS #endif /* _GMAC_H_ */ diff --git a/sys/crypto/xform.c b/sys/crypto/xform.c index da1b107747d..8c72b067c68 100644 --- a/sys/crypto/xform.c +++ b/sys/crypto/xform.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xform.c,v 1.49 2015/11/04 12:32:37 mikeb Exp $ */ +/* $OpenBSD: xform.c,v 1.50 2015/11/07 17:46:07 mikeb Exp $ */ /* * The authors of this code are John Ioannidis (ji@tla.org), * Angelos D. Keromytis (kermit@csd.uch.gr), @@ -297,31 +297,22 @@ struct auth_hash auth_hash_hmac_sha2_512_256 = { struct auth_hash auth_hash_gmac_aes_128 = { CRYPTO_AES_128_GMAC, "GMAC-AES-128", 16+4, GMAC_BLOCK_LEN, GMAC_DIGEST_LEN, sizeof(AES_GMAC_CTX), - AESCTR_BLOCKSIZE, (void (*)(void *)) AES_GMAC_Init, - (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Setkey, - (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Reinit, - (int (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Update, - (void (*)(u_int8_t *, void *)) AES_GMAC_Final + AESCTR_BLOCKSIZE, AES_GMAC_Init, AES_GMAC_Setkey, AES_GMAC_Reinit, + AES_GMAC_Update, AES_GMAC_Final }; struct auth_hash auth_hash_gmac_aes_192 = { CRYPTO_AES_192_GMAC, "GMAC-AES-192", 24+4, GMAC_BLOCK_LEN, GMAC_DIGEST_LEN, sizeof(AES_GMAC_CTX), - AESCTR_BLOCKSIZE, (void (*)(void *)) AES_GMAC_Init, - (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Setkey, - (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Reinit, - (int (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Update, - (void (*)(u_int8_t *, void *)) AES_GMAC_Final + AESCTR_BLOCKSIZE, AES_GMAC_Init, AES_GMAC_Setkey, AES_GMAC_Reinit, + AES_GMAC_Update, AES_GMAC_Final }; struct auth_hash auth_hash_gmac_aes_256 = { CRYPTO_AES_256_GMAC, "GMAC-AES-256", 32+4, GMAC_BLOCK_LEN, GMAC_DIGEST_LEN, sizeof(AES_GMAC_CTX), - AESCTR_BLOCKSIZE, (void (*)(void *)) AES_GMAC_Init, - (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Setkey, - (void (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Reinit, - (int (*)(void *, const u_int8_t *, u_int16_t)) AES_GMAC_Update, - (void (*)(u_int8_t *, void *)) AES_GMAC_Final + AESCTR_BLOCKSIZE, AES_GMAC_Init, AES_GMAC_Setkey, AES_GMAC_Reinit, + AES_GMAC_Update, AES_GMAC_Final }; struct auth_hash auth_hash_chacha20_poly1305 = { |