-
Notifications
You must be signed in to change notification settings - Fork 791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Compatibility layer #617
Merged
toddouska
merged 3 commits into
wolfSSL:master
from
JacobBarthelmeh:Compatibility-Layer
Nov 10, 2016
Merged
Compatibility layer #617
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5630,6 +5630,43 @@ int wolfSSL_use_certificate_chain_file(WOLFSSL* ssl, const char* file) | |
|
||
|
||
|
||
#if !defined(NO_WOLFSSL_CLIENT) | ||
/* Return the amount of random bytes copied over or error case. | ||
* ssl : ssl struct after handshake | ||
* out : buffer to hold random bytes | ||
* outSz : either 0 (return max buffer sz) or size of out buffer | ||
* | ||
* NOTE: wolfSSL_KeepArrays(ssl) must be called to retain handshake information. | ||
*/ | ||
int wolfSSL_get_client_random(WOLFSSL* ssl, unsigned char* out, int outSz) | ||
{ | ||
int size; | ||
|
||
/* return max size of buffer */ | ||
if (outSz == 0) { | ||
return RAN_LEN; | ||
} | ||
|
||
if (ssl == NULL || out == NULL || outSz < 0) { | ||
return BAD_FUNC_ARG; | ||
} | ||
|
||
if (ssl->options.saveArrays == 0 || ssl->arrays == NULL) { | ||
WOLFSSL_MSG("Arrays struct not saved after handshake"); | ||
} | ||
|
||
if (outSz > RAN_LEN) { | ||
size = RAN_LEN; | ||
} | ||
else { | ||
size = outSz; | ||
} | ||
|
||
XMEMCPY(out, ssl->arrays->clientRandom, size); | ||
return size; | ||
} | ||
#endif /* !defined(NO_WOLFSSL_CLIENT) */ | ||
|
||
#ifdef HAVE_ECC | ||
|
||
/* Set Temp CTX EC-DHE size in octets, should be 20 - 66 for 160 - 521 bit */ | ||
|
@@ -13272,6 +13309,125 @@ long wolfSSL_CTX_sess_number(WOLFSSL_CTX* ctx) | |
} | ||
|
||
#ifndef NO_DES3 | ||
void wolfSSL_DES_set_key(WOLFSSL_const_DES_cblock* myDes, | ||
WOLFSSL_DES_key_schedule* key) | ||
{ | ||
#ifdef WOLFSSL_CHECK_DESKEY | ||
wolfSSL_DES_set_key_checked(myDes, key); | ||
#else | ||
wolfSSL_DES_set_key_unchecked(myDes, key); | ||
#endif | ||
} | ||
|
||
|
||
|
||
/* return true in fail case (1) */ | ||
static int DES_check(word32 mask, word32 mask2, unsigned char* key) | ||
{ | ||
if ((*(word32*)(key + 0) ^ mask) == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we really assume key is 32bit aligned? On some platforms if this isn't the case this will fault. |
||
if ((*(word32*)(key + 4) ^ mask2) == 0) { | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} | ||
|
||
|
||
/* check that the key is odd parity and is not a weak key */ | ||
void wolfSSL_DES_set_key_checked(WOLFSSL_const_DES_cblock* myDes, | ||
WOLFSSL_DES_key_schedule* key) | ||
{ | ||
if (myDes == NULL || key == NULL) { | ||
WOLFSSL_MSG("Bad argument passed to wolfSSL_DES_set_key_checked"); | ||
} | ||
else { | ||
word32 i, mask, mask2; | ||
|
||
/* check odd parity */ | ||
for (i = 0; i < sizeof(WOLFSSL_DES_key_schedule); i++) { | ||
unsigned char c = *((unsigned char*)key + i); | ||
if (((c & 0x01) ^ | ||
((c >> 1) & 0x01) ^ | ||
((c >> 2) & 0x01) ^ | ||
((c >> 3) & 0x01) ^ | ||
((c >> 4) & 0x01) ^ | ||
((c >> 5) & 0x01) ^ | ||
((c >> 6) & 0x01) ^ | ||
((c >> 7) & 0x01)) != 1) { | ||
WOLFSSL_MSG("Odd parity test fail"); | ||
return; | ||
} | ||
} | ||
|
||
/* check is not weak. Weak key list from Nist | ||
"Recommendation for the Triple | ||
Data Encryption Algorithm | ||
(TDEA) Block Cipher" */ | ||
mask = 0x01010101; mask2 = 0x01010101; | ||
if (DES_check(mask, mask2, *key)) { | ||
WOLFSSL_MSG("Weak key found"); | ||
return; | ||
} | ||
|
||
mask = 0xFEFEFEFE; mask2 = 0xFEFEFEFE; | ||
if (DES_check(mask, mask2, *key)) { | ||
WOLFSSL_MSG("Weak key found"); | ||
return; | ||
} | ||
|
||
mask = 0xE0E0E0E0; mask2 = 0xF1F1F1F1; | ||
if (DES_check(mask, mask2, *key)) { | ||
WOLFSSL_MSG("Weak key found"); | ||
return; | ||
} | ||
|
||
mask = 0x1F1F1F1F; mask2 = 0x0E0E0E0E; | ||
if (DES_check(mask, mask2, *key)) { | ||
WOLFSSL_MSG("Weak key found"); | ||
return; | ||
} | ||
|
||
/* semi-weak *key check (list from same Nist paper) */ | ||
mask = 0x011F011F; mask2 = 0x010E010E; | ||
if (DES_check(mask, mask2, *key) || | ||
DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) { | ||
WOLFSSL_MSG("Weak key found"); | ||
return; | ||
} | ||
|
||
mask = 0x01E001E0; mask2 = 0x01F101F1; | ||
if (DES_check(mask, mask2, *key) || | ||
DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) { | ||
WOLFSSL_MSG("Weak key found"); | ||
return; | ||
} | ||
|
||
mask = 0x01FE01FE; mask2 = 0x01FE01FE; | ||
if (DES_check(mask, mask2, *key) || | ||
DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) { | ||
WOLFSSL_MSG("Weak key found"); | ||
return; | ||
} | ||
|
||
mask = 0x1FE01FE0; mask2 = 0x0EF10EF1; | ||
if (DES_check(mask, mask2, *key) || | ||
DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) { | ||
WOLFSSL_MSG("Weak key found"); | ||
return; | ||
} | ||
|
||
mask = 0x1FFE1FFE; mask2 = 0x0EFE0EFE; | ||
if (DES_check(mask, mask2, *key) || | ||
DES_check(ByteReverseWord32(mask), ByteReverseWord32(mask2), *key)) { | ||
WOLFSSL_MSG("Weak key found"); | ||
return; | ||
} | ||
|
||
/* passed tests, now copy over key */ | ||
XMEMCPY(key, myDes, sizeof(WOLFSSL_const_DES_cblock)); | ||
} | ||
} | ||
|
||
|
||
void wolfSSL_DES_set_key_unchecked(WOLFSSL_const_DES_cblock* myDes, | ||
WOLFSSL_DES_key_schedule* key) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this an error? Why only a message?