From c44880635c6c6f8b7b026c79ae5ec1e49e38541c Mon Sep 17 00:00:00 2001 From: areviu Date: Sun, 25 Mar 2018 09:16:57 +0000 Subject: added gcm for sama crypto git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@11851 110e8d01-0319-4d1e-a829-52ad28d1bb01 --- test/crypto/configuration.xml | 357 +++++++++++++++++++++++- test/crypto/crypto_test.mk | 4 +- test/crypto/source/test/cry_test_root.c | 3 + test/crypto/source/test/cry_test_root.h | 11 + test/crypto/source/test/cry_test_sequence_008.c | 357 ++++++++++++++++++++++++ test/crypto/source/test/cry_test_sequence_008.h | 27 ++ test/crypto/source/testref/ref_gcm.c | 77 +++++ test/crypto/source/testref/ref_gcm.h | 82 ++++++ 8 files changed, 915 insertions(+), 3 deletions(-) create mode 100644 test/crypto/source/test/cry_test_sequence_008.c create mode 100644 test/crypto/source/test/cry_test_sequence_008.h create mode 100644 test/crypto/source/testref/ref_gcm.c create mode 100644 test/crypto/source/testref/ref_gcm.h (limited to 'test/crypto') 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]; + + + ]]> @@ -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++) { + + + Internal Tests @@ -3286,9 +3300,348 @@ for (int i = 0; i < 16; i++) { - + - + + + + Internal Tests + + + GCM + + + GCM testing + + + + + + +#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} } +}; + + + + ]]> + + + + + GCM Polling + + + testing GCM in polled mode + + + + + + + + + + + + + + + + + + + loading the key, encrypt and decrypt + + + + + + + + + + + + + + + + + + + + + + GCM DMA + + + testing GCM in DMA mode + + + + + + + + + + + + + + + + + + + loading the key, encrypt and decrypt + + + + + + + + + + + + + + + + + + + + + + + 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 + * + *

Description

+ * GCM testing. + * + *

Test Cases

+ * - @subpage cry_test_008_001 + * - @subpage cry_test_008_002 + * . + */ + +/**************************************************************************** + * Shared code. + ****************************************************************************/ + +#include +#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 + * + *

Description

+ * testing GCM in polled mode. + * + *

Test Steps

+ * - [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;iDescription + * testing GCM in DMA mode. + * + *

Test Steps

+ * - [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