forked from wolfSSL/wolfssl
Fix DES_ecb_encrypt function in terms of reviewing point.
This commit is contained in:
39
src/ssl.c
39
src/ssl.c
@ -15794,28 +15794,37 @@ void wolfSSL_DES_set_odd_parity(WOLFSSL_DES_cblock* myDes)
|
|||||||
|
|
||||||
|
|
||||||
#ifdef WOLFSSL_DES_ECB
|
#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 enc)
|
WOLFSSL_DES_cblock* desb, WOLFSSL_DES_key_schedule* key, int enc)
|
||||||
{
|
{
|
||||||
WOLFSSL_ENTER("wolfSSL_DES_ecb_encrypt");
|
WOLFSSL_ENTER("wolfSSL_DES_ecb_encrypt");
|
||||||
|
|
||||||
Des3 myDes;
|
Des myDes;
|
||||||
if (desa == NULL || key == NULL || desb == NULL || (enc != DES_ENCRYPT && enc != DES_DECRYPT)){
|
if (desa == NULL || key == NULL || desb == NULL ||
|
||||||
|
(enc != DES_ENCRYPT && enc != DES_DECRYPT)) {
|
||||||
WOLFSSL_MSG("Bad argument passed to wolfSSL_DES_ecb_encrypt");
|
WOLFSSL_MSG("Bad argument passed to wolfSSL_DES_ecb_encrypt");
|
||||||
} else {
|
} else {
|
||||||
if (wc_Des3_SetKey(&myDes, (const byte*) key, (const byte*) NULL, !enc) != 0){
|
if (wc_Des_SetKey(&myDes, (const byte*) key,
|
||||||
WOLFSSL_MSG("wc_Des3_SetKey return error.");
|
(const byte*) NULL, !enc) != 0) {
|
||||||
}
|
WOLFSSL_MSG("wc_Des_SetKey return error.");
|
||||||
if (enc){
|
return;
|
||||||
if (wc_Des3_EcbEncrypt(&myDes, (byte*) desb, (const byte*) desa, sizeof(desa)) != 0){
|
}
|
||||||
WOLFSSL_MSG("wc_Des3_EcbEncrpyt return error.");
|
if (enc){
|
||||||
}
|
if (wc_Des_EcbEncrypt(&myDes, (byte*) desb,
|
||||||
} else {
|
(const byte*) desa, sizeof(desa)) != 0){
|
||||||
if (wc_Des3_EcbDecrypt(&myDes, (byte*) desb, (const byte*) desa, sizeof(desa)) != 0){
|
WOLFSSL_MSG("wc_Des_EcbEncrpyt return error.");
|
||||||
WOLFSSL_MSG("wc_Des3_EcbDecrpyt 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
|
||||||
|
|
||||||
|
17
tests/api.c
17
tests/api.c
@ -3036,18 +3036,19 @@ static void test_wolfSSL_DES_ecb_encrypt(void)
|
|||||||
|
|
||||||
printf(testingFmt, "wolfSSL_DES_ecb_encrypt()");
|
printf(testingFmt, "wolfSSL_DES_ecb_encrypt()");
|
||||||
|
|
||||||
memcpy(key,"12345678",sizeof(WOLFSSL_DES_key_schedule));
|
XMEMCPY(key,"12345678",sizeof(WOLFSSL_DES_key_schedule));
|
||||||
memcpy(input1, "Iamhuman",sizeof(WOLFSSL_DES_cblock));
|
XMEMCPY(input1, "Iamhuman",sizeof(WOLFSSL_DES_cblock));
|
||||||
memcpy(input2, "Whoisit?",sizeof(WOLFSSL_DES_cblock));
|
XMEMCPY(input2, "Whoisit?",sizeof(WOLFSSL_DES_cblock));
|
||||||
memset(output1, 0, sizeof(WOLFSSL_DES_cblock));
|
XMEMSET(output1, 0, sizeof(WOLFSSL_DES_cblock));
|
||||||
memset(output2, 0, sizeof(WOLFSSL_DES_cblock));
|
XMEMSET(output2, 0, sizeof(WOLFSSL_DES_cblock));
|
||||||
memset(back1, 0, sizeof(WOLFSSL_DES_cblock));
|
XMEMSET(back1, 0, sizeof(WOLFSSL_DES_cblock));
|
||||||
memset(back2, 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(&input1,&output1,&key,DES_ENCRYPT);
|
||||||
wolfSSL_DES_ecb_encrypt(&input2,&output2,&key,DES_ENCRYPT);
|
wolfSSL_DES_ecb_encrypt(&input2,&output2,&key,DES_ENCRYPT);
|
||||||
|
|
||||||
// Decrypt messages
|
/* Decrypt messages */
|
||||||
int ret1 = 0;
|
int ret1 = 0;
|
||||||
int ret2 = 0;
|
int ret2 = 0;
|
||||||
wolfSSL_DES_ecb_encrypt(&output1,&back1,&key,DES_DECRYPT);
|
wolfSSL_DES_ecb_encrypt(&output1,&back1,&key,DES_DECRYPT);
|
||||||
|
Reference in New Issue
Block a user