-
Notifications
You must be signed in to change notification settings - Fork 959
Add BN_bn2binpad API and enable OpenVPN master CI testing #10148
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -468,6 +468,56 @@ int wolfSSL_BN_bn2bin(const WOLFSSL_BIGNUM* bn, unsigned char* r) | |
| } | ||
|
|
||
|
|
||
| /* Encode a big number as a big-endian byte array, zero-padded to toLen bytes. | ||
| * | ||
| * Returns toLen on success, -1 on error (including when the number is too | ||
| * large to fit in toLen bytes). | ||
| * | ||
| * @param [in] bn Big number to encode. | ||
| * @param [out] r Buffer to place encoding into. Must be at least toLen | ||
| * bytes. | ||
| * @param [in] toLen Desired output length in bytes. | ||
| * @return toLen on success. | ||
| * @return -1 on error. | ||
| */ | ||
| int wolfSSL_BN_bn2binpad(const WOLFSSL_BIGNUM* bn, unsigned char* r, int toLen) | ||
| { | ||
| int numBytes; | ||
|
|
||
| WOLFSSL_ENTER("wolfSSL_BN_bn2binpad"); | ||
|
|
||
| /* Validate parameters. */ | ||
| if (BN_IS_NULL(bn) || (r == NULL) || (toLen < 0)) { | ||
| WOLFSSL_MSG("NULL bn, r, or invalid toLen error"); | ||
| return WOLFSSL_FATAL_ERROR; | ||
| } | ||
julek-wolfssl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /* Get the number of bytes needed to encode the big number. */ | ||
| numBytes = mp_unsigned_bin_size((mp_int*)bn->internal); | ||
| if (numBytes < 0) { | ||
| WOLFSSL_MSG("mp_unsigned_bin_size error"); | ||
| return WOLFSSL_FATAL_ERROR; | ||
| } | ||
| if (numBytes > toLen) { | ||
| WOLFSSL_MSG("BN too large for toLen"); | ||
| return WOLFSSL_FATAL_ERROR; | ||
| } | ||
|
Comment on lines
+501
to
+504
|
||
|
|
||
| /* Zero-pad leading bytes. */ | ||
| XMEMSET(r, 0, (size_t)(toLen - numBytes)); | ||
|
|
||
| /* Encode the big number into the remaining bytes. */ | ||
| if (numBytes > 0 && | ||
| mp_to_unsigned_bin((mp_int*)bn->internal, r + toLen - numBytes) != | ||
| MP_OKAY) { | ||
| WOLFSSL_MSG("mp_to_unsigned_bin error"); | ||
| return WOLFSSL_FATAL_ERROR; | ||
| } | ||
|
|
||
| return toLen; | ||
| } | ||
|
|
||
|
|
||
| /* Return a big number with value of the decoding of the big-endian byte array. | ||
| * | ||
| * Returns ret when not NULL. | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -323,6 +323,39 @@ int test_wolfSSL_BN_enc_dec(void) | |||||||||||||
| ExpectNotNull(BN_bin2bn(binNum, sizeof(binNum), b)); | ||||||||||||||
| ExpectIntEQ(BN_cmp(a, b), -1); | ||||||||||||||
|
|
||||||||||||||
| /* BN_bn2binpad tests */ | ||||||||||||||
| { | ||||||||||||||
| unsigned char padOut[5]; | ||||||||||||||
|
|
||||||||||||||
| /* Invalid parameters */ | ||||||||||||||
| ExpectIntEQ(BN_bn2binpad(NULL, padOut, sizeof(padOut)), -1); | ||||||||||||||
| ExpectIntEQ(BN_bn2binpad(&emptyBN, padOut, sizeof(padOut)), -1); | ||||||||||||||
| ExpectIntEQ(BN_bn2binpad(a, NULL, sizeof(padOut)), -1); | ||||||||||||||
|
Comment on lines
+331
to
+333
|
||||||||||||||
| ExpectIntEQ(BN_bn2binpad(NULL, padOut, sizeof(padOut)), -1); | |
| ExpectIntEQ(BN_bn2binpad(&emptyBN, padOut, sizeof(padOut)), -1); | |
| ExpectIntEQ(BN_bn2binpad(a, NULL, sizeof(padOut)), -1); | |
| ExpectIntEQ(BN_bn2binpad(NULL, padOut, (int)sizeof(padOut)), -1); | |
| ExpectIntEQ(BN_bn2binpad(&emptyBN, padOut, (int)sizeof(padOut)), -1); | |
| ExpectIntEQ(BN_bn2binpad(a, NULL, (int)sizeof(padOut)), -1); |
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.
The workflow comment says
ignore_words_listshould be sorted alphabetically (case sensitive). AddingtoLenat the end breaks that rule; please insert it in sorted order to keep the list maintainable and consistent with the documented expectation.