aboutsummaryrefslogtreecommitdiff
path: root/lib/libtpm/sha.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libtpm/sha.c')
-rw-r--r--lib/libtpm/sha.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/libtpm/sha.c b/lib/libtpm/sha.c
index 43de658..902a4ba 100644
--- a/lib/libtpm/sha.c
+++ b/lib/libtpm/sha.c
@@ -203,3 +203,30 @@ void sha1(const uint8_t *data, uint32_t length, uint8_t *hash)
sha1_do(&ctx, data, length);
memcpy(hash, &ctx.h[0], 20);
}
+
+#ifdef MAIN
+
+#include "sha_test.h"
+
+int main(void)
+{
+ TESTVECTORS(data);
+ uint8_t hash[20];
+ char input[64];
+ int err = 0;
+ size_t i;
+
+ for (i = 0; i < ARRAY_SIZE(data); i++)
+ err |= test_hash(sha1, hash, sizeof(hash),
+ data[i], strlen(data[i]),
+ SHA1);
+
+ memset(input, 'a', sizeof(input));
+ /* cover critical input size around 56 bytes */
+ for (i = 50; i < sizeof(input); i++)
+ err |= test_hash(sha1, hash, sizeof(hash),
+ input, i, SHA1);
+
+ return err;
+}
+#endif