Skip to content
Merged
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
20 changes: 10 additions & 10 deletions packages/ic-ed25519/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ impl PrivateKey {
let mut sha2 = Sha512::new();
sha2.update(seed);
let digest: [u8; 64] = sha2.finalize().into();
let mut truncated = [0u8; 32];
let mut truncated = [0_u8; 32];
truncated.copy_from_slice(&digest[..32]);
truncated
};
Expand Down Expand Up @@ -291,7 +291,7 @@ impl PrivateKey {
/// incompatible with additive derivation.
///
pub fn derive_subkey(&self, derivation_path: &DerivationPath) -> (DerivedPrivateKey, [u8; 32]) {
let chain_code = [0u8; 32];
let chain_code = [0_u8; 32];
self.derive_subkey_with_chain_code(derivation_path, &chain_code)
}

Expand Down Expand Up @@ -325,7 +325,7 @@ impl PrivateKey {
sha2.update(derived_scalar.to_bytes());
sha2.update(chain_code);
let hash: [u8; 64] = sha2.finalize().into();
let mut truncated = [0u8; 32];
let mut truncated = [0_u8; 32];
truncated.copy_from_slice(&hash[..32]);
truncated
};
Expand Down Expand Up @@ -381,7 +381,7 @@ impl DerivedPrivateKey {
/// incompatible with additive derivation.
///
pub fn derive_subkey(&self, derivation_path: &DerivationPath) -> (DerivedPrivateKey, [u8; 32]) {
let chain_code = [0u8; 32];
let chain_code = [0_u8; 32];
self.derive_subkey_with_chain_code(derivation_path, &chain_code)
}

Expand Down Expand Up @@ -415,7 +415,7 @@ impl DerivedPrivateKey {
sha2.update(derived_scalar.to_bytes());
sha2.update(chain_code);
let hash: [u8; 64] = sha2.finalize().into();
let mut truncated = [0u8; 32];
let mut truncated = [0_u8; 32];
truncated.copy_from_slice(&hash[..32]);
truncated
};
Expand Down Expand Up @@ -453,7 +453,7 @@ impl Signature {
}

let (r, r_bytes) = {
let mut r_bytes = [0u8; 32];
let mut r_bytes = [0_u8; 32];
r_bytes.copy_from_slice(&signature[..32]);
let r = CompressedEdwardsY(r_bytes)
.decompress()
Expand All @@ -463,7 +463,7 @@ impl Signature {
};

let s = {
let mut s_bytes = [0u8; 32];
let mut s_bytes = [0_u8; 32];
s_bytes.copy_from_slice(&signature[32..]);
Option::<Scalar>::from(Scalar::from_canonical_bytes(s_bytes))
.ok_or(SignatureError::InvalidSignature)?
Expand Down Expand Up @@ -861,7 +861,7 @@ impl PublicKey {
/// This is the same derivation system used by the Internet Computer when
/// deriving subkeys for Ed25519
pub fn derive_subkey(&self, derivation_path: &DerivationPath) -> (Self, [u8; 32]) {
let chain_code = [0u8; 32];
let chain_code = [0_u8; 32];
self.derive_subkey_with_chain_code(derivation_path, &chain_code)
}

Expand Down Expand Up @@ -953,11 +953,11 @@ impl DerivationPath {

let hkdf = hkdf::Hkdf::<Sha512>::new(Some(&chain_code), &ikm);

let mut okm = [0u8; 96];
let mut okm = [0_u8; 96];
hkdf.expand(b"Ed25519", &mut okm)
.expect("96 is a valid length for HKDF-SHA-512");

let mut offset = [0u8; 64];
let mut offset = [0_u8; 64];
offset.copy_from_slice(&okm[0..64]);
offset.reverse(); // dalek uses little endian
let offset = Scalar::from_bytes_mod_order_wide(&offset);
Expand Down
4 changes: 2 additions & 2 deletions packages/ic-ed25519/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ fn should_produce_expected_derived_public_keys() {
check_derivation(
&DerivationPath::new_bip32(&[1]),
hex!("931387a550eb4524a7af29381b938df38e76aeecac08e2cfaae4f4ca99bb4881"),
[0u8; 32],
[0_u8; 32],
hex!("6f3086e738ab5417c6e02504464f208a763f0fba0c4d7ade40694773b6c2273c"),
hex!("d34e4e22d2c008ccc7e9bb9882fbc025a1e5516e3421d8e932dbc0be35f787a0"),
);
Expand All @@ -414,7 +414,7 @@ fn should_produce_expected_derived_public_keys() {
check_derivation(
&DerivationPath::new_bip32(&[1, 2]),
hex!("931387a550eb4524a7af29381b938df38e76aeecac08e2cfaae4f4ca99bb4881"),
[0u8; 32],
[0_u8; 32],
hex!("8efb675fcaf45c93e785ff535e380d9019c876a7c5faed264b911f97ef34d838"),
hex!("2562ad75c50708f8d20c442e48b3f8ee851570be256ef0a7060b9f755a837216"),
);
Expand Down
8 changes: 4 additions & 4 deletions packages/ic-ethereum-types/src/address/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl Address {
/// assert_eq!(address.to_string(), "0x0000000000000000000000000000000000000000");
/// assert_eq!(address.into_bytes(), [0u8; 20]);
/// ```
pub const ZERO: Self = Self([0u8; 20]);
pub const ZERO: Self = Self([0_u8; 20]);

/// Create a new Ethereum address from raw bytes.
pub const fn new(bytes: [u8; 20]) -> Self {
Expand Down Expand Up @@ -108,7 +108,7 @@ impl FromStr for Address {
if !s.starts_with("0x") {
return Err("address doesn't start with '0x'".to_string());
}
let mut bytes = [0u8; 20];
let mut bytes = [0_u8; 20];
hex::decode_to_slice(&s[2..], &mut bytes)
.map_err(|e| format!("address is not hex: {e}"))?;
Ok(Self(bytes))
Expand All @@ -124,12 +124,12 @@ impl fmt::Debug for Address {
/// Display address using [EIP-55](https://eips.ethereum.org/EIPS/eip-55).
impl fmt::Display for Address {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut addr_chars = [0u8; 20 * 2];
let mut addr_chars = [0_u8; 20 * 2];
hex::encode_to_slice(self.0, &mut addr_chars)
.expect("bug: failed to encode an address as hex");

let checksum = keccak(&addr_chars[..]);
let mut cs_nibbles = [0u8; 32 * 2];
let mut cs_nibbles = [0_u8; 32 * 2];
for i in 0..32 {
cs_nibbles[2 * i] = checksum[i] >> 4;
cs_nibbles[2 * i + 1] = checksum[i] & 0x0f;
Expand Down
2 changes: 1 addition & 1 deletion packages/ic-ethereum-types/src/address/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ mod from_32_bytes {

fn thirty_two_bytes_from_ethereum_string(s: &str) -> [u8; 32] {
assert!(s.starts_with("0x"), "string must start with 0x");
let mut bytes = [0u8; 32];
let mut bytes = [0_u8; 32];
hex::decode_to_slice(&s[2..], &mut bytes).unwrap();
bytes
}
Expand Down
4 changes: 2 additions & 2 deletions packages/ic-hpke/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ impl PublicKey {
/// Serialize the public key to a bytestring
pub fn serialize(&self) -> Vec<u8> {
let len = <V1PublicKey as Serializable>::size();
let mut buf = vec![0u8; HEADER_SIZE + len];
let mut buf = vec![0_u8; HEADER_SIZE + len];
buf[0..HEADER_SIZE].copy_from_slice(&MAGIC.to_be_bytes());
self.pk.write_exact(&mut buf[HEADER_SIZE..]);
buf
Expand Down Expand Up @@ -352,7 +352,7 @@ impl PrivateKey {
/// Serialize this private key
pub fn serialize(&self) -> Vec<u8> {
let len = <V1PrivateKey as Serializable>::size();
let mut buf = vec![0u8; HEADER_SIZE + len];
let mut buf = vec![0_u8; HEADER_SIZE + len];
buf[0..HEADER_SIZE].copy_from_slice(&MAGIC.to_be_bytes());
self.sk.write_exact(&mut buf[HEADER_SIZE..]);
buf
Expand Down
4 changes: 2 additions & 2 deletions packages/ic-hpke/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn smoke_test_noauth() {
let pk = sk.public_key();

for ptext_len in 0..128 {
let mut ptext = vec![0u8; ptext_len];
let mut ptext = vec![0_u8; ptext_len];
rng.fill_bytes(&mut ptext);
let aad = rng.r#gen::<[u8; 32]>();
let ctext = pk.encrypt_noauth(&ptext, &aad, &mut rng).unwrap();
Expand All @@ -103,7 +103,7 @@ fn smoke_test_auth() {
let aad = rng.r#gen::<[u8; 32]>();

for ptext_len in 0..128 {
let mut ptext = vec![0u8; ptext_len];
let mut ptext = vec![0_u8; ptext_len];
rng.fill_bytes(&mut ptext);
let ctext = a_pk.encrypt(&ptext, &aad, &b_sk, &mut rng).unwrap();
let rec = a_sk.decrypt(&ctext, &aad, &b_pk).unwrap();
Expand Down
14 changes: 7 additions & 7 deletions packages/ic-secp256k1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl DerivationPath {

// If iL >= order, try again with the "next" index as described in SLIP-10
if next_offset.to_bytes().to_vec() != hmac_output[..32] {
let mut next_input = [0u8; 33];
let mut next_input = [0_u8; 33];
next_input[0] = 0x01;
next_input[1..].copy_from_slice(&next_chain_key);
Self::ckd(idx, &next_input, chain_code)
Expand Down Expand Up @@ -489,7 +489,7 @@ impl PrivateKey {
if digest.len() < 16 {
// k256 arbitrarily rejects digests that are < 128 bits
// handle this by prefixing with a sufficient number of zero bytes
let mut zdigest = [0u8; 32];
let mut zdigest = [0_u8; 32];
let z_prefix_len = zdigest.len() - digest.len();
zdigest[z_prefix_len..].copy_from_slice(digest);
return self.sign_digest_with_ecdsa(&zdigest);
Expand Down Expand Up @@ -617,7 +617,7 @@ impl PrivateKey {
/// for details on the derivation scheme.
///
pub fn derive_subkey(&self, derivation_path: &DerivationPath) -> (Self, [u8; 32]) {
let chain_code = [0u8; 32];
let chain_code = [0_u8; 32];
self.derive_subkey_with_chain_code(derivation_path, &chain_code)
}

Expand Down Expand Up @@ -819,7 +819,7 @@ impl PublicKey {
)));
}

let mut sec1 = [0u8; 33];
let mut sec1 = [0_u8; 33];
sec1[0] = 0x02; // even y
sec1[1..].copy_from_slice(bytes);

Expand Down Expand Up @@ -980,7 +980,7 @@ impl PublicKey {
/// Verify a (message digest,signature) pair
pub fn verify_ecdsa_signature_prehashed(&self, digest: &[u8], signature: &[u8]) -> bool {
if digest.len() < 16 {
let mut zdigest = [0u8; 32];
let mut zdigest = [0_u8; 32];
let z_prefix_len = zdigest.len() - digest.len();
zdigest[z_prefix_len..].copy_from_slice(digest);
return self.verify_ecdsa_signature_prehashed(&zdigest, signature);
Expand Down Expand Up @@ -1015,7 +1015,7 @@ impl PublicKey {
signature: &[u8],
) -> bool {
if digest.len() < 16 {
let mut zdigest = [0u8; 32];
let mut zdigest = [0_u8; 32];
let z_prefix_len = zdigest.len() - digest.len();
zdigest[z_prefix_len..].copy_from_slice(digest);
return self.verify_ecdsa_signature_prehashed_with_malleability(&zdigest, signature);
Expand Down Expand Up @@ -1120,7 +1120,7 @@ impl PublicKey {
/// deriving subkeys for threshold ECDSA with secp256k1 and BIP340 Schnorr
///
pub fn derive_subkey(&self, derivation_path: &DerivationPath) -> (Self, [u8; 32]) {
let chain_code = [0u8; 32];
let chain_code = [0_u8; 32];
self.derive_subkey_with_chain_code(derivation_path, &chain_code)
}

Expand Down
12 changes: 6 additions & 6 deletions packages/ic-secp256k1/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ fn should_accept_ecdsa_signatures_that_we_generate() {
let pk = sk.public_key();

for m in 0..100 {
let mut msg = vec![0u8; m];
let mut msg = vec![0_u8; m];
rng.fill_bytes(&mut msg);
let sig = sk.sign_message_with_ecdsa(&msg);

Expand Down Expand Up @@ -193,7 +193,7 @@ fn should_accept_bip340_signatures_that_we_generate() {

let pk = sk.public_key();

let mut msg = vec![0u8; len];
let mut msg = vec![0_u8; len];
rng.fill_bytes(&mut msg);

let sig = sk.sign_message_with_bip340(&msg, &mut rng);
Expand All @@ -212,11 +212,11 @@ fn should_accept_bip341_signatures_that_we_generate() {

let pk = sk.public_key();

let mut msg = vec![0u8; len];
let mut msg = vec![0_u8; len];
rng.fill_bytes(&mut msg);

for ttr_len in [0, 32] {
let mut ttr = vec![0u8; ttr_len];
let mut ttr = vec![0_u8; ttr_len];
rng.fill_bytes(&mut ttr);
let sig = sk.sign_message_with_bip341(&msg, &mut rng, &ttr).unwrap();
assert!(pk.verify_bip341_signature(&msg, &sig, &ttr));
Expand Down Expand Up @@ -587,7 +587,7 @@ fn key_derivation_matches_bip32() {
.collect::<Vec<u32>>();

let master_key = PrivateKey::generate_using_rng(rng).public_key();
let root_chain_code = [0u8; 32];
let root_chain_code = [0_u8; 32];

let mut derived_keys = Vec::with_capacity(path.len());
for i in 1..=path.len() {
Expand All @@ -600,7 +600,7 @@ fn key_derivation_matches_bip32() {

let attrs = bip32::ExtendedKeyAttrs {
depth: 0,
parent_fingerprint: [0u8; 4],
parent_fingerprint: [0_u8; 4],
child_number: bip32::ChildNumber(0),
chain_code: root_chain_code,
};
Expand Down
8 changes: 4 additions & 4 deletions packages/ic-secp256r1/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl DerivationPath {

// If iL >= order, try again with the "next" index as described in SLIP-10
if next_offset.to_bytes().to_vec() != hmac_output[..32] {
let mut next_input = [0u8; 33];
let mut next_input = [0_u8; 33];
next_input[0] = 0x01;
next_input[1..].copy_from_slice(&next_chain_key);
Self::ckd(idx, &next_input, chain_code)
Expand Down Expand Up @@ -509,7 +509,7 @@ impl PrivateKey {
/// bit cleared, this derivation scheme matches SLIP-10
///
pub fn derive_subkey(&self, derivation_path: &DerivationPath) -> (Self, [u8; 32]) {
let chain_code = [0u8; 32];
let chain_code = [0_u8; 32];
self.derive_subkey_with_chain_code(derivation_path, &chain_code)
}

Expand Down Expand Up @@ -574,7 +574,7 @@ impl PublicKey {
));
}

let mut sec1 = [0u8; 1 + FIELD_BYTES * 2];
let mut sec1 = [0_u8; 1 + FIELD_BYTES * 2];
sec1[0] = 0x04;
sec1[1..(1 + FIELD_BYTES)].copy_from_slice(x);
sec1[(1 + FIELD_BYTES)..(1 + 2 * FIELD_BYTES)].copy_from_slice(y);
Expand Down Expand Up @@ -689,7 +689,7 @@ impl PublicKey {
/// Derive a public key from this public key using a derivation path
///
pub fn derive_subkey(&self, derivation_path: &DerivationPath) -> (Self, [u8; 32]) {
let chain_code = [0u8; 32];
let chain_code = [0_u8; 32];
self.derive_subkey_with_chain_code(derivation_path, &chain_code)
}

Expand Down
4 changes: 2 additions & 2 deletions packages/ic-secp256r1/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn should_accept_signatures_that_we_generate() {
let pk = sk.public_key();

for m in 0..100 {
let mut msg = vec![0u8; m];
let mut msg = vec![0_u8; m];
rng.fill_bytes(&mut msg);
let sig = sk.sign_message(&msg);

Expand All @@ -118,7 +118,7 @@ fn should_accept_der_encoded_signatures_that_we_generate() {
let pk = sk.public_key();

for m in 0..100 {
let mut msg = vec![0u8; m];
let mut msg = vec![0_u8; m];
rng.fill_bytes(&mut msg);
let sig = sk.sign_message_with_der_encoded_sig(&msg);

Expand Down
4 changes: 2 additions & 2 deletions packages/ic-sha3/tests/shake256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn should_pass_nist_variable_output_test_vectors() {
let mut shake256 = Shake256::new();
shake256.update(msg);
let mut xof_reader = shake256.finalize_xof();
let buf = &mut vec![0u8; outputlen / 8];
let buf = &mut vec![0_u8; outputlen / 8];
xof_reader.read(buf);

assert_eq!(buf, &output, "test vec with COUNT = {count} failed");
Expand Down Expand Up @@ -81,7 +81,7 @@ fn should_pass_nist_short_msg_test_vectors() {
shake256.update(msg);
}
let mut xof_reader = shake256.finalize_xof();
let buf = &mut vec![0u8; output.len()];
let buf = &mut vec![0_u8; output.len()];
xof_reader.read(buf);

assert_eq!(buf, &output, "test vec for Len = {len} failed");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ fn should_fail_verify_canister_sig_on_wrong_msg() {
let rng = &mut ReproducibleRng::new();
for with_delegation in [false, true] {
let sig_data = new_valid_sig_and_crypto_component(rng, with_delegation);
let wrong_msg = [1u8, 2, 3, 4];
let wrong_msg = [1_u8, 2, 3, 4];

let result = ic_signature_verification::verify_canister_sig(
&wrong_msg,
Expand Down
2 changes: 1 addition & 1 deletion packages/icrc-cbor/src/u256.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub fn decode<Ctx>(d: &mut Decoder<'_>, _ctx: &mut Ctx) -> Result<u256, Error> {
bytes.len()
)));
}
let mut be_bytes = [0u8; 32];
let mut be_bytes = [0_u8; 32];
be_bytes[32 - bytes.len()..32].copy_from_slice(bytes);
Ok(u256::from_be_bytes(be_bytes))
}
Expand Down
Loading
Loading