aboutsummaryrefslogtreecommitdiffstats
path: root/test/crypto/source
diff options
context:
space:
mode:
Diffstat (limited to 'test/crypto/source')
-rw-r--r--test/crypto/source/test/cry_test_root.c5
-rw-r--r--test/crypto/source/test/cry_test_root.h5
-rw-r--r--test/crypto/source/test/cry_test_sequence_001.c6
-rw-r--r--test/crypto/source/test/cry_test_sequence_002.c6
-rw-r--r--test/crypto/source/test/cry_test_sequence_003.c6
-rw-r--r--test/crypto/source/test/cry_test_sequence_004.c22
-rw-r--r--test/crypto/source/test/cry_test_sequence_005.c1
-rw-r--r--test/crypto/source/test/cry_test_sequence_006.c198
-rw-r--r--test/crypto/source/test/cry_test_sequence_007.c191
-rw-r--r--test/crypto/source/testref/ref_aes.c2
-rw-r--r--test/crypto/source/testref/ref_aes.h2
-rw-r--r--test/crypto/source/testref/ref_des.c2
-rw-r--r--test/crypto/source/testref/ref_des.h2
-rw-r--r--test/crypto/source/testref/ref_sha.c73
-rw-r--r--test/crypto/source/testref/ref_sha.h9
15 files changed, 457 insertions, 73 deletions
diff --git a/test/crypto/source/test/cry_test_root.c b/test/crypto/source/test/cry_test_root.c
index 80f97bc3e..519e1fa73 100644
--- a/test/crypto/source/test/cry_test_root.c
+++ b/test/crypto/source/test/cry_test_root.c
@@ -114,10 +114,13 @@ isque dui faucibus, vitae malesuada dui fermentum. Proin ultrici\
es sit amet justo at ornare. Suspendisse efficitur purus nullam.";
-const uint8_t sha_msg0[SHA_LEN_0] = "hi!";
+const uint8_t sha_msg0[SHA_LEN_0] = "abc";
const uint8_t sha_msg1[SHA_LEN_1] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
+const uint8_t sha_msg2[SHA_LEN_2] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
+
+const uint8_t sha_msg3[SHA_LEN_3] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa";
ALIGNED_VAR(4) uint32_t msg_clear[TEST_MSG_DATA_WORD_LEN];
ALIGNED_VAR(4) uint32_t msg_encrypted[TEST_MSG_DATA_WORD_LEN];
diff --git a/test/crypto/source/test/cry_test_root.h b/test/crypto/source/test/cry_test_root.h
index 0fb922d3d..f33cb5c1a 100644
--- a/test/crypto/source/test/cry_test_root.h
+++ b/test/crypto/source/test/cry_test_root.h
@@ -72,6 +72,8 @@ extern void cryptoTest_printArray32(bool isLE,const uint32_t *a,size_t len);
#define SHA_LEN_0 3
#define SHA_LEN_1 56
+#define SHA_LEN_2 64
+#define SHA_LEN_3 128
extern const char test_plain_data[TEST_DATA_BYTE_LEN];
extern uint32_t msg_clear[TEST_MSG_DATA_WORD_LEN];
@@ -81,7 +83,8 @@ extern const uint32_t test_keys[8];
extern const uint32_t test_vectors[4];
extern const uint8_t sha_msg0[SHA_LEN_0];
extern const uint8_t sha_msg1[SHA_LEN_1];
-
+extern const uint8_t sha_msg2[SHA_LEN_2];
+extern const uint8_t sha_msg3[SHA_LEN_3];
#endif /* !defined(__DOXYGEN__) */
diff --git a/test/crypto/source/test/cry_test_sequence_001.c b/test/crypto/source/test/cry_test_sequence_001.c
index 338a62111..e4cf6d1f6 100644
--- a/test/crypto/source/test/cry_test_sequence_001.c
+++ b/test/crypto/source/test/cry_test_sequence_001.c
@@ -42,14 +42,12 @@
#include "ref_aes.h"
static const CRYConfig config_Polling = {
TRANSFER_POLLING,
- AES_CFBS_128, //cfbs
- 0
+ AES_CFBS_128 //cfbs
};
static const CRYConfig config_DMA = {
TRANSFER_DMA,
- AES_CFBS_128, //cfbs
- 0
+ AES_CFBS_128 //cfbs
};
diff --git a/test/crypto/source/test/cry_test_sequence_002.c b/test/crypto/source/test/cry_test_sequence_002.c
index db2bc4b24..e683fd0f7 100644
--- a/test/crypto/source/test/cry_test_sequence_002.c
+++ b/test/crypto/source/test/cry_test_sequence_002.c
@@ -42,14 +42,12 @@
#include "ref_aes.h"
static const CRYConfig config_Polling = {
TRANSFER_POLLING,
- AES_CFBS_128, //cfbs
- 0
+ AES_CFBS_128 //cfbs
};
static const CRYConfig config_DMA = {
TRANSFER_DMA,
- AES_CFBS_128, //cfbs
- 0
+ AES_CFBS_128 //cfbs
};
diff --git a/test/crypto/source/test/cry_test_sequence_003.c b/test/crypto/source/test/cry_test_sequence_003.c
index b0c85bd90..856ae5302 100644
--- a/test/crypto/source/test/cry_test_sequence_003.c
+++ b/test/crypto/source/test/cry_test_sequence_003.c
@@ -42,14 +42,12 @@
#include "ref_aes.h"
static const CRYConfig config_Polling = {
TRANSFER_POLLING,
- AES_CFBS_128, //cfbs
- 0
+ AES_CFBS_128 //cfbs
};
static const CRYConfig config_DMA = {
TRANSFER_DMA,
- AES_CFBS_128, //cfbs
- 0
+ AES_CFBS_128 //cfbs
};
diff --git a/test/crypto/source/test/cry_test_sequence_004.c b/test/crypto/source/test/cry_test_sequence_004.c
index 842278935..d5a5442c2 100644
--- a/test/crypto/source/test/cry_test_sequence_004.c
+++ b/test/crypto/source/test/cry_test_sequence_004.c
@@ -46,21 +46,13 @@
static const CRYConfig configDES_Polling=
{
TRANSFER_POLLING,
- 0,
- TDES_ALGO_SINGLE
-};
-static const CRYConfig configTDES_Polling=
-{
- TRANSFER_POLLING,
- 0,
- TDES_ALGO_TRIPLE
+ 0
};
-static const CRYConfig configTDES_DMA=
+static const CRYConfig configDES_DMA=
{
TRANSFER_DMA,
- 0,
- TDES_ALGO_TRIPLE
+ 0
};
@@ -164,7 +156,7 @@ static void cry_test_004_002_setup(void) {
memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
- cryStart(&CRYD1, &configTDES_Polling);
+ cryStart(&CRYD1, &configDES_Polling);
}
@@ -280,7 +272,7 @@ static void cry_test_004_003_setup(void) {
memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
- cryStart(&CRYD1, &configTDES_Polling);
+ cryStart(&CRYD1, &configDES_Polling);
}
@@ -396,7 +388,7 @@ static void cry_test_004_004_setup(void) {
memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
- cryStart(&CRYD1, &configTDES_DMA);
+ cryStart(&CRYD1, &configDES_DMA);
}
@@ -512,7 +504,7 @@ static void cry_test_004_005_setup(void) {
memcpy((char*) msg_clear, test_plain_data, TEST_DATA_BYTE_LEN);
memset(msg_encrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
memset(msg_decrypted, 0xff, TEST_MSG_DATA_BYTE_LEN);
- cryStart(&CRYD1, &configTDES_DMA);
+ cryStart(&CRYD1, &configDES_DMA);
}
diff --git a/test/crypto/source/test/cry_test_sequence_005.c b/test/crypto/source/test/cry_test_sequence_005.c
index 91478ccb1..35c759950 100644
--- a/test/crypto/source/test/cry_test_sequence_005.c
+++ b/test/crypto/source/test/cry_test_sequence_005.c
@@ -42,7 +42,6 @@
static const CRYConfig configTRNG_Polling=
{
TRANSFER_POLLING,
- 0,
0
};
diff --git a/test/crypto/source/test/cry_test_sequence_006.c b/test/crypto/source/test/cry_test_sequence_006.c
index 11189ea59..9b9f30a85 100644
--- a/test/crypto/source/test/cry_test_sequence_006.c
+++ b/test/crypto/source/test/cry_test_sequence_006.c
@@ -42,18 +42,85 @@
#include <string.h>
#include "ref_sha.h"
-#define MAX_DIGEST_SIZE_INBYTE 64
+/* Buffer size for each SHA transfer, size should be multiple of block size
+ (block size: 64 for SHA_1/SHA_256/SHA_224, 128 for SHA_384/SHA_512) */
+#define MAX_SHA_BLOCK_SIZE TEST_MSG_DATA_BYTE_LEN
+#define MAX_SHA_BLOCK_SIZE_INWORD (MAX_SHA_BLOCK_SIZE/4)
+
+#define shabuffer msg_decrypted
+
+
+#define MAX_DIGEST_SIZE_INBYTE TEST_MSG_DATA_BYTE_LEN
#define MAX_DIGEST_SIZE_INWORD (MAX_DIGEST_SIZE_INBYTE/4)
-static uint32_t digest[MAX_DIGEST_SIZE_INWORD];
+
+#define digest msg_encrypted
+
static const CRYConfig configSHA_Polling=
{
TRANSFER_POLLING,
- 0,
0
};
+static cryerror_t crySHA1(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
+
+ cryerror_t ret;
+ SHA1Context shactxp;
+
+ shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
+ shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
+
+
+ ret = crySHA1Init(cryp,&shactxp);
+
+ ret = crySHA1Update(cryp,&shactxp,size,in);
+
+ ret = crySHA1Final(cryp,&shactxp,out);
+
+
+ return ret;
+}
+
+static cryerror_t crySHA256(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
+
+ cryerror_t ret;
+ SHA256Context shactxp;
+
+ shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
+ shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
+
+
+ ret = crySHA256Init(cryp,&shactxp);
+
+ ret = crySHA256Update(cryp,&shactxp,size,in);
+
+ ret = crySHA256Final(cryp,&shactxp,out);
+
+
+ return ret;
+}
+
+static cryerror_t crySHA512(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
+
+ cryerror_t ret;
+ SHA512Context shactxp;
+
+ shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
+ shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
+
+
+ ret = crySHA512Init(cryp,&shactxp);
+
+ ret = crySHA512Update(cryp,&shactxp,size,in);
+
+ ret = crySHA512Final(cryp,&shactxp,out);
+
+
+ return ret;
+}
+
+
/****************************************************************************
* Test cases.
@@ -90,6 +157,18 @@ static void cry_test_006_001_execute(void) {
/* [6.1.1] Digest.*/
test_set_step(1);
{
+ //---- Empty Block Test
+ ret = crySHA1(&CRYD1,0,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha1 failed");
+
+ SHOW_DATA(digest,5);
+
+
+ ref = (uint32_t*)refSHA_SHA1_EMPTY;
+ for (int i = 0; i < 5; i++) {
+ test_assert(digest[i] == ref[i], "sha1 digest mismatch");
+ }
//---- One Block Test
ret = crySHA1(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
@@ -104,7 +183,7 @@ static void cry_test_006_001_execute(void) {
test_assert(digest[i] == ref[i], "sha1 digest mismatch");
}
- //---- Multi Block Test
+ //---- Multi Block Test 56 Byte
memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
@@ -119,6 +198,38 @@ static void cry_test_006_001_execute(void) {
for (int i = 0; i < 5; i++) {
test_assert(digest[i] == ref[i], "sha1 digest mismatch");
}
+ //---- Multi Block Test 64 Byte
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
+
+ ret = crySHA1(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha1 failed");
+
+ SHOW_DATA(digest,5);
+
+
+ ref = (uint32_t*)refSHA_SHA1_64;
+ for (int i = 0; i < 5; i++) {
+ test_assert(digest[i] == ref[i], "sha1 digest mismatch");
+ }
+
+ //---- Multi Block Test 128 Byte
+
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
+
+ ret = crySHA1(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha1 failed");
+
+ SHOW_DATA(digest,5);
+
+
+ ref = (uint32_t*)refSHA_SHA1_128;
+ for (int i = 0; i < 5; i++) {
+ test_assert(digest[i] == ref[i], "sha1 digest mismatch");
+ }
}
@@ -175,20 +286,51 @@ static void cry_test_006_002_execute(void) {
test_assert(digest[i] == ref[i], "sha256 digest mismatch");
}
- //---- Multi Block Test
+ //---- Multi Block Test 56 Byte
memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
ret = crySHA256(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
- test_assert(ret == CRY_NOERROR, "sha256 failed");
-
+ test_assert(ret == CRY_NOERROR, "sha256 56 byte failed");
SHOW_DATA(digest,8);
+
ref = (uint32_t*)refSHA_SHA256_56;
for (int i = 0; i < 8; i++) {
- test_assert(digest[i] == ref[i], "sha256 digest mismatch");
+ test_assert(digest[i] == ref[i], "sha256 56 byte digest mismatch");
+ }
+ //---- Multi Block Test 64 Byte
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
+
+ ret = crySHA256(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha256 64 byte failed");
+
+ SHOW_DATA(digest,8);
+
+
+ ref = (uint32_t*)refSHA_SHA256_64;
+ for (int i = 0; i < 8; i++) {
+ test_assert(digest[i] == ref[i], "sha256 64 byte digest mismatch");
+ }
+
+ //---- Multi Block Test 128 Byte
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
+
+ ret = crySHA256(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha256 128 byte failed");
+
+ SHOW_DATA(digest,8);
+
+
+ ref = (uint32_t*)refSHA_SHA256_128;
+ for (int i = 0; i < 8; i++) {
+ test_assert(digest[i] == ref[i], "sha256 128 byte digest mismatch");
}
@@ -245,20 +387,52 @@ static void cry_test_006_003_execute(void) {
test_assert(digest[i] == ref[i], "sha512 digest mismatch");
}
- //---- Multi Block Test
+
+ //---- Multi Block Test 56 Byte
memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
ret = crySHA512(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
- test_assert(ret == CRY_NOERROR, "sha512 failed");
-
+ test_assert(ret == CRY_NOERROR, "sha512 56 byte failed");
SHOW_DATA(digest,16);
+
ref = (uint32_t*)refSHA_SHA512_56;
for (int i = 0; i < 16; i++) {
- test_assert(digest[i] == ref[i], "sha512 digest mismatch");
+ test_assert(digest[i] == ref[i], "sha512 56 byte digest mismatch");
+ }
+ //---- Multi Block Test 64 Byte
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
+
+ ret = crySHA512(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha512 64 byte failed");
+
+ SHOW_DATA(digest,16);
+
+
+ ref = (uint32_t*)refSHA_SHA512_64;
+ for (int i = 0; i < 16; i++) {
+ test_assert(digest[i] == ref[i], "sha512 64 byte digest mismatch");
+ }
+
+ //---- Multi Block Test 128 Byte
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
+
+ ret = crySHA512(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha512 128 byte failed");
+
+ SHOW_DATA(digest,16);
+
+
+ ref = (uint32_t*)refSHA_SHA512_128;
+ for (int i = 0; i < 16; i++) {
+ test_assert(digest[i] == ref[i], "sha512 128 byte digest mismatch");
}
diff --git a/test/crypto/source/test/cry_test_sequence_007.c b/test/crypto/source/test/cry_test_sequence_007.c
index 71be2fbed..52f8e2c0e 100644
--- a/test/crypto/source/test/cry_test_sequence_007.c
+++ b/test/crypto/source/test/cry_test_sequence_007.c
@@ -42,17 +42,79 @@
#include <string.h>
#include "ref_sha.h"
-#define MAX_DIGEST_SIZE_INBYTE 64
+/* Buffer size for each SHA transfer, size should be multiple of block size
+ (block size: 64 for SHA_1/SHA_256/SHA_224, 128 for SHA_384/SHA_512) */
+#define MAX_SHA_BLOCK_SIZE TEST_MSG_DATA_BYTE_LEN
+#define MAX_SHA_BLOCK_SIZE_INWORD (MAX_SHA_BLOCK_SIZE/4)
+
+#define shabuffer msg_decrypted
+
+
+#define MAX_DIGEST_SIZE_INBYTE TEST_MSG_DATA_BYTE_LEN
#define MAX_DIGEST_SIZE_INWORD (MAX_DIGEST_SIZE_INBYTE/4)
-static uint32_t digest[MAX_DIGEST_SIZE_INWORD];
+#define digest msg_encrypted
static const CRYConfig configSHA_DMA=
{
TRANSFER_DMA,
- 0,
0
};
+static cryerror_t crySHA1(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
+
+ cryerror_t ret;
+ SHA1Context shactxp;
+
+ shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
+ shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
+
+ ret = crySHA1Init(cryp,&shactxp);
+
+ ret = crySHA1Update(cryp,&shactxp,size,in);
+
+ ret = crySHA1Final(cryp,&shactxp,out);
+
+
+ return ret;
+}
+
+static cryerror_t crySHA256(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
+
+ cryerror_t ret;
+ SHA256Context shactxp;
+
+ shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
+ shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
+
+
+ ret = crySHA256Init(cryp,&shactxp);
+
+ ret = crySHA256Update(cryp,&shactxp,size,in);
+
+ ret = crySHA256Final(cryp,&shactxp,out);
+
+
+ return ret;
+}
+
+static cryerror_t crySHA512(CRYDriver *cryp, size_t size,const uint8_t *in, uint8_t *out) {
+
+ cryerror_t ret;
+ SHA512Context shactxp;
+
+ shactxp.sha.sha_buffer = (uint8_t*)&shabuffer[0];
+ shactxp.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
+
+ ret = crySHA512Init(cryp,&shactxp);
+
+ ret = crySHA512Update(cryp,&shactxp,size,in);
+
+ ret = crySHA512Final(cryp,&shactxp,out);
+
+
+ return ret;
+}
+
/****************************************************************************
@@ -90,6 +152,18 @@ static void cry_test_007_001_execute(void) {
/* [7.1.1] Digest.*/
test_set_step(1);
{
+ //---- Empty Block Test
+ ret = crySHA1(&CRYD1,0,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha1 failed");
+
+ SHOW_DATA(digest,5);
+
+
+ ref = (uint32_t*)refSHA_SHA1_EMPTY;
+ for (int i = 0; i < 5; i++) {
+ test_assert(digest[i] == ref[i], "sha1 digest mismatch");
+ }
//---- One Block Test
ret = crySHA1(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
@@ -104,7 +178,7 @@ static void cry_test_007_001_execute(void) {
test_assert(digest[i] == ref[i], "sha1 digest mismatch");
}
- //---- Multi Block Test
+ //---- Multi Block Test 56 Byte
memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
@@ -119,7 +193,38 @@ static void cry_test_007_001_execute(void) {
for (int i = 0; i < 5; i++) {
test_assert(digest[i] == ref[i], "sha1 digest mismatch");
}
+ //---- Multi Block Test 64 Byte
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
+
+ ret = crySHA1(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha1 failed");
+
+ SHOW_DATA(digest,5);
+
+
+ ref = (uint32_t*)refSHA_SHA1_64;
+ for (int i = 0; i < 5; i++) {
+ test_assert(digest[i] == ref[i], "sha1 digest mismatch");
+ }
+
+ //---- Multi Block Test 128 Byte
+
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
+ ret = crySHA1(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha1 failed");
+
+ SHOW_DATA(digest,5);
+
+
+ ref = (uint32_t*)refSHA_SHA1_128;
+ for (int i = 0; i < 5; i++) {
+ test_assert(digest[i] == ref[i], "sha1 digest mismatch");
+ }
}
}
@@ -175,20 +280,51 @@ static void cry_test_007_002_execute(void) {
test_assert(digest[i] == ref[i], "sha256 digest mismatch");
}
- //---- Multi Block Test
+ //---- Multi Block Test 56 Byte
memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
ret = crySHA256(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
- test_assert(ret == CRY_NOERROR, "sha256 failed");
-
+ test_assert(ret == CRY_NOERROR, "sha256 56 byte failed");
SHOW_DATA(digest,8);
+
ref = (uint32_t*)refSHA_SHA256_56;
for (int i = 0; i < 8; i++) {
- test_assert(digest[i] == ref[i], "sha256 digest mismatch");
+ test_assert(digest[i] == ref[i], "sha256 56 byte digest mismatch");
+ }
+ //---- Multi Block Test 64 Byte
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
+
+ ret = crySHA256(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha256 64 byte failed");
+
+ SHOW_DATA(digest,8);
+
+
+ ref = (uint32_t*)refSHA_SHA256_64;
+ for (int i = 0; i < 8; i++) {
+ test_assert(digest[i] == ref[i], "sha256 64 byte digest mismatch");
+ }
+
+ //---- Multi Block Test 128 Byte
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
+
+ ret = crySHA256(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha256 128 byte failed");
+
+ SHOW_DATA(digest,8);
+
+
+ ref = (uint32_t*)refSHA_SHA256_128;
+ for (int i = 0; i < 8; i++) {
+ test_assert(digest[i] == ref[i], "sha256 128 byte digest mismatch");
}
@@ -245,23 +381,54 @@ static void cry_test_007_003_execute(void) {
test_assert(digest[i] == ref[i], "sha512 digest mismatch");
}
- //---- Multi Block Test
+
+ //---- Multi Block Test 56 Byte
memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
ret = crySHA512(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
- test_assert(ret == CRY_NOERROR, "sha512 failed");
-
+ test_assert(ret == CRY_NOERROR, "sha512 56 byte failed");
SHOW_DATA(digest,16);
+
ref = (uint32_t*)refSHA_SHA512_56;
for (int i = 0; i < 16; i++) {
- test_assert(digest[i] == ref[i], "sha512 digest mismatch");
+ test_assert(digest[i] == ref[i], "sha512 56 byte digest mismatch");
}
+ //---- Multi Block Test 64 Byte
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg2, SHA_LEN_2);
+
+ ret = crySHA512(&CRYD1,SHA_LEN_2,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha512 64 byte failed");
+
+ SHOW_DATA(digest,16);
+ ref = (uint32_t*)refSHA_SHA512_64;
+ for (int i = 0; i < 16; i++) {
+ test_assert(digest[i] == ref[i], "sha512 64 byte digest mismatch");
+ }
+
+ //---- Multi Block Test 128 Byte
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg3, SHA_LEN_3);
+
+ ret = crySHA512(&CRYD1,SHA_LEN_3,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha512 128 byte failed");
+
+ SHOW_DATA(digest,16);
+
+
+ ref = (uint32_t*)refSHA_SHA512_128;
+ for (int i = 0; i < 16; i++) {
+ test_assert(digest[i] == ref[i], "sha512 128 byte digest mismatch");
+ }
+
}
}
diff --git a/test/crypto/source/testref/ref_aes.c b/test/crypto/source/testref/ref_aes.c
index 33f47556e..11c6ef480 100644
--- a/test/crypto/source/testref/ref_aes.c
+++ b/test/crypto/source/testref/ref_aes.c
@@ -1,5 +1,5 @@
/*
- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/test/crypto/source/testref/ref_aes.h b/test/crypto/source/testref/ref_aes.h
index e2a7e57cd..a4e6759fc 100644
--- a/test/crypto/source/testref/ref_aes.h
+++ b/test/crypto/source/testref/ref_aes.h
@@ -1,5 +1,5 @@
/*
- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/test/crypto/source/testref/ref_des.c b/test/crypto/source/testref/ref_des.c
index 046a642ed..fca75627c 100644
--- a/test/crypto/source/testref/ref_des.c
+++ b/test/crypto/source/testref/ref_des.c
@@ -1,5 +1,5 @@
/*
- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/test/crypto/source/testref/ref_des.h b/test/crypto/source/testref/ref_des.h
index 31516447a..c839084b7 100644
--- a/test/crypto/source/testref/ref_des.h
+++ b/test/crypto/source/testref/ref_des.h
@@ -1,5 +1,5 @@
/*
- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
diff --git a/test/crypto/source/testref/ref_sha.c b/test/crypto/source/testref/ref_sha.c
index 741c13dee..8e9822ded 100644
--- a/test/crypto/source/testref/ref_sha.c
+++ b/test/crypto/source/testref/ref_sha.c
@@ -1,5 +1,5 @@
/*
- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -16,9 +16,14 @@
#include "hal.h"
+const uint8_t refSHA_SHA1_EMPTY[]={
+0xDA,0x39,0xA3,0xEE,0x5E,0x6B,0x4B,0x0D,0x32,0x55,
+0xBF,0xEF,0x95,0x60,0x18,0x90,0xAF,0xD8,0x07,0x09,
+0x0D,0x0A,
+};
const uint8_t refSHA_SHA1_3[]={
-0x3A,0x98,0x7A,0xCF,0x8C,0xBC,0x10,0x28,0xB7,0xDB,
-0xC8,0x6B,0xD0,0x86,0x83,0x11,0x51,0x89,0x9A,0x2B,
+0xA9,0x99,0x3E,0x36,0x47,0x06,0x81,0x6A,0xBA,0x3E,
+0x25,0x71,0x78,0x50,0xC2,0x6C,0x9C,0xD0,0xD8,0x9D,
};
const uint8_t refSHA_SHA1_56[]={
@@ -26,11 +31,21 @@ const uint8_t refSHA_SHA1_56[]={
0x4A,0xA1,0xF9,0x51,0x29,0xE5,0xE5,0x46,0x70,0xF1,
};
+const uint8_t refSHA_SHA1_64[]={
+0x00,0x98,0xBA,0x82,0x4B,0x5C,0x16,0x42,0x7B,0xD7,
+0xA1,0x12,0x2A,0x5A,0x44,0x2A,0x25,0xEC,0x64,0x4D,
+
+};
+const uint8_t refSHA_SHA1_128[]={
+0xAD,0x5B,0x3F,0xDB,0xCB,0x52,0x67,0x78,0xC2,0x83,
+0x9D,0x2F,0x15,0x1E,0xA7,0x53,0x99,0x5E,0x26,0xA0,
+
+};
const uint8_t refSHA_SHA256_3[]={
-0xC0,0xDD,0xD6,0x2C,0x77,0x17,0x18,0x0E,0x7F,0xFB,
-0x8A,0x15,0xBB,0x96,0x74,0xD3,0xEC,0x92,0x59,0x2E,
-0x0B,0x7A,0xC7,0xD1,0xD5,0x28,0x98,0x36,0xB4,0x55,
-0x3B,0xE2,
+0xBA,0x78,0x16,0xBF,0x8F,0x01,0xCF,0xEA,0x41,0x41,
+0x40,0xDE,0x5D,0xAE,0x22,0x23,0xB0,0x03,0x61,0xA3,
+0x96,0x17,0x7A,0x9C,0xB4,0x10,0xFF,0x61,0xF2,0x00,
+0x15,0xAD,
};
const uint8_t refSHA_SHA256_56[]={
0x24,0x8D,0x6A,0x61,0xD2,0x06,0x38,0xB8,0xE5,0xC0,
@@ -38,14 +53,26 @@ const uint8_t refSHA_SHA256_56[]={
0x64,0xFF,0x21,0x67,0xF6,0xEC,0xED,0xD4,0x19,0xDB,
0x06,0xC1,
};
+const uint8_t refSHA_SHA256_64[]={
+0xFF,0xE0,0x54,0xFE,0x7A,0xE0,0xCB,0x6D,0xC6,0x5C,
+0x3A,0xF9,0xB6,0x1D,0x52,0x09,0xF4,0x39,0x85,0x1D,
+0xB4,0x3D,0x0B,0xA5,0x99,0x73,0x37,0xDF,0x15,0x46,
+0x68,0xEB,
+};
+const uint8_t refSHA_SHA256_128[]={
+0x68,0x36,0xCF,0x13,0xBA,0xC4,0x00,0xE9,0x10,0x50,
+0x71,0xCD,0x6A,0xF4,0x70,0x84,0xDF,0xAC,0xAD,0x4E,
+0x5E,0x30,0x2C,0x94,0xBF,0xED,0x24,0xE0,0x13,0xAF,
+0xB7,0x3E,
+};
const uint8_t refSHA_SHA512_3[]={
-0x3E,0xBB,0x6E,0x93,0x1E,0xAA,0x4D,0xCF,0x74,0x1A,
-0xD1,0x23,0x37,0xD4,0xF7,0x10,0x5B,0x02,0xD4,0xA9,
-0xB1,0x94,0x21,0x4E,0x88,0x55,0x9E,0x8E,0x41,0xEC,
-0x04,0xD3,0x20,0xE9,0x6A,0x3C,0xF9,0x12,0xED,0x27,
-0x34,0x29,0x35,0xA6,0xF8,0x9D,0x1F,0x5C,0x1A,0x5C,
-0xD7,0xF7,0xFF,0xBF,0xA9,0xB1,0xBE,0x1A,0x41,0x62,
-0xED,0x32,0x3C,0x7A,
+0xDD,0xAF,0x35,0xA1,0x93,0x61,0x7A,0xBA,0xCC,0x41,
+0x73,0x49,0xAE,0x20,0x41,0x31,0x12,0xE6,0xFA,0x4E,
+0x89,0xA9,0x7E,0xA2,0x0A,0x9E,0xEE,0xE6,0x4B,0x55,
+0xD3,0x9A,0x21,0x92,0x99,0x2A,0x27,0x4F,0xC1,0xA8,
+0x36,0xBA,0x3C,0x23,0xA3,0xFE,0xEB,0xBD,0x45,0x4D,
+0x44,0x23,0x64,0x3C,0xE8,0x0E,0x2A,0x9A,0xC9,0x4F,
+0xA5,0x4C,0xA4,0x9F,
};
const uint8_t refSHA_SHA512_56[]={
0x20,0x4A,0x8F,0xC6,0xDD,0xA8,0x2F,0x0A,0x0C,0xED,
@@ -56,3 +83,21 @@ const uint8_t refSHA_SHA512_56[]={
0x85,0xC7,0xA7,0x1D,0xD7,0x03,0x54,0xEC,0x63,0x12,
0x38,0xCA,0x34,0x45,
};
+const uint8_t refSHA_SHA512_64[]={
+0x01,0xD3,0x5C,0x10,0xC6,0xC3,0x8C,0x2D,0xCF,0x48,
+0xF7,0xEE,0xBB,0x32,0x35,0xFB,0x5A,0xD7,0x4A,0x65,
+0xEC,0x4C,0xD0,0x16,0xE2,0x35,0x4C,0x63,0x7A,0x8F,
+0xB4,0x9B,0x69,0x5E,0xF3,0xC1,0xD6,0xF7,0xAE,0x4C,
+0xD7,0x4D,0x78,0xCC,0x9C,0x9B,0xCA,0xC9,0xD4,0xF2,
+0x3A,0x73,0x01,0x99,0x98,0xA7,0xF7,0x30,0x38,0xA5,
+0xC9,0xB2,0xDB,0xDE,
+};
+const uint8_t refSHA_SHA512_128[]={
+0xB7,0x3D,0x19,0x29,0xAA,0x61,0x59,0x34,0xE6,0x1A,
+0x87,0x15,0x96,0xB3,0xF3,0xB3,0x33,0x59,0xF4,0x2B,
+0x81,0x75,0x60,0x2E,0x89,0xF7,0xE0,0x6E,0x5F,0x65,
+0x8A,0x24,0x36,0x67,0x80,0x7E,0xD3,0x00,0x31,0x4B,
+0x95,0xCA,0xCD,0xD5,0x79,0xF3,0xE3,0x3A,0xBD,0xFB,
+0xE3,0x51,0x90,0x95,0x19,0xA8,0x46,0xD4,0x65,0xC5,
+0x95,0x82,0xF3,0x21,
+};
diff --git a/test/crypto/source/testref/ref_sha.h b/test/crypto/source/testref/ref_sha.h
index 0d413b672..36e399ffe 100644
--- a/test/crypto/source/testref/ref_sha.h
+++ b/test/crypto/source/testref/ref_sha.h
@@ -1,5 +1,5 @@
/*
- ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
+ ChibiOS - Copyright (C) 2006..2017 Giovanni Di Sirio
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -16,10 +16,17 @@
#ifndef TEST_REF_SHA_H_
#define TEST_REF_SHA_H_
+extern const uint8_t refSHA_SHA1_EMPTY[];
extern const uint8_t refSHA_SHA1_3[];
extern const uint8_t refSHA_SHA1_56[];
+extern const uint8_t refSHA_SHA1_64[];
+extern const uint8_t refSHA_SHA1_128[];
extern const uint8_t refSHA_SHA256_3[];
extern const uint8_t refSHA_SHA256_56[];
+extern const uint8_t refSHA_SHA256_64[];
+extern const uint8_t refSHA_SHA256_128[];
extern const uint8_t refSHA_SHA512_3[];
extern const uint8_t refSHA_SHA512_56[];
+extern const uint8_t refSHA_SHA512_64[];
+extern const uint8_t refSHA_SHA512_128[];
#endif //TEST_REF_SHA_H_