aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConrad Meyer <cem@FreeBSD.org>2018-07-09 07:26:12 +0000
committerConrad Meyer <cem@FreeBSD.org>2018-07-09 07:26:12 +0000
commitc97f39ce17114100b5c463a7544912698193576a (patch)
tree31597bc9a73032d185ed04196460f851990c1bdb
parent1245c6d1a5984eeb64aa4d508874d48d966da823 (diff)
downloadsrc-c97f39ce17114100b5c463a7544912698193576a.tar.gz
src-c97f39ce17114100b5c463a7544912698193576a.zip
OCF: Add CRYPTO_SHA2_224_HMAC mode
Round out the complete set of basic SHA2 HMAC modes with SHA2-224. Support is added to the cryptocheck test tool.
Notes
Notes: svn path=/head/; revision=336124
-rw-r--r--sys/opencrypto/cryptodev.c3
-rw-r--r--sys/opencrypto/cryptodev.h5
-rw-r--r--sys/opencrypto/cryptosoft.c8
-rw-r--r--sys/opencrypto/xform_auth.h1
-rw-r--r--sys/opencrypto/xform_sha2.c21
-rw-r--r--tools/tools/crypto/cryptocheck.c2
6 files changed, 39 insertions, 1 deletions
diff --git a/sys/opencrypto/cryptodev.c b/sys/opencrypto/cryptodev.c
index d0a8e249a63b..e80de0c159a4 100644
--- a/sys/opencrypto/cryptodev.c
+++ b/sys/opencrypto/cryptodev.c
@@ -460,6 +460,9 @@ cryptof_ioctl(
case CRYPTO_SHA1_HMAC:
thash = &auth_hash_hmac_sha1;
break;
+ case CRYPTO_SHA2_224_HMAC:
+ thash = &auth_hash_hmac_sha2_224;
+ break;
case CRYPTO_SHA2_256_HMAC:
thash = &auth_hash_hmac_sha2_256;
break;
diff --git a/sys/opencrypto/cryptodev.h b/sys/opencrypto/cryptodev.h
index 18a8b22e7ab3..3c1b7b278b3d 100644
--- a/sys/opencrypto/cryptodev.h
+++ b/sys/opencrypto/cryptodev.h
@@ -74,6 +74,7 @@
#define MD5_HASH_LEN 16
#define SHA1_HASH_LEN 20
#define RIPEMD160_HASH_LEN 20
+#define SHA2_224_HASH_LEN 28
#define SHA2_256_HASH_LEN 32
#define SHA2_384_HASH_LEN 48
#define SHA2_512_HASH_LEN 64
@@ -86,6 +87,7 @@
#define MD5_BLOCK_LEN 64
#define SHA1_BLOCK_LEN 64
#define RIPEMD160_BLOCK_LEN 64
+#define SHA2_224_BLOCK_LEN 64
#define SHA2_256_BLOCK_LEN 64
#define SHA2_384_BLOCK_LEN 128
#define SHA2_512_BLOCK_LEN 128
@@ -183,7 +185,8 @@
#define CRYPTO_BLAKE2B 29 /* Blake2b hash */
#define CRYPTO_BLAKE2S 30 /* Blake2s hash */
#define CRYPTO_CHACHA20 31 /* Chacha20 stream cipher */
-#define CRYPTO_ALGORITHM_MAX 31 /* Keep updated - see below */
+#define CRYPTO_SHA2_224_HMAC 32
+#define CRYPTO_ALGORITHM_MAX 32 /* Keep updated - see below */
#define CRYPTO_ALGO_VALID(x) ((x) >= CRYPTO_ALGORITHM_MIN && \
(x) <= CRYPTO_ALGORITHM_MAX)
diff --git a/sys/opencrypto/cryptosoft.c b/sys/opencrypto/cryptosoft.c
index 1cab483c305b..dea8499bbf58 100644
--- a/sys/opencrypto/cryptosoft.c
+++ b/sys/opencrypto/cryptosoft.c
@@ -337,6 +337,7 @@ swcr_authprepare(struct auth_hash *axf, struct swcr_data *sw, u_char *key,
switch (axf->type) {
case CRYPTO_MD5_HMAC:
case CRYPTO_SHA1_HMAC:
+ case CRYPTO_SHA2_224_HMAC:
case CRYPTO_SHA2_256_HMAC:
case CRYPTO_SHA2_384_HMAC:
case CRYPTO_SHA2_512_HMAC:
@@ -422,6 +423,7 @@ swcr_authcompute(struct cryptodesc *crd, struct swcr_data *sw, caddr_t buf,
switch (sw->sw_alg) {
case CRYPTO_MD5_HMAC:
case CRYPTO_SHA1_HMAC:
+ case CRYPTO_SHA2_224_HMAC:
case CRYPTO_SHA2_256_HMAC:
case CRYPTO_SHA2_384_HMAC:
case CRYPTO_SHA2_512_HMAC:
@@ -853,6 +855,9 @@ swcr_newsession(device_t dev, u_int32_t *sid, struct cryptoini *cri)
case CRYPTO_SHA1_HMAC:
axf = &auth_hash_hmac_sha1;
goto authcommon;
+ case CRYPTO_SHA2_224_HMAC:
+ axf = &auth_hash_hmac_sha2_224;
+ goto authcommon;
case CRYPTO_SHA2_256_HMAC:
axf = &auth_hash_hmac_sha2_256;
goto authcommon;
@@ -1069,6 +1074,7 @@ swcr_freesession_locked(device_t dev, u_int64_t tid)
case CRYPTO_MD5_HMAC:
case CRYPTO_SHA1_HMAC:
+ case CRYPTO_SHA2_224_HMAC:
case CRYPTO_SHA2_256_HMAC:
case CRYPTO_SHA2_384_HMAC:
case CRYPTO_SHA2_512_HMAC:
@@ -1200,6 +1206,7 @@ swcr_process(device_t dev, struct cryptop *crp, int hint)
break;
case CRYPTO_MD5_HMAC:
case CRYPTO_SHA1_HMAC:
+ case CRYPTO_SHA2_224_HMAC:
case CRYPTO_SHA2_256_HMAC:
case CRYPTO_SHA2_384_HMAC:
case CRYPTO_SHA2_512_HMAC:
@@ -1283,6 +1290,7 @@ swcr_attach(device_t dev)
REGISTER(CRYPTO_NULL_CBC);
REGISTER(CRYPTO_MD5_HMAC);
REGISTER(CRYPTO_SHA1_HMAC);
+ REGISTER(CRYPTO_SHA2_224_HMAC);
REGISTER(CRYPTO_SHA2_256_HMAC);
REGISTER(CRYPTO_SHA2_384_HMAC);
REGISTER(CRYPTO_SHA2_512_HMAC);
diff --git a/sys/opencrypto/xform_auth.h b/sys/opencrypto/xform_auth.h
index 74c6d063037f..04654f9ada5d 100644
--- a/sys/opencrypto/xform_auth.h
+++ b/sys/opencrypto/xform_auth.h
@@ -69,6 +69,7 @@ extern struct auth_hash auth_hash_key_sha1;
extern struct auth_hash auth_hash_hmac_md5;
extern struct auth_hash auth_hash_hmac_sha1;
extern struct auth_hash auth_hash_hmac_ripemd_160;
+extern struct auth_hash auth_hash_hmac_sha2_224;
extern struct auth_hash auth_hash_hmac_sha2_256;
extern struct auth_hash auth_hash_hmac_sha2_384;
extern struct auth_hash auth_hash_hmac_sha2_512;
diff --git a/sys/opencrypto/xform_sha2.c b/sys/opencrypto/xform_sha2.c
index 2f4d60d85677..d9cbbb585de0 100644
--- a/sys/opencrypto/xform_sha2.c
+++ b/sys/opencrypto/xform_sha2.c
@@ -50,16 +50,30 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
+#include <crypto/sha2/sha224.h>
#include <crypto/sha2/sha256.h>
#include <crypto/sha2/sha384.h>
#include <crypto/sha2/sha512.h>
#include <opencrypto/xform_auth.h>
+static int SHA224Update_int(void *, const u_int8_t *, u_int16_t);
static int SHA256Update_int(void *, const u_int8_t *, u_int16_t);
static int SHA384Update_int(void *, const u_int8_t *, u_int16_t);
static int SHA512Update_int(void *, const u_int8_t *, u_int16_t);
/* Authentication instances */
+struct auth_hash auth_hash_hmac_sha2_224 = {
+ .type = CRYPTO_SHA2_224_HMAC,
+ .name = "HMAC-SHA2-224",
+ .keysize = SHA2_224_BLOCK_LEN,
+ .hashsize = SHA2_224_HASH_LEN,
+ .ctxsize = sizeof(SHA224_CTX),
+ .blocksize = SHA2_224_BLOCK_LEN,
+ .Init = (void (*)(void *)) SHA224_Init,
+ .Update = SHA224Update_int,
+ .Final = (void (*)(u_int8_t *, void *)) SHA224_Final,
+};
+
struct auth_hash auth_hash_hmac_sha2_256 = {
.type = CRYPTO_SHA2_256_HMAC,
.name = "HMAC-SHA2-256",
@@ -100,6 +114,13 @@ struct auth_hash auth_hash_hmac_sha2_512 = {
* And now for auth.
*/
static int
+SHA224Update_int(void *ctx, const u_int8_t *buf, u_int16_t len)
+{
+ SHA224_Update(ctx, buf, len);
+ return 0;
+}
+
+static int
SHA256Update_int(void *ctx, const u_int8_t *buf, u_int16_t len)
{
SHA256_Update(ctx, buf, len);
diff --git a/tools/tools/crypto/cryptocheck.c b/tools/tools/crypto/cryptocheck.c
index d5fb8a8c3bd7..8e7629856af0 100644
--- a/tools/tools/crypto/cryptocheck.c
+++ b/tools/tools/crypto/cryptocheck.c
@@ -137,6 +137,8 @@ struct alg {
} algs[] = {
{ .name = "sha1", .mac = CRYPTO_SHA1_HMAC, .type = T_HMAC,
.evp_md = EVP_sha1 },
+ { .name = "sha224", .mac = CRYPTO_SHA2_224_HMAC, .type = T_HMAC,
+ .evp_md = EVP_sha224 },
{ .name = "sha256", .mac = CRYPTO_SHA2_256_HMAC, .type = T_HMAC,
.evp_md = EVP_sha256 },
{ .name = "sha384", .mac = CRYPTO_SHA2_384_HMAC, .type = T_HMAC,