-
Notifications
You must be signed in to change notification settings - Fork 141
Move dynamic dispatching to C for x86_64-mont5.pl #2592
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
Open
m271828
wants to merge
39
commits into
aws:main
Choose a base branch
from
m271828:move_x86_64-mont5_dispatching
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
39 commits
Select commit
Hold shift + click to select a range
bd3f1a2
Remove dynamic dispatching, update names to match BoringSSL
m271828 28c2368
Move dispatching into C
m271828 d6720b2
Fix inconsistent name
m271828 63c621b
Accidentally removed guard
m271828 2037e02
Merge branch 'main' into move_x86_64-mont5_dispatching
m271828 e42eb0a
Add generated-src files
m271828 8a6ce05
Merge branch 'main' into move_x86_64-mont5_dispatching
m271828 d305b22
Generate for other platforms
m271828 8e44aa5
Fix name for windows
m271828 4865271
Fix function name
m271828 4085be6
AVX fix
m271828 12073c3
Test moving macro guard
m271828 b3844ea
Pull guards in
m271828 45b2eb7
Add default implementation
m271828 e5418f5
Fix compiler warning
m271828 39cb816
Fix compiler warning
m271828 cb40a8a
Fix compiler warning
m271828 79cc722
Clean up header
m271828 c4ecf91
Invert guard logic
m271828 d0dd56f
Merge branch 'main' into move_x86_64-mont5_dispatching
m271828 92af303
Remove guards
m271828 3dafe95
Change to perror/abort pattern
m271828 9b8c355
Move default implementations to more logical location
m271828 d96d329
Fix guards and comments
m271828 4542f58
Merge branch 'main' into move_x86_64-mont5_dispatching
m271828 c369e88
Update sqr8x_mont to new style
m271828 980bcff
Fix typo
m271828 10a46a0
Add implicit dispatch tests
m271828 6062827
Add dispatch function
m271828 96a03ef
Merge branch 'main' into move_x86_64-mont5_dispatching
m271828 0cf8b2d
Change to single dispatch log function
m271828 03d8c2d
Add ctx
m271828 3e143d4
Merge branch 'main' into move_x86_64-mont5_dispatching
m271828 d993aeb
Header guard
m271828 b18b250
Add capture
m271828 c431326
Remove guard
m271828 5e4cf23
Change scope of function defininition
m271828 13e40c1
Add header file for bn functions
m271828 c7e253f
Comment out dynamic distpatch tests using static decls
m271828 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -107,6 +107,7 @@ | |
* Hudson ([email protected]). */ | ||
|
||
#include <openssl/bn.h> | ||
#include <openssl/cpu.h> | ||
|
||
#include <assert.h> | ||
#include <limits.h> | ||
|
@@ -163,6 +164,56 @@ static void exponentiation_s2n_bignum_copy_from_prebuf(BN_ULONG *dest, int width | |
#endif | ||
} | ||
|
||
#if defined(OPENSSL_BN_ASM_MONT5) | ||
|
||
// bn_mul_mont_gather5 multiples loads index |power| of |table|, multiplies it | ||
// by |ap| modulo |np|, and stores the result in |rp|. The values are |num| | ||
// words long and represented in Montgomery form. |n0| is a pointer to the | ||
// corresponding field in |BN_MONT_CTX|. |table| must be aligned to at least | ||
// 16 bytes. |power| must be less than 32 and is treated as secret. | ||
// | ||
// WARNING: This function implements Almost Montgomery Multiplication from | ||
// https://eprint.iacr.org/2011/239. The inputs do not need to be fully reduced. | ||
// However, even if they are fully reduced, the output may not be. | ||
static void bn_mul_mont_gather5( | ||
BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *table, const BN_ULONG *np, | ||
const BN_ULONG *n0, int num, int power) { | ||
if (bn_mulx4x_mont_gather5_capable(num)) { | ||
log_dispatch(15); | ||
bn_mulx4x_mont_gather5(rp, ap, table, np, n0, num, power); | ||
} else if (bn_mul4x_mont_gather5_capable(num)) { | ||
log_dispatch(16); | ||
bn_mul4x_mont_gather5(rp, ap, table, np, n0, num, power); | ||
} else { | ||
log_dispatch(17); | ||
bn_mul_mont_gather5_nohw(rp, ap, table, np, n0, num, power); | ||
} | ||
} | ||
|
||
// bn_power5 squares |ap| five times and multiplies it by the value stored at | ||
// index |power| of |table|, modulo |np|. It stores the result in |rp|. The | ||
// values are |num| words long and represented in Montgomery form. |n0| is a | ||
// pointer to the corresponding field in |BN_MONT_CTX|. |num| must be divisible | ||
// by 8. |power| must be less than 32 and is treated as secret. | ||
// | ||
// WARNING: This function implements Almost Montgomery Multiplication from | ||
// https://eprint.iacr.org/2011/239. The inputs do not need to be fully reduced. | ||
// However, even if they are fully reduced, the output may not be. | ||
static void bn_power5(BN_ULONG *rp, const BN_ULONG *ap, const BN_ULONG *table, | ||
const BN_ULONG *np, const BN_ULONG *n0, int num, | ||
int power) | ||
{ | ||
assert(bn_power5_capable(num)); | ||
if (bn_powerx5_capable(num)) { | ||
log_dispatch(18); | ||
bn_powerx5(rp, ap, table, np, n0, num, power); | ||
} else { | ||
log_dispatch(19); | ||
bn_power5_nohw(rp, ap, table, np, n0, num, power); | ||
} | ||
} | ||
|
||
#endif // defined(OPENSSL_BN_ASM_MONT5) | ||
|
||
int BN_exp(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx) { | ||
int i, bits, ret = 0; | ||
|
@@ -1122,7 +1173,7 @@ int BN_mod_exp_mont_consttime(BIGNUM *rr, const BIGNUM *a, const BIGNUM *p, | |
|
||
// Scan the exponent one window at a time starting from the most | ||
// significant bits. | ||
if (top & 7) { | ||
if (!bn_power5_capable(top)) { | ||
while (bits >= 0) { | ||
for (wvalue = 0, i = 0; i < 5; i++, bits--) { | ||
wvalue = (wvalue << 1) + BN_is_bit_set(p, bits); | ||
|
This file contains hidden or 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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.