mirror of https://github.com/wolfSSL/wolfssl.git
Test case created by @miyazakh.
parent
dc57adcfed
commit
191165a021
|
@ -31,7 +31,8 @@
|
|||
#include <wolfssl/wolfcrypt/port/Renesas/renesas-tsip-crypt.h>
|
||||
#endif
|
||||
|
||||
#define SIMPLE_TLSSEVER_IP "192.168.11.5"
|
||||
#if defined(SIMPLE_TLS_TSIP_CLIENT) || defined(SIMPLE_TLS_CLIENT)
|
||||
#define SIMPLE_TLSSEVER_IP "192.168.11.11"
|
||||
#define SIMPLE_TLSSERVER_PORT "11111"
|
||||
|
||||
ER t4_tcp_callback(ID cepid, FN fncd , VP p_parblk);
|
||||
|
@ -360,3 +361,4 @@ void wolfSSL_TLS_client( )
|
|||
|
||||
return;
|
||||
}
|
||||
#endif /* SIMPLE_TSIP TLS_CLIENT || SIMPLE_TLS_CLIENT */
|
||||
|
|
|
@ -27,6 +27,8 @@
|
|||
#include "wolfssl/certs_test.h"
|
||||
#include <wolfssl_simple_demo.h>
|
||||
|
||||
#if defined(SIMPLE_TLS_SERVER)
|
||||
|
||||
static WOLFSSL_CTX *server_ctx;
|
||||
|
||||
static int my_IORecv(WOLFSSL* ssl, char* buff, int sz, void* ctx)
|
||||
|
@ -192,3 +194,4 @@ out:
|
|||
tcp_sht_cep(cepid);
|
||||
tcp_cls_cep(cepid, TMO_FEVR);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
</toolchain>
|
||||
</configuration>
|
||||
<platform id="R5F572NNHxFB"/>
|
||||
<option id="board" value="EnvisionKitRX72N (V1.12)"/>
|
||||
<option id="board" value="EnvisionKitRX72N (V1.14)"/>
|
||||
</general>
|
||||
<tool id="Clock">
|
||||
<option enabled="true" id="vccinput" selection="textinputitem">
|
||||
|
@ -1166,8 +1166,8 @@
|
|||
<gridItem id="TSIP_MD5" selectedIndex="1"/>
|
||||
<gridItem id="TSIP_SHA_1_HMAC" selectedIndex="1"/>
|
||||
<gridItem id="TSIP_SHA_256_HMAC" selectedIndex="1"/>
|
||||
<gridItem id="TSIP_RSAES_1024" selectedIndex="0"/>
|
||||
<gridItem id="TSIP_RSAES_2048" selectedIndex="0"/>
|
||||
<gridItem id="TSIP_RSAES_1024" selectedIndex="1"/>
|
||||
<gridItem id="TSIP_RSAES_2048" selectedIndex="1"/>
|
||||
<gridItem id="TSIP_RSAES_3072" selectedIndex="0"/>
|
||||
<gridItem id="TSIP_RSAES_4096" selectedIndex="0"/>
|
||||
<gridItem id="TSIP_RSASSA_1024" selectedIndex="1"/>
|
||||
|
|
|
@ -103,6 +103,8 @@
|
|||
#define HAVE_AESGCM
|
||||
#define HAVE_AESCCM
|
||||
#define HAVE_AES_CBC
|
||||
#define WOLFSSL_AES_DIRECT
|
||||
#define WOLFSSL_AES_COUNTER
|
||||
#define WOLFSSL_SHA512
|
||||
|
||||
#define HAVE_SUPPORTED_CURVES
|
||||
|
|
|
@ -191,6 +191,328 @@ static int tsip_aes_cbc_test(int prnt, tsip_aes_key_index_t* aes_key)
|
|||
return ret;
|
||||
}
|
||||
|
||||
#if defined(WOLFSSL_AES_COUNTER)
|
||||
#if (defined(TSIP_AES_128_CTR) && TSIP_AES_128_CTR == 1) &&\
|
||||
(defined(WOLFSSL_AES_128))
|
||||
static int tsip_aes128_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
|
||||
{
|
||||
int ret;
|
||||
Aes *enc = NULL;
|
||||
Aes *dec = NULL;
|
||||
byte cipher[WC_AES_BLOCK_SIZE * 4];
|
||||
byte plain [WC_AES_BLOCK_SIZE * 4];
|
||||
/* test vectors from "Recommendation for Block Cipher Modes of
|
||||
* Operation" NIST Special Publication 800-38A */
|
||||
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
|
||||
{
|
||||
0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
|
||||
0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
|
||||
};
|
||||
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
|
||||
{
|
||||
0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
|
||||
0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
|
||||
0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
|
||||
0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
|
||||
0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
|
||||
0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
|
||||
0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
|
||||
0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
|
||||
};
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128[] =
|
||||
{
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
|
||||
};
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
|
||||
{
|
||||
0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
|
||||
0xc2
|
||||
};
|
||||
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctr128Key[] =
|
||||
{
|
||||
0x2b,0x7e,0x15,0x16,0x28,0xae,0xd2,0xa6,
|
||||
0xab,0xf7,0x15,0x88,0x09,0xcf,0x4f,0x3c
|
||||
};
|
||||
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctr128Cipher[] =
|
||||
{
|
||||
0x87,0x4d,0x61,0x91,0xb6,0x20,0xe3,0x26,
|
||||
0x1b,0xef,0x68,0x64,0x99,0x0d,0xb6,0xce,
|
||||
0x98,0x06,0xf6,0x6b,0x79,0x70,0xfd,0xff,
|
||||
0x86,0x17,0x18,0x7b,0xb9,0xff,0xfd,0xff,
|
||||
0x5a,0xe4,0xdf,0x3e,0xdb,0xd5,0xd3,0x5e,
|
||||
0x5b,0x4f,0x09,0x02,0x0d,0xb0,0x3e,0xab,
|
||||
0x1e,0x03,0x1d,0xda,0x2f,0xbe,0x03,0xd1,
|
||||
0x79,0x21,0x70,0xa0,0xf3,0x00,0x9c,0xee
|
||||
};
|
||||
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128Cipher[] =
|
||||
{
|
||||
0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
|
||||
0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
|
||||
0xd3,0xda,0xe1,0x5b,0x04
|
||||
};
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctr128Wrap128CipherLong[] =
|
||||
{
|
||||
0xe1,0x33,0x38,0xe3,0x6c,0xb7,0x19,0x62,
|
||||
0xe0,0x0d,0x02,0x0b,0x4c,0xed,0xbd,0x86,
|
||||
0xd3,0xda,0xe1,0x5b,0x04,0xbb,0x35,0x2f,
|
||||
0xa0,0xf5,0x9f,0xeb,0xfc,0xb4,0xda,0x3e
|
||||
};
|
||||
int i;
|
||||
struct {
|
||||
const byte* key;
|
||||
int keySz;
|
||||
const byte* iv;
|
||||
const byte* plain;
|
||||
int len;
|
||||
const byte* cipher;
|
||||
} testVec[] = {
|
||||
{ ctr128Key, (int)sizeof(ctr128Key), ctrIv,
|
||||
ctrPlain, (int)sizeof(ctrPlain), ctr128Cipher },
|
||||
/* let's try with just 9 bytes, non block size test */
|
||||
{ ctr128Key, (int)sizeof(ctr128Key), ctrIv,
|
||||
ctrPlain, (int)sizeof(oddCipher), ctr128Cipher },
|
||||
/* and an additional 9 bytes to reuse tmp left buffer */
|
||||
{ NULL, 0, NULL, ctrPlain, (int)sizeof(oddCipher), oddCipher },
|
||||
/* Counter wrapping */
|
||||
{ ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
|
||||
ctrPlain, (int)sizeof(ctr128Wrap128Cipher), ctr128Wrap128Cipher },
|
||||
{ ctr128Key, (int)sizeof(ctr128Key), ctrIvWrap128,
|
||||
ctrPlain, (int)sizeof(ctr128Wrap128CipherLong),
|
||||
ctr128Wrap128CipherLong },
|
||||
};
|
||||
int AES_CTR_TEST_LEN = (int)(sizeof(testVec) / sizeof(*testVec));
|
||||
|
||||
if (prnt)
|
||||
printf(" tsip_aes128_ctr_test() ");
|
||||
|
||||
enc = wc_AesNew(NULL, INVALID_DEVID, &ret);
|
||||
if (enc == NULL){
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
dec = wc_AesNew(NULL, INVALID_DEVID, &ret);
|
||||
if (dec == NULL){
|
||||
ret = -2;
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; i < AES_CTR_TEST_LEN; i++) {
|
||||
if (testVec[i].key != NULL) {
|
||||
ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
|
||||
testVec[i].iv, AES_ENCRYPTION);
|
||||
|
||||
if (ret != 0) {
|
||||
ret = -3;
|
||||
goto out;
|
||||
} else {
|
||||
/* set TSIP Aes key */
|
||||
XMEMCPY(&enc->ctx.tsip_keyIdx, aes_key,
|
||||
sizeof(tsip_aes_key_index_t));
|
||||
enc->ctx.keySize = enc->keylen;
|
||||
}
|
||||
/* Ctr only uses encrypt, even on key setup */
|
||||
ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)testVec[i].keySz,
|
||||
testVec[i].iv, AES_ENCRYPTION);
|
||||
if (ret != 0) {
|
||||
ret = -4;
|
||||
goto out;
|
||||
} else {
|
||||
XMEMCPY(&dec->ctx.tsip_keyIdx, aes_key,
|
||||
sizeof(tsip_aes_key_index_t));
|
||||
dec->ctx.keySize = dec->keylen;
|
||||
}
|
||||
}
|
||||
|
||||
ret = wc_tsip_AesCtr(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
|
||||
if (ret != 0) {
|
||||
ret = -5;
|
||||
goto out;
|
||||
}
|
||||
ret = wc_tsip_AesCtr(dec, plain, cipher, (word32)testVec[i].len);
|
||||
if (ret != 0) {
|
||||
ret = -6;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (XMEMCMP(plain, ctrPlain, (size_t)testVec[i].len)) {
|
||||
ret = -7;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
out:
|
||||
wc_AesDelete(enc, &enc);
|
||||
wc_AesDelete(dec, &dec);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_128 */
|
||||
#if (defined(TSIP_AES_256_CTR) && TSIP_AES_256_CTR == 1) &&\
|
||||
(defined(WOLFSSL_AES_256))
|
||||
static int tsip_aes256_ctr_test(int prnt, tsip_aes_key_index_t* aes_key)
|
||||
{
|
||||
int ret;
|
||||
Aes *enc = NULL;
|
||||
Aes *dec = NULL;
|
||||
byte cipher[WC_AES_BLOCK_SIZE * 4];
|
||||
byte plain [WC_AES_BLOCK_SIZE * 4];
|
||||
/* test vectors from "Recommendation for Block Cipher Modes of
|
||||
* Operation" NIST Special Publication 800-38A */
|
||||
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctrIv[] =
|
||||
{
|
||||
0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,
|
||||
0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff
|
||||
};
|
||||
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctrPlain[] =
|
||||
{
|
||||
0x6b,0xc1,0xbe,0xe2,0x2e,0x40,0x9f,0x96,
|
||||
0xe9,0x3d,0x7e,0x11,0x73,0x93,0x17,0x2a,
|
||||
0xae,0x2d,0x8a,0x57,0x1e,0x03,0xac,0x9c,
|
||||
0x9e,0xb7,0x6f,0xac,0x45,0xaf,0x8e,0x51,
|
||||
0x30,0xc8,0x1c,0x46,0xa3,0x5c,0xe4,0x11,
|
||||
0xe5,0xfb,0xc1,0x19,0x1a,0x0a,0x52,0xef,
|
||||
0xf6,0x9f,0x24,0x45,0xdf,0x4f,0x9b,0x17,
|
||||
0xad,0x2b,0x41,0x7b,0xe6,0x6c,0x37,0x10
|
||||
};
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctrIvWrap128[] =
|
||||
{
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
|
||||
0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
|
||||
};
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte oddCipher[] =
|
||||
{
|
||||
0xb9,0xd7,0xcb,0x08,0xb0,0xe1,0x7b,0xa0,
|
||||
0xc2
|
||||
};
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctr256Key[] =
|
||||
{
|
||||
0x60,0x3d,0xeb,0x10,0x15,0xca,0x71,0xbe,
|
||||
0x2b,0x73,0xae,0xf0,0x85,0x7d,0x77,0x81,
|
||||
0x1f,0x35,0x2c,0x07,0x3b,0x61,0x08,0xd7,
|
||||
0x2d,0x98,0x10,0xa3,0x09,0x14,0xdf,0xf4
|
||||
};
|
||||
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctr256Cipher[] =
|
||||
{
|
||||
0x60,0x1e,0xc3,0x13,0x77,0x57,0x89,0xa5,
|
||||
0xb7,0xa7,0xf5,0x04,0xbb,0xf3,0xd2,0x28,
|
||||
0xf4,0x43,0xe3,0xca,0x4d,0x62,0xb5,0x9a,
|
||||
0xca,0x84,0xe9,0x90,0xca,0xca,0xf5,0xc5,
|
||||
0x2b,0x09,0x30,0xda,0xa2,0x3d,0xe9,0x4c,
|
||||
0xe8,0x70,0x17,0xba,0x2d,0x84,0x98,0x8d,
|
||||
0xdf,0xc9,0xc5,0x8d,0xb6,0x7a,0xad,0xa6,
|
||||
0x13,0xc2,0xdd,0x08,0x45,0x79,0x41,0xa6
|
||||
};
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128Cipher[] =
|
||||
{
|
||||
0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
|
||||
0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
|
||||
0x4b,0x45,0x7c,0xd6,0x8a
|
||||
};
|
||||
WOLFSSL_SMALL_STACK_STATIC const byte ctr256Wrap128CipherLong[] =
|
||||
{
|
||||
0x50,0xfd,0x97,0xc3,0xe6,0x1a,0xbb,0x48,
|
||||
0x73,0xfb,0x78,0xdf,0x1e,0x8e,0x77,0xe6,
|
||||
0x4b,0x45,0x7c,0xd6,0x8a,0xcc,0xda,0x4a,
|
||||
0x89,0xfa,0x23,0x6c,0x06,0xbf,0x26,0x05
|
||||
};
|
||||
|
||||
int i;
|
||||
struct {
|
||||
const byte* key;
|
||||
int keySz;
|
||||
const byte* iv;
|
||||
const byte* plain;
|
||||
int len;
|
||||
const byte* cipher;
|
||||
} testVec[] = {
|
||||
{ ctr256Key, (int)sizeof(ctr256Key), ctrIv,
|
||||
ctrPlain, (int)sizeof(ctrPlain), ctr256Cipher },
|
||||
/* let's try with just 9 bytes, non block size test */
|
||||
{ ctr256Key, (int)sizeof(ctr256Key), ctrIv,
|
||||
ctrPlain, (int)sizeof(oddCipher), ctr256Cipher },
|
||||
/* Counter wrapping */
|
||||
{ ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
|
||||
ctrPlain, (int)sizeof(ctr256Wrap128Cipher), ctr256Wrap128Cipher },
|
||||
{ ctr256Key, (int)sizeof(ctr256Key), ctrIvWrap128,
|
||||
ctrPlain, (int)sizeof(ctr256Wrap128CipherLong),
|
||||
ctr256Wrap128CipherLong },
|
||||
};
|
||||
int AES_CTR_TEST_LEN = (int)(sizeof(testVec) / sizeof(*testVec));
|
||||
|
||||
if (prnt)
|
||||
printf(" tsip_aes256_ctr_test() ");
|
||||
|
||||
enc = wc_AesNew(NULL, INVALID_DEVID, &ret);
|
||||
if (enc == NULL){
|
||||
ret = -1;
|
||||
goto out;
|
||||
}
|
||||
dec = wc_AesNew(NULL, INVALID_DEVID, &ret);
|
||||
if (dec == NULL){
|
||||
ret = -2;
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (i = 0; i < AES_CTR_TEST_LEN; i++) {
|
||||
if (testVec[i].key != NULL) {
|
||||
ret = wc_AesSetKeyDirect(enc, testVec[i].key, (word32)testVec[i].keySz,
|
||||
testVec[i].iv, AES_ENCRYPTION);
|
||||
if (ret != 0) {
|
||||
ret = -3;
|
||||
goto out;
|
||||
} else {
|
||||
/* set TSIP Aes key */
|
||||
XMEMCPY(&enc->ctx.tsip_keyIdx, aes_key,
|
||||
sizeof(tsip_aes_key_index_t));
|
||||
enc->ctx.keySize = enc->keylen;
|
||||
}
|
||||
/* Ctr only uses encrypt, even on key setup */
|
||||
ret = wc_AesSetKeyDirect(dec, testVec[i].key, (word32)testVec[i].keySz,
|
||||
testVec[i].iv, AES_ENCRYPTION);
|
||||
if (ret != 0) {
|
||||
ret = -4;
|
||||
goto out;
|
||||
} else {
|
||||
/* set TSIP Aes key */
|
||||
XMEMCPY(&dec->ctx.tsip_keyIdx, aes_key,
|
||||
sizeof(tsip_aes_key_index_t));
|
||||
dec->ctx.keySize = enc->keylen;
|
||||
}
|
||||
}
|
||||
|
||||
ret = wc_tsip_AesCtr(enc, cipher, testVec[i].plain, (word32)testVec[i].len);
|
||||
if (ret != 0) {
|
||||
ret = -5;
|
||||
goto out;
|
||||
}
|
||||
ret = wc_tsip_AesCtr(dec, plain, cipher, (word32)testVec[i].len);
|
||||
if (ret != 0) {
|
||||
ret = -6;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (XMEMCMP(plain, ctrPlain, (size_t)testVec[i].len)) {
|
||||
ret = -7;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
out:
|
||||
wc_AesDelete(enc, &enc);
|
||||
wc_AesDelete(dec, &dec);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif /* WOLFSSL_AES_256 */
|
||||
#endif /* TSIP_AES_256_CTR && WOLFSSL_AES_COUNTER */
|
||||
|
||||
#ifdef FREERTOS
|
||||
static void tskAes128_Cbc_Test(void *pvParam)
|
||||
{
|
||||
|
@ -1250,7 +1572,17 @@ int tsip_crypt_test(void)
|
|||
|
||||
}
|
||||
#endif
|
||||
#ifdef WOLFSSL_AES_COUNTER
|
||||
if (ret == 0) {
|
||||
ret = tsip_aes128_ctr_test(1, &g_user_aes128_key_index1);
|
||||
RESULT_STR(ret)
|
||||
}
|
||||
|
||||
if (ret == 0) {
|
||||
ret = tsip_aes256_ctr_test(1, &g_user_aes256_key_index1);
|
||||
RESULT_STR(ret)
|
||||
}
|
||||
#endif
|
||||
#if defined(WOLFSSL_KEY_GEN) && \
|
||||
defined(WOLFSSL_RENESAS_TSIP_CRYPTONLY)
|
||||
|
||||
|
|
Loading…
Reference in New Issue