Skip to content

Commit

Permalink
Merge branch 'master' into dependabot/cargo/rand-0.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ordian committed Dec 29, 2020
2 parents 94b0740 + f9d468e commit 53cf7e9
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 40 deletions.
4 changes: 2 additions & 2 deletions parity-crypto/src/aes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

use aes::block_cipher::generic_array::GenericArray;
use aes::cipher::generic_array::GenericArray;
use aes::{Aes128, Aes256};
use aes_ctr::stream_cipher::{NewStreamCipher, SyncStreamCipher};
use aes_ctr::cipher::stream::{NewStreamCipher, SyncStreamCipher};
use block_modes::{
block_padding::{Pkcs7, ZeroPadding},
BlockMode, Cbc, Ecb,
Expand Down
12 changes: 6 additions & 6 deletions parity-crypto/src/digest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ impl Hasher<Ripemd160> {
impl<T> Hasher<T> {
pub fn update(&mut self, data: &[u8]) {
match self.0 {
Inner::Sha256(ref mut ctx) => ctx.input(data),
Inner::Sha512(ref mut ctx) => ctx.input(data),
Inner::Ripemd160(ref mut ctx) => ctx.input(data),
Inner::Sha256(ref mut ctx) => ctx.update(data),
Inner::Sha512(ref mut ctx) => ctx.update(data),
Inner::Ripemd160(ref mut ctx) => ctx.update(data),
}
}

pub fn finish(self) -> Digest<T> {
match self.0 {
Inner::Sha256(ctx) => Digest(InnerDigest::Sha256(ctx.result()), PhantomData),
Inner::Sha512(ctx) => Digest(InnerDigest::Sha512(ctx.result()), PhantomData),
Inner::Ripemd160(ctx) => Digest(InnerDigest::Ripemd160(ctx.result()), PhantomData),
Inner::Sha256(ctx) => Digest(InnerDigest::Sha256(ctx.finalize()), PhantomData),
Inner::Sha512(ctx) => Digest(InnerDigest::Sha512(ctx.finalize()), PhantomData),
Inner::Ripemd160(ctx) => Digest(InnerDigest::Ripemd160(ctx.finalize()), PhantomData),
}
}
}
6 changes: 3 additions & 3 deletions parity-crypto/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ pub struct SymmError(PrivSymmErr);
#[derive(Debug)]
enum PrivSymmErr {
BlockMode(block_modes::BlockModeError),
KeyStream(aes_ctr::stream_cipher::LoopError),
KeyStream(aes_ctr::cipher::stream::LoopError),
InvalidKeyLength(block_modes::InvalidKeyIvLength),
}

Expand Down Expand Up @@ -111,8 +111,8 @@ impl From<block_modes::InvalidKeyIvLength> for SymmError {
}
}

impl From<aes_ctr::stream_cipher::LoopError> for SymmError {
fn from(e: aes_ctr::stream_cipher::LoopError) -> SymmError {
impl From<aes_ctr::cipher::stream::LoopError> for SymmError {
fn from(e: aes_ctr::cipher::stream::LoopError) -> SymmError {
SymmError(PrivSymmErr::KeyStream(e))
}
}
Expand Down
14 changes: 7 additions & 7 deletions parity-crypto/src/hmac/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use digest::generic_array::{
typenum::{U32, U64},
GenericArray,
};
use hmac::{Hmac, Mac as _};
use hmac::{Hmac, Mac as _, NewMac as _};
use zeroize::Zeroize;

use crate::digest::{Sha256, Sha512};
Expand Down Expand Up @@ -113,15 +113,15 @@ impl<T> Signer<T> {

pub fn update(&mut self, data: &[u8]) {
match &mut self.0 {
SignerInner::Sha256(hmac) => hmac.input(data),
SignerInner::Sha512(hmac) => hmac.input(data),
SignerInner::Sha256(hmac) => hmac.update(data),
SignerInner::Sha512(hmac) => hmac.update(data),
}
}

pub fn sign(self) -> Signature<T> {
match self.0 {
SignerInner::Sha256(hmac) => Signature(HashInner::Sha256(hmac.result().code()), PhantomData),
SignerInner::Sha512(hmac) => Signature(HashInner::Sha512(hmac.result().code()), PhantomData),
SignerInner::Sha256(hmac) => Signature(HashInner::Sha256(hmac.finalize().into_bytes()), PhantomData),
SignerInner::Sha512(hmac) => Signature(HashInner::Sha512(hmac.finalize().into_bytes()), PhantomData),
}
}
}
Expand All @@ -146,12 +146,12 @@ pub fn verify<T>(key: &VerifyKey<T>, data: &[u8], sig: &[u8]) -> bool {
match &key.0 {
KeyInner::Sha256(key_bytes) => {
let mut ctx = Hmac::<sha2::Sha256>::new_varkey(&key_bytes.0).expect("always returns Ok; qed");
ctx.input(data);
ctx.update(data);
ctx.verify(sig).is_ok()
}
KeyInner::Sha512(key_bytes) => {
let mut ctx = Hmac::<sha2::Sha512>::new_varkey(&key_bytes.0).expect("always returns Ok; qed");
ctx.input(data);
ctx.update(data);
ctx.verify(sig).is_ok()
}
}
Expand Down
18 changes: 0 additions & 18 deletions parity-crypto/src/hmac/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,21 +232,3 @@ fn ietf_test_vectors() {
),
);
}

#[test]
fn secrets_are_zeroed_on_drop() {
let ptr: *const KeyInner;
let zeros = KeyInner::Sha256(DisposableBox::from_slice(&[0u8; 6][..]));
let expected = KeyInner::Sha256(DisposableBox::from_slice(b"sikrit"));
{
let secret = b"sikrit";
let signing_key = SigKey::sha256(secret);
ptr = &signing_key.0;
unsafe {
assert_eq!(*ptr, expected);
}
}
unsafe {
assert_eq!(*ptr, zeros);
}
}
4 changes: 2 additions & 2 deletions parity-crypto/src/pbkdf2/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ pub struct Salt<'a>(pub &'a [u8]);
pub struct Secret<'a>(pub &'a [u8]);

pub fn sha256(iter: u32, salt: Salt<'_>, sec: Secret<'_>, out: &mut [u8; 32]) {
pbkdf2::pbkdf2::<hmac::Hmac<sha2::Sha256>>(sec.0, salt.0, iter as usize, out)
pbkdf2::pbkdf2::<hmac::Hmac<sha2::Sha256>>(sec.0, salt.0, iter, out)
}

pub fn sha512(iter: u32, salt: Salt<'_>, sec: Secret<'_>, out: &mut [u8; 64]) {
pbkdf2::pbkdf2::<hmac::Hmac<sha2::Sha512>>(sec.0, salt.0, iter as usize, out)
pbkdf2::pbkdf2::<hmac::Hmac<sha2::Sha512>>(sec.0, salt.0, iter, out)
}

#[cfg(test)]
Expand Down
2 changes: 0 additions & 2 deletions rlp/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
// except according to those terms.

//! Common RLP traits
#[cfg(not(feature = "std"))]
use alloc::vec::Vec;
use bytes::BytesMut;

use crate::{error::DecoderError, rlpin::Rlp, stream::RlpStream};
Expand Down

0 comments on commit 53cf7e9

Please sign in to comment.