summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sha3.c273
1 files changed, 254 insertions, 19 deletions
diff --git a/sha3.c b/sha3.c
index 07f1c82..1572cc5 100644
--- a/sha3.c
+++ b/sha3.c
@@ -25,7 +25,7 @@
* - TupleHash256 and TupleHash256-XOF
* - ParallelHash128 and ParallelHash128-XOF
* - ParallelHash256 and ParallelHash256-XOF
- * - TurboHash128 and TurboHash256 (incomplete)
+ * - TurboHash128 and TurboHash256
*/
#include <stdbool.h> // true, false
@@ -1695,11 +1695,8 @@ void parallelhash256_xof_once(const parallelhash_params_t params, const uint8_t
// default turboshake pad byte (can be customized for domain separation)
#define TURBOSHAKE_PAD 0x1f
-typedef struct {
- sha3_xof_t xof;
- uint8_t pad;
-} turboshake_t;
-
+// init turboeshake context with given pad byte. returns false if the
+// pad byte is out of range.
static inline _Bool turboshake_init(turboshake_t * const ts, const uint8_t pad) {
// check for valid pad
if (!pad || pad > 0x1f) {
@@ -1715,14 +1712,18 @@ static inline _Bool turboshake_init(turboshake_t * const ts, const uint8_t pad)
return true;
}
+// init turboeshake128 context with custom pad byte. returns false if the
+// pad byte is out of range.
_Bool turboshake128_init_custom(turboshake_t * const ts, const uint8_t pad) {
return turboshake_init(ts, pad);
}
+// init turboeshake128 context.
void turboshake128_init(turboshake_t * const ts) {
(void) turboshake_init(ts, TURBOSHAKE_PAD);
}
+// absorb bytes into turboshake128 context.
_Bool turboshake128_absorb(turboshake_t * const ts, const uint8_t * const m, const size_t len) {
return xof_absorb(&(ts->xof), SHAKE128_XOF_RATE, TURBOSHAKE_NUM_ROUNDS, m, len);
}
@@ -5951,34 +5952,127 @@ static void test_hmac_sha3_512_ctx(void) {
}
static void test_turboshake128(void) {
- // FIXME: these tests do not work at the moment; going to revisit
- // turboshake later
- return; // currently disabled
+ // test pattern
+ // src: https://www.ietf.org/archive/id/draft-irtf-cfrg-kangarootwelve-10.html#name-test-vectors
+ static const uint8_t PATTERN[] = {
+ 0x00, 0x01, 0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, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
+ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
+ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA,
+ };
+
static const struct {
const char *name; // test name
const uint8_t pad; // padding byte (domain separator)
- const uint8_t msg[256]; // input data
- const size_t len; // message length, in bytes
+ const size_t len; // message length, in bytes (data itself comes from PATTERN)
const uint8_t exp[32]; // expected hash
} tests[] = {{
- // src: https://www.ietf.org/archive/id/draft-irtf-cfrg-kangarootwelve-10.html#name-test-vectors
- .name = "empty",
+ .name = "len=0, d=7",
.pad = 0x07,
- .msg = { 0
- },
.len = 0,
.exp = {
0x5A, 0x22, 0x3A, 0xD3, 0x0B, 0x3B, 0x8C, 0x66, 0xA2, 0x43, 0x04, 0x8C, 0xFC, 0xED, 0x43, 0x0F,
0x54, 0xE7, 0x52, 0x92, 0x87, 0xD1, 0x51, 0x50, 0xB9, 0x73, 0x13, 0x3A, 0xDF, 0xAC, 0x6A, 0x2F,
},
+ }, {
+ .name = "len=1, d=7",
+ .pad = 0x07,
+ .len = 1,
+ .exp = {
+ 0x1A, 0xC2, 0xD4, 0x50, 0xFC, 0x3B, 0x42, 0x05, 0xD1, 0x9D, 0xA7, 0xBF, 0xCA, 0x1B, 0x37, 0x51,
+ 0x3C, 0x08, 0x03, 0x57, 0x7A, 0xC7, 0x16, 0x7F, 0x06, 0xFE, 0x2C, 0xE1, 0xF0, 0xEF, 0x39, 0xE5,
+ },
+ }, {
+ .name = "len=17, d=7",
+ .pad = 0x07,
+ .len = 17,
+ .exp = {
+ 0xAC, 0xBD, 0x4A, 0xA5, 0x75, 0x07, 0x04, 0x3B, 0xCE, 0xE5, 0x5A, 0xD3, 0xF4, 0x85, 0x04, 0xD8,
+ 0x15, 0xE7, 0x07, 0xFE, 0x82, 0xEE, 0x3D, 0xAD, 0x6D, 0x58, 0x52, 0xC8, 0x92, 0x0B, 0x90, 0x5E,
+ },
+ }, {
+ .name = "len=17**2, d=7",
+ .pad = 0x07,
+ .len = 17*17,
+ .exp = {
+ 0x7A, 0x4D, 0xE8, 0xB1, 0xD9, 0x27, 0xA6, 0x82, 0xB9, 0x29, 0x61, 0x01, 0x03, 0xF0, 0xE9, 0x64,
+ 0x55, 0x9B, 0xD7, 0x45, 0x42, 0xCF, 0xAD, 0x74, 0x0E, 0xE3, 0xD9, 0xB0, 0x36, 0x46, 0x9E, 0x0A,
+ },
+ }, {
+ .name = "len=17**3, d=7",
+ .pad = 0x07,
+ .len = 17*17*17,
+ .exp = {
+ 0x74, 0x52, 0xED, 0x0E, 0xD8, 0x60, 0xAA, 0x8F, 0xE8, 0xE7, 0x96, 0x99, 0xEC, 0xE3, 0x24, 0xF8,
+ 0xD9, 0x32, 0x71, 0x46, 0x36, 0x10, 0xDA, 0x76, 0x80, 0x1E, 0xBC, 0xEE, 0x4F, 0xCA, 0xFE, 0x42,
+ },
+ }, {
+ .name = "len=17**4, d=7",
+ .pad = 0x07,
+ .len = 17*17*17*17,
+ .exp = {
+ 0xCA, 0x5F, 0x1F, 0x3E, 0xEA, 0xC9, 0x92, 0xCD, 0xC2, 0xAB, 0xEB, 0xCA, 0x0E, 0x21, 0x67, 0x65,
+ 0xDB, 0xF7, 0x79, 0xC3, 0xC1, 0x09, 0x46, 0x05, 0x5A, 0x94, 0xAB, 0x32, 0x72, 0x57, 0x35, 0x22,
+ },
+ }, {
+ .name = "len=17**5, d=7",
+ .pad = 0x07,
+ .len = 17*17*17*17*17,
+ .exp = {
+ 0xE9, 0x88, 0x19, 0x3F, 0xB9, 0x11, 0x9F, 0x11, 0xCD, 0x34, 0x46, 0x79, 0x14, 0xE2, 0xA2, 0x6D,
+ 0xA9, 0xBD, 0xF9, 0x6C, 0x8B, 0xEF, 0x07, 0x6A, 0xEE, 0xAD, 0x1A, 0x89, 0x7B, 0x86, 0x63, 0x83,
+ },
+ }, {
+ .name = "len=17**6, d=7",
+ .pad = 0x07,
+ .len = 17*17*17*17*17*17,
+ .exp = {
+ 0x9C, 0x0F, 0xFB, 0x98, 0x7E, 0xEE, 0xED, 0xAD, 0xFA, 0x55, 0x94, 0x89, 0x87, 0x75, 0x6D, 0x09,
+ 0x0B, 0x67, 0xCC, 0xB6, 0x12, 0x36, 0xE3, 0x06, 0xAC, 0x8A, 0x24, 0xDE, 0x1D, 0x0A, 0xF7, 0x74,
+ },
+ }, {
+ .name = "len=0, d=6",
+ .pad = 0x06,
+ .len = 0,
+ .exp = {
+ 0xC7, 0x90, 0x29, 0x30, 0x6B, 0xFA, 0x2F, 0x17, 0x83, 0x6A, 0x3D, 0x65, 0x16, 0xD5, 0x56, 0x63,
+ 0x40, 0xFE, 0xA6, 0xEB, 0x1A, 0x11, 0x39, 0xAD, 0x90, 0x0B, 0x41, 0x24, 0x3C, 0x49, 0x4B, 0x37,
+ },
+ }, {
+ .name = "len=0, d=B",
+ .pad = 0x0B,
+ .len = 0,
+ .exp = {
+ 0x8B, 0x03, 0x5A, 0xB8, 0xF8, 0xEA, 0x7B, 0x41, 0x02, 0x17, 0x16, 0x74, 0x58, 0x33, 0x2E, 0x46,
+ 0xF5, 0x4B, 0xE4, 0xFF, 0x83, 0x54, 0xBA, 0xF3, 0x68, 0x71, 0x04, 0xA6, 0xD2, 0x4B, 0x0E, 0xAB,
+ },
}};
for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
- // run
- uint8_t got[32];
+ // init
turboshake_t ts;
turboshake128_init_custom(&ts, tests[i].pad);
- turboshake128_absorb(&ts, tests[i].msg, tests[i].len);
+
+ // absorb
+ for (size_t ofs = 0; ofs < tests[i].len; ofs += sizeof(PATTERN)) {
+ const size_t len = MIN(tests[i].len - ofs, sizeof(PATTERN));
+ turboshake128_absorb(&ts, PATTERN, len);
+ }
+
+ // squeeze
+ uint8_t got[32];
turboshake128_squeeze(&ts, got, sizeof(got));
// check
@@ -5993,7 +6087,148 @@ static void test_turboshake128(void) {
}
static void test_turboshake256(void) {
- // TODO
+ // test pattern
+ // src: https://www.ietf.org/archive/id/draft-irtf-cfrg-kangarootwelve-10.html#name-test-vectors
+ static const uint8_t PATTERN[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8A, 0x8B, 0x8C, 0x8D, 0x8E, 0x8F,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9A, 0x9B, 0x9C, 0x9D, 0x9E, 0x9F,
+ 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8, 0xA9, 0xAA, 0xAB, 0xAC, 0xAD, 0xAE, 0xAF,
+ 0xB0, 0xB1, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9, 0xBA, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF,
+ 0xC0, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8, 0xC9, 0xCA, 0xCB, 0xCC, 0xCD, 0xCE, 0xCF,
+ 0xD0, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9, 0xDA, 0xDB, 0xDC, 0xDD, 0xDE, 0xDF,
+ 0xE0, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7, 0xE8, 0xE9, 0xEA, 0xEB, 0xEC, 0xED, 0xEE, 0xEF,
+ 0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8, 0xF9, 0xFA,
+ };
+
+ static const struct {
+ const char *name; // test name
+ const uint8_t pad; // padding byte (domain separator)
+ const size_t len; // message length, in bytes (data itself comes from PATTERN)
+ const uint8_t exp[64]; // expected hash
+ } tests[] = {{
+ .name = "len=0, d=7",
+ .pad = 0x07,
+ .len = 0,
+ .exp = {
+ 0x4A, 0x55, 0x5B, 0x06, 0xEC, 0xF8, 0xF1, 0x53, 0x8C, 0xCF, 0x5C, 0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A, 0x13, 0x17, 0x98, 0x30, 0xC3, 0xC7, 0x50,
+ 0xC9, 0x23, 0x7E, 0x83, 0xFD, 0x9A, 0x3F, 0xEC, 0x46, 0x03, 0xFF, 0x57, 0xE4, 0x22, 0x2E, 0xF2,
+ },
+ }, {
+ .name = "len=17**3, d=7",
+ .pad = 0x07,
+ .len = 17*17*17,
+ .exp = {
+ 0x62, 0xA5, 0xA0, 0xBF, 0xF0, 0x64, 0x26, 0xD7, 0x1A, 0x7A, 0x3E, 0x9E, 0x3F, 0x2F, 0xD6, 0xE2,
+ 0x52, 0xFF, 0x3F, 0xC1, 0x88, 0xA6, 0xA5, 0x36, 0xEC, 0xA4, 0x5A, 0x49, 0xA3, 0x43, 0x7C, 0xB3,
+ 0xBC, 0x3A, 0x0F, 0x81, 0x49, 0xC8, 0x50, 0xE6, 0xE7, 0xF4, 0x74, 0x7A, 0x70, 0x62, 0x7F, 0xD2,
+ 0x30, 0x30, 0x41, 0xC6, 0xC3, 0x36, 0x30, 0xF9, 0x43, 0xAD, 0x92, 0xF8, 0xE1, 0xFF, 0x43, 0x90,
+ },
+ }, {
+ .name = "len=17**4, d=7",
+ .pad = 0x07,
+ .len = 17*17*17*17,
+ .exp = {
+ 0x52, 0x3C, 0x06, 0x47, 0x18, 0x2D, 0x89, 0x41, 0xF0, 0xDD, 0x5C, 0x5C, 0x0A, 0xB6, 0x2D, 0x4F,
+ 0xC2, 0x95, 0x61, 0x61, 0x53, 0x96, 0xBB, 0x5B, 0x9A, 0x9D, 0xEB, 0x02, 0x2B, 0x80, 0xC5, 0xBF,
+ 0x2D, 0x83, 0xA3, 0xBB, 0x36, 0xFF, 0xC0, 0x4F, 0xAC, 0x58, 0xCF, 0x11, 0x49, 0xC6, 0x6D, 0xEC,
+ 0x4A, 0x59, 0x52, 0x6E, 0x51, 0xF2, 0x95, 0x96, 0xD8, 0x24, 0x42, 0x1A, 0x4B, 0x84, 0xB4, 0x4D,
+ },
+ }, {
+ .name = "len=17**5, d=7",
+ .pad = 0x07,
+ .len = 17*17*17*17*17,
+ .exp = {
+ 0xD1, 0x14, 0xA1, 0xC1, 0xA2, 0x08, 0xFF, 0x05, 0xFD, 0x49, 0xD0, 0x9E, 0xE0, 0x35, 0x46, 0x5D,
+ 0x86, 0x54, 0x7E, 0xBA, 0xD8, 0xE9, 0xAF, 0x4F, 0x8E, 0x87, 0x53, 0x70, 0x57, 0x3D, 0x6B, 0x7B,
+ 0xB2, 0x0A, 0xB9, 0x60, 0x63, 0x5A, 0xB5, 0x74, 0xE2, 0x21, 0x95, 0xEF, 0x9D, 0x17, 0x1C, 0x9A,
+ 0x28, 0x01, 0x04, 0x4B, 0x6E, 0x2E, 0xDF, 0x27, 0x2E, 0x23, 0x02, 0x55, 0x4B, 0x3A, 0x77, 0xC9,
+ },
+ }, {
+ .name = "len=17**6, d=7",
+ .pad = 0x07,
+ .len = 17*17*17*17*17*17,
+ .exp = {
+ 0x1E, 0x51, 0x34, 0x95, 0xD6, 0x16, 0x98, 0x75, 0xB5, 0x94, 0x53, 0xA5, 0x94, 0xE0, 0x8A, 0xE2,
+ 0x71, 0xCA, 0x20, 0xE0, 0x56, 0x43, 0xC8, 0x8A, 0x98, 0x7B, 0x5B, 0x6A, 0xB4, 0x23, 0xED, 0xE7,
+ 0x24, 0x0F, 0x34, 0xF2, 0xB3, 0x35, 0xFA, 0x94, 0xBC, 0x4B, 0x0D, 0x70, 0xE3, 0x1F, 0xB6, 0x33,
+ 0xB0, 0x79, 0x84, 0x43, 0x31, 0xFE, 0xA4, 0x2A, 0x9C, 0x4D, 0x79, 0xBB, 0x8C, 0x5F, 0x9E, 0x73,
+ },
+ }, {
+ .name = "len=0, d=B",
+ .pad = 0x0B,
+ .len = 0,
+ .exp = {
+ 0xC7, 0x49, 0xF7, 0xFB, 0x23, 0x64, 0x4A, 0x02, 0x1D, 0x35, 0x65, 0x3D, 0x1B, 0xFD, 0xF7, 0x47,
+ 0xCE, 0xCE, 0x5F, 0x97, 0x39, 0xF9, 0xA3, 0x44, 0xAD, 0x16, 0x9F, 0x10, 0x90, 0x6C, 0x68, 0x17,
+ 0xC8, 0xEE, 0x12, 0x78, 0x4E, 0x42, 0xFF, 0x57, 0x81, 0x4E, 0xFC, 0x1C, 0x89, 0x87, 0x89, 0xD5,
+ 0xE4, 0x15, 0xDB, 0x49, 0x05, 0x2E, 0xA4, 0x3A, 0x09, 0x90, 0x1D, 0x7A, 0x82, 0xA2, 0x14, 0x5C,
+ },
+ }, {
+ .name = "len=0, d=6",
+ .pad = 0x06,
+ .len = 0,
+ .exp = {
+ 0xFF, 0x23, 0xDC, 0xCD, 0x62, 0x16, 0x8F, 0x5A, 0x44, 0x46, 0x52, 0x49, 0xA8, 0x6D, 0xC1, 0x0E,
+ 0x8A, 0xAB, 0x4B, 0xD2, 0x6A, 0x22, 0xDE, 0xBF, 0x23, 0x48, 0x02, 0x0A, 0x83, 0x1C, 0xDB, 0xE1,
+ 0x2C, 0xDD, 0x36, 0xA7, 0xDD, 0xD3, 0x1E, 0x71, 0xC0, 0x1F, 0x7C, 0x97, 0xA0, 0xD4, 0xC3, 0xA0,
+ 0xCC, 0x1B, 0x21, 0x21, 0xE6, 0xB7, 0xCE, 0xAB, 0x38, 0x87, 0xA4, 0xC9, 0xA5, 0xAF, 0x8B, 0x03,
+ },
+ }};
+
+ for (size_t i = 0; i < sizeof(tests) / sizeof(tests[0]); i++) {
+ // init
+ turboshake_t ts;
+ turboshake256_init_custom(&ts, tests[i].pad);
+
+ // absorb
+ for (size_t ofs = 0; ofs < tests[i].len; ofs += sizeof(PATTERN)) {
+ const size_t len = MIN(tests[i].len - ofs, sizeof(PATTERN));
+ turboshake256_absorb(&ts, PATTERN, len);
+ }
+
+ // squeeze
+ uint8_t got[64];
+ turboshake256_squeeze(&ts, got, sizeof(got));
+
+ // check
+ if (memcmp(got, tests[i].exp, sizeof(got))) {
+ fprintf(stderr, "test_turboshake256(\"%s\") failed, got:\n", tests[i].name);
+ dump_hex(stderr, got, sizeof(got));
+
+ fprintf(stderr, "exp:\n");
+ dump_hex(stderr, tests[i].exp, sizeof(got));
+ }
+ }
}
int main(void) {