-
Notifications
You must be signed in to change notification settings - Fork 704
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
bigint: Provide a fallback implementation for
bn_mul_mont
.
Provide an implementation of `bn_mul_mont` that works on all targets that don't have an assembly language implementation. Expand `prefixed_export!` to support prefixing functions defined in Rust. Function definitions don't end with a semicolon so move the semicolon insertion from `prefixed_item!` to its callers. Unify the codepaths in `bigint` so that `bn_mul_mont` is always used.
- Loading branch information
1 parent
0121a80
commit 81f4e8d
Showing
3 changed files
with
77 additions
and
72 deletions.
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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2015-2022 Brian Smith. | ||
// | ||
// Permission to use, copy, modify, and/or distribute this software for any | ||
// purpose with or without fee is hereby granted, provided that the above | ||
// copyright notice and this permission notice appear in all copies. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES | ||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY | ||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION | ||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN | ||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
|
||
#![cfg(not(any( | ||
target_arch = "aarch64", | ||
target_arch = "arm", | ||
target_arch = "x86", | ||
target_arch = "x86_64" | ||
)))] | ||
|
||
use super::{limbs_from_mont_in_place, limbs_mul, Limb, MODULUS_MAX_LIMBS, N0}; | ||
use crate::c; | ||
|
||
prefixed_export! { | ||
unsafe fn bn_mul_mont( | ||
r: *mut Limb, | ||
a: *const Limb, | ||
b: *const Limb, | ||
n: *const Limb, | ||
n0: &N0, | ||
num_limbs: c::size_t, | ||
) { | ||
// The mutable pointer `r` may alias `a` and/or `b`, so the lifetimes of | ||
// any slices for `a` or `b` must not overlap with the lifetime of any | ||
// mutable for `r`. | ||
|
||
// Nothing aliases `n` | ||
let n = unsafe { core::slice::from_raw_parts(n, num_limbs) }; | ||
|
||
let mut tmp = [0; 2 * MODULUS_MAX_LIMBS]; | ||
let tmp = &mut tmp[..(2 * num_limbs)]; | ||
{ | ||
let a: &[Limb] = unsafe { core::slice::from_raw_parts(a, num_limbs) }; | ||
let b: &[Limb] = unsafe { core::slice::from_raw_parts(b, num_limbs) }; | ||
limbs_mul(tmp, a, b); | ||
} | ||
let r: &mut [Limb] = unsafe { core::slice::from_raw_parts_mut(r, num_limbs) }; | ||
limbs_from_mont_in_place(r, tmp, n, n0); | ||
} | ||
} |
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