Skip to content

Commit

Permalink
Add support for the bignum system library
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed May 28, 2019
1 parent 11c18c0 commit fbab0e3
Show file tree
Hide file tree
Showing 3 changed files with 43 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 = []
bignum = []
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: *mut u32);
pub fn bignum_umulmod256(a: *const u32, b: *const u32, modulo: *const u32, ret: *mut u32);
}
}

pub fn mul256(a: &Uint256, b: &Uint256) -> Uint256 {
let mut ret = Uin256::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 = Uin256::default();

unsafe {
native::bignum_mul256(
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 @@ -30,6 +30,9 @@ mod utils;
#[cfg(feature = "debug")]
pub mod debug;

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

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

Expand Down

0 comments on commit fbab0e3

Please sign in to comment.