Skip to content

Commit

Permalink
Merge pull request #48 from ewasm/bignum
Browse files Browse the repository at this point in the history
Add bignum support
  • Loading branch information
axic committed May 28, 2019
2 parents 6b372a8 + 9f7aef7 commit da8faef
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ wee_alloc = "0.4.4"
default = [ "std" ]
std = []
debug = []
experimental = []
4 changes: 4 additions & 0 deletions circle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ jobs:
cargo build --release --no-default-features
cargo build --release --features debug
cargo build --release --no-default-features --features debug
cargo build --release --features experimental
cargo build --release --no-default-features --features experimental
cargo build --release --features experimental,debug
cargo build --release --no-default-features --features experimental,debug
39 changes: 39 additions & 0 deletions src/bignum.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
//! The bignum system library.

use super::*;

pub mod native {
extern "C" {
pub fn bignum_mul256(a: *const u32, b: *const u32, ret: *const u32);
pub fn bignum_umulmod256(a: *const u32, b: *const u32, modulo: *const u32, ret: *const u32);
}
}

pub fn mul256(a: &Uint256, b: &Uint256) -> Uint256 {
let mut ret = Uint256::default();

unsafe {
native::bignum_mul256(
a.bytes.as_ptr() as *const u32,
b.bytes.as_ptr() as *const u32,
ret.bytes.as_mut_ptr() as *const u32,
)
}

ret
}

pub fn umulmod256(a: &Uint256, b: &Uint256, modulo: &Uint256) -> Uint256 {
let mut ret = Uint256::default();

unsafe {
native::bignum_umulmod256(
a.bytes.as_ptr() as *const u32,
b.bytes.as_ptr() as *const u32,
modulo.bytes.as_ptr() as *const u32,
ret.bytes.as_mut_ptr() as *const u32,
)
}

ret
}
3 changes: 3 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ mod utils;
#[cfg(feature = "debug")]
pub mod debug;

#[cfg(feature = "experimental")]
pub mod bignum;

#[cfg(not(feature = "std"))]
pub mod convert;

Expand Down

0 comments on commit da8faef

Please sign in to comment.