aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorareviu <areviu.info@gmail.com>2018-03-25 09:16:57 +0000
committerareviu <areviu.info@gmail.com>2018-03-25 09:16:57 +0000
commitc44880635c6c6f8b7b026c79ae5ec1e49e38541c (patch)
treeb66a5c2903e3123642b5f20804beb15ff13a7939 /test
parent1d3bbc72c326e87bb688cbce39ea93b71b4406d3 (diff)
downloadChibiOS-c44880635c6c6f8b7b026c79ae5ec1e49e38541c.tar.gz
ChibiOS-c44880635c6c6f8b7b026c79ae5ec1e49e38541c.tar.bz2
ChibiOS-c44880635c6c6f8b7b026c79ae5ec1e49e38541c.zip
added gcm for sama crypto
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11851 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'test')
-rw-r--r--test/crypto/configuration.xml357
-rw-r--r--test/crypto/crypto_test.mk4
-rw-r--r--test/crypto/source/test/cry_test_root.c3
-rw-r--r--test/crypto/source/test/cry_test_root.h11
-rw-r--r--test/crypto/source/test/cry_test_sequence_008.c357
-rw-r--r--test/crypto/source/test/cry_test_sequence_008.h27
-rw-r--r--test/crypto/source/testref/ref_gcm.c77
-rw-r--r--test/crypto/source/testref/ref_gcm.h82
8 files changed, 915 insertions, 3 deletions
diff --git a/test/crypto/configuration.xml b/test/crypto/configuration.xml
index dc894e692..846702494 100644
--- a/test/crypto/configuration.xml
+++ b/test/crypto/configuration.xml
@@ -63,6 +63,13 @@ extern void cryptoTest_printArray32(bool isLE,const uint32_t *a,size_t len);
#define SHA_LEN_2 64
#define SHA_LEN_3 128
+#define TEST_GCM_KEY1_LEN 32
+#define TEST_P_LEN 60
+#define TEST_A_LEN 20
+#define TEST_IV1_LEN 12
+#define TEST_CL_LEN 60
+#define TEST_TL_LEN 16
+
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];
@@ -73,6 +80,9 @@ 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];
+
+
+
]]></value>
</global_definitions>
<global_code>
@@ -128,6 +138,7 @@ const uint8_t sha_msg2[SHA_LEN_2] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
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];
ALIGNED_VAR(4) uint32_t msg_decrypted[TEST_MSG_DATA_WORD_LEN];
@@ -2292,6 +2303,9 @@ for (int i = 0; i < TEST_DATA_WORD_LEN; i++) {
</cases>
</sequence>
+
+
+
<sequence>
<type index="0">
<value>Internal Tests</value>
@@ -3286,9 +3300,348 @@ for (int i = 0; i < 16; i++) {
</steps>
</case>
- </cases>
+ </cases>
</sequence>
- </sequences>
+
+<sequence>
+ <type index="0">
+ <value>Internal Tests</value>
+ </type>
+ <brief>
+ <value>GCM</value>
+ </brief>
+ <description>
+ <value>GCM testing</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <shared_code>
+ <value><![CDATA[
+#include <string.h>
+#include "ref_gcm.h"
+#define plaintext msg_clear
+#define cypher msg_encrypted
+#define authtag msg_decrypted
+
+static const CRYConfig config_Polling=
+{
+ TRANSFER_POLLING,
+ 0
+};
+
+static const CRYConfig config_DMA=
+{
+ TRANSFER_DMA,
+ 0
+};
+
+struct test_el_t
+{
+ uint32_t size;
+ const uint8_t * data;
+
+};
+struct test_gcm_t
+{
+ struct test_el_t key;
+ struct test_el_t p;
+ struct test_el_t iv;
+ struct test_el_t aad;
+ struct test_el_t c;
+ struct test_el_t t;
+
+};
+#define TEST_GCM_LEN 3
+
+const struct test_gcm_t test_gcm_k[TEST_GCM_LEN]={
+
+ { {K3_LEN,K3},{P3_LEN,P3},{IV3_LEN,IV3},{AAD3_LEN,A3},{C3_LEN,C3},{T3_LEN,T3} },
+ { {K4_LEN,K4},{P4_LEN,P4},{IV4_LEN,IV4},{AAD4_LEN,A4},{C4_LEN,C4},{T4_LEN,T4} },
+ { {K5_LEN,K5},{P5_LEN,P5},{IV5_LEN,IV5},{AAD5_LEN,A5},{C5_LEN,C5},{T5_LEN,T5} }
+};
+
+
+
+ ]]></value>
+ </shared_code>
+ <cases>
+ <case>
+ <brief>
+ <value>GCM Polling</value>
+ </brief>
+ <description>
+ <value>testing GCM in polled mode</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <various_code>
+ <setup_code>
+ <value><![CDATA[
+ memset(cypher, 0xff, TEST_MSG_DATA_BYTE_LEN);
+ memset(authtag, 0xff, TEST_MSG_DATA_BYTE_LEN);
+ cryStart(&CRYD1, &config_Polling);
+
+ ]]></value>
+ </setup_code>
+ <teardown_code>
+ <value><![CDATA[cryStop(&CRYD1);]]></value>
+ </teardown_code>
+ <local_variables>
+ <value><![CDATA[
+cryerror_t ret;
+ uint32_t *ref;
+ uint8_t i,len1,len2;
+]]></value>
+ </local_variables>
+ </various_code>
+ <steps>
+ <step>
+ <description>
+ <value>loading the key, encrypt and decrypt</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[
+for (i = 0;i<TEST_GCM_LEN;i++) {
+
+ test_print("gcm test : ");
+ test_printn(i);
+ test_println("");
+ /* loading the key .*/
+
+ {
+ ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,test_gcm_k[i].key.size, (uint8_t *) test_gcm_k[i].key.data);
+
+ test_assert(ret == CRY_NOERROR, "failed load transient key");
+ }
+
+ /* Encrypt.*/
+
+ {
+
+ ret = cryEncryptAES_GCM(&CRYD1,
+ 0,
+ test_gcm_k[i].p.size,
+ test_gcm_k[i].p.data,
+ (uint8_t*)cypher,
+ test_gcm_k[i].iv.data,
+ test_gcm_k[i].aad.size,
+ test_gcm_k[i].aad.data,
+ (uint8_t*)authtag);
+
+ test_assert(ret == CRY_NOERROR, "failed encryption");
+
+ len1 = test_gcm_k[i].c.size/4;
+ len2 = test_gcm_k[i].t.size/4;
+ SHOW_DATA(cypher,len1);
+ SHOW_DATA(authtag,len2);
+
+ ref = (uint32_t*)test_gcm_k[i].c.data;
+
+ for (uint8_t i = 0; i < len1; i++) {
+ test_assert(ref[i] == cypher[i], "c mismatch");
+ }
+ ref = (uint32_t*)test_gcm_k[i].t.data;
+
+ for (uint8_t i = 0; i < len2; i++) {
+ test_assert(ref[i] == authtag[i], "t mismatch");
+ }
+
+
+
+ }
+
+ /* Decrypt.*/
+
+ {
+
+
+ memset(plaintext, 0, test_gcm_k[i].p.size);
+
+ ret = cryDecryptAES_GCM(&CRYD1,
+ 0,
+ test_gcm_k[i].c.size,
+ (uint8_t*)cypher,
+ (uint8_t*)plaintext,
+ test_gcm_k[i].iv.data,
+ test_gcm_k[i].aad.size,
+ test_gcm_k[i].aad.data,
+ (uint8_t*)authtag);
+
+ test_assert(ret == CRY_NOERROR, "failed decryption");
+
+ len1 = test_gcm_k[i].p.size/4;
+ SHOW_DATA(plaintext,len1);
+
+ ref = (uint32_t*)test_gcm_k[i].p.data;
+
+ for (uint8_t i = 0; i < len1; i++) {
+ test_assert(ref[i] == plaintext[i], "decrypt plain mismatch");
+ }
+
+
+
+ }
+
+ }
+]]></value>
+ </code>
+ </step>
+
+
+
+
+
+
+
+ </steps>
+ </case>
+
+
+ <case>
+ <brief>
+ <value>GCM DMA</value>
+ </brief>
+ <description>
+ <value>testing GCM in DMA mode</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <various_code>
+ <setup_code>
+ <value><![CDATA[
+ memset(cypher, 0xff, TEST_MSG_DATA_BYTE_LEN);
+ memset(authtag, 0xff, TEST_MSG_DATA_BYTE_LEN);
+ cryStart(&CRYD1, &config_DMA);
+
+ ]]></value>
+ </setup_code>
+ <teardown_code>
+ <value><![CDATA[cryStop(&CRYD1);]]></value>
+ </teardown_code>
+ <local_variables>
+ <value><![CDATA[
+cryerror_t ret;
+ uint32_t *ref;
+ uint8_t i,len1,len2;
+]]></value>
+ </local_variables>
+ </various_code>
+ <steps>
+ <step>
+ <description>
+ <value>loading the key, encrypt and decrypt</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[
+for (i = 0;i<TEST_GCM_LEN;i++) {
+
+ test_print("gcm test : ");
+ test_printn(i);
+ test_println("");
+ /* loading the key .*/
+
+ {
+ ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,test_gcm_k[i].key.size, (uint8_t *) test_gcm_k[i].key.data);
+
+ test_assert(ret == CRY_NOERROR, "failed load transient key");
+ }
+
+ /* Encrypt.*/
+
+ {
+
+ ret = cryEncryptAES_GCM(&CRYD1,
+ 0,
+ test_gcm_k[i].p.size,
+ test_gcm_k[i].p.data,
+ (uint8_t*)cypher,
+ test_gcm_k[i].iv.data,
+ test_gcm_k[i].aad.size,
+ test_gcm_k[i].aad.data,
+ (uint8_t*)authtag);
+
+ test_assert(ret == CRY_NOERROR, "failed encryption");
+
+ len1 = test_gcm_k[i].c.size/4;
+ len2 = test_gcm_k[i].t.size/4;
+ SHOW_DATA(cypher,len1);
+ SHOW_DATA(authtag,len2);
+
+ ref = (uint32_t*)test_gcm_k[i].c.data;
+
+ for (uint8_t i = 0; i < len1; i++) {
+ test_assert(ref[i] == cypher[i], "c mismatch");
+ }
+ ref = (uint32_t*)test_gcm_k[i].t.data;
+
+ for (uint8_t i = 0; i < len2; i++) {
+ test_assert(ref[i] == authtag[i], "t mismatch");
+ }
+
+
+
+ }
+
+ /* Decrypt.*/
+
+ {
+
+
+ memset(plaintext, 0, test_gcm_k[i].p.size);
+
+ ret = cryDecryptAES_GCM(&CRYD1,
+ 0,
+ test_gcm_k[i].c.size,
+ (uint8_t*)cypher,
+ (uint8_t*)plaintext,
+ test_gcm_k[i].iv.data,
+ test_gcm_k[i].aad.size,
+ test_gcm_k[i].aad.data,
+ (uint8_t*)authtag);
+
+ test_assert(ret == CRY_NOERROR, "failed decryption");
+
+ len1 = test_gcm_k[i].p.size/4;
+ SHOW_DATA(plaintext,len1);
+
+ ref = (uint32_t*)test_gcm_k[i].p.data;
+
+ for (uint8_t i = 0; i < len1; i++) {
+ test_assert(ref[i] == plaintext[i], "decrypt plain mismatch");
+ }
+
+
+
+ }
+
+ }
+]]></value>
+ </code>
+ </step>
+
+
+
+
+
+
+
+ </steps>
+ </case>
+
+
+ </cases>
+ </sequence>
+
+ </sequences>
</instance>
</instances>
<exportedFeatures />
diff --git a/test/crypto/crypto_test.mk b/test/crypto/crypto_test.mk
index 0d7310271..1e53235f3 100644
--- a/test/crypto/crypto_test.mk
+++ b/test/crypto/crypto_test.mk
@@ -3,13 +3,15 @@ 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/testref/ref_gcm.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_005.c \
${CHIBIOS}/test/crypto/source/test/cry_test_sequence_006.c \
- ${CHIBIOS}/test/crypto/source/test/cry_test_sequence_007.c
+ ${CHIBIOS}/test/crypto/source/test/cry_test_sequence_007.c \
+ ${CHIBIOS}/test/crypto/source/test/cry_test_sequence_008.c
# Required include directories
TESTINC += ${CHIBIOS}/test/crypto/source/testref \
${CHIBIOS}/test/crypto/source/test
diff --git a/test/crypto/source/test/cry_test_root.c b/test/crypto/source/test/cry_test_root.c
index 519e1fa73..9c8feb713 100644
--- a/test/crypto/source/test/cry_test_root.c
+++ b/test/crypto/source/test/cry_test_root.c
@@ -28,6 +28,7 @@
* - @subpage cry_test_sequence_005
* - @subpage cry_test_sequence_006
* - @subpage cry_test_sequence_007
+ * - @subpage cry_test_sequence_008
* .
*/
@@ -56,6 +57,7 @@ const testsequence_t * const cry_test_suite_array[] = {
&cry_test_sequence_005,
&cry_test_sequence_006,
&cry_test_sequence_007,
+ &cry_test_sequence_008,
NULL
};
@@ -122,6 +124,7 @@ const uint8_t sha_msg2[SHA_LEN_2] = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
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];
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 f33cb5c1a..110dd851f 100644
--- a/test/crypto/source/test/cry_test_root.h
+++ b/test/crypto/source/test/cry_test_root.h
@@ -31,6 +31,7 @@
#include "cry_test_sequence_005.h"
#include "cry_test_sequence_006.h"
#include "cry_test_sequence_007.h"
+#include "cry_test_sequence_008.h"
#if !defined(__DOXYGEN__)
@@ -75,6 +76,13 @@ extern void cryptoTest_printArray32(bool isLE,const uint32_t *a,size_t len);
#define SHA_LEN_2 64
#define SHA_LEN_3 128
+#define TEST_GCM_KEY1_LEN 32
+#define TEST_P_LEN 60
+#define TEST_A_LEN 20
+#define TEST_IV1_LEN 12
+#define TEST_CL_LEN 60
+#define TEST_TL_LEN 16
+
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];
@@ -86,6 +94,9 @@ 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__) */
#endif /* CRY_TEST_ROOT_H */
diff --git a/test/crypto/source/test/cry_test_sequence_008.c b/test/crypto/source/test/cry_test_sequence_008.c
new file mode 100644
index 000000000..d22d6b020
--- /dev/null
+++ b/test/crypto/source/test/cry_test_sequence_008.c
@@ -0,0 +1,357 @@
+/*
+ ChibiOS - Copyright (C) 2006..2018 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_008.c
+ * @brief Test Sequence 008 code.
+ *
+ * @page cry_test_sequence_008 [8] GCM
+ *
+ * File: @ref cry_test_sequence_008.c
+ *
+ * <h2>Description</h2>
+ * GCM testing.
+ *
+ * <h2>Test Cases</h2>
+ * - @subpage cry_test_008_001
+ * - @subpage cry_test_008_002
+ * .
+ */
+
+/****************************************************************************
+ * Shared code.
+ ****************************************************************************/
+
+#include <string.h>
+#include "ref_gcm.h"
+#define plaintext msg_clear
+#define cypher msg_encrypted
+#define authtag msg_decrypted
+
+static const CRYConfig config_Polling=
+{
+ TRANSFER_POLLING,
+ 0
+};
+
+static const CRYConfig config_DMA=
+{
+ TRANSFER_DMA,
+ 0
+};
+
+struct test_el_t
+{
+ uint32_t size;
+ const uint8_t * data;
+
+};
+struct test_gcm_t
+{
+ struct test_el_t key;
+ struct test_el_t p;
+ struct test_el_t iv;
+ struct test_el_t aad;
+ struct test_el_t c;
+ struct test_el_t t;
+
+};
+#define TEST_GCM_LEN 3
+
+const struct test_gcm_t test_gcm_k[TEST_GCM_LEN]={
+
+ { {K3_LEN,K3},{P3_LEN,P3},{IV3_LEN,IV3},{AAD3_LEN,A3},{C3_LEN,C3},{T3_LEN,T3} },
+ { {K4_LEN,K4},{P4_LEN,P4},{IV4_LEN,IV4},{AAD4_LEN,A4},{C4_LEN,C4},{T4_LEN,T4} },
+ { {K5_LEN,K5},{P5_LEN,P5},{IV5_LEN,IV5},{AAD5_LEN,A5},{C5_LEN,C5},{T5_LEN,T5} }
+};
+
+
+
+
+
+/****************************************************************************
+ * Test cases.
+ ****************************************************************************/
+
+/**
+ * @page cry_test_008_001 [8.1] GCM Polling
+ *
+ * <h2>Description</h2>
+ * testing GCM in polled mode.
+ *
+ * <h2>Test Steps</h2>
+ * - [8.1.1] loading the key, encrypt and decrypt.
+ * .
+ */
+
+static void cry_test_008_001_setup(void) {
+ memset(cypher, 0xff, TEST_MSG_DATA_BYTE_LEN);
+ memset(authtag, 0xff, TEST_MSG_DATA_BYTE_LEN);
+ cryStart(&CRYD1, &config_Polling);
+
+
+}
+
+static void cry_test_008_001_teardown(void) {
+ cryStop(&CRYD1);
+}
+
+static void cry_test_008_001_execute(void) {
+ cryerror_t ret;
+ uint32_t *ref;
+ uint8_t i,len1,len2;
+
+ /* [8.1.1] loading the key, encrypt and decrypt.*/
+ test_set_step(1);
+ {
+ for (i = 0;i<TEST_GCM_LEN;i++) {
+
+ test_print("gcm test : ");
+ test_printn(i);
+ test_println("");
+ /* loading the key .*/
+
+ {
+ ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,test_gcm_k[i].key.size, (uint8_t *) test_gcm_k[i].key.data);
+
+ test_assert(ret == CRY_NOERROR, "failed load transient key");
+ }
+
+ /* Encrypt.*/
+
+ {
+
+ ret = cryEncryptAES_GCM(&CRYD1,
+ 0,
+ test_gcm_k[i].p.size,
+ test_gcm_k[i].p.data,
+ (uint8_t*)cypher,
+ test_gcm_k[i].iv.data,
+ test_gcm_k[i].aad.size,
+ test_gcm_k[i].aad.data,
+ (uint8_t*)authtag);
+
+ test_assert(ret == CRY_NOERROR, "failed encryption");
+
+ len1 = test_gcm_k[i].c.size/4;
+ len2 = test_gcm_k[i].t.size/4;
+ SHOW_DATA(cypher,len1);
+ SHOW_DATA(authtag,len2);
+
+ ref = (uint32_t*)test_gcm_k[i].c.data;
+
+ for (uint8_t i = 0; i < len1; i++) {
+ test_assert(ref[i] == cypher[i], "c mismatch");
+ }
+ ref = (uint32_t*)test_gcm_k[i].t.data;
+
+ for (uint8_t i = 0; i < len2; i++) {
+ test_assert(ref[i] == authtag[i], "t mismatch");
+ }
+
+
+
+ }
+
+ /* Decrypt.*/
+
+ {
+
+
+ memset(plaintext, 0, test_gcm_k[i].p.size);
+
+ ret = cryDecryptAES_GCM(&CRYD1,
+ 0,
+ test_gcm_k[i].c.size,
+ (uint8_t*)cypher,
+ (uint8_t*)plaintext,
+ test_gcm_k[i].iv.data,
+ test_gcm_k[i].aad.size,
+ test_gcm_k[i].aad.data,
+ (uint8_t*)authtag);
+
+ test_assert(ret == CRY_NOERROR, "failed decryption");
+
+ len1 = test_gcm_k[i].p.size/4;
+ SHOW_DATA(plaintext,len1);
+
+ ref = (uint32_t*)test_gcm_k[i].p.data;
+
+ for (uint8_t i = 0; i < len1; i++) {
+ test_assert(ref[i] == plaintext[i], "decrypt plain mismatch");
+ }
+
+
+
+ }
+
+ }
+ }
+}
+
+static const testcase_t cry_test_008_001 = {
+ "GCM Polling",
+ cry_test_008_001_setup,
+ cry_test_008_001_teardown,
+ cry_test_008_001_execute
+};
+
+/**
+ * @page cry_test_008_002 [8.2] GCM DMA
+ *
+ * <h2>Description</h2>
+ * testing GCM in DMA mode.
+ *
+ * <h2>Test Steps</h2>
+ * - [8.2.1] loading the key, encrypt and decrypt.
+ * .
+ */
+
+static void cry_test_008_002_setup(void) {
+ memset(cypher, 0xff, TEST_MSG_DATA_BYTE_LEN);
+ memset(authtag, 0xff, TEST_MSG_DATA_BYTE_LEN);
+ cryStart(&CRYD1, &config_DMA);
+
+
+}
+
+static void cry_test_008_002_teardown(void) {
+ cryStop(&CRYD1);
+}
+
+static void cry_test_008_002_execute(void) {
+ cryerror_t ret;
+ uint32_t *ref;
+ uint8_t i,len1,len2;
+
+ /* [8.2.1] loading the key, encrypt and decrypt.*/
+ test_set_step(1);
+ {
+ for (i = 0;i<TEST_GCM_LEN;i++) {
+
+ test_print("gcm test : ");
+ test_printn(i);
+ test_println("");
+ /* loading the key .*/
+
+ {
+ ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_aes,test_gcm_k[i].key.size, (uint8_t *) test_gcm_k[i].key.data);
+
+ test_assert(ret == CRY_NOERROR, "failed load transient key");
+ }
+
+ /* Encrypt.*/
+
+ {
+
+ ret = cryEncryptAES_GCM(&CRYD1,
+ 0,
+ test_gcm_k[i].p.size,
+ test_gcm_k[i].p.data,
+ (uint8_t*)cypher,
+ test_gcm_k[i].iv.data,
+ test_gcm_k[i].aad.size,
+ test_gcm_k[i].aad.data,
+ (uint8_t*)authtag);
+
+ test_assert(ret == CRY_NOERROR, "failed encryption");
+
+ len1 = test_gcm_k[i].c.size/4;
+ len2 = test_gcm_k[i].t.size/4;
+ SHOW_DATA(cypher,len1);
+ SHOW_DATA(authtag,len2);
+
+ ref = (uint32_t*)test_gcm_k[i].c.data;
+
+ for (uint8_t i = 0; i < len1; i++) {
+ test_assert(ref[i] == cypher[i], "c mismatch");
+ }
+ ref = (uint32_t*)test_gcm_k[i].t.data;
+
+ for (uint8_t i = 0; i < len2; i++) {
+ test_assert(ref[i] == authtag[i], "t mismatch");
+ }
+
+
+
+ }
+
+ /* Decrypt.*/
+
+ {
+
+
+ memset(plaintext, 0, test_gcm_k[i].p.size);
+
+ ret = cryDecryptAES_GCM(&CRYD1,
+ 0,
+ test_gcm_k[i].c.size,
+ (uint8_t*)cypher,
+ (uint8_t*)plaintext,
+ test_gcm_k[i].iv.data,
+ test_gcm_k[i].aad.size,
+ test_gcm_k[i].aad.data,
+ (uint8_t*)authtag);
+
+ test_assert(ret == CRY_NOERROR, "failed decryption");
+
+ len1 = test_gcm_k[i].p.size/4;
+ SHOW_DATA(plaintext,len1);
+
+ ref = (uint32_t*)test_gcm_k[i].p.data;
+
+ for (uint8_t i = 0; i < len1; i++) {
+ test_assert(ref[i] == plaintext[i], "decrypt plain mismatch");
+ }
+
+
+
+ }
+
+ }
+ }
+}
+
+static const testcase_t cry_test_008_002 = {
+ "GCM DMA",
+ cry_test_008_002_setup,
+ cry_test_008_002_teardown,
+ cry_test_008_002_execute
+};
+
+/****************************************************************************
+ * Exported data.
+ ****************************************************************************/
+
+/**
+ * @brief Array of test cases.
+ */
+const testcase_t * const cry_test_sequence_008_array[] = {
+ &cry_test_008_001,
+ &cry_test_008_002,
+ NULL
+};
+
+/**
+ * @brief GCM.
+ */
+const testsequence_t cry_test_sequence_008 = {
+ "GCM",
+ cry_test_sequence_008_array
+};
diff --git a/test/crypto/source/test/cry_test_sequence_008.h b/test/crypto/source/test/cry_test_sequence_008.h
new file mode 100644
index 000000000..1c282ade7
--- /dev/null
+++ b/test/crypto/source/test/cry_test_sequence_008.h
@@ -0,0 +1,27 @@
+/*
+ ChibiOS - Copyright (C) 2006..2018 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_008.h
+ * @brief Test Sequence 008 header.
+ */
+
+#ifndef CRY_TEST_SEQUENCE_008_H
+#define CRY_TEST_SEQUENCE_008_H
+
+extern const testsequence_t cry_test_sequence_008;
+
+#endif /* CRY_TEST_SEQUENCE_008_H */
diff --git a/test/crypto/source/testref/ref_gcm.c b/test/crypto/source/testref/ref_gcm.c
new file mode 100644
index 000000000..74b3e8444
--- /dev/null
+++ b/test/crypto/source/testref/ref_gcm.c
@@ -0,0 +1,77 @@
+
+#include "hal.h"
+#include "ref_gcm.h"
+
+
+///////
+// http://csrc.nist.gov/groups/STM/cavp/gcmtestvectors.zip gcmEncryptExtIV128.rsp
+// [Keylen = 128]
+// [IVlen = 96]
+// [PTlen = 128]
+// [AADlen = 128]
+// [Taglen = 128]
+// Count = 0
+// K: c939cc13397c1d37de6ae0e1cb7c423c
+// IV: b3d8cc017cbb89b39e0f67e2
+// P: c3b3c41f113a31b73d9a5cd432103069
+// AAD: 24825602bd12a984e0092d3e448eda5f
+// C: 93fe7d9e9bfd10348a5606e5cafa7354
+// AT: 0032a1dc85f1c9786925a2e71d8272dd
+///////
+const uint8_t K3[] = {0xc9, 0x39, 0xcc, 0x13, 0x39, 0x7c, 0x1d, 0x37, 0xde, 0x6a, 0xe0, 0xe1, 0xcb, 0x7c, 0x42, 0x3c};
+const uint8_t IV3[] = {0xb3, 0xd8, 0xcc, 0x01, 0x7c, 0xbb, 0x89, 0xb3, 0x9e, 0x0f, 0x67, 0xe2,
+ 0x00,0x00,0x00,0x01};
+const uint8_t P3[] = {0xc3, 0xb3, 0xc4, 0x1f, 0x11, 0x3a, 0x31, 0xb7, 0x3d, 0x9a, 0x5c, 0xd4, 0x32, 0x10, 0x30, 0x69};
+const uint8_t A3[] = {0x24, 0x82, 0x56, 0x02, 0xbd, 0x12, 0xa9, 0x84, 0xe0, 0x09, 0x2d, 0x3e, 0x44, 0x8e, 0xda, 0x5f};
+#define A3_len sizeof(A3)
+const uint8_t C3[] = {0x93, 0xfe, 0x7d, 0x9e, 0x9b, 0xfd, 0x10, 0x34, 0x8a, 0x56, 0x06, 0xe5, 0xca, 0xfa, 0x73, 0x54};
+const uint8_t T3[] = {0x00, 0x32, 0xa1, 0xdc, 0x85, 0xf1, 0xc9, 0x78, 0x69, 0x25, 0xa2, 0xe7, 0x1d, 0x82, 0x72, 0xdd};
+
+///////
+// http://csrc.nist.gov/groups/STM/cavp/gcmtestvectors.zip gcmEncryptExtIV128.rsp
+// [Keylen = 128]
+// [IVlen = 96]
+// [PTlen = 256]
+// [AADlen = 128]
+// [Taglen = 128]
+// Count = 0
+// K = 298efa1ccf29cf62ae6824bfc19557fc
+// IV = 6f58a93fe1d207fae4ed2f6d
+// P = cc38bccd6bc536ad919b1395f5d63801f99f8068d65ca5ac63872daf16b93901
+// AAD = 021fafd238463973ffe80256e5b1c6b1
+// C = dfce4e9cd291103d7fe4e63351d9e79d3dfd391e3267104658212da96521b7db
+// T = 542465ef599316f73a7a560509a2d9f2
+///////
+const uint8_t K4[] = {0x29, 0x8e, 0xfa, 0x1c, 0xcf, 0x29, 0xcf, 0x62, 0xae, 0x68, 0x24, 0xbf, 0xc1, 0x95, 0x57, 0xfc};
+const uint8_t IV4[] = {0x6f, 0x58, 0xa9, 0x3f, 0xe1, 0xd2, 0x07, 0xfa, 0xe4, 0xed, 0x2f, 0x6d,
+ 0x00,0x00,0x00,0x01};
+const uint8_t P4[] = {0xcc, 0x38, 0xbc, 0xcd, 0x6b, 0xc5, 0x36, 0xad, 0x91, 0x9b, 0x13, 0x95, 0xf5, 0xd6, 0x38, 0x01, 0xf9, 0x9f, 0x80, 0x68, 0xd6, 0x5c, 0xa5, 0xac, 0x63, 0x87, 0x2d, 0xaf, 0x16, 0xb9, 0x39, 0x01};
+const uint8_t A4[] = {0x02, 0x1f, 0xaf, 0xd2, 0x38, 0x46, 0x39, 0x73, 0xff, 0xe8, 0x02, 0x56, 0xe5, 0xb1, 0xc6, 0xb1};
+const uint8_t C4[] = {0xdf, 0xce, 0x4e, 0x9c, 0xd2, 0x91, 0x10, 0x3d, 0x7f, 0xe4, 0xe6, 0x33, 0x51, 0xd9, 0xe7, 0x9d, 0x3d, 0xfd, 0x39, 0x1e, 0x32, 0x67, 0x10, 0x46, 0x58, 0x21, 0x2d, 0xa9, 0x65, 0x21, 0xb7, 0xdb};
+const uint8_t T4[] = {0x54, 0x24, 0x65, 0xef, 0x59, 0x93, 0x16, 0xf7, 0x3a, 0x7a, 0x56, 0x05, 0x09, 0xa2, 0xd9, 0xf2};
+
+///////
+// http://csrc.nist.gov/groups/STM/cavp/gcmtestvectors.zip gcmEncryptExtIV128.rsp
+// [Keylen = 128]
+// [IVlen = 96]
+// [PTlen = 256]
+// [AADlen = 128]
+// [Taglen = 128]
+// Count = 0
+// K = 298efa1ccf29cf62ae6824bfc19557fc
+// IV = 6f58a93fe1d207fae4ed2f6d
+// P = cc38bccd6bc536ad919b1395f5d63801f99f8068d65ca5ac63872daf16b93901
+// AAD = 021fafd238463973ffe80256e5b1c6b1
+// C = dfce4e9cd291103d7fe4e63351d9e79d3dfd391e3267104658212da96521b7db
+// T = 542465ef599316f73a7a560509a2d9f2
+///////
+const uint8_t K5[] = {0x29, 0x8e, 0xfa, 0x1c, 0xcf, 0x29, 0xcf, 0x62, 0xae, 0x68, 0x24, 0xbf, 0xc1, 0x95, 0x57, 0xfc};
+const uint8_t IV5[] = {0x6f, 0x58, 0xa9, 0x3f, 0xe1, 0xd2, 0x07, 0xfa, 0xe4, 0xed, 0x2f, 0x6d,
+ 0x00,0x00,0x00,0x01};
+const uint8_t P5[] = {0xcc, 0x38, 0xbc, 0xcd, 0x6b, 0xc5, 0x36, 0xad, 0x91, 0x9b, 0x13, 0x95, 0xf5, 0xd6, 0x38, 0x01, 0xf9, 0x9f, 0x80, 0x68, 0xd6, 0x5c, 0xa5, 0xac, 0x63, 0x87, 0x2d, 0xaf, 0x16, 0xb9, 0x39, 0x01};
+const uint8_t A5[] = {0x02, 0x1f, 0xaf, 0xd2, 0x38, 0x46, 0x39, 0x73, 0xff, 0xe8, 0x02, 0x56, 0xe5, 0xb1, 0xc6, 0xb1};
+const uint8_t C5[] = {0xdf, 0xce, 0x4e, 0x9c, 0xd2, 0x91, 0x10, 0x3d, 0x7f, 0xe4, 0xe6, 0x33, 0x51, 0xd9, 0xe7, 0x9d, 0x3d, 0xfd, 0x39, 0x1e, 0x32, 0x67, 0x10, 0x46, 0x58, 0x21, 0x2d, 0xa9, 0x65, 0x21, 0xb7, 0xdb};
+const uint8_t T5[] = {0x54, 0x24, 0x65, 0xef, 0x59, 0x93, 0x16, 0xf7, 0x3a, 0x7a, 0x56, 0x05, 0x09, 0xa2, 0xd9, 0xf2};
+
+
+
diff --git a/test/crypto/source/testref/ref_gcm.h b/test/crypto/source/testref/ref_gcm.h
new file mode 100644
index 000000000..cc2d43544
--- /dev/null
+++ b/test/crypto/source/testref/ref_gcm.h
@@ -0,0 +1,82 @@
+#ifndef TEST_REF_GCM_H_
+#define TEST_REF_GCM_H_
+
+
+
+#define K3_LEN 16
+#define P3_LEN 16
+#define IV3_LEN (12+4)
+#define AAD3_LEN 16
+#define C3_LEN 16
+#define T3_LEN 16
+
+extern const uint8_t K3[K3_LEN];
+extern const uint8_t IV3[IV3_LEN];
+extern const uint8_t P3[P3_LEN];
+extern const uint8_t A3[AAD3_LEN];
+extern const uint8_t C3[C3_LEN];
+extern const uint8_t T3[T3_LEN];
+
+///////
+// http://csrc.nist.gov/groups/STM/cavp/gcmtestvectors.zip gcmEncryptExtIV128.rsp
+// [Keylen = 128]
+// [IVlen = 96]
+// [PTlen = 256]
+// [AADlen = 128]
+// [Taglen = 128]
+// Count = 0
+// K = 298efa1ccf29cf62ae6824bfc19557fc
+// IV = 6f58a93fe1d207fae4ed2f6d
+// P = cc38bccd6bc536ad919b1395f5d63801f99f8068d65ca5ac63872daf16b93901
+// AAD = 021fafd238463973ffe80256e5b1c6b1
+// C = dfce4e9cd291103d7fe4e63351d9e79d3dfd391e3267104658212da96521b7db
+// T = 542465ef599316f73a7a560509a2d9f2
+///////
+#define K4_LEN 16
+#define P4_LEN 32
+#define IV4_LEN (12+4)
+#define AAD4_LEN 16
+#define C4_LEN 32
+#define T4_LEN 16
+
+extern const uint8_t K4[K4_LEN] ;
+extern const uint8_t IV4[IV4_LEN];
+extern const uint8_t P4[P4_LEN] ;
+extern const uint8_t A4[AAD4_LEN] ;
+extern const uint8_t C4[C4_LEN] ;
+extern const uint8_t T4[T4_LEN] ;
+
+///////
+// http://csrc.nist.gov/groups/STM/cavp/gcmtestvectors.zip gcmEncryptExtIV128.rsp
+// [Keylen = 128]
+// [IVlen = 96]
+// [PTlen = 256]
+// [AADlen = 128]
+// [Taglen = 128]
+// Count = 0
+// K = 298efa1ccf29cf62ae6824bfc19557fc
+// IV = 6f58a93fe1d207fae4ed2f6d
+// P = cc38bccd6bc536ad919b1395f5d63801f99f8068d65ca5ac63872daf16b93901
+// AAD = 021fafd238463973ffe80256e5b1c6b1
+// C = dfce4e9cd291103d7fe4e63351d9e79d3dfd391e3267104658212da96521b7db
+// T = 542465ef599316f73a7a560509a2d9f2
+///////
+#define K5_LEN 16
+#define P5_LEN 32
+#define IV5_LEN (12+4)
+#define AAD5_LEN 16
+#define C5_LEN 32
+#define T5_LEN 16
+
+extern const uint8_t K5[K5_LEN] ;
+extern const uint8_t IV5[IV5_LEN];
+extern const uint8_t P5[P5_LEN] ;
+extern const uint8_t A5[AAD5_LEN] ;
+extern const uint8_t C5[C5_LEN] ;
+extern const uint8_t T5[T5_LEN] ;
+
+
+
+
+
+#endif //TEST_REF_GCM_H_