On 03/25/2013 12:57 PM, Niels Möller wrote: > Nikos Mavrogiannopoulos <[email protected]> writes: > >> This patch adds a function to use the Salsa20 with 12 rounds. > > Committed, except for the change to salsa20-crypt.c, which seemed > unrelated. > > Do you have any test vectors?
Attached. btw. the current _salsa20_core takes rounds as a variable. Wouldn't it allow for better optimizations (loop unrolling actually) if that was a static function, or that doesn't matter much? As far as I understand it is highly unlikely that salsa20 will be used with anything else than 20 or 12 rounds. regards, Nikos
>From 173eff458fdc791826f7c8e0ee4dabd92296a746 Mon Sep 17 00:00:00 2001 From: Nikos Mavrogiannopoulos <[email protected]> Date: Mon, 25 Mar 2013 20:18:14 +0100 Subject: [PATCH] Added salsa20/12 test vectors. --- testsuite/salsa20-test.c | 52 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/testsuite/salsa20-test.c b/testsuite/salsa20-test.c index d742ce4..958b4e7 100644 --- a/testsuite/salsa20-test.c +++ b/testsuite/salsa20-test.c @@ -116,11 +116,14 @@ test_salsa20_stream(const struct tstring *key, } } +#define test_salsa20(key, iv, cl, ci) _test_salsa20(key, iv, cl, ci, 0) +#define test_salsa20r12(key, iv, cl, ci) _test_salsa20(key, iv, cl, ci, 1) + static void -test_salsa20(const struct tstring *key, +_test_salsa20(const struct tstring *key, const struct tstring *iv, const struct tstring *cleartext, - const struct tstring *ciphertext) + const struct tstring *ciphertext, int r12) { struct salsa20_ctx ctx; uint8_t *data; @@ -136,7 +139,11 @@ test_salsa20(const struct tstring *key, salsa20_set_key(&ctx, key->length, key->data); salsa20_set_iv(&ctx, iv->data); data[length] = 17; - salsa20_crypt(&ctx, length, data, cleartext->data); + + if (r12) + salsa20r12_crypt(&ctx, length, data, cleartext->data); + else + salsa20_crypt(&ctx, length, data, cleartext->data); if (data[length] != 17) { fprintf(stderr, "Encrypt of %u bytes wrote too much!\nInput:", length); @@ -157,7 +164,10 @@ test_salsa20(const struct tstring *key, } salsa20_set_key(&ctx, key->length, key->data); salsa20_set_iv(&ctx, iv->data); - salsa20_crypt(&ctx, length, data, data); + if (r12) + salsa20r12_crypt(&ctx, length, data, data); + else + salsa20_crypt(&ctx, length, data, data); if (!MEMEQ(length, data, cleartext->data)) { @@ -177,6 +187,40 @@ test_salsa20(const struct tstring *key, void test_main(void) { + /* http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/salsa20/reduced/12-rounds/verified.test-vectors?logsort=rev&rev=210&view=markup */ + test_salsa20r12(SHEX("80000000 00000000 00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("FC207DBF C76C5E17")); + + test_salsa20r12(SHEX("00400000 00000000 00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("6C11A3F9 5FEC7F48")); + + test_salsa20r12(SHEX("09090909090909090909090909090909"), + SHEX("0000000000000000"), + SHEX("00000000 00000000"), + SHEX("78E11FC3 33DEDE88")); + + test_salsa20r12(SHEX("1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B1B"), + SHEX("00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("A6747461 1DF551FF")); + + test_salsa20r12(SHEX("80000000000000000000000000000000" + "00000000000000000000000000000000"), + SHEX("00000000 00000000"), + SHEX("00000000 00000000"), + SHEX("AFE411ED 1C4E07E4")); + + test_salsa20r12(SHEX("0053A6F94C9FF24598EB3E91E4378ADD" + "3083D6297CCF2275C81B6EC11467BA0D"), + SHEX("0D74DB42A91077DE"), + SHEX("00000000 00000000"), + SHEX("52E20CF8 775AE882")); + + /* http://www.ecrypt.eu.org/stream/svn/viewcvs.cgi/ecrypt/trunk/submissions/salsa20/full/verified.test-vectors?logsort=rev&rev=210&view=markup */ test_salsa20(SHEX("80000000 00000000 00000000 00000000"), -- 1.7.10.4
_______________________________________________ nettle-bugs mailing list [email protected] http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs
