aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorareviu <areviu.info@gmail.com>2017-11-30 21:12:58 +0000
committerareviu <areviu.info@gmail.com>2017-11-30 21:12:58 +0000
commit2ebbe6eb870313331bba48884112675107a6b866 (patch)
treef2eb4b050f057c5ebddb6a48cb1e511296940544 /test
parent5b31410098434a2aff0c0729621fee6c6f2b3519 (diff)
downloadChibiOS-2ebbe6eb870313331bba48884112675107a6b866.tar.gz
ChibiOS-2ebbe6eb870313331bba48884112675107a6b866.tar.bz2
ChibiOS-2ebbe6eb870313331bba48884112675107a6b866.zip
update sha and trng lld
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11091 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'test')
-rw-r--r--test/crypto/configuration.xml390
-rw-r--r--test/crypto/crypto_test.mk5
-rw-r--r--test/crypto/ref/gen_cfiles.bat1
-rw-r--r--test/crypto/ref/gen_testref.bat5
-rw-r--r--test/crypto/ref/sha_ref.bat20
-rw-r--r--test/crypto/source/test/cry_test_root.c10
-rw-r--r--test/crypto/source/test/cry_test_root.h9
-rw-r--r--test/crypto/source/test/cry_test_sequence_005.c128
-rw-r--r--test/crypto/source/test/cry_test_sequence_005.h27
-rw-r--r--test/crypto/source/test/cry_test_sequence_006.c295
-rw-r--r--test/crypto/source/test/cry_test_sequence_006.h27
-rw-r--r--test/crypto/source/testref/ref_sha.c58
-rw-r--r--test/crypto/source/testref/ref_sha.h25
13 files changed, 999 insertions, 1 deletions
diff --git a/test/crypto/configuration.xml b/test/crypto/configuration.xml
index 958839811..4d5edd304 100644
--- a/test/crypto/configuration.xml
+++ b/test/crypto/configuration.xml
@@ -44,9 +44,11 @@ extern void cryptoTest_printArray32(bool isLE,const uint32_t *a,size_t len);
#ifdef LOG_CRYPTO_DATA
#define SHOW_ENCRYPDATA(w) cryptoTest_printArray32(true,msg_encrypted,w)
#define SHOW_DECRYPDATA(w) cryptoTest_printArray32(true,msg_decrypted,w)
+#define SHOW_DATA(d,w) cryptoTest_printArray32(true,d,w)
#else
#define SHOW_ENCRYPDATA(w)
#define SHOW_DECRYPDATA(w)
+#define SHOW_DATA(d,w)
#endif
#define TEST_DATA_BYTE_LEN 640
@@ -56,12 +58,17 @@ extern void cryptoTest_printArray32(bool isLE,const uint32_t *a,size_t len);
#define TEST_MSG_DATA_BYTE_LEN 640
#define TEST_MSG_DATA_WORD_LEN (TEST_MSG_DATA_BYTE_LEN / 4)
+#define SHA_LEN_0 3
+#define SHA_LEN_1 56
+
extern const char test_plain_data[TEST_DATA_BYTE_LEN];
extern uint32_t msg_clear[TEST_MSG_DATA_WORD_LEN];
extern uint32_t msg_encrypted[TEST_MSG_DATA_WORD_LEN];
extern uint32_t msg_decrypted[TEST_MSG_DATA_WORD_LEN];
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];
]]></value>
</global_definitions>
@@ -109,6 +116,12 @@ am quis dolor in libero placerat congue. Sed sodales urna sceler\
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_msg1[SHA_LEN_1] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
+
+
ALIGNED_VAR(4) uint32_t msg_clear[TEST_MSG_DATA_WORD_LEN];
ALIGNED_VAR(4) uint32_t msg_encrypted[TEST_MSG_DATA_WORD_LEN];
ALIGNED_VAR(4) uint32_t msg_decrypted[TEST_MSG_DATA_WORD_LEN];
@@ -2287,6 +2300,383 @@ for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
</cases>
</sequence>
+<sequence>
+ <type index="0">
+ <value>Internal Tests</value>
+ </type>
+ <brief>
+ <value>TRNG</value>
+ </brief>
+ <description>
+ <value>TRNG testing</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <shared_code>
+ <value><![CDATA[
+#include <string.h>
+
+static const CRYConfig configTRNG_Polling=
+{
+ TRANSFER_POLLING,
+ 0,
+ 0
+};
+
+ ]]></value>
+ </shared_code>
+ <cases>
+ <case>
+ <brief>
+ <value>TRNG Polling</value>
+ </brief>
+ <description>
+ <value>testing TRNG in polled mode</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <various_code>
+ <setup_code>
+ <value><![CDATA[
+cryStart(&CRYD1, &configTRNG_Polling);
+
+ ]]></value>
+ </setup_code>
+ <teardown_code>
+ <value><![CDATA[cryStop(&CRYD1);]]></value>
+ </teardown_code>
+ <local_variables>
+ <value><![CDATA[
+ cryerror_t ret;
+]]></value>
+ </local_variables>
+ </various_code>
+ <steps>
+
+ <step>
+ <description>
+ <value>Random generation and test</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[
+uint32_t random[10];
+ int i,j;
+ for (i=0;i<10;i++)
+ {
+ ret = cryTRNG(&CRYD1,(uint8_t*)&random[i]);
+
+ test_assert(ret == CRY_NOERROR , "failed random");
+
+ SHOW_DATA(&random[i],1);
+
+ test_assert(random[i] != 0 , "failed random generation (zero)");
+
+ for (j=0;j<i;j++)
+ {
+ test_assert(random[i] != random[j] , "failed random generation");
+ }
+ }
+
+]]></value>
+ </code>
+ </step>
+
+
+
+
+
+ </steps>
+ </case>
+
+
+
+ </cases>
+ </sequence>
+
+<sequence>
+ <type index="0">
+ <value>Internal Tests</value>
+ </type>
+ <brief>
+ <value>SHA</value>
+ </brief>
+ <description>
+ <value>SHA testing</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <shared_code>
+ <value><![CDATA[
+#include <string.h>
+#include "ref_sha.h"
+
+#define MAX_DIGEST_SIZE_INBYTE 64
+#define MAX_DIGEST_SIZE_INWORD (MAX_DIGEST_SIZE_INBYTE/4)
+static uint32_t digest[MAX_DIGEST_SIZE_INWORD];
+
+static const CRYConfig configSHA_Polling=
+{
+ TRANSFER_POLLING,
+ 0,
+ 0
+};
+
+ ]]></value>
+ </shared_code>
+ <cases>
+ <case>
+ <brief>
+ <value>SHA1 Polling</value>
+ </brief>
+ <description>
+ <value>testing SHA1 in polled mode</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <various_code>
+ <setup_code>
+ <value><![CDATA[
+memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
+memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
+cryStart(&CRYD1, &configSHA_Polling);
+
+ ]]></value>
+ </setup_code>
+ <teardown_code>
+ <value><![CDATA[cryStop(&CRYD1);]]></value>
+ </teardown_code>
+ <local_variables>
+ <value><![CDATA[
+ cryerror_t ret;
+ uint32_t *ref;
+]]></value>
+ </local_variables>
+ </various_code>
+ <steps>
+
+ <step>
+ <description>
+ <value>Digest</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[
+//---- One Block Test
+ret = crySHA1(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+
+test_assert(ret == CRY_NOERROR, "sha1 failed");
+
+
+SHOW_DATA(digest,5);
+
+ref = (uint32_t*)refSHA_SHA1_3;
+for (int i = 0; i < 5; i++) {
+ test_assert(digest[i] == ref[i], "sha1 digest mismatch");
+}
+
+//---- Multi Block Test
+memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
+
+ret = crySHA1(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+test_assert(ret == CRY_NOERROR, "sha1 failed");
+
+ SHOW_DATA(digest,5);
+
+
+ref = (uint32_t*)refSHA_SHA1_56;
+for (int i = 0; i < 5; i++) {
+ test_assert(digest[i] == ref[i], "sha1 digest mismatch");
+}
+
+
+]]></value>
+ </code>
+ </step>
+
+
+
+
+
+ </steps>
+ </case>
+
+ <case>
+ <brief>
+ <value>SHA256 Polling</value>
+ </brief>
+ <description>
+ <value>testing SHA256 in polled mode</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <various_code>
+ <setup_code>
+ <value><![CDATA[
+memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
+memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
+cryStart(&CRYD1, &configSHA_Polling);
+
+ ]]></value>
+ </setup_code>
+ <teardown_code>
+ <value><![CDATA[cryStop(&CRYD1);]]></value>
+ </teardown_code>
+ <local_variables>
+ <value><![CDATA[
+ cryerror_t ret;
+ uint32_t *ref;
+]]></value>
+ </local_variables>
+ </various_code>
+ <steps>
+
+ <step>
+ <description>
+ <value>Digest</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[
+
+//---- One Block Test
+ret = crySHA256(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+test_assert(ret == CRY_NOERROR, "sha256 failed");
+
+SHOW_DATA(digest,8);
+
+ref = (uint32_t*)refSHA_SHA256_3;
+for (int i = 0; i < 8; i++) {
+ test_assert(digest[i] == ref[i], "sha256 digest mismatch");
+}
+
+//---- Multi Block Test
+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");
+
+
+ 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");
+}
+
+
+]]></value>
+ </code>
+ </step>
+
+
+
+
+
+ </steps>
+ </case>
+ <case>
+ <brief>
+ <value>SHA512 Polling</value>
+ </brief>
+ <description>
+ <value>testing SHA512 in polled mode</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <various_code>
+ <setup_code>
+ <value><![CDATA[
+memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
+memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
+cryStart(&CRYD1, &configSHA_Polling);
+
+ ]]></value>
+ </setup_code>
+ <teardown_code>
+ <value><![CDATA[cryStop(&CRYD1);]]></value>
+ </teardown_code>
+ <local_variables>
+ <value><![CDATA[
+ cryerror_t ret;
+ uint32_t *ref;
+]]></value>
+ </local_variables>
+ </various_code>
+ <steps>
+
+ <step>
+ <description>
+ <value>Digest</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[
+//---- One Block Test
+ret = crySHA512(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+test_assert(ret == CRY_NOERROR, "sha512 failed");
+
+SHOW_DATA(digest,16);
+
+ref = (uint32_t*)refSHA_SHA512_3;
+for (int i = 0; i < 16; i++) {
+ test_assert(digest[i] == ref[i], "sha512 digest mismatch");
+}
+
+//---- Multi Block Test
+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");
+
+
+ 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");
+}
+
+
+]]></value>
+ </code>
+ </step>
+
+
+
+
+
+ </steps>
+ </case>
+ </cases>
+ </sequence>
+
</sequences>
</instance>
</instances>
diff --git a/test/crypto/crypto_test.mk b/test/crypto/crypto_test.mk
index 039cff349..efd7faf88 100644
--- a/test/crypto/crypto_test.mk
+++ b/test/crypto/crypto_test.mk
@@ -2,10 +2,13 @@
TESTSRC += ${CHIBIOS}/test/crypto/source/test/cry_test_root.c \
${CHIBIOS}/test/crypto/source/testref/ref_aes.c \
${CHIBIOS}/test/crypto/source/testref/ref_des.c \
+ ${CHIBIOS}/test/crypto/source/testref/ref_sha.c \
${CHIBIOS}/test/crypto/source/test/cry_test_sequence_001.c \
${CHIBIOS}/test/crypto/source/test/cry_test_sequence_002.c \
${CHIBIOS}/test/crypto/source/test/cry_test_sequence_003.c \
- ${CHIBIOS}/test/crypto/source/test/cry_test_sequence_004.c
+ ${CHIBIOS}/test/crypto/source/test/cry_test_sequence_004.c \
+ ${CHIBIOS}/test/crypto/source/test/cry_test_sequence_005.c \
+ ${CHIBIOS}/test/crypto/source/test/cry_test_sequence_006.c
# Required include directories
TESTINC += ${CHIBIOS}/test/crypto/source/testref \
${CHIBIOS}/test/crypto/source/test
diff --git a/test/crypto/ref/gen_cfiles.bat b/test/crypto/ref/gen_cfiles.bat
index d0bc19ff9..d63807b38 100644
--- a/test/crypto/ref/gen_cfiles.bat
+++ b/test/crypto/ref/gen_cfiles.bat
@@ -2,3 +2,4 @@
%PYTHON%\python genfile.py -f des_ecb_8,tdes_ecb_16,tdes_ecb_24,tdes_cbc_16,tdes_cbc_24 -o ref_des -p ../source/testref
+%PYTHON%\python genfile.py -f sha_sha1_3,sha_sha1_56,sha_sha256_3,sha_sha256_56,sha_sha512_3,sha_sha512_56 -o ref_sha -p ../source/testref
diff --git a/test/crypto/ref/gen_testref.bat b/test/crypto/ref/gen_testref.bat
index 311376773..38c329606 100644
--- a/test/crypto/ref/gen_testref.bat
+++ b/test/crypto/ref/gen_testref.bat
@@ -6,7 +6,12 @@ del *.enc
%PYTHON%\python -c "print 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent et pellentesque risus. Sed id gravida elit. Proin eget accumsan mi. Aliquam vitae dui porta, euismod velit viverra, elementum lacus. Nunc turpis orci, venenatis vel vulputate nec, luctus sitamet urna. Ut et nunc purus. Aliquam erat volutpat. Vestibulum nulla dolor, cursus vitae cursus eget, dapibus eget sapien. Integer justo eros, commodo ut massa eu, bibendum elementum tellus. Nam quis dolor in libero placerat congue. Sed sodales urna scelerisque dui faucibus, vitae malesuada dui fermentum. Proin ultricies sit amet justo at ornare. Suspendisse efficitur purus nullam.'.decode('ascii')" > plaintext
+echo|set /p="hi!" > plaintext_2
+
+echo|set /p="abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq" > plaintext_3
+
call aes_ref.bat
call des_ref.bat
+call sha_ref.bat
call gen_cfiles.bat \ No newline at end of file
diff --git a/test/crypto/ref/sha_ref.bat b/test/crypto/ref/sha_ref.bat
new file mode 100644
index 000000000..9eaa96463
--- /dev/null
+++ b/test/crypto/ref/sha_ref.bat
@@ -0,0 +1,20 @@
+
+call %OPENSSL%\openssl dgst -sha1 -c -binary -out sha_sha1_3 plaintext_2
+ren sha_sha1_3 sha_sha1_3.enc
+
+call %OPENSSL%\openssl dgst -sha1 -c -binary -out sha_sha1_56 plaintext_3
+ren sha_sha1_56 sha_sha1_56.enc
+
+call %OPENSSL%\openssl dgst -sha256 -c -binary -out sha_sha256_3 plaintext_2
+ren sha_sha256_3 sha_sha256_3.enc
+
+call %OPENSSL%\openssl dgst -sha256 -c -binary -out sha_sha256_56 plaintext_3
+ren sha_sha256_56 sha_sha256_56.enc
+
+
+call %OPENSSL%\openssl dgst -sha512 -c -binary -out sha_sha512_3 plaintext_2
+ren sha_sha512_3 sha_sha512_3.enc
+
+
+call %OPENSSL%\openssl dgst -sha512 -c -binary -out sha_sha512_56 plaintext_3
+ren sha_sha512_56 sha_sha512_56.enc \ No newline at end of file
diff --git a/test/crypto/source/test/cry_test_root.c b/test/crypto/source/test/cry_test_root.c
index e80e1d3fb..bd176b409 100644
--- a/test/crypto/source/test/cry_test_root.c
+++ b/test/crypto/source/test/cry_test_root.c
@@ -25,6 +25,8 @@
* - @subpage cry_test_sequence_002
* - @subpage cry_test_sequence_003
* - @subpage cry_test_sequence_004
+ * - @subpage cry_test_sequence_005
+ * - @subpage cry_test_sequence_006
* .
*/
@@ -50,6 +52,8 @@ const testsequence_t * const cry_test_suite_array[] = {
&cry_test_sequence_002,
&cry_test_sequence_003,
&cry_test_sequence_004,
+ &cry_test_sequence_005,
+ &cry_test_sequence_006,
NULL
};
@@ -107,6 +111,12 @@ am quis dolor in libero placerat congue. Sed sodales urna sceler\
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_msg1[SHA_LEN_1] = "abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
+
+
ALIGNED_VAR(4) uint32_t msg_clear[TEST_MSG_DATA_WORD_LEN];
ALIGNED_VAR(4) uint32_t msg_encrypted[TEST_MSG_DATA_WORD_LEN];
ALIGNED_VAR(4) uint32_t msg_decrypted[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 2bb5ab029..24842646f 100644
--- a/test/crypto/source/test/cry_test_root.h
+++ b/test/crypto/source/test/cry_test_root.h
@@ -28,6 +28,8 @@
#include "cry_test_sequence_002.h"
#include "cry_test_sequence_003.h"
#include "cry_test_sequence_004.h"
+#include "cry_test_sequence_005.h"
+#include "cry_test_sequence_006.h"
#if !defined(__DOXYGEN__)
@@ -53,9 +55,11 @@ extern void cryptoTest_printArray32(bool isLE,const uint32_t *a,size_t len);
#ifdef LOG_CRYPTO_DATA
#define SHOW_ENCRYPDATA(w) cryptoTest_printArray32(true,msg_encrypted,w)
#define SHOW_DECRYPDATA(w) cryptoTest_printArray32(true,msg_decrypted,w)
+#define SHOW_DATA(d,w) cryptoTest_printArray32(true,d,w)
#else
#define SHOW_ENCRYPDATA(w)
#define SHOW_DECRYPDATA(w)
+#define SHOW_DATA(d,w)
#endif
#define TEST_DATA_BYTE_LEN 640
@@ -65,12 +69,17 @@ extern void cryptoTest_printArray32(bool isLE,const uint32_t *a,size_t len);
#define TEST_MSG_DATA_BYTE_LEN 640
#define TEST_MSG_DATA_WORD_LEN (TEST_MSG_DATA_BYTE_LEN / 4)
+#define SHA_LEN_0 3
+#define SHA_LEN_1 56
+
extern const char test_plain_data[TEST_DATA_BYTE_LEN];
extern uint32_t msg_clear[TEST_MSG_DATA_WORD_LEN];
extern uint32_t msg_encrypted[TEST_MSG_DATA_WORD_LEN];
extern uint32_t msg_decrypted[TEST_MSG_DATA_WORD_LEN];
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];
#endif /* !defined(__DOXYGEN__) */
diff --git a/test/crypto/source/test/cry_test_sequence_005.c b/test/crypto/source/test/cry_test_sequence_005.c
new file mode 100644
index 000000000..fb15c13c1
--- /dev/null
+++ b/test/crypto/source/test/cry_test_sequence_005.c
@@ -0,0 +1,128 @@
+/*
+ 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.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "hal.h"
+#include "cry_test_root.h"
+
+/**
+ * @file cry_test_sequence_005.c
+ * @brief Test Sequence 005 code.
+ *
+ * @page cry_test_sequence_005 [5] TRNG
+ *
+ * File: @ref cry_test_sequence_005.c
+ *
+ * <h2>Description</h2>
+ * TRNG testing.
+ *
+ * <h2>Test Cases</h2>
+ * - @subpage cry_test_005_001
+ * .
+ */
+
+/****************************************************************************
+ * Shared code.
+ ****************************************************************************/
+
+#include <string.h>
+
+static const CRYConfig configTRNG_Polling=
+{
+ TRANSFER_POLLING,
+ 0,
+ 0
+};
+
+
+
+/****************************************************************************
+ * Test cases.
+ ****************************************************************************/
+
+/**
+ * @page cry_test_005_001 [5.1] TRNG Polling
+ *
+ * <h2>Description</h2>
+ * testing TRNG in polled mode.
+ *
+ * <h2>Test Steps</h2>
+ * - [5.1.1] Random generation and test.
+ * .
+ */
+
+static void cry_test_005_001_setup(void) {
+ cryStart(&CRYD1, &configTRNG_Polling);
+
+
+}
+
+static void cry_test_005_001_teardown(void) {
+ cryStop(&CRYD1);
+}
+
+static void cry_test_005_001_execute(void) {
+ cryerror_t ret;
+
+ /* [5.1.1] Random generation and test.*/
+ test_set_step(1);
+ {
+ uint32_t random[10];
+ int i,j;
+ for (i=0;i<10;i++)
+ {
+ ret = cryTRNG(&CRYD1,(uint8_t*)&random[i]);
+
+ test_assert(ret == CRY_NOERROR , "failed random");
+
+ SHOW_DATA(&random[i],1);
+
+ test_assert(random[i] != 0 , "failed random generation (zero)");
+
+ for (j=0;j<i;j++)
+ {
+ test_assert(random[i] != random[j] , "failed random generation");
+ }
+ }
+
+ }
+}
+
+static const testcase_t cry_test_005_001 = {
+ "TRNG Polling",
+ cry_test_005_001_setup,
+ cry_test_005_001_teardown,
+ cry_test_005_001_execute
+};
+
+/****************************************************************************
+ * Exported data.
+ ****************************************************************************/
+
+/**
+ * @brief Array of test cases.
+ */
+const testcase_t * const cry_test_sequence_005_array[] = {
+ &cry_test_005_001,
+ NULL
+};
+
+/**
+ * @brief TRNG.
+ */
+const testsequence_t cry_test_sequence_005 = {
+ "TRNG",
+ cry_test_sequence_005_array
+};
diff --git a/test/crypto/source/test/cry_test_sequence_005.h b/test/crypto/source/test/cry_test_sequence_005.h
new file mode 100644
index 000000000..c0e945365
--- /dev/null
+++ b/test/crypto/source/test/cry_test_sequence_005.h
@@ -0,0 +1,27 @@
+/*
+ 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.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+/**
+ * @file cry_test_sequence_005.h
+ * @brief Test Sequence 005 header.
+ */
+
+#ifndef CRY_TEST_SEQUENCE_005_H
+#define CRY_TEST_SEQUENCE_005_H
+
+extern const testsequence_t cry_test_sequence_005;
+
+#endif /* CRY_TEST_SEQUENCE_005_H */
diff --git a/test/crypto/source/test/cry_test_sequence_006.c b/test/crypto/source/test/cry_test_sequence_006.c
new file mode 100644
index 000000000..b2c54facb
--- /dev/null
+++ b/test/crypto/source/test/cry_test_sequence_006.c
@@ -0,0 +1,295 @@
+/*
+ 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.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "hal.h"
+#include "cry_test_root.h"
+
+/**
+ * @file cry_test_sequence_006.c
+ * @brief Test Sequence 006 code.
+ *
+ * @page cry_test_sequence_006 [6] SHA
+ *
+ * File: @ref cry_test_sequence_006.c
+ *
+ * <h2>Description</h2>
+ * SHA testing.
+ *
+ * <h2>Test Cases</h2>
+ * - @subpage cry_test_006_001
+ * - @subpage cry_test_006_002
+ * - @subpage cry_test_006_003
+ * .
+ */
+
+/****************************************************************************
+ * Shared code.
+ ****************************************************************************/
+
+#include <string.h>
+#include "ref_sha.h"
+
+#define MAX_DIGEST_SIZE_INBYTE 64
+#define MAX_DIGEST_SIZE_INWORD (MAX_DIGEST_SIZE_INBYTE/4)
+static uint32_t digest[MAX_DIGEST_SIZE_INWORD];
+
+static const CRYConfig configSHA_Polling=
+{
+ TRANSFER_POLLING,
+ 0,
+ 0
+};
+
+
+
+/****************************************************************************
+ * Test cases.
+ ****************************************************************************/
+
+/**
+ * @page cry_test_006_001 [6.1] SHA1 Polling
+ *
+ * <h2>Description</h2>
+ * testing SHA1 in polled mode.
+ *
+ * <h2>Test Steps</h2>
+ * - [6.1.1] Digest.
+ * .
+ */
+
+static void cry_test_006_001_setup(void) {
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
+ memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
+ cryStart(&CRYD1, &configSHA_Polling);
+
+
+}
+
+static void cry_test_006_001_teardown(void) {
+ cryStop(&CRYD1);
+}
+
+static void cry_test_006_001_execute(void) {
+ cryerror_t ret;
+ uint32_t *ref;
+
+ /* [6.1.1] Digest.*/
+ test_set_step(1);
+ {
+ //---- One Block Test
+ ret = crySHA1(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+
+ test_assert(ret == CRY_NOERROR, "sha1 failed");
+
+
+ SHOW_DATA(digest,5);
+
+ ref = (uint32_t*)refSHA_SHA1_3;
+ for (int i = 0; i < 5; i++) {
+ test_assert(digest[i] == ref[i], "sha1 digest mismatch");
+ }
+
+ //---- Multi Block Test
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memcpy((char*) msg_clear, sha_msg1, SHA_LEN_1);
+
+ ret = crySHA1(&CRYD1,SHA_LEN_1,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha1 failed");
+
+ SHOW_DATA(digest,5);
+
+
+ ref = (uint32_t*)refSHA_SHA1_56;
+ for (int i = 0; i < 5; i++) {
+ test_assert(digest[i] == ref[i], "sha1 digest mismatch");
+ }
+
+
+ }
+}
+
+static const testcase_t cry_test_006_001 = {
+ "SHA1 Polling",
+ cry_test_006_001_setup,
+ cry_test_006_001_teardown,
+ cry_test_006_001_execute
+};
+
+/**
+ * @page cry_test_006_002 [6.2] SHA256 Polling
+ *
+ * <h2>Description</h2>
+ * testing SHA256 in polled mode.
+ *
+ * <h2>Test Steps</h2>
+ * - [6.2.1] Digest.
+ * .
+ */
+
+static void cry_test_006_002_setup(void) {
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
+ memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
+ cryStart(&CRYD1, &configSHA_Polling);
+
+
+}
+
+static void cry_test_006_002_teardown(void) {
+ cryStop(&CRYD1);
+}
+
+static void cry_test_006_002_execute(void) {
+ cryerror_t ret;
+ uint32_t *ref;
+
+ /* [6.2.1] Digest.*/
+ test_set_step(1);
+ {
+
+ //---- One Block Test
+ ret = crySHA256(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha256 failed");
+
+ SHOW_DATA(digest,8);
+
+ ref = (uint32_t*)refSHA_SHA256_3;
+ for (int i = 0; i < 8; i++) {
+ test_assert(digest[i] == ref[i], "sha256 digest mismatch");
+ }
+
+ //---- Multi Block Test
+ 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");
+
+
+ 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");
+ }
+
+
+ }
+}
+
+static const testcase_t cry_test_006_002 = {
+ "SHA256 Polling",
+ cry_test_006_002_setup,
+ cry_test_006_002_teardown,
+ cry_test_006_002_execute
+};
+
+/**
+ * @page cry_test_006_003 [6.3] SHA512 Polling
+ *
+ * <h2>Description</h2>
+ * testing SHA512 in polled mode.
+ *
+ * <h2>Test Steps</h2>
+ * - [6.3.1] Digest.
+ * .
+ */
+
+static void cry_test_006_003_setup(void) {
+ memset(msg_clear, 0, TEST_MSG_DATA_BYTE_LEN);
+ memset(digest, 0, MAX_DIGEST_SIZE_INWORD);
+ memcpy((char*) msg_clear, sha_msg0, SHA_LEN_0);
+ cryStart(&CRYD1, &configSHA_Polling);
+
+
+}
+
+static void cry_test_006_003_teardown(void) {
+ cryStop(&CRYD1);
+}
+
+static void cry_test_006_003_execute(void) {
+ cryerror_t ret;
+ uint32_t *ref;
+
+ /* [6.3.1] Digest.*/
+ test_set_step(1);
+ {
+ //---- One Block Test
+ ret = crySHA512(&CRYD1,SHA_LEN_0,(uint8_t*)msg_clear,(uint8_t*)digest);
+
+ test_assert(ret == CRY_NOERROR, "sha512 failed");
+
+ SHOW_DATA(digest,16);
+
+ ref = (uint32_t*)refSHA_SHA512_3;
+ for (int i = 0; i < 16; i++) {
+ test_assert(digest[i] == ref[i], "sha512 digest mismatch");
+ }
+
+ //---- Multi Block Test
+ 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");
+
+
+ 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");
+ }
+
+
+ }
+}
+
+static const testcase_t cry_test_006_003 = {
+ "SHA512 Polling",
+ cry_test_006_003_setup,
+ cry_test_006_003_teardown,
+ cry_test_006_003_execute
+};
+
+/****************************************************************************
+ * Exported data.
+ ****************************************************************************/
+
+/**
+ * @brief Array of test cases.
+ */
+const testcase_t * const cry_test_sequence_006_array[] = {
+ &cry_test_006_001,
+ &cry_test_006_002,
+ &cry_test_006_003,
+ NULL
+};
+
+/**
+ * @brief SHA.
+ */
+const testsequence_t cry_test_sequence_006 = {
+ "SHA",
+ cry_test_sequence_006_array
+};
diff --git a/test/crypto/source/test/cry_test_sequence_006.h b/test/crypto/source/test/cry_test_sequence_006.h
new file mode 100644
index 000000000..8bc6061ce
--- /dev/null
+++ b/test/crypto/source/test/cry_test_sequence_006.h
@@ -0,0 +1,27 @@
+/*
+ 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.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+/**
+ * @file cry_test_sequence_006.h
+ * @brief Test Sequence 006 header.
+ */
+
+#ifndef CRY_TEST_SEQUENCE_006_H
+#define CRY_TEST_SEQUENCE_006_H
+
+extern const testsequence_t cry_test_sequence_006;
+
+#endif /* CRY_TEST_SEQUENCE_006_H */
diff --git a/test/crypto/source/testref/ref_sha.c b/test/crypto/source/testref/ref_sha.c
new file mode 100644
index 000000000..bada14c93
--- /dev/null
+++ b/test/crypto/source/testref/ref_sha.c
@@ -0,0 +1,58 @@
+/*
+ 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.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include "hal.h"
+
+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,
+
+};
+const uint8_t refSHA_SHA1_56[]={
+0x84,0x98,0x3E,0x44,0x1C,0x3B,0xD2,0x6E,0xBA,0xAE,
+0x4A,0xA1,0xF9,0x51,0x29,0xE5,0xE5,0x46,0x70,0xF1,
+
+};
+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,
+};
+const uint8_t refSHA_SHA256_56[]={
+0x24,0x8D,0x6A,0x61,0xD2,0x06,0x38,0xB8,0xE5,0xC0,
+0x26,0x93,0x0C,0x3E,0x60,0x39,0xA3,0x3C,0xE4,0x59,
+0x64,0xFF,0x21,0x67,0xF6,0xEC,0xED,0xD4,0x19,0xDB,
+0x06,0xC1,
+};
+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,
+};
+const uint8_t refSHA_SHA512_56[]={
+0x20,0x4A,0x8F,0xC6,0xDD,0xA8,0x2F,0x0A,0x0C,0xED,
+0x7B,0xEB,0x8E,0x08,0xA4,0x16,0x57,0xC1,0x6E,0xF4,
+0x68,0xB2,0x28,0xA8,0x27,0x9B,0xE3,0x31,0xA7,0x03,
+0xC3,0x35,0x96,0xFD,0x15,0xC1,0x3B,0x1B,0x07,0xF9,
+0xAA,0x1D,0x3B,0xEA,0x57,0x78,0x9C,0xA0,0x31,0xAD,
+0x85,0xC7,0xA7,0x1D,0xD7,0x03,0x54,0xEC,0x63,0x12,
+0x38,0xCA,0x34,0x45,
+};
diff --git a/test/crypto/source/testref/ref_sha.h b/test/crypto/source/testref/ref_sha.h
new file mode 100644
index 000000000..b487d519b
--- /dev/null
+++ b/test/crypto/source/testref/ref_sha.h
@@ -0,0 +1,25 @@
+/*
+ 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.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+#ifndef TEST_REF_SHA_H_
+#define TEST_REF_SHA_H_
+
+extern const uint8_t refSHA_SHA1_3[];
+extern const uint8_t refSHA_SHA1_56[];
+extern const uint8_t refSHA_SHA256_3[];
+extern const uint8_t refSHA_SHA256_56[];
+extern const uint8_t refSHA_SHA512_3[];
+extern const uint8_t refSHA_SHA512_56[];
+#endif //TEST_REF_SHA_H_