aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorareviu <areviu.info@gmail.com>2018-05-19 13:15:06 +0000
committerareviu <areviu.info@gmail.com>2018-05-19 13:15:06 +0000
commit7454fa6ad5597582688495252c801c8daeeaf07e (patch)
tree48d89549877a21be7d22fe922d45ff70a2c65df4 /test
parente9399566d7eaa76ca6114d108d1b7bf34fca157b (diff)
downloadChibiOS-7454fa6ad5597582688495252c801c8daeeaf07e.tar.gz
ChibiOS-7454fa6ad5597582688495252c801c8daeeaf07e.tar.bz2
ChibiOS-7454fa6ad5597582688495252c801c8daeeaf07e.zip
added SAMA HMAC + fixed TRNG 128 bit generation
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@12042 110e8d01-0319-4d1e-a829-52ad28d1bb01
Diffstat (limited to 'test')
-rw-r--r--test/crypto/configuration.xml298
-rw-r--r--test/crypto/crypto_test.mk14
-rw-r--r--test/crypto/ref/gen_cfiles.bat3
-rw-r--r--test/crypto/ref/gen_testref.bat6
-rw-r--r--test/crypto/ref/hmac_ref.bat13
-rw-r--r--test/crypto/source/test/cry_test_root.c2
-rw-r--r--test/crypto/source/test/cry_test_root.h1
-rw-r--r--test/crypto/source/test/cry_test_sequence_005.c26
-rw-r--r--test/crypto/source/test/cry_test_sequence_009.c279
-rw-r--r--test/crypto/source/test/cry_test_sequence_009.h27
-rw-r--r--test/crypto/source/testref/ref_hmac.c48
-rw-r--r--test/crypto/source/testref/ref_hmac.h23
12 files changed, 707 insertions, 33 deletions
diff --git a/test/crypto/configuration.xml b/test/crypto/configuration.xml
index 846702494..a06e67e98 100644
--- a/test/crypto/configuration.xml
+++ b/test/crypto/configuration.xml
@@ -2369,23 +2369,23 @@ cryStart(&CRYD1, &configTRNG_Polling);
</tags>
<code>
<value><![CDATA[
-uint32_t random[10];
- int i,j;
- for (i=0;i<10;i++)
- {
- ret = cryTRNG(&CRYD1,(uint8_t*)&random[i]);
+uint32_t random[4];
+int i;
- test_assert(ret == CRY_NOERROR , "failed random");
+ret = cryTRNG(&CRYD1,(uint8_t*)&random);
- SHOW_DATA(&random[i],1);
+test_assert(ret == CRY_NOERROR , "failed random");
- test_assert(random[i] != 0 , "failed random generation (zero)");
+SHOW_DATA(&random[0],4);
+
+for (i=0;i<4;i++) {
+ test_assert(random[i] != 0 , "failed random generation (zero)");
+}
+for (i=1;i<4;i++)
+{
+ test_assert(random[i-1] != random[i] , "failed random generation");
+}
- for (j=0;j<i;j++)
- {
- test_assert(random[i] != random[j] , "failed random generation");
- }
- }
]]></value>
</code>
@@ -3641,6 +3641,278 @@ for (i = 0;i<TEST_GCM_LEN;i++) {
</cases>
</sequence>
+
+<sequence>
+ <type index="0">
+ <value>Internal Tests</value>
+ </type>
+ <brief>
+ <value>HMAC</value>
+ </brief>
+ <description>
+ <value>HMAC testing</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <shared_code>
+ <value><![CDATA[
+#include <string.h>
+#include "ref_hmac.h"
+#define plaintext msg_clear
+#define HMACOUT msg_encrypted
+#define shabuffer msg_decrypted
+
+#define MAX_SHA_BLOCK_SIZE TEST_MSG_DATA_BYTE_LEN
+#define MAX_SHA_BLOCK_SIZE_INWORD (MAX_SHA_BLOCK_SIZE/4)
+
+static const CRYConfig config_Polling=
+{
+ TRANSFER_POLLING,
+ 0
+};
+
+static const CRYConfig config_DMA=
+{
+ TRANSFER_DMA,
+ 0
+};
+
+
+static const int hmackeys_size[]=
+{
+ 20,
+ 4,
+ 20
+};
+
+static const uint8_t hmackey_1[]=
+{
+ 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
+ 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
+
+};
+
+// "Hi There",
+static const uint8_t hmacmsg1[8]= "Hi There";
+static const size_t hmacmsg_size[]=
+{
+ 8,
+};
+static void cryHMAC256(CRYDriver *cryp) {
+
+ cryerror_t ret;
+ HMACSHA256Context hmacshactxp;
+ uint8_t *keyp;
+
+
+ hmacshactxp.shacontext.sha.sha_buffer = (uint8_t*)&shabuffer[0];
+ hmacshactxp.shacontext.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
+
+ keyp =(uint8_t *)hmackey_1;
+ ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_hmac,hmackeys_size[0], keyp);
+
+ test_assert(ret == CRY_NOERROR, "failed load transient key");
+
+ ret = cryHMACSHA256Init(cryp,&hmacshactxp);
+
+ test_assert(ret == CRY_NOERROR, "failed init HMACSHA256");
+
+ ret = cryHMACSHA256Update(cryp,&hmacshactxp,hmacmsg_size[0],(const uint8_t *)&hmacmsg1);
+
+ test_assert(ret == CRY_NOERROR, "failed update HMACSHA256");
+
+ ret = cryHMACSHA256Final(cryp,&hmacshactxp,(uint8_t *)HMACOUT);
+
+ test_assert(ret == CRY_NOERROR, "failed final HMACSHA256");
+
+
+ SHOW_DATA(HMACOUT,8);
+
+}
+
+static void cryHMAC512(CRYDriver *cryp) {
+
+ cryerror_t ret;
+ HMACSHA512Context hmacshactxp;
+ uint8_t *keyp;
+
+
+ hmacshactxp.shacontext.sha.sha_buffer = (uint8_t*)&shabuffer[0];
+ hmacshactxp.shacontext.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
+
+ keyp =(uint8_t *)hmackey_1;
+ ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_hmac,hmackeys_size[0], keyp);
+
+ test_assert(ret == CRY_NOERROR, "failed load transient key");
+
+ ret = cryHMACSHA512Init(cryp,&hmacshactxp);
+
+ test_assert(ret == CRY_NOERROR, "failed init HMACSHA512");
+
+ ret = cryHMACSHA512Update(cryp,&hmacshactxp,hmacmsg_size[0],(const uint8_t *)&hmacmsg1);
+
+ test_assert(ret == CRY_NOERROR, "failed update HMACSHA512");
+
+ ret = cryHMACSHA512Final(cryp,&hmacshactxp,(uint8_t *)HMACOUT);
+
+ test_assert(ret == CRY_NOERROR, "failed final HMACSHA512");
+
+
+ SHOW_DATA(HMACOUT,16);
+
+}
+
+ ]]></value>
+ </shared_code>
+ <cases>
+ <case>
+ <brief>
+ <value>HMAC Polling</value>
+ </brief>
+ <description>
+ <value>testing HMAC in polled mode</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <various_code>
+ <setup_code>
+ <value><![CDATA[
+memset(HMACOUT, 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[
+]]></value>
+ </local_variables>
+ </various_code>
+ <steps>
+ <step>
+ <description>
+ <value>hmac 256</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[
+cryHMAC256(&CRYD1);
+
+for (int i = 0; i < 8; i++) {
+ test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC256_1)[i], "hmac mismatch");
+}
+]]></value>
+ </code>
+ </step>
+ <step>
+ <description>
+ <value>hmac 512</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[
+cryHMAC512(&CRYD1);
+
+for (int i = 0; i < 16; i++) {
+ test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC512_1)[i], "hmac mismatch");
+}
+]]></value>
+ </code>
+ </step>
+
+
+
+
+ </steps>
+ </case>
+
+
+ <case>
+ <brief>
+ <value>HMAC DMA</value>
+ </brief>
+ <description>
+ <value>testing HMAC in DMA mode</value>
+ </description>
+ <condition>
+ <value />
+ </condition>
+ <various_code>
+ <setup_code>
+ <value><![CDATA[
+memset(HMACOUT, 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[
+]]></value>
+ </local_variables>
+ </various_code>
+ <steps>
+ <step>
+ <description>
+ <value>hmac 256</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[
+cryHMAC256(&CRYD1);
+
+
+for (int i = 0; i < 8; i++) {
+ test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC256_1)[i], "hmac mismatch");
+}
+]]></value>
+ </code>
+ </step>
+
+ <step>
+ <description>
+ <value>hmac 512</value>
+ </description>
+ <tags>
+ <value />
+ </tags>
+ <code>
+ <value><![CDATA[
+cryHMAC512(&CRYD1);
+
+for (int i = 0; i < 16; i++) {
+ test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC512_1)[i], "hmac 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 1e53235f3..787fa1d66 100644
--- a/test/crypto/crypto_test.mk
+++ b/test/crypto/crypto_test.mk
@@ -1,9 +1,10 @@
# List of all the ChibiOS OS Library test files.
-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 \
+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/testref/ref_hmac.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 \
@@ -11,7 +12,8 @@ TESTSRC += ${CHIBIOS}/test/crypto/source/test/cry_test_root.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_008.c
+ ${CHIBIOS}/test/crypto/source/test/cry_test_sequence_008.c \
+ ${CHIBIOS}/test/crypto/source/test/cry_test_sequence_009.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 9d09a3f82..2269f91f3 100644
--- a/test/crypto/ref/gen_cfiles.bat
+++ b/test/crypto/ref/gen_cfiles.bat
@@ -3,3 +3,6 @@
%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_empty,sha_sha1_3,sha_sha1_56,sha_sha1_64,sha_sha1_128,sha_sha256_3,sha_sha256_56,sha_sha256_64,sha_sha256_128,sha_sha512_3,sha_sha512_56,sha_sha512_64,sha_sha512_128 -o ref_sha -p ../source/testref
+
+
+%PYTHON%\python genfile.py -f hmac_hmac256_1,hmac_hmac256_2,hmac_hmac512_1,hmac_hmac512_2 -o ref_hmac -p ../source/testref \ No newline at end of file
diff --git a/test/crypto/ref/gen_testref.bat b/test/crypto/ref/gen_testref.bat
index 17abaaae9..ac8e90dbc 100644
--- a/test/crypto/ref/gen_testref.bat
+++ b/test/crypto/ref/gen_testref.bat
@@ -14,8 +14,12 @@ echo|set /p="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" >
echo|set /p="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" > plaintext_5
+echo|set /p="Hi There" > plaintext_6
+
+echo|set /p="what do ya want for nothing?" > plaintext_7
+
call aes_ref.bat
call des_ref.bat
call sha_ref.bat
-
+call hmac_ref.bat
call gen_cfiles.bat \ No newline at end of file
diff --git a/test/crypto/ref/hmac_ref.bat b/test/crypto/ref/hmac_ref.bat
new file mode 100644
index 000000000..78eb88b00
--- /dev/null
+++ b/test/crypto/ref/hmac_ref.bat
@@ -0,0 +1,13 @@
+
+
+call %OPENSSL%\openssl dgst -sha256 -hmac " " -c -binary -out hmac_hmac256_1 plaintext_6
+ren hmac_hmac256_1 hmac_hmac256_1.enc
+
+call %OPENSSL%\openssl dgst -sha256 -hmac "Jefe" -c -binary -out hmac_hmac256_2 plaintext_7
+ren hmac_hmac256_2 hmac_hmac256_2.enc
+
+call %OPENSSL%\openssl dgst -sha512 -hmac " " -c -binary -out hmac_hmac512_1 plaintext_6
+ren hmac_hmac512_1 hmac_hmac512_1.enc
+
+call %OPENSSL%\openssl dgst -sha512 -hmac "Jefe" -c -binary -out hmac_hmac512_2 plaintext_7
+ren hmac_hmac512_2 hmac_hmac512_2.enc
diff --git a/test/crypto/source/test/cry_test_root.c b/test/crypto/source/test/cry_test_root.c
index 9c8feb713..397e49131 100644
--- a/test/crypto/source/test/cry_test_root.c
+++ b/test/crypto/source/test/cry_test_root.c
@@ -29,6 +29,7 @@
* - @subpage cry_test_sequence_006
* - @subpage cry_test_sequence_007
* - @subpage cry_test_sequence_008
+ * - @subpage cry_test_sequence_009
* .
*/
@@ -58,6 +59,7 @@ const testsequence_t * const cry_test_suite_array[] = {
&cry_test_sequence_006,
&cry_test_sequence_007,
&cry_test_sequence_008,
+ &cry_test_sequence_009,
NULL
};
diff --git a/test/crypto/source/test/cry_test_root.h b/test/crypto/source/test/cry_test_root.h
index 110dd851f..689339013 100644
--- a/test/crypto/source/test/cry_test_root.h
+++ b/test/crypto/source/test/cry_test_root.h
@@ -32,6 +32,7 @@
#include "cry_test_sequence_006.h"
#include "cry_test_sequence_007.h"
#include "cry_test_sequence_008.h"
+#include "cry_test_sequence_009.h"
#if !defined(__DOXYGEN__)
diff --git a/test/crypto/source/test/cry_test_sequence_005.c b/test/crypto/source/test/cry_test_sequence_005.c
index 35c759950..6649d39a6 100644
--- a/test/crypto/source/test/cry_test_sequence_005.c
+++ b/test/crypto/source/test/cry_test_sequence_005.c
@@ -78,23 +78,23 @@ static void cry_test_005_001_execute(void) {
/* [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]);
+ uint32_t random[4];
+ int i;
- test_assert(ret == CRY_NOERROR , "failed random");
+ ret = cryTRNG(&CRYD1,(uint8_t*)&random);
- SHOW_DATA(&random[i],1);
+ test_assert(ret == CRY_NOERROR , "failed random");
- test_assert(random[i] != 0 , "failed random generation (zero)");
+ SHOW_DATA(&random[0],4);
+
+ for (i=0;i<4;i++) {
+ test_assert(random[i] != 0 , "failed random generation (zero)");
+ }
+ for (i=1;i<4;i++)
+ {
+ test_assert(random[i-1] != random[i] , "failed random generation");
+ }
- for (j=0;j<i;j++)
- {
- test_assert(random[i] != random[j] , "failed random generation");
- }
- }
}
}
diff --git a/test/crypto/source/test/cry_test_sequence_009.c b/test/crypto/source/test/cry_test_sequence_009.c
new file mode 100644
index 000000000..c0023ea7e
--- /dev/null
+++ b/test/crypto/source/test/cry_test_sequence_009.c
@@ -0,0 +1,279 @@
+/*
+ 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_009.c
+ * @brief Test Sequence 009 code.
+ *
+ * @page cry_test_sequence_009 [9] HMAC
+ *
+ * File: @ref cry_test_sequence_009.c
+ *
+ * <h2>Description</h2>
+ * HMAC testing.
+ *
+ * <h2>Test Cases</h2>
+ * - @subpage cry_test_009_001
+ * - @subpage cry_test_009_002
+ * .
+ */
+
+/****************************************************************************
+ * Shared code.
+ ****************************************************************************/
+
+#include <string.h>
+#include "ref_hmac.h"
+#define plaintext msg_clear
+#define HMACOUT msg_encrypted
+#define shabuffer msg_decrypted
+
+#define MAX_SHA_BLOCK_SIZE TEST_MSG_DATA_BYTE_LEN
+#define MAX_SHA_BLOCK_SIZE_INWORD (MAX_SHA_BLOCK_SIZE/4)
+
+static const CRYConfig config_Polling=
+{
+ TRANSFER_POLLING,
+ 0
+};
+
+static const CRYConfig config_DMA=
+{
+ TRANSFER_DMA,
+ 0
+};
+
+
+static const int hmackeys_size[]=
+{
+ 20,
+ 4,
+ 20
+};
+
+static const uint8_t hmackey_1[]=
+{
+ 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
+ 0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,0x0B,
+
+};
+
+// "Hi There",
+static const uint8_t hmacmsg1[8]= "Hi There";
+static const size_t hmacmsg_size[]=
+{
+ 8,
+};
+static void cryHMAC256(CRYDriver *cryp) {
+
+ cryerror_t ret;
+ HMACSHA256Context hmacshactxp;
+ uint8_t *keyp;
+
+
+ hmacshactxp.shacontext.sha.sha_buffer = (uint8_t*)&shabuffer[0];
+ hmacshactxp.shacontext.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
+
+ keyp =(uint8_t *)hmackey_1;
+ ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_hmac,hmackeys_size[0], keyp);
+
+ test_assert(ret == CRY_NOERROR, "failed load transient key");
+
+ ret = cryHMACSHA256Init(cryp,&hmacshactxp);
+
+ test_assert(ret == CRY_NOERROR, "failed init HMACSHA256");
+
+ ret = cryHMACSHA256Update(cryp,&hmacshactxp,hmacmsg_size[0],(const uint8_t *)&hmacmsg1);
+
+ test_assert(ret == CRY_NOERROR, "failed update HMACSHA256");
+
+ ret = cryHMACSHA256Final(cryp,&hmacshactxp,(uint8_t *)HMACOUT);
+
+ test_assert(ret == CRY_NOERROR, "failed final HMACSHA256");
+
+
+ SHOW_DATA(HMACOUT,8);
+
+}
+
+static void cryHMAC512(CRYDriver *cryp) {
+
+ cryerror_t ret;
+ HMACSHA512Context hmacshactxp;
+ uint8_t *keyp;
+
+
+ hmacshactxp.shacontext.sha.sha_buffer = (uint8_t*)&shabuffer[0];
+ hmacshactxp.shacontext.sha.sha_buffer_size = MAX_SHA_BLOCK_SIZE;
+
+ keyp =(uint8_t *)hmackey_1;
+ ret = cryLoadTransientKey(&CRYD1, (cryalgorithm_t) cry_algo_hmac,hmackeys_size[0], keyp);
+
+ test_assert(ret == CRY_NOERROR, "failed load transient key");
+
+ ret = cryHMACSHA512Init(cryp,&hmacshactxp);
+
+ test_assert(ret == CRY_NOERROR, "failed init HMACSHA512");
+
+ ret = cryHMACSHA512Update(cryp,&hmacshactxp,hmacmsg_size[0],(const uint8_t *)&hmacmsg1);
+
+ test_assert(ret == CRY_NOERROR, "failed update HMACSHA512");
+
+ ret = cryHMACSHA512Final(cryp,&hmacshactxp,(uint8_t *)HMACOUT);
+
+ test_assert(ret == CRY_NOERROR, "failed final HMACSHA512");
+
+
+ SHOW_DATA(HMACOUT,16);
+
+}
+
+
+
+/****************************************************************************
+ * Test cases.
+ ****************************************************************************/
+
+/**
+ * @page cry_test_009_001 [9.1] HMAC Polling
+ *
+ * <h2>Description</h2>
+ * testing HMAC in polled mode.
+ *
+ * <h2>Test Steps</h2>
+ * - [9.1.1] hmac 256.
+ * - [9.1.2] hmac 512.
+ * .
+ */
+
+static void cry_test_009_001_setup(void) {
+ memset(HMACOUT, 0xff, TEST_MSG_DATA_BYTE_LEN);
+ cryStart(&CRYD1, &config_Polling);
+
+
+}
+
+static void cry_test_009_001_teardown(void) {
+ cryStop(&CRYD1);
+}
+
+static void cry_test_009_001_execute(void) {
+
+ /* [9.1.1] hmac 256.*/
+ test_set_step(1);
+ {
+ cryHMAC256(&CRYD1);
+
+ for (int i = 0; i < 8; i++) {
+ test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC256_1)[i], "hmac mismatch");
+ }
+ }
+
+ /* [9.1.2] hmac 512.*/
+ test_set_step(2);
+ {
+ cryHMAC512(&CRYD1);
+
+ for (int i = 0; i < 16; i++) {
+ test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC512_1)[i], "hmac mismatch");
+ }
+ }
+}
+
+static const testcase_t cry_test_009_001 = {
+ "HMAC Polling",
+ cry_test_009_001_setup,
+ cry_test_009_001_teardown,
+ cry_test_009_001_execute
+};
+
+/**
+ * @page cry_test_009_002 [9.2] HMAC DMA
+ *
+ * <h2>Description</h2>
+ * testing HMAC in DMA mode.
+ *
+ * <h2>Test Steps</h2>
+ * - [9.2.1] hmac 256.
+ * - [9.2.2] hmac 512.
+ * .
+ */
+
+static void cry_test_009_002_setup(void) {
+ memset(HMACOUT, 0xff, TEST_MSG_DATA_BYTE_LEN);
+ cryStart(&CRYD1, &config_DMA);
+
+
+}
+
+static void cry_test_009_002_teardown(void) {
+ cryStop(&CRYD1);
+}
+
+static void cry_test_009_002_execute(void) {
+
+ /* [9.2.1] hmac 256.*/
+ test_set_step(1);
+ {
+ cryHMAC256(&CRYD1);
+
+
+ for (int i = 0; i < 8; i++) {
+ test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC256_1)[i], "hmac mismatch");
+ }
+ }
+
+ /* [9.2.2] hmac 512.*/
+ test_set_step(2);
+ {
+ cryHMAC512(&CRYD1);
+
+ for (int i = 0; i < 16; i++) {
+ test_assert(HMACOUT[i] == ((uint32_t*) refHMAC_HMAC512_1)[i], "hmac mismatch");
+ }
+ }
+}
+
+static const testcase_t cry_test_009_002 = {
+ "HMAC DMA",
+ cry_test_009_002_setup,
+ cry_test_009_002_teardown,
+ cry_test_009_002_execute
+};
+
+/****************************************************************************
+ * Exported data.
+ ****************************************************************************/
+
+/**
+ * @brief Array of test cases.
+ */
+const testcase_t * const cry_test_sequence_009_array[] = {
+ &cry_test_009_001,
+ &cry_test_009_002,
+ NULL
+};
+
+/**
+ * @brief HMAC.
+ */
+const testsequence_t cry_test_sequence_009 = {
+ "HMAC",
+ cry_test_sequence_009_array
+};
diff --git a/test/crypto/source/test/cry_test_sequence_009.h b/test/crypto/source/test/cry_test_sequence_009.h
new file mode 100644
index 000000000..a57f9848a
--- /dev/null
+++ b/test/crypto/source/test/cry_test_sequence_009.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_009.h
+ * @brief Test Sequence 009 header.
+ */
+
+#ifndef CRY_TEST_SEQUENCE_009_H
+#define CRY_TEST_SEQUENCE_009_H
+
+extern const testsequence_t cry_test_sequence_009;
+
+#endif /* CRY_TEST_SEQUENCE_009_H */
diff --git a/test/crypto/source/testref/ref_hmac.c b/test/crypto/source/testref/ref_hmac.c
new file mode 100644
index 000000000..4b5e9a760
--- /dev/null
+++ b/test/crypto/source/testref/ref_hmac.c
@@ -0,0 +1,48 @@
+/*
+ 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 refHMAC_HMAC256_1[]={
+0xB0,0x34,0x4C,0x61,0xD8,0xDB,0x38,0x53,0x5C,0xA8,
+0xAF,0xCE,0xAF,0x0B,0xF1,0x2B,0x88,0x1D,0xC2,0x00,
+0xC9,0x83,0x3D,0xA7,0x26,0xE9,0x37,0x6C,0x2E,0x32,
+0xCF,0xF7,
+};
+const uint8_t refHMAC_HMAC256_2[]={
+0x5B,0xDC,0xC1,0x46,0xBF,0x60,0x75,0x4E,0x6A,0x04,
+0x24,0x26,0x08,0x95,0x75,0xC7,0x5A,0x00,0x3F,0x08,
+0x9D,0x27,0x39,0x83,0x9D,0xEC,0x58,0xB9,0x64,0xEC,
+0x38,0x43,
+};
+const uint8_t refHMAC_HMAC512_1[]={
+0x87,0xAA,0x7C,0xDE,0xA5,0xEF,0x61,0x9D,0x4F,0xF0,
+0xB4,0x24,0x1A,0x1D,0x6C,0xB0,0x23,0x79,0xF4,0xE2,
+0xCE,0x4E,0xC2,0x78,0x7A,0xD0,0xB3,0x05,0x45,0xE1,
+0x7C,0xDE,0xDA,0xA8,0x33,0xB7,0xD6,0xB8,0xA7,0x02,
+0x03,0x8B,0x27,0x4E,0xAE,0xA3,0xF4,0xE4,0xBE,0x9D,
+0x91,0x4E,0xEB,0x61,0xF1,0x70,0x2E,0x69,0x6C,0x20,
+0x3A,0x12,0x68,0x54,
+};
+const uint8_t refHMAC_HMAC512_2[]={
+0x16,0x4B,0x7A,0x7B,0xFC,0xF8,0x19,0xE2,0xE3,0x95,
+0xFB,0xE7,0x3B,0x56,0xE0,0xA3,0x87,0xBD,0x64,0x22,
+0x2E,0x83,0x1F,0xD6,0x10,0x27,0x0C,0xD7,0xEA,0x25,
+0x05,0x54,0x97,0x58,0xBF,0x75,0xC0,0x5A,0x99,0x4A,
+0x6D,0x03,0x4F,0x65,0xF8,0xF0,0xE6,0xFD,0xCA,0xEA,
+0xB1,0xA3,0x4D,0x4A,0x6B,0x4B,0x63,0x6E,0x07,0x0A,
+0x38,0xBC,0xE7,0x37,
+};
diff --git a/test/crypto/source/testref/ref_hmac.h b/test/crypto/source/testref/ref_hmac.h
new file mode 100644
index 000000000..fa9738c2d
--- /dev/null
+++ b/test/crypto/source/testref/ref_hmac.h
@@ -0,0 +1,23 @@
+/*
+ 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_HMAC_H_
+#define TEST_REF_HMAC_H_
+
+extern const uint8_t refHMAC_HMAC256_1[];
+extern const uint8_t refHMAC_HMAC256_2[];
+extern const uint8_t refHMAC_HMAC512_1[];
+extern const uint8_t refHMAC_HMAC512_2[];
+#endif //TEST_REF_HMAC_H_