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
|
||||
/* 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,
|
||||
WOLFSSL_DES_cblock* desb, WOLFSSL_DES_key_schedule* key, int enc)
|
||||
{
|
||||
WOLFSSL_ENTER("wolfSSL_DES_ecb_encrypt");
|
||||
|
||||
Des3 myDes;
|
||||
if (desa == NULL || key == NULL || desb == NULL || (enc != DES_ENCRYPT && enc != DES_DECRYPT)){
|
||||
Des myDes;
|
||||
if (desa == NULL || key == NULL || desb == NULL ||
|
||||
(enc != DES_ENCRYPT && enc != DES_DECRYPT)) {
|
||||
WOLFSSL_MSG("Bad argument passed to wolfSSL_DES_ecb_encrypt");
|
||||
} else {
|
||||
if (wc_Des3_SetKey(&myDes, (const byte*) key, (const byte*) NULL, !enc) != 0){
|
||||
WOLFSSL_MSG("wc_Des3_SetKey return error.");
|
||||
}
|
||||
if (enc){
|
||||
if (wc_Des3_EcbEncrypt(&myDes, (byte*) desb, (const byte*) desa, sizeof(desa)) != 0){
|
||||
WOLFSSL_MSG("wc_Des3_EcbEncrpyt return error.");
|
||||
}
|
||||
} else {
|
||||
if (wc_Des3_EcbDecrypt(&myDes, (byte*) desb, (const byte*) desa, sizeof(desa)) != 0){
|
||||
WOLFSSL_MSG("wc_Des3_EcbDecrpyt return error.");
|
||||
}
|
||||
}
|
||||
}
|
||||
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
|
||||
|
||||
|
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()");
|
||||
|
||||
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));
|
||||
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
|
||||
/* Decrypt messages */
|
||||
int ret1 = 0;
|
||||
int ret2 = 0;
|
||||
wolfSSL_DES_ecb_encrypt(&output1,&back1,&key,DES_DECRYPT);
|
||||
|
Reference in New Issue
Block a user