mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 20:24:39 +02:00
Merge pull request #848 from ghoso/des_ecb_encrypt_impl
openSSL compatibility API
This commit is contained in:
37
src/ssl.c
37
src/ssl.c
@@ -16095,15 +16095,40 @@ void wolfSSL_DES_set_odd_parity(WOLFSSL_DES_cblock* myDes)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef WOLFSSL_DES_ECB
|
||||||
|
/* Encrpyt or decrypt input message desa with key and get output in desb.
|
||||||
|
* if enc is DES_ENCRYPT,input message is encrypted or
|
||||||
|
* if enc is DES_DECRYPT,input message is decrypted.
|
||||||
|
* */
|
||||||
void wolfSSL_DES_ecb_encrypt(WOLFSSL_DES_cblock* desa,
|
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 enc)
|
||||||
{
|
{
|
||||||
(void)desa;
|
WOLFSSL_ENTER("wolfSSL_DES_ecb_encrypt");
|
||||||
(void)desb;
|
|
||||||
(void)key;
|
Des myDes;
|
||||||
(void)len;
|
if (desa == NULL || key == NULL || desb == NULL ||
|
||||||
WOLFSSL_STUB("wolfSSL_DES_ecb_encrypt");
|
(enc != DES_ENCRYPT && enc != DES_DECRYPT)) {
|
||||||
|
WOLFSSL_MSG("Bad argument passed to wolfSSL_DES_ecb_encrypt");
|
||||||
|
} else {
|
||||||
|
if (wc_Des_SetKey(&myDes, (const byte*) key,
|
||||||
|
(const byte*) NULL, !enc) != 0) {
|
||||||
|
WOLFSSL_MSG("wc_Des_SetKey return error.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (enc){
|
||||||
|
if (wc_Des_EcbEncrypt(&myDes, (byte*) desb,
|
||||||
|
(const byte*) desa, sizeof(desa)) != 0){
|
||||||
|
WOLFSSL_MSG("wc_Des_EcbEncrpyt return error.");
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (wc_Des_EcbDecrypt(&myDes, (byte*) desb,
|
||||||
|
(const byte*) desa, sizeof(desa)) != 0){
|
||||||
|
WOLFSSL_MSG("wc_Des_EcbDecrpyt return error.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* NO_DES3 */
|
#endif /* NO_DES3 */
|
||||||
|
|
||||||
|
34
tests/api.c
34
tests/api.c
@@ -3038,7 +3038,39 @@ static void test_wolfSSL_BIO(void)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void test_wolfSSL_DES_ecb_encrypt(void)
|
||||||
|
{
|
||||||
|
#if defined(OPENSSL_EXTRA) && !defined(NO_DES3) && defined(WOLFSSL_DES_ECB)
|
||||||
|
WOLFSSL_DES_cblock input1,input2,output1,output2,back1,back2;
|
||||||
|
WOLFSSL_DES_key_schedule key;
|
||||||
|
|
||||||
|
printf(testingFmt, "wolfSSL_DES_ecb_encrypt()");
|
||||||
|
|
||||||
|
XMEMCPY(key,"12345678",sizeof(WOLFSSL_DES_key_schedule));
|
||||||
|
XMEMCPY(input1, "Iamhuman",sizeof(WOLFSSL_DES_cblock));
|
||||||
|
XMEMCPY(input2, "Whoisit?",sizeof(WOLFSSL_DES_cblock));
|
||||||
|
XMEMSET(output1, 0, sizeof(WOLFSSL_DES_cblock));
|
||||||
|
XMEMSET(output2, 0, sizeof(WOLFSSL_DES_cblock));
|
||||||
|
XMEMSET(back1, 0, sizeof(WOLFSSL_DES_cblock));
|
||||||
|
XMEMSET(back2, 0, sizeof(WOLFSSL_DES_cblock));
|
||||||
|
|
||||||
|
/* Encrypt messages */
|
||||||
|
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);
|
||||||
|
|
||||||
|
printf(resultFmt, passed);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
/*----------------------------------------------------------------------------*
|
/*----------------------------------------------------------------------------*
|
||||||
| wolfCrypt ASN
|
| wolfCrypt ASN
|
||||||
*----------------------------------------------------------------------------*/
|
*----------------------------------------------------------------------------*/
|
||||||
@@ -3397,7 +3429,7 @@ void ApiTest(void)
|
|||||||
test_wolfSSL_set_options();
|
test_wolfSSL_set_options();
|
||||||
test_wolfSSL_PEM_read_bio();
|
test_wolfSSL_PEM_read_bio();
|
||||||
test_wolfSSL_BIO();
|
test_wolfSSL_BIO();
|
||||||
|
test_wolfSSL_DES_ecb_encrypt();
|
||||||
AssertIntEQ(test_wolfSSL_Cleanup(), SSL_SUCCESS);
|
AssertIntEQ(test_wolfSSL_Cleanup(), SSL_SUCCESS);
|
||||||
|
|
||||||
/* wolfCrypt ASN tests */
|
/* wolfCrypt ASN tests */
|
||||||
|
Reference in New Issue
Block a user