summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormikeb <mikeb@openbsd.org>2015-11-04 12:32:37 +0000
committermikeb <mikeb@openbsd.org>2015-11-04 12:32:37 +0000
commita9a4b78e0176f5d3038511d03dd3a2fded4b69b8 (patch)
tree58e483b41788e0f0f42ec72024eb171f2dc5d8f1
parentHook up chacha20-poly1305 test vectors (missed in previous commit) (diff)
downloadwireguard-openbsd-a9a4b78e0176f5d3038511d03dd3a2fded4b69b8.tar.xz
wireguard-openbsd-a9a4b78e0176f5d3038511d03dd3a2fded4b69b8.zip
Pass context as a void pointer to cut down on casts in xform.c
-rw-r--r--sys/crypto/chachapoly.c24
-rw-r--r--sys/crypto/chachapoly.h14
-rw-r--r--sys/crypto/xform.c10
3 files changed, 24 insertions, 24 deletions
diff --git a/sys/crypto/chachapoly.c b/sys/crypto/chachapoly.c
index 76d3e591729..013220900b0 100644
--- a/sys/crypto/chachapoly.c
+++ b/sys/crypto/chachapoly.c
@@ -55,15 +55,18 @@ chacha20_crypt(caddr_t key, u_int8_t *data)
}
void
-Chacha20_Poly1305_Init(CHACHA20_POLY1305_CTX *ctx)
+Chacha20_Poly1305_Init(void *xctx)
{
+ CHACHA20_POLY1305_CTX *ctx = xctx;
+
memset(ctx, 0, sizeof(*ctx));
}
void
-Chacha20_Poly1305_Setkey(CHACHA20_POLY1305_CTX *ctx, const uint8_t *key,
- uint16_t klen)
+Chacha20_Poly1305_Setkey(void *xctx, const uint8_t *key, uint16_t klen)
{
+ CHACHA20_POLY1305_CTX *ctx = xctx;
+
/* salt is provided with the key material */
memcpy(ctx->nonce + CHACHA20_CTR, key + CHACHA20_KEYSIZE,
CHACHA20_SALT);
@@ -71,9 +74,10 @@ Chacha20_Poly1305_Setkey(CHACHA20_POLY1305_CTX *ctx, const uint8_t *key,
}
void
-Chacha20_Poly1305_Reinit(CHACHA20_POLY1305_CTX *ctx, const uint8_t *iv,
- uint16_t ivlen)
+Chacha20_Poly1305_Reinit(void *xctx, const uint8_t *iv, uint16_t ivlen)
{
+ CHACHA20_POLY1305_CTX *ctx = xctx;
+
/* initial counter is 0 */
chacha_ivsetup((chacha_ctx *)&ctx->chacha, iv, ctx->nonce);
chacha_encrypt_bytes((chacha_ctx *)&ctx->chacha, ctx->key, ctx->key,
@@ -82,9 +86,10 @@ Chacha20_Poly1305_Reinit(CHACHA20_POLY1305_CTX *ctx, const uint8_t *iv,
}
int
-Chacha20_Poly1305_Update(CHACHA20_POLY1305_CTX *ctx, const uint8_t *data,
- uint16_t len)
+Chacha20_Poly1305_Update(void *xctx, const uint8_t *data, uint16_t len)
{
+ CHACHA20_POLY1305_CTX *ctx = xctx;
+
static const char zeroes[POLY1305_BLOCK_LEN];
size_t rem;
@@ -99,9 +104,10 @@ Chacha20_Poly1305_Update(CHACHA20_POLY1305_CTX *ctx, const uint8_t *data,
}
void
-Chacha20_Poly1305_Final(uint8_t tag[POLY1305_TAGLEN],
- CHACHA20_POLY1305_CTX *ctx)
+Chacha20_Poly1305_Final(uint8_t tag[POLY1305_TAGLEN], void *xctx)
{
+ CHACHA20_POLY1305_CTX *ctx = xctx;
+
poly1305_finish((poly1305_state *)&ctx->poly, tag);
explicit_bzero(ctx, sizeof(*ctx));
}
diff --git a/sys/crypto/chachapoly.h b/sys/crypto/chachapoly.h
index b2f162248ff..60ced96504a 100644
--- a/sys/crypto/chachapoly.h
+++ b/sys/crypto/chachapoly.h
@@ -53,14 +53,10 @@ typedef struct {
struct poly1305_ctx poly;
} CHACHA20_POLY1305_CTX;
-void Chacha20_Poly1305_Init(CHACHA20_POLY1305_CTX *);
-void Chacha20_Poly1305_Setkey(CHACHA20_POLY1305_CTX *, const uint8_t *,
- uint16_t);
-void Chacha20_Poly1305_Reinit(CHACHA20_POLY1305_CTX *, const uint8_t *,
- uint16_t);
-int Chacha20_Poly1305_Update(CHACHA20_POLY1305_CTX *, const uint8_t *,
- uint16_t);
-void Chacha20_Poly1305_Final(uint8_t[POLY1305_TAGLEN],
- CHACHA20_POLY1305_CTX *);
+void Chacha20_Poly1305_Init(void *);
+void Chacha20_Poly1305_Setkey(void *, const uint8_t *, uint16_t);
+void Chacha20_Poly1305_Reinit(void *, const uint8_t *, uint16_t);
+int Chacha20_Poly1305_Update(void *, const uint8_t *, uint16_t);
+void Chacha20_Poly1305_Final(uint8_t[POLY1305_TAGLEN], void *);
#endif /* _CHACHAPOLY_H_ */
diff --git a/sys/crypto/xform.c b/sys/crypto/xform.c
index 27b30689475..da1b107747d 100644
--- a/sys/crypto/xform.c
+++ b/sys/crypto/xform.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: xform.c,v 1.48 2015/11/03 01:31:36 mikeb Exp $ */
+/* $OpenBSD: xform.c,v 1.49 2015/11/04 12:32:37 mikeb Exp $ */
/*
* The authors of this code are John Ioannidis (ji@tla.org),
* Angelos D. Keromytis (kermit@csd.uch.gr),
@@ -328,11 +328,9 @@ struct auth_hash auth_hash_chacha20_poly1305 = {
CRYPTO_CHACHA20_POLY1305_MAC, "CHACHA20-POLY1305",
CHACHA20_KEYSIZE+CHACHA20_SALT, POLY1305_BLOCK_LEN, POLY1305_TAGLEN,
sizeof(CHACHA20_POLY1305_CTX), CHACHA20_BLOCK_LEN,
- (void (*)(void *))Chacha20_Poly1305_Init,
- (void (*)(void *, const u_int8_t *, u_int16_t))Chacha20_Poly1305_Setkey,
- (void (*)(void *, const u_int8_t *, u_int16_t))Chacha20_Poly1305_Reinit,
- (int (*)(void *, const u_int8_t *, u_int16_t))Chacha20_Poly1305_Update,
- (void (*)(u_int8_t *, void *))Chacha20_Poly1305_Final
+ Chacha20_Poly1305_Init, Chacha20_Poly1305_Setkey,
+ Chacha20_Poly1305_Reinit, Chacha20_Poly1305_Update,
+ Chacha20_Poly1305_Final
};
struct auth_hash auth_hash_md5 = {