Add test_wolfSSL_DES_ecb_encrypt()
This commit is contained in:
parent
c466e3c078
commit
b19cf2cfb8
@ -15794,7 +15794,7 @@ void wolfSSL_DES_set_odd_parity(WOLFSSL_DES_cblock* myDes)
|
||||
|
||||
|
||||
void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* desa,
|
||||
WOLFSSL_DES_cblock* desb, WOLFSSL_DES_key_schedule* key, int len)
|
||||
WOLFSSL_DES_cblock* desb, WOLFSSL_DES_key_schedule* key, int dir)
|
||||
{
|
||||
#ifdef WOLFSSL_DES_ECB
|
||||
WOLFSSL_ENTER("wolfSSL_DES_ecb_encrypt");
|
||||
@ -15803,10 +15803,10 @@ void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* desa,
|
||||
if (desa == NULL || key == NULL){
|
||||
WOLFSSL_MSG("Bad argument passed to wolfSSL_DES_ecb_encrypt");
|
||||
} else {
|
||||
if (wc_Des3_SetKey(&enc, (const byte*) key, (const byte*) NULL, DES_ENCRYPTION) != 0){
|
||||
if (wc_Des3_SetKey(&enc, (const byte*) key, (const byte*) NULL, dir) != 0){
|
||||
WOLFSSL_MSG("wc_Des3_SetKey return error.");
|
||||
}
|
||||
if (wc_Des3_EcbEncrypt(&enc, (byte*) desb, (const byte*) desa, len) != 0){
|
||||
if (wc_Des3_EcbEncrypt(&enc, (byte*) desb, (const byte*) desa, sizeof(desb)) != 0){
|
||||
WOLFSSL_MSG("wc_Des3_EcbEncrpyt return error.");
|
||||
}
|
||||
}
|
||||
|
29
tests/api.c
29
tests/api.c
@ -3028,7 +3028,34 @@ static void test_wolfSSL_BIO(void)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void test_wolfSSL_DES_ecb_encrypt(void)
|
||||
{
|
||||
#if defined(OPENSSL_EXTRA) && !defined(NO_DES3)
|
||||
WOLFSSL_DES_cblock input1,input2,output1,output2,back1,back2;
|
||||
WOLFSSL_DES_key_schedule key;
|
||||
|
||||
memcpy(key,"12345678",sizeof(WOLFSSL_DES_key_schedule));
|
||||
memcpy(input1, "Iamhuman",sizeof(WOLFSSL_DES_cblock));
|
||||
memcpy(input2, "Whoisit?",sizeof(WOLFSSL_DES_cblock));
|
||||
memset(output1, 0, sizeof(WOLFSSL_DES_cblock));
|
||||
memset(output2, 0, sizeof(WOLFSSL_DES_cblock));
|
||||
memset(back1, 0, sizeof(WOLFSSL_DES_cblock));
|
||||
memset(back2, 0, sizeof(WOLFSSL_DES_cblock));
|
||||
|
||||
wolfSSL_DES_ecb_encrypt(&input1,&output1,&key,DES_ENCRYPT);
|
||||
wolfSSL_DES_ecb_encrypt(&input2,&output2,&key,DES_ENCRYPT);
|
||||
|
||||
// Decrypt messages
|
||||
int ret1 = 0;
|
||||
int ret2 = 0;
|
||||
wolfSSL_DES_ecb_encrypt(&output1,&back1,&key,DES_DECRYPT);
|
||||
ret1 = memcmp((unsigned char *) back1,(unsigned char *) input1,sizeof(WOLFSSL_DES_cblock));
|
||||
AssertIntEQ(ret1,0);
|
||||
wolfSSL_DES_ecb_encrypt(&output2,&back2,&key,DES_DECRYPT);
|
||||
ret2 = memcmp((unsigned char *) back2,(unsigned char *) input2,sizeof(WOLFSSL_DES_cblock));
|
||||
AssertIntEQ(ret2,0);
|
||||
#endif
|
||||
}
|
||||
/*----------------------------------------------------------------------------*
|
||||
| wolfCrypt ASN
|
||||
*----------------------------------------------------------------------------*/
|
||||
@ -3133,7 +3160,7 @@ void ApiTest(void)
|
||||
test_wolfSSL_set_options();
|
||||
test_wolfSSL_PEM_read_bio();
|
||||
test_wolfSSL_BIO();
|
||||
|
||||
test_wolfSSL_DES_ecb_encrypt();
|
||||
AssertIntEQ(test_wolfSSL_Cleanup(), SSL_SUCCESS);
|
||||
|
||||
/* wolfCrypt ASN tests */
|
||||
|
Loading…
Reference in New Issue
Block a user