Skip to content

Commit da8faef

Browse files
authored
Merge pull request #48 from ewasm/bignum
Add bignum support
2 parents 6b372a8 + 9f7aef7 commit da8faef

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-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+
experimental = []

circle.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,7 @@ jobs:
3030
cargo build --release --no-default-features
3131
cargo build --release --features debug
3232
cargo build --release --no-default-features --features debug
33+
cargo build --release --features experimental
34+
cargo build --release --no-default-features --features experimental
35+
cargo build --release --features experimental,debug
36+
cargo build --release --no-default-features --features experimental,debug

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+
pub mod native {
6+
extern "C" {
7+
pub fn bignum_mul256(a: *const u32, b: *const u32, ret: *const u32);
8+
pub fn bignum_umulmod256(a: *const u32, b: *const u32, modulo: *const u32, ret: *const u32);
9+
}
10+
}
11+
12+
pub fn mul256(a: &Uint256, b: &Uint256) -> Uint256 {
13+
let mut ret = Uint256::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 = Uint256::default();
28+
29+
unsafe {
30+
native::bignum_umulmod256(
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
@@ -31,6 +31,9 @@ mod utils;
3131
#[cfg(feature = "debug")]
3232
pub mod debug;
3333

34+
#[cfg(feature = "experimental")]
35+
pub mod bignum;
36+
3437
#[cfg(not(feature = "std"))]
3538
pub mod convert;
3639

0 commit comments

Comments
 (0)