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.
This commit is contained in:
parent
1245c6d1a5
commit
c97f39ce17
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=336124
@ -460,6 +460,9 @@ cryptof_ioctl(
|
|||||||
case CRYPTO_SHA1_HMAC:
|
case CRYPTO_SHA1_HMAC:
|
||||||
thash = &auth_hash_hmac_sha1;
|
thash = &auth_hash_hmac_sha1;
|
||||||
break;
|
break;
|
||||||
|
case CRYPTO_SHA2_224_HMAC:
|
||||||
|
thash = &auth_hash_hmac_sha2_224;
|
||||||
|
break;
|
||||||
case CRYPTO_SHA2_256_HMAC:
|
case CRYPTO_SHA2_256_HMAC:
|
||||||
thash = &auth_hash_hmac_sha2_256;
|
thash = &auth_hash_hmac_sha2_256;
|
||||||
break;
|
break;
|
||||||
|
@ -74,6 +74,7 @@
|
|||||||
#define MD5_HASH_LEN 16
|
#define MD5_HASH_LEN 16
|
||||||
#define SHA1_HASH_LEN 20
|
#define SHA1_HASH_LEN 20
|
||||||
#define RIPEMD160_HASH_LEN 20
|
#define RIPEMD160_HASH_LEN 20
|
||||||
|
#define SHA2_224_HASH_LEN 28
|
||||||
#define SHA2_256_HASH_LEN 32
|
#define SHA2_256_HASH_LEN 32
|
||||||
#define SHA2_384_HASH_LEN 48
|
#define SHA2_384_HASH_LEN 48
|
||||||
#define SHA2_512_HASH_LEN 64
|
#define SHA2_512_HASH_LEN 64
|
||||||
@ -86,6 +87,7 @@
|
|||||||
#define MD5_BLOCK_LEN 64
|
#define MD5_BLOCK_LEN 64
|
||||||
#define SHA1_BLOCK_LEN 64
|
#define SHA1_BLOCK_LEN 64
|
||||||
#define RIPEMD160_BLOCK_LEN 64
|
#define RIPEMD160_BLOCK_LEN 64
|
||||||
|
#define SHA2_224_BLOCK_LEN 64
|
||||||
#define SHA2_256_BLOCK_LEN 64
|
#define SHA2_256_BLOCK_LEN 64
|
||||||
#define SHA2_384_BLOCK_LEN 128
|
#define SHA2_384_BLOCK_LEN 128
|
||||||
#define SHA2_512_BLOCK_LEN 128
|
#define SHA2_512_BLOCK_LEN 128
|
||||||
@ -183,7 +185,8 @@
|
|||||||
#define CRYPTO_BLAKE2B 29 /* Blake2b hash */
|
#define CRYPTO_BLAKE2B 29 /* Blake2b hash */
|
||||||
#define CRYPTO_BLAKE2S 30 /* Blake2s hash */
|
#define CRYPTO_BLAKE2S 30 /* Blake2s hash */
|
||||||
#define CRYPTO_CHACHA20 31 /* Chacha20 stream cipher */
|
#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 && \
|
#define CRYPTO_ALGO_VALID(x) ((x) >= CRYPTO_ALGORITHM_MIN && \
|
||||||
(x) <= CRYPTO_ALGORITHM_MAX)
|
(x) <= CRYPTO_ALGORITHM_MAX)
|
||||||
|
@ -337,6 +337,7 @@ swcr_authprepare(struct auth_hash *axf, struct swcr_data *sw, u_char *key,
|
|||||||
switch (axf->type) {
|
switch (axf->type) {
|
||||||
case CRYPTO_MD5_HMAC:
|
case CRYPTO_MD5_HMAC:
|
||||||
case CRYPTO_SHA1_HMAC:
|
case CRYPTO_SHA1_HMAC:
|
||||||
|
case CRYPTO_SHA2_224_HMAC:
|
||||||
case CRYPTO_SHA2_256_HMAC:
|
case CRYPTO_SHA2_256_HMAC:
|
||||||
case CRYPTO_SHA2_384_HMAC:
|
case CRYPTO_SHA2_384_HMAC:
|
||||||
case CRYPTO_SHA2_512_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) {
|
switch (sw->sw_alg) {
|
||||||
case CRYPTO_MD5_HMAC:
|
case CRYPTO_MD5_HMAC:
|
||||||
case CRYPTO_SHA1_HMAC:
|
case CRYPTO_SHA1_HMAC:
|
||||||
|
case CRYPTO_SHA2_224_HMAC:
|
||||||
case CRYPTO_SHA2_256_HMAC:
|
case CRYPTO_SHA2_256_HMAC:
|
||||||
case CRYPTO_SHA2_384_HMAC:
|
case CRYPTO_SHA2_384_HMAC:
|
||||||
case CRYPTO_SHA2_512_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:
|
case CRYPTO_SHA1_HMAC:
|
||||||
axf = &auth_hash_hmac_sha1;
|
axf = &auth_hash_hmac_sha1;
|
||||||
goto authcommon;
|
goto authcommon;
|
||||||
|
case CRYPTO_SHA2_224_HMAC:
|
||||||
|
axf = &auth_hash_hmac_sha2_224;
|
||||||
|
goto authcommon;
|
||||||
case CRYPTO_SHA2_256_HMAC:
|
case CRYPTO_SHA2_256_HMAC:
|
||||||
axf = &auth_hash_hmac_sha2_256;
|
axf = &auth_hash_hmac_sha2_256;
|
||||||
goto authcommon;
|
goto authcommon;
|
||||||
@ -1069,6 +1074,7 @@ swcr_freesession_locked(device_t dev, u_int64_t tid)
|
|||||||
|
|
||||||
case CRYPTO_MD5_HMAC:
|
case CRYPTO_MD5_HMAC:
|
||||||
case CRYPTO_SHA1_HMAC:
|
case CRYPTO_SHA1_HMAC:
|
||||||
|
case CRYPTO_SHA2_224_HMAC:
|
||||||
case CRYPTO_SHA2_256_HMAC:
|
case CRYPTO_SHA2_256_HMAC:
|
||||||
case CRYPTO_SHA2_384_HMAC:
|
case CRYPTO_SHA2_384_HMAC:
|
||||||
case CRYPTO_SHA2_512_HMAC:
|
case CRYPTO_SHA2_512_HMAC:
|
||||||
@ -1200,6 +1206,7 @@ swcr_process(device_t dev, struct cryptop *crp, int hint)
|
|||||||
break;
|
break;
|
||||||
case CRYPTO_MD5_HMAC:
|
case CRYPTO_MD5_HMAC:
|
||||||
case CRYPTO_SHA1_HMAC:
|
case CRYPTO_SHA1_HMAC:
|
||||||
|
case CRYPTO_SHA2_224_HMAC:
|
||||||
case CRYPTO_SHA2_256_HMAC:
|
case CRYPTO_SHA2_256_HMAC:
|
||||||
case CRYPTO_SHA2_384_HMAC:
|
case CRYPTO_SHA2_384_HMAC:
|
||||||
case CRYPTO_SHA2_512_HMAC:
|
case CRYPTO_SHA2_512_HMAC:
|
||||||
@ -1283,6 +1290,7 @@ swcr_attach(device_t dev)
|
|||||||
REGISTER(CRYPTO_NULL_CBC);
|
REGISTER(CRYPTO_NULL_CBC);
|
||||||
REGISTER(CRYPTO_MD5_HMAC);
|
REGISTER(CRYPTO_MD5_HMAC);
|
||||||
REGISTER(CRYPTO_SHA1_HMAC);
|
REGISTER(CRYPTO_SHA1_HMAC);
|
||||||
|
REGISTER(CRYPTO_SHA2_224_HMAC);
|
||||||
REGISTER(CRYPTO_SHA2_256_HMAC);
|
REGISTER(CRYPTO_SHA2_256_HMAC);
|
||||||
REGISTER(CRYPTO_SHA2_384_HMAC);
|
REGISTER(CRYPTO_SHA2_384_HMAC);
|
||||||
REGISTER(CRYPTO_SHA2_512_HMAC);
|
REGISTER(CRYPTO_SHA2_512_HMAC);
|
||||||
|
@ -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_md5;
|
||||||
extern struct auth_hash auth_hash_hmac_sha1;
|
extern struct auth_hash auth_hash_hmac_sha1;
|
||||||
extern struct auth_hash auth_hash_hmac_ripemd_160;
|
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_256;
|
||||||
extern struct auth_hash auth_hash_hmac_sha2_384;
|
extern struct auth_hash auth_hash_hmac_sha2_384;
|
||||||
extern struct auth_hash auth_hash_hmac_sha2_512;
|
extern struct auth_hash auth_hash_hmac_sha2_512;
|
||||||
|
@ -50,16 +50,30 @@
|
|||||||
#include <sys/cdefs.h>
|
#include <sys/cdefs.h>
|
||||||
__FBSDID("$FreeBSD$");
|
__FBSDID("$FreeBSD$");
|
||||||
|
|
||||||
|
#include <crypto/sha2/sha224.h>
|
||||||
#include <crypto/sha2/sha256.h>
|
#include <crypto/sha2/sha256.h>
|
||||||
#include <crypto/sha2/sha384.h>
|
#include <crypto/sha2/sha384.h>
|
||||||
#include <crypto/sha2/sha512.h>
|
#include <crypto/sha2/sha512.h>
|
||||||
#include <opencrypto/xform_auth.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 SHA256Update_int(void *, const u_int8_t *, u_int16_t);
|
||||||
static int SHA384Update_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);
|
static int SHA512Update_int(void *, const u_int8_t *, u_int16_t);
|
||||||
|
|
||||||
/* Authentication instances */
|
/* 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 = {
|
struct auth_hash auth_hash_hmac_sha2_256 = {
|
||||||
.type = CRYPTO_SHA2_256_HMAC,
|
.type = CRYPTO_SHA2_256_HMAC,
|
||||||
.name = "HMAC-SHA2-256",
|
.name = "HMAC-SHA2-256",
|
||||||
@ -99,6 +113,13 @@ struct auth_hash auth_hash_hmac_sha2_512 = {
|
|||||||
/*
|
/*
|
||||||
* And now for auth.
|
* 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
|
static int
|
||||||
SHA256Update_int(void *ctx, const u_int8_t *buf, u_int16_t len)
|
SHA256Update_int(void *ctx, const u_int8_t *buf, u_int16_t len)
|
||||||
{
|
{
|
||||||
|
@ -137,6 +137,8 @@ struct alg {
|
|||||||
} algs[] = {
|
} algs[] = {
|
||||||
{ .name = "sha1", .mac = CRYPTO_SHA1_HMAC, .type = T_HMAC,
|
{ .name = "sha1", .mac = CRYPTO_SHA1_HMAC, .type = T_HMAC,
|
||||||
.evp_md = EVP_sha1 },
|
.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,
|
{ .name = "sha256", .mac = CRYPTO_SHA2_256_HMAC, .type = T_HMAC,
|
||||||
.evp_md = EVP_sha256 },
|
.evp_md = EVP_sha256 },
|
||||||
{ .name = "sha384", .mac = CRYPTO_SHA2_384_HMAC, .type = T_HMAC,
|
{ .name = "sha384", .mac = CRYPTO_SHA2_384_HMAC, .type = T_HMAC,
|
||||||
|
Loading…
Reference in New Issue
Block a user