Skip to content

Commit cfa5857

Browse files
committed
Fixed warnings
Signed-off-by: Michael Lodder <[email protected]>
1 parent 1c279ea commit cfa5857

File tree

9 files changed

+161
-163
lines changed

9 files changed

+161
-163
lines changed

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "amcl_wrapper"
3-
version = "0.3.5"
4-
authors = ["lovesh harchandani <[email protected]>"]
3+
version = "0.4.0"
4+
authors = ["lovesh harchandani <[email protected]>", "Michael Lodder <[email protected]>"]
55
description = "Wapper over Milagro Cryptographic Library (version 3)"
66
repository = "https://github.com/lovesh/amcl_rust_wrapper"
77

src/constants.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,39 @@ use super::ECCurve::rom;
55

66
pub const MODBYTES: usize = curve_MODBYTES;
77
pub const NLEN: usize = curve_NLEN;
8-
pub const BigNumBits: usize = BASEBITS;
8+
pub const BIG_NUM_BITS: usize = BASEBITS;
99

1010
// Byte size of element in group G1, 1 extra byte for compression flag
11-
pub const FieldElement_SIZE: usize = MODBYTES;
11+
pub const FIELD_ELEMENT_SIZE: usize = MODBYTES;
1212

1313
// Byte size of element in group G1, 1 extra byte for compression flag
14-
pub const GroupG1_SIZE: usize = (2 * MODBYTES + 1) as usize;
14+
pub const GROUP_G1_SIZE: usize = (2 * MODBYTES + 1) as usize;
1515

