Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatible with Codec & Wasm32 #3

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3,152 changes: 2,786 additions & 366 deletions Cargo.lock

Large diffs are not rendered by default.

49 changes: 42 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ authors = ["Nikita Khateev <[email protected]>", "Kirk Baird <b
description = "The Apache Milagro Cryptographic Library (version 3)"
license = "Apache-2.0"
repository = "https://github.com/apache/incubator-milagro-crypto-rust"
edition = "2018"
edition = "2021"

[dependencies]
codec = { version = "3.6.1", package = "parity-scale-codec", default-features = false, features = ["derive", "max-encoded-len"] }
scale-info = { version = "2.9.0", default-features = false, features = ["derive"] }
sp-core = { version = "25.0.0", default-features = false }

[dev-dependencies]
hex = "0.3"
Expand Down Expand Up @@ -48,13 +53,43 @@ name = "rsa4096"
harness = false

[features]
default = ["bn254", "std"]
std = []
default = ["std"]
std = [
"bls381",
"codec/std",
"scale-info/std",
"sp-core/std",
]
all = [
"anssi","bls24","bls48","bls381","bls383","bls461","bn254","bn254cx",
"brainpool","c25519","c41417","ed25519","fp256bn","fp512bn","goldilocks","hifive",
"nist256","nist384","nist521","nums256e","nums256w","nums384e","nums384w","nums512e",
"nums512w","rsa2048","rsa3072","rsa4096","secp256k1",
"anssi",
"bls24",
"bls48",
"bls381",
"bls383",
"bls461",
"bn254",
"bn254cx",
"brainpool",
"c25519",
"c41417",
"ed25519",
"fp256bn",
"fp512bn",
"goldilocks",
"hifive",
"nist256",
"nist384",
"nist521",
"nums256e",
"nums256w",
"nums384e",
"nums384w",
"nums512e",
"nums512w",
"rsa2048",
"rsa3072",
"rsa4096",
"secp256k1",
]
anssi = []
bls24 = []
Expand Down
4 changes: 3 additions & 1 deletion src/big.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ use crate::rand::RAND;

pub use super::rom::BASEBITS;
pub use super::rom::MODBYTES;
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;

pub const NLEN: usize = 1 + (8 * MODBYTES - 1) / BASEBITS;
pub const DNLEN: usize = 2 * NLEN;
Expand All @@ -33,7 +35,7 @@ pub const NEXCESS: isize = 1 << (arch::CHUNK - BASEBITS - 1);
pub const BIGBITS: usize = MODBYTES * 8;
use crate::std::{string::String, fmt, cmp::Ordering, format};

#[derive(Clone)]
#[derive(Default, Copy, Clone, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub struct Big {
pub w: [Chunk; NLEN],
}
Expand Down
9 changes: 0 additions & 9 deletions src/bls381/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,7 @@ pub mod utils;
mod core;
mod iso;

#[cfg(target_pointer_width = "64")]
mod iso_constants_x64;
#[cfg(target_pointer_width = "64")]
pub(crate) use iso_constants_x64::{
ISO11_XDEN, ISO11_XNUM, ISO11_YDEN, ISO11_YNUM, ISO3_XDEN, ISO3_XNUM, ISO3_YDEN, ISO3_YNUM,
};

#[cfg(target_pointer_width = "32")]
mod iso_constants_x32;
#[cfg(target_pointer_width = "32")]
pub(crate) use iso_constants_x32::{
ISO11_XDEN, ISO11_XNUM, ISO11_YDEN, ISO11_YNUM, ISO3_XDEN, ISO3_XNUM, ISO3_YDEN, ISO3_YNUM,
};
5 changes: 4 additions & 1 deletion src/ecp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ pub use super::rom::{AESKEY, CURVETYPE, CURVE_PAIRING_TYPE, HASH_TYPE, SEXTIC_TW
pub use crate::types::CurveType;
use crate::std::{string::String, fmt, str::SplitWhitespace, format};

#[derive(Clone)]
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;

#[derive(Default, Copy, Clone, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub struct ECP {
x: FP,
y: FP,
Expand Down
6 changes: 5 additions & 1 deletion src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#[derive(Debug, PartialEq, Clone)]
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;
use sp_core::RuntimeDebug;

#[derive(PartialEq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, RuntimeDebug)]
Copy link

@vgeddes vgeddes Jan 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, lets rather not add a dependency on RuntimeDebug, by replacing it with:

Suggested change
#[derive(PartialEq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen, RuntimeDebug)]
#[derive(PartialEq, Clone, Encode, Decode, TypeInfo, MaxEncodedLen)]
#[cfg_attr(feature = "std", derive(Debug))]

pub enum AmclError {
AggregateEmptyPoints,
HashToFieldError,
Expand Down
5 changes: 4 additions & 1 deletion src/fp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ use crate::arch::{self, Chunk};
use crate::types::ModType;
use crate::std::{string::String, string::ToString, str::FromStr, str::SplitWhitespace, format, fmt};

#[derive(Clone)]
use codec::{Decode, Encode, MaxEncodedLen};
use scale_info::TypeInfo;

#[derive(Default, Copy, Clone, Encode, Decode, TypeInfo, MaxEncodedLen)]
pub struct FP {
pub x: Big,
pub xes: i32,
Expand Down
9 changes: 0 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,8 @@ extern crate serde_derive;
extern crate alloc;

pub mod aes;
#[cfg(target_pointer_width = "32")]
#[path = "arch/arch32.rs"]
pub mod arch;
#[cfg(target_pointer_width = "64")]
#[path = "arch/arch64.rs"]
pub mod arch;
pub mod errors;
pub mod gcm;
pub mod hash256;
Expand Down Expand Up @@ -100,13 +96,8 @@ pub mod bls383 {
#[cfg(feature = "bls381")]
#[path = "./"]
pub mod bls381 {
#[cfg(target_pointer_width = "32")]
#[path = "roms/rom_bls381_32.rs"]
pub mod rom;
#[cfg(target_pointer_width = "64")]
#[path = "roms/rom_bls381_64.rs"]
pub mod rom;

pub mod big;
pub mod bls381;
pub mod dbig;
Expand Down