summaryrefslogtreecommitdiff
path: root/sys/crypto
diff options
context:
space:
mode:
authorChristian Weisgerber <naddy@cvs.openbsd.org>2015-11-07 01:37:27 +0000
committerChristian Weisgerber <naddy@cvs.openbsd.org>2015-11-07 01:37:27 +0000
commit966a9b7591f8b4daf8ce119a6690e0575ffec433 (patch)
treea110966e36d9687ebd13f730a77bb3257e543099 /sys/crypto
parentacfe0a6f79f135c701e5b2ce57db63a0703470e7 (diff)
Allow overriding ghash_update() with an optimized MD function. Use
this on amd64 to provide a version that uses the PCLMUL instruction on CPUs that support it but don't have AESNI. ok mikeb@
Diffstat (limited to 'sys/crypto')
-rw-r--r--sys/crypto/gmac.c14
-rw-r--r--sys/crypto/gmac.h4
2 files changed, 12 insertions, 6 deletions
diff --git a/sys/crypto/gmac.c b/sys/crypto/gmac.c
index 4dd2019edb2..cff97e50be0 100644
--- a/sys/crypto/gmac.c
+++ b/sys/crypto/gmac.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gmac.c,v 1.5 2015/11/06 16:43:51 naddy Exp $ */
+/* $OpenBSD: gmac.c,v 1.6 2015/11/07 01:37:26 naddy Exp $ */
/*
* Copyright (c) 2010 Mike Belopuhov <mike@vantronix.net>
@@ -29,7 +29,10 @@
#include <crypto/gmac.h>
void ghash_gfmul(uint32_t *, uint32_t *, uint32_t *);
-void ghash_update(GHASH_CTX *, uint8_t *, size_t);
+void ghash_update_mi(GHASH_CTX *, uint8_t *, size_t);
+
+/* Allow overriding with optimized MD function */
+void (*ghash_update)(GHASH_CTX *, uint8_t *, size_t) = ghash_update_mi;
/* Computes a block multiplication in the GF(2^128) */
void
@@ -70,7 +73,7 @@ ghash_gfmul(uint32_t *X, uint32_t *Y, uint32_t *product)
}
void
-ghash_update(GHASH_CTX *ctx, uint8_t *X, size_t len)
+ghash_update_mi(GHASH_CTX *ctx, uint8_t *X, size_t len)
{
uint32_t *x = (uint32_t *)X;
uint32_t *s = (uint32_t *)ctx->S;
@@ -131,11 +134,12 @@ AES_GMAC_Update(AES_GMAC_CTX *ctx, const uint8_t *data, uint16_t len)
if (len > 0) {
plen = len % GMAC_BLOCK_LEN;
if (len >= GMAC_BLOCK_LEN)
- ghash_update(&ctx->ghash, (uint8_t *)data, len - plen);
+ (*ghash_update)(&ctx->ghash, (uint8_t *)data,
+ len - plen);
if (plen) {
bcopy((uint8_t *)data + (len - plen), (uint8_t *)blk,
plen);
- ghash_update(&ctx->ghash, (uint8_t *)blk,
+ (*ghash_update)(&ctx->ghash, (uint8_t *)blk,
GMAC_BLOCK_LEN);
}
}
diff --git a/sys/crypto/gmac.h b/sys/crypto/gmac.h
index 94c1247bbd7..393b21d302d 100644
--- a/sys/crypto/gmac.h
+++ b/sys/crypto/gmac.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: gmac.h,v 1.2 2012/12/05 23:20:15 deraadt Exp $ */
+/* $OpenBSD: gmac.h,v 1.3 2015/11/07 01:37:26 naddy Exp $ */
/*
* Copyright (c) 2010 Mike Belopuhov <mike@vantronix.net>
@@ -38,6 +38,8 @@ typedef struct _AES_GMAC_CTX {
} 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);