aboutsummaryrefslogtreecommitdiff
path: root/lib/libtpm/sha256.c
diff options
context:
space:
mode:
authorStefan Berger <stefanb@linux.ibm.com>2021-07-09 11:39:02 -0400
committerAlexey Kardashevskiy <aik@ozlabs.ru>2021-07-11 23:46:49 +1000
commit62e0d4153468bc29873a34346c945726cd3c197d (patch)
treee86a2383b0c4cc44536f38e59311633e55e6d17c /lib/libtpm/sha256.c
parent89509533ace768d593fb4eab4293a2a5e24839ab (diff)
downloadSLOF-62e0d4153468bc29873a34346c945726cd3c197d.zip
SLOF-62e0d4153468bc29873a34346c945726cd3c197d.tar.gz
SLOF-62e0d4153468bc29873a34346c945726cd3c197d.tar.bz2
tcgbios: Add test cases and test script to run them
Add test cases for sha1, sha256, sha384, and sha512 and a test script to run the test cases. The tests are passing on little and big endian machines (Fedora 28). Signed-off-by: Stefan Berger <stefanb@linux.ibm.com> Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Diffstat (limited to 'lib/libtpm/sha256.c')
-rw-r--r--lib/libtpm/sha256.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/libtpm/sha256.c b/lib/libtpm/sha256.c
index 1a0aa9a..79bcb83 100644
--- a/lib/libtpm/sha256.c
+++ b/lib/libtpm/sha256.c
@@ -218,3 +218,29 @@ void sha256(const uint8_t *data, uint32_t length, uint8_t *hash)
sha256_do(&ctx, data, length);
memcpy(hash, ctx.h, sizeof(ctx.h));
}
+
+#ifdef MAIN
+
+#include "sha_test.h"
+
+int main(void)
+{
+ TESTVECTORS(data);
+ uint8_t hash[32];
+ char input[64];
+ int err = 0;
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(data); i++)
+ err |= test_hash(sha256, hash, sizeof(hash),
+ data[i], strlen(data[i]),
+ SHA256);
+
+ memset(input, 'a', sizeof(input));
+ /* cover critical input size around 56 bytes */
+ for (i = 50; i < sizeof(input); i++)
+ err |= test_hash(sha256, hash, sizeof(hash), input, i, SHA256);
+
+ return err;
+}
+#endif