-
Notifications
You must be signed in to change notification settings - Fork 163
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cb3aa30
commit 48f3520
Showing
9 changed files
with
465 additions
and
4 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,88 @@ | ||
use crate::c_api::utils::*; | ||
use std::os::raw::c_int; | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct I1024 { | ||
words: [u64; 16], | ||
} | ||
|
||
impl From<crate::integer::bigint::I1024> for I1024 { | ||
fn from(value: crate::integer::bigint::I1024) -> Self { | ||
Self { words: value.0 } | ||
} | ||
} | ||
|
||
impl From<I1024> for crate::integer::bigint::I1024 { | ||
fn from(value: I1024) -> Self { | ||
Self(value.words) | ||
} | ||
} | ||
|
||
/// Creates a I1024 from little endian bytes | ||
/// | ||
/// len must be 128 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I1024_from_little_endian_bytes( | ||
input: *const u8, | ||
len: usize, | ||
result: *mut I1024, | ||
) -> c_int { | ||
catch_panic(|| { | ||
let mut inner = crate::integer::bigint::I1024::default(); | ||
|
||
let input = std::slice::from_raw_parts(input, len); | ||
inner.copy_from_le_byte_slice(input); | ||
|
||
*result = I1024::from(inner); | ||
}) | ||
} | ||
|
||
/// Creates a I1024 from big endian bytes | ||
/// | ||
/// len must be 128 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I1024_from_big_endian_bytes( | ||
input: *const u8, | ||
len: usize, | ||
result: *mut I1024, | ||
) -> c_int { | ||
catch_panic(|| { | ||
let mut inner = crate::integer::bigint::I1024::default(); | ||
|
||
let input = std::slice::from_raw_parts(input, len); | ||
inner.copy_from_be_byte_slice(input); | ||
|
||
*result = I1024::from(inner); | ||
}) | ||
} | ||
|
||
/// len must be 128 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I1024_little_endian_bytes( | ||
input: I1024, | ||
result: *mut u8, | ||
len: usize, | ||
) -> c_int { | ||
catch_panic(|| { | ||
check_ptr_is_non_null_and_aligned(result).unwrap(); | ||
|
||
let bytes = std::slice::from_raw_parts_mut(result, len); | ||
crate::integer::bigint::I1024::from(input).copy_to_le_byte_slice(bytes); | ||
}) | ||
} | ||
|
||
/// len must be 128 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I1024_big_endian_bytes( | ||
input: I1024, | ||
result: *mut u8, | ||
len: usize, | ||
) -> c_int { | ||
catch_panic(|| { | ||
check_ptr_is_non_null_and_aligned(result).unwrap(); | ||
|
||
let bytes = std::slice::from_raw_parts_mut(result, len); | ||
crate::integer::bigint::I1024::from(input).copy_to_be_byte_slice(bytes); | ||
}) | ||
} |
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,88 @@ | ||
use crate::c_api::utils::*; | ||
use std::os::raw::c_int; | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct I2048 { | ||
words: [u64; 32], | ||
} | ||
|
||
impl From<crate::integer::bigint::I2048> for I2048 { | ||
fn from(value: crate::integer::bigint::I2048) -> Self { | ||
Self { words: value.0 } | ||
} | ||
} | ||
|
||
impl From<I2048> for crate::integer::bigint::I2048 { | ||
fn from(value: I2048) -> Self { | ||
Self(value.words) | ||
} | ||
} | ||
|
||
/// Creates a I2048 from little endian bytes | ||
/// | ||
/// len must be 256 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I2048_from_little_endian_bytes( | ||
input: *const u8, | ||
len: usize, | ||
result: *mut I2048, | ||
) -> c_int { | ||
catch_panic(|| { | ||
let mut inner = crate::integer::bigint::I2048::default(); | ||
|
||
let input = std::slice::from_raw_parts(input, len); | ||
inner.copy_from_le_byte_slice(input); | ||
|
||
*result = I2048::from(inner); | ||
}) | ||
} | ||
|
||
/// Creates a I2048 from big endian bytes | ||
/// | ||
/// len must be 256 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I2048_from_big_endian_bytes( | ||
input: *const u8, | ||
len: usize, | ||
result: *mut I2048, | ||
) -> c_int { | ||
catch_panic(|| { | ||
let mut inner = crate::integer::bigint::I2048::default(); | ||
|
||
let input = std::slice::from_raw_parts(input, len); | ||
inner.copy_from_be_byte_slice(input); | ||
|
||
*result = I2048::from(inner); | ||
}) | ||
} | ||
|
||
/// len must be 256 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I2048_little_endian_bytes( | ||
input: I2048, | ||
result: *mut u8, | ||
len: usize, | ||
) -> c_int { | ||
catch_panic(|| { | ||
check_ptr_is_non_null_and_aligned(result).unwrap(); | ||
|
||
let bytes = std::slice::from_raw_parts_mut(result, len); | ||
crate::integer::bigint::I2048::from(input).copy_to_le_byte_slice(bytes); | ||
}) | ||
} | ||
|
||
/// len must be 256 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I2048_big_endian_bytes( | ||
input: I2048, | ||
result: *mut u8, | ||
len: usize, | ||
) -> c_int { | ||
catch_panic(|| { | ||
check_ptr_is_non_null_and_aligned(result).unwrap(); | ||
|
||
let bytes = std::slice::from_raw_parts_mut(result, len); | ||
crate::integer::bigint::I2048::from(input).copy_to_be_byte_slice(bytes); | ||
}) | ||
} |
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,84 @@ | ||
use crate::c_api::utils::*; | ||
use std::os::raw::c_int; | ||
|
||
#[derive(Copy, Clone)] | ||
#[repr(C)] | ||
pub struct I512 { | ||
words: [u64; 8], | ||
} | ||
|
||
impl From<crate::integer::bigint::I512> for I512 { | ||
fn from(value: crate::integer::bigint::I512) -> Self { | ||
Self { words: value.0 } | ||
} | ||
} | ||
|
||
impl From<I512> for crate::integer::bigint::I512 { | ||
fn from(value: I512) -> Self { | ||
Self(value.words) | ||
} | ||
} | ||
|
||
/// Creates a I512 from little endian bytes | ||
/// | ||
/// len must be 64 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I512_from_little_endian_bytes( | ||
input: *const u8, | ||
len: usize, | ||
result: *mut I512, | ||
) -> c_int { | ||
catch_panic(|| { | ||
let mut inner = crate::integer::bigint::I512::default(); | ||
|
||
let input = std::slice::from_raw_parts(input, len); | ||
inner.copy_from_le_byte_slice(input); | ||
|
||
*result = I512::from(inner); | ||
}) | ||
} | ||
|
||
/// Creates a I512 from big endian bytes | ||
/// | ||
/// len must be 64 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I512_from_big_endian_bytes( | ||
input: *const u8, | ||
len: usize, | ||
result: *mut I512, | ||
) -> c_int { | ||
catch_panic(|| { | ||
let mut inner = crate::integer::bigint::I512::default(); | ||
|
||
let input = std::slice::from_raw_parts(input, len); | ||
inner.copy_from_be_byte_slice(input); | ||
|
||
*result = I512::from(inner); | ||
}) | ||
} | ||
|
||
/// len must be 64 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I512_little_endian_bytes( | ||
input: I512, | ||
result: *mut u8, | ||
len: usize, | ||
) -> c_int { | ||
catch_panic(|| { | ||
check_ptr_is_non_null_and_aligned(result).unwrap(); | ||
|
||
let bytes = std::slice::from_raw_parts_mut(result, len); | ||
crate::integer::bigint::I512::from(input).copy_to_le_byte_slice(bytes); | ||
}) | ||
} | ||
|
||
/// len must be 64 | ||
#[no_mangle] | ||
pub unsafe extern "C" fn I512_big_endian_bytes(input: I512, result: *mut u8, len: usize) -> c_int { | ||
catch_panic(|| { | ||
check_ptr_is_non_null_and_aligned(result).unwrap(); | ||
|
||
let bytes = std::slice::from_raw_parts_mut(result, len); | ||
crate::integer::bigint::I512::from(input).copy_to_be_byte_slice(bytes); | ||
}) | ||
} |
Oops, something went wrong.