COMPAT. LAYER : fix missing return value and alignment

This commit is contained in:
Jacob Barthelmeh
2016-11-08 14:16:02 -07:00
parent f7a951709f
commit c122558810

View File

@@ -5653,6 +5653,7 @@ int wolfSSL_get_client_random(WOLFSSL* ssl, unsigned char* out, int outSz)
if (ssl->options.saveArrays == 0 || ssl->arrays == NULL) { if (ssl->options.saveArrays == 0 || ssl->arrays == NULL) {
WOLFSSL_MSG("Arrays struct not saved after handshake"); WOLFSSL_MSG("Arrays struct not saved after handshake");
return BAD_FUNC_ARG;
} }
if (outSz > RAN_LEN) { if (outSz > RAN_LEN) {
@@ -13324,12 +13325,12 @@ void wolfSSL_DES_set_key(WOLFSSL_const_DES_cblock* myDes,
/* return true in fail case (1) */ /* return true in fail case (1) */
static int DES_check(word32 mask, word32 mask2, unsigned char* key) static int DES_check(word32 mask, word32 mask2, unsigned char* key)
{ {
if ((*(word32*)(key + 0) ^ mask) == 0) { word32 value[2];
if ((*(word32*)(key + 4) ^ mask2) == 0) {
return 1; /* sanity check on length made in wolfSSL_DES_set_key_checked */
} value[0] = mask;
} value[1] = mask2;
return 0; return (XMEMCMP(value, key, sizeof(value)) == 0)? 1: 0;
} }
@@ -13342,9 +13343,16 @@ void wolfSSL_DES_set_key_checked(WOLFSSL_const_DES_cblock* myDes,
} }
else { else {
word32 i, mask, mask2; word32 i, mask, mask2;
word32 sz = sizeof(WOLFSSL_DES_key_schedule);
/* sanity check before call to DES_check */
if (sz != (sizeof(word32) * 2)) {
WOLFSSL_MSG("Unexpected WOLFSSL_DES_key_schedule size");
return;
}
/* check odd parity */ /* check odd parity */
for (i = 0; i < sizeof(WOLFSSL_DES_key_schedule); i++) { for (i = 0; i < sz; i++) {
unsigned char c = *((unsigned char*)key + i); unsigned char c = *((unsigned char*)key + i);
if (((c & 0x01) ^ if (((c & 0x01) ^
((c >> 1) & 0x01) ^ ((c >> 1) & 0x01) ^
@@ -13390,35 +13398,35 @@ void wolfSSL_DES_set_key_checked(WOLFSSL_const_DES_cblock* myDes,
/* semi-weak *key check (list from same Nist paper) */ /* semi-weak *key check (list from same Nist paper) */
mask = 0x011F011F; mask2 = 0x010E010E; mask = 0x011F011F; mask2 = 0x010E010E;
if (DES_check(mask, mask2, *key) || if (DES_check(mask, mask2, *key) ||
DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) { DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) {
WOLFSSL_MSG("Weak key found"); WOLFSSL_MSG("Weak key found");
return; return;
} }
mask = 0x01E001E0; mask2 = 0x01F101F1; mask = 0x01E001E0; mask2 = 0x01F101F1;
if (DES_check(mask, mask2, *key) || if (DES_check(mask, mask2, *key) ||
DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) { DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) {
WOLFSSL_MSG("Weak key found"); WOLFSSL_MSG("Weak key found");
return; return;
} }
mask = 0x01FE01FE; mask2 = 0x01FE01FE; mask = 0x01FE01FE; mask2 = 0x01FE01FE;
if (DES_check(mask, mask2, *key) || if (DES_check(mask, mask2, *key) ||
DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) { DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) {
WOLFSSL_MSG("Weak key found"); WOLFSSL_MSG("Weak key found");
return; return;
} }
mask = 0x1FE01FE0; mask2 = 0x0EF10EF1; mask = 0x1FE01FE0; mask2 = 0x0EF10EF1;
if (DES_check(mask, mask2, *key) || if (DES_check(mask, mask2, *key) ||
DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) { DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) {
WOLFSSL_MSG("Weak key found"); WOLFSSL_MSG("Weak key found");
return; return;
} }
mask = 0x1FFE1FFE; mask2 = 0x0EFE0EFE; mask = 0x1FFE1FFE; mask2 = 0x0EFE0EFE;
if (DES_check(mask, mask2, *key) || if (DES_check(mask, mask2, *key) ||
DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) { DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) {
WOLFSSL_MSG("Weak key found"); WOLFSSL_MSG("Weak key found");
return; return;
} }