Date: Mon, 9 Jul 2018 07:26:13 +0000 (UTC) From: Conrad Meyer <cem@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r336124 - in head: sys/opencrypto tools/tools/crypto Message-ID: <201807090726.w697QDfg025115@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: cem Date: Mon Jul 9 07:26:12 2018 New Revision: 336124 URL: https://svnweb.freebsd.org/changeset/base/336124 Log: 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. Modified: head/sys/opencrypto/cryptodev.c head/sys/opencrypto/cryptodev.h head/sys/opencrypto/cryptosoft.c head/sys/opencrypto/xform_auth.h head/sys/opencrypto/xform_sha2.c head/tools/tools/crypto/cryptocheck.c Modified: head/sys/opencrypto/cryptodev.c ============================================================================== --- head/sys/opencrypto/cryptodev.c Mon Jul 9 07:24:05 2018 (r336123) +++ head/sys/opencrypto/cryptodev.c Mon Jul 9 07:26:12 2018 (r336124) @@ -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; Modified: head/sys/opencrypto/cryptodev.h ============================================================================== --- head/sys/opencrypto/cryptodev.h Mon Jul 9 07:24:05 2018 (r336123) +++ head/sys/opencrypto/cryptodev.h Mon Jul 9 07:26:12 2018 (r336124) @@ -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) Modified: head/sys/opencrypto/cryptosoft.c ============================================================================== --- head/sys/opencrypto/cryptosoft.c Mon Jul 9 07:24:05 2018 (r336123) +++ head/sys/opencrypto/cryptosoft.c Mon Jul 9 07:26:12 2018 (r336124) @@ -337,6 +337,7 @@ swcr_authprepare(struct auth_hash *axf, struct swcr_da 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_d 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 c 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 hi 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); Modified: head/sys/opencrypto/xform_auth.h ============================================================================== --- head/sys/opencrypto/xform_auth.h Mon Jul 9 07:24:05 2018 (r336123) +++ head/sys/opencrypto/xform_auth.h Mon Jul 9 07:26:12 2018 (r336124) @@ -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; Modified: head/sys/opencrypto/xform_sha2.c ============================================================================== --- head/sys/opencrypto/xform_sha2.c Mon Jul 9 07:24:05 2018 (r336123) +++ head/sys/opencrypto/xform_sha2.c Mon Jul 9 07:26:12 2018 (r336124) @@ -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", @@ -99,6 +113,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) { Modified: head/tools/tools/crypto/cryptocheck.c ============================================================================== --- head/tools/tools/crypto/cryptocheck.c Mon Jul 9 07:24:05 2018 (r336123) +++ head/tools/tools/crypto/cryptocheck.c Mon Jul 9 07:26:12 2018 (r336124) @@ -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,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201807090726.w697QDfg025115>