Skip to content

Commit 9ce4040

Browse files
committed
Add support for the bignum system library
1 parent 2fff902 commit 9ce4040

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ wee_alloc = "0.4.4"
1414
default = [ "std" ]
1515
std = []
1616
debug = []
17+
bignum = []

src/bignum.rs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//! The bignum system library.
2+
3+
use super::*;
4+
5+
mod native {
6+
extern "C" {
7+
pub fn bignum_mul256(a: *const u32, b: *const u32, ret: *mut u32);
8+
pub fn bignum_umulmod256(a: *const u32, b: *const u32, modulo: *const u32, ret: *mut u32);
9+
}
10+
}
11+
12+
pub fn mul256(a: &Uint256, b: &Uint256) -> Uint256 {
13+
let mut ret = Uin256::default();
14+
15+
unsafe {
16+
native::bignum_mul256(
17+
a.bytes.as_ptr() as *const u32,
18+
b.bytes.as_ptr() as *const u32,
19+
ret.bytes.as_mut_ptr() as *const u32,
20+
)
21+
}
22+
23+
ret
24+
}
25+
26+
pub fn umulmod256(a: &Uint256, b: &Uint256, modulo: &Uint256) -> Uint256 {
27+
let mut ret = Uin256::default();
28+
29+
unsafe {
30+
native::bignum_mul256(
31+
a.bytes.as_ptr() as *const u32,
32+
b.bytes.as_ptr() as *const u32,
33+
modulo.bytes.as_ptr() as *const u32,
34+
ret.bytes.as_mut_ptr() as *const u32,
35+
)
36+
}
37+
38+
ret
39+
}

src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ pub mod types;
2929
#[cfg(feature = "debug")]
3030
pub mod debug;
3131

32+
#[cfg(feature = "bignum")]
33+
pub mod bignum;
34+
3235
#[cfg(not(feature = "std"))]
3336
pub mod convert;
3437

0 commit comments

Comments
 (0)