DES_set_odd_parity to MLB

This commit is contained in:
Takashi Kojo
2017-07-17 08:49:23 +09:00
committed by Jacob Barthelmeh
parent a3ad8c5bae
commit c80cadb25f
2 changed files with 4 additions and 3 deletions

View File

@ -20392,7 +20392,7 @@ void wolfSSL_DES_set_odd_parity(WOLFSSL_DES_cblock* myDes)
for (i = 0; i < sz; i++) {
unsigned char c = *((unsigned char*)myDes + i);
if (((c & 0x01) ^
if ((
((c >> 1) & 0x01) ^
((c >> 2) & 0x01) ^
((c >> 3) & 0x01) ^
@ -20401,7 +20401,7 @@ void wolfSSL_DES_set_odd_parity(WOLFSSL_DES_cblock* myDes)
((c >> 6) & 0x01) ^
((c >> 7) & 0x01)) != 1) {
WOLFSSL_MSG("Setting odd parity bit");
*((unsigned char*)myDes + i) = *((unsigned char*)myDes + i) | 0x80;
*((unsigned char*)myDes + i) = *((unsigned char*)myDes + i) | 0x01;
}
}
}

View File

@ -13501,13 +13501,14 @@ static void test_wolfSSL_DES(void)
DES_set_key(&myDes, &key);
/* check, check of odd parity */
XMEMSET(myDes, 4, sizeof(const_DES_cblock)); myDes[0] = 3; /*set even parity*/
XMEMSET(myDes, 4, sizeof(const_DES_cblock)); myDes[0] = 6; /*set even parity*/
XMEMSET(key, 5, sizeof(DES_key_schedule));
AssertIntEQ(DES_set_key_checked(&myDes, &key), -1);
AssertIntNE(key[0], myDes[0]); /* should not have copied over key */
/* set odd parity for success case */
DES_set_odd_parity(&myDes);
printf("%02x %02x %02x %02x", myDes[0], myDes[1], myDes[2], myDes[3]);
AssertIntEQ(DES_set_key_checked(&myDes, &key), 0);
for (i = 0; i < sizeof(DES_key_schedule); i++) {
AssertIntEQ(key[i], myDes[i]);