1616
lazy_static! {
17-
pub static ref GeneratorG1: GroupG1 = GroupG1::generator();
18-
pub static ref CurveOrder: BigNum = BigNum::new_ints(&rom::CURVE_ORDER);
19-
pub static ref CurveOrderBitSize: usize = CurveOrder.nbits();
20-
pub static ref FieldElementZero: BigNum = BigNum::new();
21-
pub static ref BarrettRedc_k: usize = CurveOrder.nbits();
22-
pub static ref BarrettRedc_u: BigNum = {
23-
let k = CurveOrder.nbits();
17+
pub static ref GENERATOR_G1: GroupG1 = GroupG1::generator();
18+
pub static ref CURVE_ORDER: BigNum = BigNum::new_ints(&rom::CURVE_ORDER);
19+
pub static ref CURVE_ORDER_BIT_SIZE: usize = CURVE_ORDER.nbits();
20+
pub static ref FIELD_ELEMENT_ZERO: BigNum = BigNum::new();
21+
pub static ref BARRETT_REDC_K: usize = CURVE_ORDER.nbits();
22+
pub static ref BARRETT_REDC_U: BigNum = {
23+
let k = CURVE_ORDER.nbits();
2424
let mut u = DoubleBigNum::new();
2525
u.w[0] = 1;
2626
// `u.shl(2*k)` crashes, so perform shl(k) twice
2727
u.shl(k);
2828
u.shl(k);
2929

3030
// div returns floored value
31-
u.div(&CurveOrder)
31+
u.div(&CURVE_ORDER)
3232
};
3333

34-
pub static ref BarrettRedc_v: BigNum = {
35-
let k = CurveOrder.nbits();
34+
pub static ref BARRETT_REDC_V: BigNum = {
35+
let k = CURVE_ORDER.nbits();
3636
let mut v = BigNum::new_int(1isize);
3737
v.shl(k+1);
3838
v
3939
};
4040
}
4141

4242
#[cfg(any(feature = "bls381", feature = "bn254"))]
43-
pub use crate::types_g2::{GeneratorG2, GroupG2_SIZE, GroupGT_SIZE};
43+
pub use crate::types_g2::{GENERATOR_G2, GROUP_G2_SIZE, GROUP_GT_SIZE};

src/extension_field_gt.rs

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@ use crate::types::GroupGT;
33
use super::ECCurve::fp12::{DENSE, FP12};
44
use super::ECCurve::fp4::FP4;
55
use super::ECCurve::pair::{another, ate, ate2, fexp, initmp, miller};
6-
use crate::constants::GroupGT_SIZE;
6+
use crate::constants::GROUP_GT_SIZE;
77
use crate::errors::{SerzDeserzError, ValueError};
88
use crate::field_elem::FieldElement;
99
use crate::group_elem::GroupElement;
1010
use crate::group_elem_g1::G1;
11-
use crate::group_elem_g2::{parse_hex_as_FP2, G2};
11+
use crate::group_elem_g2::{parse_hex_as_fp2, G2};
1212
use std::fmt;
1313
use std::hash::{Hash, Hasher};
1414
use std::ops::Mul;
1515

1616
use serde::de::{Deserialize, Deserializer, Error as DError, Visitor};
17-
use serde::ser::{Error as SError, Serialize, Serializer};
18-
use std::str::{FromStr, SplitWhitespace};
17+
use serde::ser::{Serialize, Serializer};
18+
use std::str::SplitWhitespace;
1919
use zeroize::Zeroize;
2020

2121
#[derive(Clone)]
@@ -132,16 +132,16 @@ impl GT {
132132
pub fn to_bytes(&self) -> Vec<u8> {
133133
let mut temp = FP12::new();
134134
temp.copy(&self.value);
135-
let mut bytes: [u8; GroupGT_SIZE] = [0; GroupGT_SIZE];
135+
let mut bytes: [u8; GROUP_GT_SIZE] = [0; GROUP_GT_SIZE];
136136
temp.tobytes(&mut bytes);
137137
bytes.to_vec()
138138
}
139139

140140
pub fn from_bytes(bytes: &[u8]) -> Result<Self, SerzDeserzError> {
141-
if bytes.len() != GroupGT_SIZE {
141+
if bytes.len() != GROUP_GT_SIZE {
142142
return Err(SerzDeserzError::GTBytesIncorrectSize(
143143
bytes.len(),
144-
GroupGT_SIZE,
144+
GROUP_GT_SIZE,
145145
));
146146
}
147147
Ok(Self {
@@ -152,10 +152,10 @@ impl GT {
152152
/// Writes bytes to given slice. Raises exception when given slice is not of
153153
/// desired length.
154154
pub fn write_to_slice(&self, target: &mut [u8]) -> Result<(), SerzDeserzError> {
155-
if target.len() != GroupGT_SIZE {
155+
if target.len() != GROUP_GT_SIZE {
156156
return Err(SerzDeserzError::GTBytesIncorrectSize(
157157
target.len(),
158-
GroupGT_SIZE,
158+
GROUP_GT_SIZE,
159159
));
160160
}
161161
let mut temp = FP12::new();
@@ -178,9 +178,9 @@ impl GT {
178178

179179
pub fn from_hex(s: String) -> Result<Self, SerzDeserzError> {
180180
let mut iter = s.split_whitespace();
181-
let a = parse_hex_as_FP4(&mut iter)?;
182-
let b = parse_hex_as_FP4(&mut iter)?;
183-
let c = parse_hex_as_FP4(&mut iter)?;
181+
let a = parse_hex_as_fp4(&mut iter)?;
182+
let b = parse_hex_as_fp4(&mut iter)?;
183+
let c = parse_hex_as_fp4(&mut iter)?;
184184
let mut value = FP12::new();
185185
value.seta(a);
186186
value.setb(b);
@@ -199,13 +199,13 @@ impl GT {
199199
}
200200

201201
/// Parse given hex string as FP4
202-
pub fn parse_hex_as_FP4(iter: &mut SplitWhitespace) -> Result<FP4, SerzDeserzError> {
202+
pub fn parse_hex_as_fp4(iter: &mut SplitWhitespace) -> Result<FP4, SerzDeserzError> {
203203
// Logic almost copied from AMCL but with error handling and constant time execution.
204204
// Constant time is important as hex is used during serialization and deserialization.
205205
// A seemingly effortless solution is to filter string for errors and pad with 0s before
206206
// passing to AMCL but that would be expensive as the string is scanned twice
207-
let a = parse_hex_as_FP2(iter)?;
208-
let b = parse_hex_as_FP2(iter)?;
207+
let a = parse_hex_as_fp2(iter)?;
208+
let b = parse_hex_as_fp2(iter)?;
209209
let mut fp4 = FP4::new();
210210
fp4.seta(a);
211211
fp4.setb(b);
@@ -218,7 +218,7 @@ impl PartialEq for GT {
218218
}
219219
}
220220

221-
impl_group_elem_conversions!(GT, GroupGT, GroupGT_SIZE);
221+
impl_group_elem_conversions!(GT, GroupGT, GROUP_GT_SIZE);
222222

223223
impl_group_elem_traits!(GT, GroupGT);
224224

0 commit comments

Comments
 (0)