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

fix: Use Cargo Clippy to avoid the gen reserved keyword #181

Open
wants to merge 1 commit into
base: dev
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
4 changes: 2 additions & 2 deletions crates/clmul/benches/clmul.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use rand_chacha::ChaCha12Rng;

fn criterion_benchmark(c: &mut Criterion) {
let mut rng = ChaCha12Rng::seed_from_u64(0);
let a: [u8; 16] = rng.gen();
let b: [u8; 16] = rng.gen();
let a: [u8; 16] = rng.r#gen();
let b: [u8; 16] = rng.r#gen();
let a = Clmul::new(&a);
let b = Clmul::new(&b);

Expand Down
4 changes: 2 additions & 2 deletions crates/clmul/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ mod tests {
use soft64::Clmul as s64;

let mut rng = ChaCha12Rng::from_seed([0; 32]);
let a: [u8; 16] = rng.gen();
let b: [u8; 16] = rng.gen();
let a: [u8; 16] = rng.r#gen();
let b: [u8; 16] = rng.r#gen();

let (r64_0, r64_1) = s64::new(&a).clmul(s64::new(&b));
let (r32_0, r32_1) = s32::new(&a).clmul(s32::new(&b));
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-transpose/benches/transpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ where
Standard: Distribution<T>,
{
let mut rng = thread_rng();
(0..elements).map(|_| rng.gen::<T>()).collect()
(0..elements).map(|_| rng.r#gen::<T>()).collect()
}

#[inline]
Expand Down
2 changes: 1 addition & 1 deletion crates/matrix-transpose/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ mod tests {
Standard: Distribution<T>,
{
let mut rng = thread_rng();
(0..elements).map(|_| rng.gen::<T>()).collect()
(0..elements).map(|_| rng.r#gen::<T>()).collect()
}

fn transpose_naive(data: &[u8], row_width: usize) -> Vec<u8> {
Expand Down
12 changes: 6 additions & 6 deletions crates/mpz-circuits/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,12 @@ impl Value {
/// Creates a new value using the provided rng.
pub fn random<R: Rng>(rng: &mut R, ty: &ValueType) -> Self {
match ty {
ValueType::Bit => Value::Bit(rng.gen()),
ValueType::U8 => Value::U8(rng.gen()),
ValueType::U16 => Value::U16(rng.gen()),
ValueType::U32 => Value::U32(rng.gen()),
ValueType::U64 => Value::U64(rng.gen()),
ValueType::U128 => Value::U128(rng.gen()),
ValueType::Bit => Value::Bit(rng.r#gen()),
ValueType::U8 => Value::U8(rng.r#gen()),
ValueType::U16 => Value::U16(rng.r#gen()),
ValueType::U32 => Value::U32(rng.r#gen()),
ValueType::U64 => Value::U64(rng.r#gen()),
ValueType::U128 => Value::U128(rng.r#gen()),
ValueType::Array(ty, len) => Value::Array(
(0..*len)
.map(|_| Value::random(rng, ty))
Expand Down
2 changes: 1 addition & 1 deletion crates/mpz-core/benches/ggm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut k1 = vec![Block::ZERO; depth];
let seed = rand::random::<Block>();
bench.iter(|| {
black_box(ggm.gen(
black_box(ggm.r#gen(
black_box(seed),
black_box(&mut tree),
black_box(&mut k0),
Expand Down
14 changes: 7 additions & 7 deletions crates/mpz-core/src/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,19 @@ impl Block {
/// Generate a random block using the provided RNG
#[inline]
pub fn random<R: Rng + CryptoRng + ?Sized>(rng: &mut R) -> Self {
Self::new(rng.gen())
Self::new(rng.r#gen())
}

/// Generate a random array of blocks using the provided RNG
#[inline]
pub fn random_array<const N: usize, R: Rng + CryptoRng>(rng: &mut R) -> [Self; N] {
std::array::from_fn(|_| rng.gen::<[u8; 16]>().into())
std::array::from_fn(|_| rng.r#gen::<[u8; 16]>().into())
}

/// Generate a random vector of blocks using the provided RNG
#[inline]
pub fn random_vec<R: Rng + CryptoRng + ?Sized>(rng: &mut R, n: usize) -> Vec<Self> {
(0..n).map(|_| rng.gen::<[u8; 16]>().into()).collect()
(0..n).map(|_| rng.r#gen::<[u8; 16]>().into()).collect()
}

/// Carry-less multiplication of two blocks, without the reduction step.
Expand Down Expand Up @@ -286,7 +286,7 @@ impl BitAndAssign for Block {

impl Distribution<Block> for Standard {
fn sample<R: Rng + ?Sized>(&self, rng: &mut R) -> Block {
Block::new(rng.gen())
Block::new(rng.r#gen())
}
}

Expand Down Expand Up @@ -367,9 +367,9 @@ mod tests {
let mut c = (Block::ZERO, Block::ZERO);
let mut d = Block::ZERO;
for i in 0..SIZE {
let r: [u8; 16] = rng.gen();
let r: [u8; 16] = rng.r#gen();
a.push(Block::from(r));
let r: [u8; 16] = rng.gen();
let r: [u8; 16] = rng.r#gen();
b.push(Block::from(r));

let z = a[i].clmul(b[i]);
Expand All @@ -389,7 +389,7 @@ mod tests {
use rand::{Rng, SeedableRng};
use rand_chacha::ChaCha12Rng;
let mut rng = ChaCha12Rng::from_seed([0; 32]);
let mut x: [u8; 16] = rng.gen();
let mut x: [u8; 16] = rng.r#gen();
let bx = Block::sigma(Block::from(x));
let (xl, xr) = x.split_at_mut(8);

Expand Down
2 changes: 1 addition & 1 deletion crates/mpz-core/src/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct Nonce([u8; 32]);
impl Nonce {
/// Creates a random 32 byte nonce
fn random() -> Self {
Self(thread_rng().gen())
Self(thread_rng().r#gen())
}
}

Expand Down
4 changes: 2 additions & 2 deletions crates/mpz-core/src/ggm_tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl GgmTree {
/// * `k0` - XORs of all the left-node values in each level, with size `depth`.
/// * `k1`- XORs of all the right-node values in each level, with size `depth`.
// This implementation is adapted from EMP Toolkit.
pub fn gen(&self, seed: Block, tree: &mut [Block], k0: &mut [Block], k1: &mut [Block]) {
pub fn r#gen(&self, seed: Block, tree: &mut [Block], k0: &mut [Block], k1: &mut [Block]) {
assert_eq!(tree.len(), 1 << (self.depth));
assert_eq!(k0.len(), self.depth);
assert_eq!(k1.len(), self.depth);
Expand Down Expand Up @@ -150,7 +150,7 @@ fn ggm_test() {

let ggm = GgmTree::new(depth);

ggm.gen(Block::ZERO, &mut tree, &mut k0, &mut k1);
ggm.r#gen(Block::ZERO, &mut tree, &mut k0, &mut k1);

for i in 0..depth {
if alpha[i] {
Expand Down
6 changes: 3 additions & 3 deletions crates/mpz-core/src/prg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ impl Prg {
/// Generate a random bool value.
#[inline(always)]
pub fn random_bool(&mut self) -> bool {
self.gen()
self.r#gen()
}

/// Fill a bool slice with random bool values.
Expand All @@ -154,7 +154,7 @@ impl Prg {
/// Generate a random byte value.
#[inline(always)]
pub fn random_byte(&mut self) -> u8 {
self.gen()
self.r#gen()
}

/// Fill a byte slice with random values.
Expand All @@ -166,7 +166,7 @@ impl Prg {
/// Generate a random block.
#[inline(always)]
pub fn random_block(&mut self) -> Block {
self.gen()
self.r#gen()
}

/// Fill a block slice with random block values.
Expand Down
2 changes: 1 addition & 1 deletion crates/mpz-fields/benches/inverse_gf2_128.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rand::{Rng, SeedableRng};

fn bench_gf2_128_inverse(c: &mut Criterion) {
let mut rng = Prg::from_seed(Block::ZERO);
let a: Gf2_128 = rng.gen();
let a: Gf2_128 = rng.r#gen();

c.bench_function("inverse", move |bench| {
bench.iter(|| {
Expand Down
2 changes: 1 addition & 1 deletion crates/mpz-fields/src/p256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ mod tests {
let mut rng = Prg::from_seed(Block::ZERO);

for _ in 0..32 {
let a = P256(rng.gen());
let a = P256(rng.r#gen());
let bytes: [u8; 32] = a.into();
let b = P256::try_from(bytes).unwrap();

Expand Down
16 changes: 8 additions & 8 deletions crates/mpz-garble-core/benches/garble.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ fn criterion_benchmark(c: &mut Criterion) {
];

gb_group.bench_function("aes128", |b| {
let mut gen = Generator::default();
let mut r#gen = Generator::default();
b.iter(|| {
let mut gen_iter = gen
let mut gen_iter = r#gen
.generate(&AES128, encoder.delta(), full_inputs.clone())
.unwrap();

Expand All @@ -31,9 +31,9 @@ fn criterion_benchmark(c: &mut Criterion) {
});

gb_group.bench_function("aes128_batched", |b| {
let mut gen = Generator::default();
let mut r#gen = Generator::default();
b.iter(|| {
let mut gen_iter = gen
let mut gen_iter = r#gen
.generate_batched(&AES128, encoder.delta(), full_inputs.clone())
.unwrap();

Expand All @@ -44,9 +44,9 @@ fn criterion_benchmark(c: &mut Criterion) {
});

gb_group.bench_function("aes128_with_hash", |b| {
let mut gen = Generator::default();
let mut r#gen = Generator::default();
b.iter(|| {
let mut gen_iter = gen
let mut gen_iter = r#gen
.generate(&AES128, encoder.delta(), full_inputs.clone())
.unwrap();

Expand All @@ -63,8 +63,8 @@ fn criterion_benchmark(c: &mut Criterion) {
let mut ev_group = c.benchmark_group("evaluate");

ev_group.bench_function("aes128", |b| {
let mut gen = Generator::default();
let mut gen_iter = gen
let mut r#gen = Generator::default();
let mut gen_iter = r#gen
.generate(&AES128, encoder.delta(), full_inputs.clone())
.unwrap();
let gates: Vec<_> = gen_iter.by_ref().collect();
Expand Down
2 changes: 1 addition & 1 deletion crates/mpz-garble-core/src/encoding/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ pub struct ChaChaEncoder {

impl Default for ChaChaEncoder {
fn default() -> Self {
Self::new(OsRng.gen())
Self::new(OsRng.r#gen())
}
}

Expand Down
8 changes: 4 additions & 4 deletions crates/mpz-garble-core/src/encoding/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ mod tests {
{
let mut rng = ChaCha12Rng::from_seed([0u8; 32]);

let a: T = rng.gen();
let b: T = rng.gen();
let a: T = rng.r#gen();
let b: T = rng.r#gen();

let a_full: EncodedValue<_> = encoder.encode_by_type(0, &T::value_type());
let b_full: EncodedValue<_> = encoder.encode_by_type(1, &T::value_type());
Expand Down Expand Up @@ -200,8 +200,8 @@ mod tests {
{
let mut rng = ChaCha12Rng::from_seed([0u8; 32]);

let a: [T; 16] = rng.gen();
let b: [T; 16] = rng.gen();
let a: [T; 16] = rng.r#gen();
let b: [T; 16] = rng.r#gen();

let a_full: EncodedValue<_> = encoder.encode_by_type(0, &<[T; 16]>::value_type());
let b_full: EncodedValue<_> = encoder.encode_by_type(1, &<[T; 16]>::value_type());
Expand Down
2 changes: 1 addition & 1 deletion crates/mpz-garble-core/src/encoding/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -817,7 +817,7 @@ mod tests {
{
let mut rng = ChaCha12Rng::from_seed([0u8; 32]);

let value: T = rng.gen();
let value: T = rng.r#gen();

let encoded: EncodedValue<_> = encoder.encode_by_type(0, &T::value_type());
let decoding = encoded.decoding();
Expand Down
8 changes: 4 additions & 4 deletions crates/mpz-garble-core/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,8 @@ mod tests {
.map(|input| encoder.encode_by_type(0, &input.value_type()))
.collect();

let mut gen = Generator::default();
let mut gate_iter = gen.generate(&AES128, encoder.delta(), inputs).unwrap();
let mut r#gen = Generator::default();
let mut gate_iter = r#gen.generate(&AES128, encoder.delta(), inputs).unwrap();

let enc_gates: Vec<EncryptedGate> = gate_iter.by_ref().collect();

Expand Down Expand Up @@ -408,8 +408,8 @@ mod tests {
.map(|input| encoder.encode_by_type(0, &input.value_type()))
.collect();

let mut gen = Generator::default();
let mut gate_iter = gen
let mut r#gen = Generator::default();
let mut gate_iter = r#gen
.generate_batched(&circ, encoder.delta(), inputs)
.unwrap();

Expand Down
12 changes: 6 additions & 6 deletions crates/mpz-garble-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ mod tests {

#[test]
fn test_and_gate() {
use crate::{evaluator as ev, generator as gen};
use crate::{evaluator as ev, generator as r#gen};

let mut rng = ChaCha12Rng::seed_from_u64(0);
let cipher = &(*FIXED_KEY_AES);
Expand All @@ -106,7 +106,7 @@ mod tests {
let y_1 = y_0 ^ delta;
let gid: usize = 1;

let (z_0, encrypted_gate) = gen::and_gate(cipher, &x_0, &y_0, &delta, gid);
let (z_0, encrypted_gate) = r#gen::and_gate(cipher, &x_0, &y_0, &delta, gid);
let z_1 = z_0 ^ delta;

assert_eq!(ev::and_gate(cipher, &x_0, &y_0, &encrypted_gate, gid), z_0);
Expand Down Expand Up @@ -140,10 +140,10 @@ mod tests {
full_inputs[1].clone().select(msg).unwrap(),
];

let mut gen = Generator::default();
let mut r#gen = Generator::default();
let mut ev = Evaluator::default();

let mut gen_iter = gen
let mut gen_iter = r#gen
.generate_batched(&AES128, encoder.delta(), full_inputs)
.unwrap();
let mut ev_consumer = ev.evaluate_batched(&AES128, active_inputs).unwrap();
Expand Down Expand Up @@ -192,7 +192,7 @@ mod tests {
let circ = builder.build().unwrap();
assert_eq!(circ.and_count(), 0);

let mut gen = Generator::default();
let mut r#gen = Generator::default();
let mut ev = Evaluator::default();

let a = 1u8;
Expand All @@ -209,7 +209,7 @@ mod tests {
full_inputs[1].clone().select(b).unwrap(),
];

let mut gen_iter = gen
let mut gen_iter = r#gen
.generate_batched(&circ, encoder.delta(), full_inputs)
.unwrap();
let mut ev_consumer = ev.evaluate_batched(&circ, active_inputs).unwrap();
Expand Down
Loading
Loading