Commit 98eca72f authored by raveendra padasalagi's avatar raveendra padasalagi Committed by Herbert Xu

crypto: sha3 - Add HMAC-SHA3 test modes and test vectors

This patch adds HMAC-SHA3 test modes in tcrypt module
and related test vectors.
Signed-off-by: default avatarRaveendra Padasalagi <raveendra.padasalagi@broadcom.com>
Signed-off-by: default avatarHerbert Xu <herbert@gondor.apana.org.au>
parent eb354785
......@@ -1313,6 +1313,22 @@ static int do_test(const char *alg, u32 type, u32 mask, int m)
ret += tcrypt_test("hmac(crc32)");
break;
case 111:
ret += tcrypt_test("hmac(sha3-224)");
break;
case 112:
ret += tcrypt_test("hmac(sha3-256)");
break;
case 113:
ret += tcrypt_test("hmac(sha3-384)");
break;
case 114:
ret += tcrypt_test("hmac(sha3-512)");
break;
case 150:
ret += tcrypt_test("ansi_cprng");
break;
......
......@@ -3399,6 +3399,46 @@ static const struct alg_test_desc alg_test_descs[] = {
.count = HMAC_SHA256_TEST_VECTORS
}
}
}, {
.alg = "hmac(sha3-224)",
.test = alg_test_hash,
.fips_allowed = 1,
.suite = {
.hash = {
.vecs = hmac_sha3_224_tv_template,
.count = HMAC_SHA3_224_TEST_VECTORS
}
}
}, {
.alg = "hmac(sha3-256)",
.test = alg_test_hash,
.fips_allowed = 1,
.suite = {
.hash = {
.vecs = hmac_sha3_256_tv_template,
.count = HMAC_SHA3_256_TEST_VECTORS
}
}
}, {
.alg = "hmac(sha3-384)",
.test = alg_test_hash,
.fips_allowed = 1,
.suite = {
.hash = {
.vecs = hmac_sha3_384_tv_template,
.count = HMAC_SHA3_384_TEST_VECTORS
}
}
}, {
.alg = "hmac(sha3-512)",
.test = alg_test_hash,
.fips_allowed = 1,
.suite = {
.hash = {
.vecs = hmac_sha3_512_tv_template,
.count = HMAC_SHA3_512_TEST_VECTORS
}
}
}, {
.alg = "hmac(sha384)",
.test = alg_test_hash,
......
......@@ -3694,6 +3694,394 @@ static struct hash_testvec hmac_sha512_tv_template[] = {
},
};
#define HMAC_SHA3_224_TEST_VECTORS 4
static struct hash_testvec hmac_sha3_224_tv_template[] = {
{
.key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b",
.ksize = 20,
.plaintext = "Hi There",
.psize = 8,
.digest = "\x3b\x16\x54\x6b\xbc\x7b\xe2\x70"
"\x6a\x03\x1d\xca\xfd\x56\x37\x3d"
"\x98\x84\x36\x76\x41\xd8\xc5\x9a"
"\xf3\xc8\x60\xf7",
}, {
.key = "Jefe",
.ksize = 4,
.plaintext = "what do ya want for nothing?",
.psize = 28,
.digest = "\x7f\xdb\x8d\xd8\x8b\xd2\xf6\x0d"
"\x1b\x79\x86\x34\xad\x38\x68\x11"
"\xc2\xcf\xc8\x5b\xfa\xf5\xd5\x2b"
"\xba\xce\x5e\x66",
.np = 4,
.tap = { 7, 7, 7, 7 }
}, {
.key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa",
.ksize = 131,
.plaintext = "Test Using Large"
"r Than Block-Siz"
"e Key - Hash Key"
" First",
.psize = 54,
.digest = "\xb4\xa1\xf0\x4c\x00\x28\x7a\x9b"
"\x7f\x60\x75\xb3\x13\xd2\x79\xb8"
"\x33\xbc\x8f\x75\x12\x43\x52\xd0"
"\x5f\xb9\x99\x5f",
}, {
.key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa",
.ksize = 131,
.plaintext =
"This is a test u"
"sing a larger th"
"an block-size ke"
"y and a larger t"
"han block-size d"
"ata. The key nee"
"ds to be hashed "
"before being use"
"d by the HMAC al"
"gorithm.",
.psize = 152,
.digest = "\x05\xd8\xcd\x6d\x00\xfa\xea\x8d"
"\x1e\xb6\x8a\xde\x28\x73\x0b\xbd"
"\x3c\xba\xb6\x92\x9f\x0a\x08\x6b"
"\x29\xcd\x62\xa0",
},
};
#define HMAC_SHA3_256_TEST_VECTORS 4
static struct hash_testvec hmac_sha3_256_tv_template[] = {
{
.key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b",
.ksize = 20,
.plaintext = "Hi There",
.psize = 8,
.digest = "\xba\x85\x19\x23\x10\xdf\xfa\x96"
"\xe2\xa3\xa4\x0e\x69\x77\x43\x51"
"\x14\x0b\xb7\x18\x5e\x12\x02\xcd"
"\xcc\x91\x75\x89\xf9\x5e\x16\xbb",
}, {
.key = "Jefe",
.ksize = 4,
.plaintext = "what do ya want for nothing?",
.psize = 28,
.digest = "\xc7\xd4\x07\x2e\x78\x88\x77\xae"
"\x35\x96\xbb\xb0\xda\x73\xb8\x87"
"\xc9\x17\x1f\x93\x09\x5b\x29\x4a"
"\xe8\x57\xfb\xe2\x64\x5e\x1b\xa5",
.np = 4,
.tap = { 7, 7, 7, 7 }
}, {
.key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa",
.ksize = 131,
.plaintext = "Test Using Large"
"r Than Block-Siz"
"e Key - Hash Key"
" First",
.psize = 54,
.digest = "\xed\x73\xa3\x74\xb9\x6c\x00\x52"
"\x35\xf9\x48\x03\x2f\x09\x67\x4a"
"\x58\xc0\xce\x55\x5c\xfc\x1f\x22"
"\x3b\x02\x35\x65\x60\x31\x2c\x3b",
}, {
.key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa",
.ksize = 131,
.plaintext =
"This is a test u"
"sing a larger th"
"an block-size ke"
"y and a larger t"
"han block-size d"
"ata. The key nee"
"ds to be hashed "
"before being use"
"d by the HMAC al"
"gorithm.",
.psize = 152,
.digest = "\x65\xc5\xb0\x6d\x4c\x3d\xe3\x2a"
"\x7a\xef\x87\x63\x26\x1e\x49\xad"
"\xb6\xe2\x29\x3e\xc8\xe7\xc6\x1e"
"\x8d\xe6\x17\x01\xfc\x63\xe1\x23",
},
};
#define HMAC_SHA3_384_TEST_VECTORS 4
static struct hash_testvec hmac_sha3_384_tv_template[] = {
{
.key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b",
.ksize = 20,
.plaintext = "Hi There",
.psize = 8,
.digest = "\x68\xd2\xdc\xf7\xfd\x4d\xdd\x0a"
"\x22\x40\xc8\xa4\x37\x30\x5f\x61"
"\xfb\x73\x34\xcf\xb5\xd0\x22\x6e"
"\x1b\xc2\x7d\xc1\x0a\x2e\x72\x3a"
"\x20\xd3\x70\xb4\x77\x43\x13\x0e"
"\x26\xac\x7e\x3d\x53\x28\x86\xbd",
}, {
.key = "Jefe",
.ksize = 4,
.plaintext = "what do ya want for nothing?",
.psize = 28,
.digest = "\xf1\x10\x1f\x8c\xbf\x97\x66\xfd"
"\x67\x64\xd2\xed\x61\x90\x3f\x21"
"\xca\x9b\x18\xf5\x7c\xf3\xe1\xa2"
"\x3c\xa1\x35\x08\xa9\x32\x43\xce"
"\x48\xc0\x45\xdc\x00\x7f\x26\xa2"
"\x1b\x3f\x5e\x0e\x9d\xf4\xc2\x0a",
.np = 4,
.tap = { 7, 7, 7, 7 }
}, {
.key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xa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"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa",
.ksize = 131,
.plaintext =
"This is a test u"
"sing a larger th"
"an block-size ke"
"y and a larger t"
"han block-size d"
"ata. The key nee"
"ds to be hashed "
"before being use"
"d by the HMAC al"
"gorithm.",
.psize = 152,
.digest = "\x02\x6f\xdf\x6b\x50\x74\x1e\x37"
"\x38\x99\xc9\xf7\xd5\x40\x6d\x4e"
"\xb0\x9f\xc6\x66\x56\x36\xfc\x1a"
"\x53\x00\x29\xdd\xf5\xcf\x3c\xa5"
"\xa9\x00\xed\xce\x01\xf5\xf6\x1e"
"\x2f\x40\x8c\xdf\x2f\xd3\xe7\xe8",
},
};
#define HMAC_SHA3_512_TEST_VECTORS 4
static struct hash_testvec hmac_sha3_512_tv_template[] = {
{
.key = "\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b"
"\x0b\x0b\x0b\x0b",
.ksize = 20,
.plaintext = "Hi There",
.psize = 8,
.digest = "\xeb\x3f\xbd\x4b\x2e\xaa\xb8\xf5"
"\xc5\x04\xbd\x3a\x41\x46\x5a\xac"
"\xec\x15\x77\x0a\x7c\xab\xac\x53"
"\x1e\x48\x2f\x86\x0b\x5e\xc7\xba"
"\x47\xcc\xb2\xc6\xf2\xaf\xce\x8f"
"\x88\xd2\x2b\x6d\xc6\x13\x80\xf2"
"\x3a\x66\x8f\xd3\x88\x8b\xb8\x05"
"\x37\xc0\xa0\xb8\x64\x07\x68\x9e",
}, {
.key = "Jefe",
.ksize = 4,
.plaintext = "what do ya want for nothing?",
.psize = 28,
.digest = "\x5a\x4b\xfe\xab\x61\x66\x42\x7c"
"\x7a\x36\x47\xb7\x47\x29\x2b\x83"
"\x84\x53\x7c\xdb\x89\xaf\xb3\xbf"
"\x56\x65\xe4\xc5\xe7\x09\x35\x0b"
"\x28\x7b\xae\xc9\x21\xfd\x7c\xa0"
"\xee\x7a\x0c\x31\xd0\x22\xa9\x5e"
"\x1f\xc9\x2b\xa9\xd7\x7d\xf8\x83"
"\x96\x02\x75\xbe\xb4\xe6\x20\x24",
.np = 4,
.tap = { 7, 7, 7, 7 }
}, {
.key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa",
.ksize = 131,
.plaintext = "Test Using Large"
"r Than Block-Siz"
"e Key - Hash Key"
" First",
.psize = 54,
.digest = "\x00\xf7\x51\xa9\xe5\x06\x95\xb0"
"\x90\xed\x69\x11\xa4\xb6\x55\x24"
"\x95\x1c\xdc\x15\xa7\x3a\x5d\x58"
"\xbb\x55\x21\x5e\xa2\xcd\x83\x9a"
"\xc7\x9d\x2b\x44\xa3\x9b\xaf\xab"
"\x27\xe8\x3f\xde\x9e\x11\xf6\x34"
"\x0b\x11\xd9\x91\xb1\xb9\x1b\xf2"
"\xee\xe7\xfc\x87\x24\x26\xc3\xa4",
}, {
.key = "\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa"
"\xaa\xaa\xaa",
.ksize = 131,
.plaintext =
"This is a test u"
"sing a larger th"
"an block-size ke"
"y and a larger t"
"han block-size d"
"ata. The key nee"
"ds to be hashed "
"before being use"
"d by the HMAC al"
"gorithm.",
.psize = 152,
.digest = "\x38\xa4\x56\xa0\x04\xbd\x10\xd3"
"\x2c\x9a\xb8\x33\x66\x84\x11\x28"
"\x62\xc3\xdb\x61\xad\xcc\xa3\x18"
"\x29\x35\x5e\xaf\x46\xfd\x5c\x73"
"\xd0\x6a\x1f\x0d\x13\xfe\xc9\xa6"
"\x52\xfb\x38\x11\xb5\x77\xb1\xb1"
"\xd1\xb9\x78\x9f\x97\xae\x5b\x83"
"\xc6\xf4\x4d\xfc\xf1\xd6\x7e\xba",
},
};
/*
* Poly1305 test vectors from RFC7539 A.3.
*/
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment