diff options
author | areviu <areviu.info@gmail.com> | 2017-11-30 21:12:58 +0000 |
---|---|---|
committer | areviu <areviu.info@gmail.com> | 2017-11-30 21:12:58 +0000 |
commit | 2ebbe6eb870313331bba48884112675107a6b866 (patch) | |
tree | f2eb4b050f057c5ebddb6a48cb1e511296940544 /test/crypto/configuration.xml | |
parent | 5b31410098434a2aff0c0729621fee6c6f2b3519 (diff) | |
download | ChibiOS-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/crypto/configuration.xml')
-rw-r--r-- | test/crypto/configuration.xml | 390 |
1 files changed, 390 insertions, 0 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> |