summaryrefslogtreecommitdiff
path: root/test/sha256.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/sha256.c')
-rw-r--r--test/sha256.c73
1 files changed, 34 insertions, 39 deletions
diff --git a/test/sha256.c b/test/sha256.c
index 105ae8fec5..4b5326d189 100644
--- a/test/sha256.c
+++ b/test/sha256.c
@@ -1,4 +1,4 @@
-/* Copyright 2017 The Chromium OS Authors. All rights reserved.
+/* Copyright 2017 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -12,23 +12,20 @@
#include "util.h"
/* Short Msg from NIST FIPS 180-4 (Len = 8) */
-static const uint8_t sha256_8_input[] = {
- 0xd3
-};
+static const uint8_t sha256_8_input[] = { 0xd3 };
static const uint8_t sha256_8_output[SHA256_DIGEST_SIZE] = {
- 0x28, 0x96, 0x9c, 0xdf, 0xa7, 0x4a, 0x12, 0xc8, 0x2f, 0x3b, 0xad, 0x96,
- 0x0b, 0x0b, 0x00, 0x0a, 0xca, 0x2a, 0xc3, 0x29, 0xde, 0xea, 0x5c, 0x23,
- 0x28, 0xeb, 0xc6, 0xf2, 0xba, 0x98, 0x02, 0xc1
+ 0x28, 0x96, 0x9c, 0xdf, 0xa7, 0x4a, 0x12, 0xc8, 0x2f, 0x3b, 0xad,
+ 0x96, 0x0b, 0x0b, 0x00, 0x0a, 0xca, 0x2a, 0xc3, 0x29, 0xde, 0xea,
+ 0x5c, 0x23, 0x28, 0xeb, 0xc6, 0xf2, 0xba, 0x98, 0x02, 0xc1
};
/* Short Msg from NIST FIPS 180-4 (Len = 72) */
-static const uint8_t sha256_72_input[] = {
- 0x33, 0x34, 0xc5, 0x80, 0x75, 0xd3, 0xf4, 0x13, 0x9e
-};
+static const uint8_t sha256_72_input[] = { 0x33, 0x34, 0xc5, 0x80, 0x75,
+ 0xd3, 0xf4, 0x13, 0x9e };
static const uint8_t sha256_72_output[SHA256_DIGEST_SIZE] = {
- 0x07, 0x8d, 0xa3, 0xd7, 0x7e, 0xd4, 0x3b, 0xd3, 0x03, 0x7a, 0x43, 0x3f,
- 0xd0, 0x34, 0x18, 0x55, 0x02, 0x37, 0x93, 0xf9, 0xaf, 0xd0, 0x8b, 0x4b,
- 0x08, 0xea, 0x1e, 0x55, 0x97, 0xce, 0xef, 0x20
+ 0x07, 0x8d, 0xa3, 0xd7, 0x7e, 0xd4, 0x3b, 0xd3, 0x03, 0x7a, 0x43,
+ 0x3f, 0xd0, 0x34, 0x18, 0x55, 0x02, 0x37, 0x93, 0xf9, 0xaf, 0xd0,
+ 0x8b, 0x4b, 0x08, 0xea, 0x1e, 0x55, 0x97, 0xce, 0xef, 0x20
};
/* Long Msg from NIST FIPS 180-4 (Len = 2888) */
@@ -66,9 +63,9 @@ static const uint8_t sha256_2888_input[] = {
0x93
};
static const uint8_t sha256_2888_output[SHA256_DIGEST_SIZE] = {
- 0x5f, 0x4e, 0x16, 0xa7, 0x2d, 0x6c, 0x98, 0x57, 0xda, 0x0b, 0xa0, 0x09,
- 0xcc, 0xac, 0xd4, 0xf2, 0x6d, 0x7f, 0x6b, 0xf6, 0xc1, 0xb7, 0x8a, 0x2e,
- 0xd3, 0x5e, 0x68, 0xfc, 0xb1, 0x5b, 0x8e, 0x40
+ 0x5f, 0x4e, 0x16, 0xa7, 0x2d, 0x6c, 0x98, 0x57, 0xda, 0x0b, 0xa0,
+ 0x09, 0xcc, 0xac, 0xd4, 0xf2, 0x6d, 0x7f, 0x6b, 0xf6, 0xc1, 0xb7,
+ 0x8a, 0x2e, 0xd3, 0x5e, 0x68, 0xfc, 0xb1, 0x5b, 0x8e, 0x40
};
/* HMAC short key (40 bytes) from NIST FIPS 198-1 (Count = 34) */
@@ -86,15 +83,15 @@ static const uint8_t hmac_short_msg[] = {
0x03, 0x2b, 0x31, 0xd2, 0x41, 0xad, 0x33, 0x71
};
static const uint8_t hmac_short_key[] = {
- 0x9d, 0xa0, 0xc1, 0x14, 0x68, 0x2f, 0x82, 0xc1, 0xd1, 0xe9, 0xb5, 0x44,
- 0x30, 0x58, 0x0b, 0x9c, 0x56, 0x94, 0x89, 0xca, 0x16, 0xb9, 0x2e, 0xe1,
- 0x04, 0x98, 0xd5, 0x5d, 0x7c, 0xad, 0x5d, 0xb5, 0xe6, 0x52, 0x06, 0x34,
- 0x39, 0x31, 0x1e, 0x04
+ 0x9d, 0xa0, 0xc1, 0x14, 0x68, 0x2f, 0x82, 0xc1, 0xd1, 0xe9,
+ 0xb5, 0x44, 0x30, 0x58, 0x0b, 0x9c, 0x56, 0x94, 0x89, 0xca,
+ 0x16, 0xb9, 0x2e, 0xe1, 0x04, 0x98, 0xd5, 0x5d, 0x7c, 0xad,
+ 0x5d, 0xb5, 0xe6, 0x52, 0x06, 0x34, 0x39, 0x31, 0x1e, 0x04
};
static const uint8_t hmac_short_output[] = {
- 0xcd, 0xea, 0xcf, 0xce, 0xbf, 0x46, 0xcc, 0x9d, 0x7e, 0x4d, 0x41, 0x75,
- 0xe5, 0xd8, 0xd2, 0x67, 0xc2, 0x3a, 0x64, 0xcd, 0xe8, 0x3e, 0x86, 0x7e,
- 0x50, 0x01, 0xec, 0xf2, 0x6f, 0xbd, 0x30, 0xd2
+ 0xcd, 0xea, 0xcf, 0xce, 0xbf, 0x46, 0xcc, 0x9d, 0x7e, 0x4d, 0x41,
+ 0x75, 0xe5, 0xd8, 0xd2, 0x67, 0xc2, 0x3a, 0x64, 0xcd, 0xe8, 0x3e,
+ 0x86, 0x7e, 0x50, 0x01, 0xec, 0xf2, 0x6f, 0xbd, 0x30, 0xd2
};
/* HMAC medium key (64 bytes) from NIST FIPS 198-1 (Count = 120) */
@@ -112,17 +109,17 @@ static const uint8_t hmac_medium_msg[] = {
0x85, 0x46, 0x80, 0x4f, 0x9c, 0xf2, 0xec, 0xfe
};
static const uint8_t hmac_medium_key[] = {
- 0x99, 0x28, 0x68, 0x50, 0x4d, 0x25, 0x64, 0xc4, 0xfb, 0x47, 0xbc, 0xbd,
- 0x4a, 0xe4, 0x82, 0xd8, 0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d, 0xdf
};
static int test_sha256(const uint8_t *input, int input_len,
@@ -156,9 +153,8 @@ static int test_sha256(const uint8_t *input, int input_len,
return 1;
}
-static int test_hmac(const uint8_t *key, int key_len,
- const uint8_t *input, int input_len,
- const uint8_t *output)
+static int test_hmac(const uint8_t *key, int key_len, const uint8_t *input,
+ int input_len, const uint8_t *output)
{
uint8_t tmp[SHA256_DIGEST_SIZE];
@@ -172,7 +168,7 @@ static int test_hmac(const uint8_t *key, int key_len,
return 1;
}
-void run_test(int argc, char **argv)
+void run_test(int argc, const char **argv)
{
ccprintf("Testing short message (8 bytes)\n");
if (!test_sha256(sha256_8_input, sizeof(sha256_8_input),
@@ -196,9 +192,8 @@ void run_test(int argc, char **argv)
}
ccprintf("HMAC: Testing short key\n");
- if (!test_hmac(hmac_short_key, sizeof(hmac_short_key),
- hmac_short_msg, sizeof(hmac_short_msg),
- hmac_short_output)) {
+ if (!test_hmac(hmac_short_key, sizeof(hmac_short_key), hmac_short_msg,
+ sizeof(hmac_short_msg), hmac_short_output)) {
test_fail();
return;
}