Add a testuite for SM3 hash function. Test vectors are based on: https://datatracker.ietf.org/doc/html/draft-shen-sm3-hash-01
Signed-off-by: Tianjia Zhang tianjia.zhang@linux.alibaba.com --- testsuite/.gitignore | 1 + testsuite/Makefile.in | 2 +- testsuite/sm3-test.c | 20 ++++++++++++++++++++ 3 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 testsuite/sm3-test.c
diff --git a/testsuite/.gitignore b/testsuite/.gitignore index 9d8a7681..ca41472e 100644 --- a/testsuite/.gitignore +++ b/testsuite/.gitignore @@ -97,6 +97,7 @@ /sha512-224-test /sha512-256-test /sha512-test +/sm3-test /streebog-test /twofish-test /umac-test diff --git a/testsuite/Makefile.in b/testsuite/Makefile.in index 2b554261..6734d3e6 100644 --- a/testsuite/Makefile.in +++ b/testsuite/Makefile.in @@ -24,7 +24,7 @@ TS_NETTLE_SOURCES = aes-test.c aes-keywrap-test.c arcfour-test.c arctwo-test.c \ sha384-test.c sha512-test.c sha512-224-test.c sha512-256-test.c \ sha3-permute-test.c sha3-224-test.c sha3-256-test.c \ sha3-384-test.c sha3-512-test.c \ - shake256-test.c streebog-test.c \ + shake256-test.c streebog-test.c sm3-test.c \ serpent-test.c twofish-test.c version-test.c \ knuth-lfib-test.c \ cbc-test.c cfb-test.c ctr-test.c gcm-test.c eax-test.c ccm-test.c \ diff --git a/testsuite/sm3-test.c b/testsuite/sm3-test.c new file mode 100644 index 00000000..d3684afd --- /dev/null +++ b/testsuite/sm3-test.c @@ -0,0 +1,20 @@ +#include "testutils.h" +#include "sm3.h" + +void +test_main(void) +{ + /* test vectors from: + * https://datatracker.ietf.org/doc/html/draft-shen-sm3-hash-01 + */ + test_hash(&nettle_sm3, + SDATA("abc"), + SHEX("66c7f0f462eeedd9 d1f2d46bdc10e4e2" + "4167c4875cf2f7a2 297da02b8f4ba8e0")); + + test_hash(&nettle_sm3, + SDATA("abcdabcdabcdabcdabcdabcdabcdabcd" + "abcdabcdabcdabcdabcdabcdabcdabcd"), + SHEX("debe9ff92275b8a1 38604889c18e5a4d" + "6fdb70e5387e5765 293dcba39c0c5732")); +}