crypto: Add Skein hash algorithm variants
Subsystems (2)
PATCH 1/1 crypto: Add Skein hash algorithm variants
This is the first draft of the Skein hash algorithm that was recently mentioned, as a prominent submission to NIST's SHA-3 competition.
Website: http://www.schneier.com/skein.html
It still needs more work, linux-ifying, testing, and reviewing.
One note I forgot to mention in the commit itself, but should be considered when reviewing this:
Skein permits the output digest size to be specified by the user. "Skein-256" means 256 bits of internal state, NOT 256 bits of output digest. The output digest size is specified to Skein at init time.
In my implementation below, I attempted to follow the Principle of Least Surprise, by hardcoding output digest size == internal state size. Thus, in my implementation, "skein256" really does mean 256 output bits.
I am currently pushing this work to the 'skein' branch ofgit://git.kernel.org/pub/scm/linux/kernel/git/jgarzik/misc-2.6.git skein
Comments welcome!
--- crypto/Kconfig | 12 + crypto/Makefile | 3 + crypto/skein.h | 265 ++++++++++++++++++++++ crypto/skein1024_generic.c | 518 ++++++++++++++++++++++++++++++++++++++++++++ crypto/skein256_generic.c | 367 +++++++++++++++++++++++++++++++ crypto/skein512_generic.c | 417 +++++++++++++++++++++++++++++++++++ 6 files changed, 1582 insertions(+), 0 deletions(-) create mode 100644 crypto/skein.h create mode 100644 crypto/skein1024_generic.c create mode 100644 crypto/skein256_generic.c create mode 100644 crypto/skein512_generic.c
Jeff Garzik (1):
[CRYPTO] Add Skein hash algorithm, 256-, 512-, and 1024-bit variants
Import the public domain reference implementation of the Skein hash algorithm into the Linux Crypto API. This is a prominent submission to the NIST's competition for SHA-3.
See Skein website for more info: http://www.schneier.com/skein.html
This is just a rough import, and still needs more cleaning and Linux-ifying.
crypto/Kconfig +12 -0
@@ -352,6 +352,18 @@ config CRYPTO_SHA512 This code also includes SHA-384, a 384 bit hash with 192 bits of security against collision attacks. +config CRYPTO_SKEIN256 + tristate "Skein-256(256) digest algorithm" + select CRYPTO_ALGAPI + +config CRYPTO_SKEIN512 + tristate "Skein-512(512) digest algorithm" + select CRYPTO_ALGAPI + +config CRYPTO_SKEIN1024 + tristate "Skein-1024(1024) digest algorithm" + select CRYPTO_ALGAPI + config CRYPTO_TGR192 tristate "Tiger digest algorithms" select CRYPTO_ALGAPI
crypto/Makefile +3 -0
@@ -39,6 +39,9 @@ obj-$(CONFIG_CRYPTO_RMD320) += rmd320.o obj-$(CONFIG_CRYPTO_SHA1) += sha1_generic.o obj-$(CONFIG_CRYPTO_SHA256) += sha256_generic.o obj-$(CONFIG_CRYPTO_SHA512) += sha512_generic.o +obj-$(CONFIG_CRYPTO_SKEIN256) += skein256_generic.o +obj-$(CONFIG_CRYPTO_SKEIN512) += skein512_generic.o +obj-$(CONFIG_CRYPTO_SKEIN1024) += skein1024_generic.o obj-$(CONFIG_CRYPTO_WP512) += wp512.o obj-$(CONFIG_CRYPTO_TGR192) += tgr192.o obj-$(CONFIG_CRYPTO_GF128MUL) += gf128mul.o
crypto/skein.h new file +265 -0
265 lines not on this page · raw message
crypto/skein1024_generic.c new file +518 -0
518 lines not on this page · raw message
crypto/skein256_generic.c new file +367 -0
367 lines not on this page · raw message
crypto/skein512_generic.c new file +417 -0
417 lines not on this page · raw message
PATCH 1/1 crypto: add test vectors for skein256/512/1024
I grabed them from http://www.schneier.com/skein.html. The last test vector
(3) in every category is currently deactivated because it failed always. It is unlikely that I made a type because I copy+pasted the tables + vim magiced them. So maybe code may missbehave on requests lengths which are not a multiple of 4 or the vectors can not be used due to some other limitations that I've overseen.
--- crypto/tcrypt.c | 24 ++++++++ crypto/testmgr.c | 27 +++++++++ crypto/testmgr.h | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 216 insertions(+), 1 deletions(-)
crypto/tcrypt.c +24 -0
@@ -661,6 +661,18 @@ static void do_test(int m)tcrypt_test ("ecb(seed)" );break ; +case 44 : +tcrypt_test ("skein256" ); +break ; + +case 45 : +tcrypt_test ("skein512" ); +break ; + +case 46 : +tcrypt_test ("skein1024" ); +break ; +case 100 :tcrypt_test ("hmac(md5)" );break ;
@@ -851,6 +863,18 @@ static void do_test(int m)test_hash_speed ("rmd320" , sec, generic_hash_speed_template);if (mode >300 && mode <400 )break ; +case 318 : +test_hash_speed ("skein256" , sec, generic_hash_speed_template); +if (mode >300 && mode <400 )break ; + +case 319 : +test_hash_speed ("skein512" , sec, generic_hash_speed_template); +if (mode >300 && mode <400 )break ; + +case 320 : +test_hash_speed ("skein1024" , sec, generic_hash_speed_template); +if (mode >300 && mode <400 )break ; +case 399 :break ;
crypto/testmgr.c +27 -0
@@ -1693,6 +1693,33 @@ static const struct alg_test_desc alg_test_descs[] = { } } }, { + .alg = "skein1024", + .test = alg_test_hash, + .suite = { + .hash = { + .vecs = skein1024_tv_template, + .count = SKEIN1024_TEST_VECTORS + } + } + }, { + .alg = "skein256", + .test = alg_test_hash, + .suite = { + .hash = { + .vecs = skein256_tv_template, + .count = SKEIN256_TEST_VECTORS + } + } + }, { + .alg = "skein512", + .test = alg_test_hash, + .suite = { + .hash = { + .vecs = skein512_tv_template, + .count = SKEIN512_TEST_VECTORS + } + } + }, { .alg = "tgr128", .test = alg_test_hash, .suite = {
crypto/testmgr.h +165 -1
178 lines not on this page · raw message
Signature · 1 line
1.5.6.5
Quoted 2 lines · Jeff Garzik
This is the first draft of the Skein hash algorithm that was recently mentioned, as a prominent submission to NIST's SHA-3 competition.
Adding Skein to the kernel makes no sense, from a cryptographic point of view, at this point in time. The appropriate point would be after it has been analyzed and vetted by crypto experts over a period of time. I suspect even the designers of Skein would advise you not to use the algorithm until other cryptographers have had a chance to examine it and it has been subjected to cryptanalysis over a period of time. The same goes for all new submissions to the NIST competition.
Re: [PATCH] crypto: add test vectors for skein256/512/1024
In reply to Sebastian Andrzej SiewiorQuoted 7 lines · Sebastian Andrzej Siewior
I grabed them from http://www.schneier.com/skein.html. The last test vector
(3) in every category is currently deactivated because it failed always. It is unlikely that I made a type because I copy+pasted the tables + vim magiced them. So maybe code may missbehave on requests lengths which are not a multiple of 4 or the vectors can not be used due to some other limitations that I've overseen.
Quoted 6 lines
Signed-off-by Sebastian Andrzej Siewior <[email protected]>--- crypto/tcrypt.c | 24 ++++++++ crypto/testmgr.c | 27 +++++++++ crypto/testmgr.h | 166 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 216 insertions(+), 1 deletions(-)
Nice, thanks!
I'm wondering if the failure has to do with the alignmask value in struct crypto_alg for each variant.
Jeff
Re: [PATCH] crypto: add test vectors for skein256/512/1024
In reply to Sebastian Andrzej SiewiorQuoted 6 lines · Sebastian Andrzej Siewior
I grabed them from http://www.schneier.com/skein.html. The last test vector
(3) in every category is currently deactivated because it failed always. It is unlikely that I made a type because I copy+pasted the tables + vim magiced them. So maybe code may missbehave on requests lengths which are not a multiple of 4 or the vectors can not be used due to some other limitations that I've overseen.
Another thought: did you verify that the test vectors' output sizes matched the Linux kernel's?
My implementation assumed a 256-bit output size for Skein-256, for example, but it is quite possible that Schneier and co. ran tests where the output size differed from the internal state size.
Jeff
Re: [PATCH] crypto: add test vectors for skein256/512/1024
Quoted 11 lines · * Jeff Garzik | 2008-11-02 20:44:40 [-0500]:
Quoted 7 lines · Sebastian Andrzej Siewior
I grabed them from http://www.schneier.com/skein.html. The last test vector
(3) in every category is currently deactivated because it failed always. It is unlikely that I made a type because I copy+pasted the tables + vim magiced them. So maybe code may missbehave on requests lengths which are not a multiple of 4 or the vectors can not be used due to some other limitations that I've overseen.Another thought: did you verify that the test vectors' output sizes matched the Linux kernel's?
It should. All have something like:
| :Skein-512: 512-bit hash, msgLen = 8 bits
512 algo, 512 output.
The third one has:
| :Skein-512: 512-bit hash, msgLen = 2040 bits. Tree: leaf=02, node=02, maxLevels=02
So it looks like the same except that it has the "Tree: leaf node" attribes as well. So maybe this is something special maybe not. As I browsed the .txt files for other vectors I did not find any where msglen wasn't a multiple of 4 bytes (except some odd ones where msgles was 7 bits). Maybe I did not look close enough.
Quoted 1 line
Jeff
Sebastian
Quoted 6 lines · David Wagner
Quoted 3 lines · Jeff Garzik
This is the first draft of the Skein hash algorithm that was recently mentioned, as a prominent submission to NIST's SHA-3 competition.
Quoted 9 lines
Adding Skein to the kernel makes no sense, from a cryptographic point of view, at this point in time. The appropriate point would be after it has been analyzed and vetted by crypto experts over a period of time. I suspect even the designers of Skein would advise you not to use the algorithm until other cryptographers have had a chance to examine it and it has been subjected to cryptanalysis over a period of time. The same goes for all new submissions to the NIST competition.
The final date is by the end of 2012. It's still some time until then.
http://csrc.nist.gov/groups/ST/hash/timeline.html
Re: [PATCH] crypto: add test vectors for skein256/512/1024
In reply to Jeff GarzikQuoted 8 lines · * Jeff Garzik | 2008-11-02 20:44:40 [-0500]:
Quoted 7 lines · Sebastian Andrzej Siewior
I grabed them from http://www.schneier.com/skein.html. The last test vector
(3) in every category is currently deactivated because it failed always. It is unlikely that I made a type because I copy+pasted the tables + vim magiced them. So maybe code may missbehave on requests lengths which are not a multiple of 4 or the vectors can not be used due to some other limitations that I've overseen.
Okay, that was a false positive :)
The "untouched" reference implementation outputs the same hash. The additional information (tree, ...) is part of the third argument in Skein_XXX_InitExt() which isn't used. So we can safely drop the third test vector.
Quoted 2 lines
Jeff
Sebastian