Skip to content

Commit

Permalink
fsb: fix Reset impl and reduce crate size (#300)
Browse files Browse the repository at this point in the history
  • Loading branch information
newpavlov authored Jul 21, 2021
1 parent a45eaef commit 1cb3dee
Show file tree
Hide file tree
Showing 13 changed files with 33 additions and 17,121 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion fsb/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 0.0.1 (2020-07-18)
## 0.0.2 (2020-07-21)
- Fixed `Reset` implementation bug. Reduce crate size by using binary dump
of `PI` ([#300])

[#300]: https://github.com/RustCrypto/hashes/pull/300

## 0.0.1 (2020-07-18) [YANKED]
- Initial release
3 changes: 2 additions & 1 deletion fsb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "fsb"
description = "FSB hash function"
version = "0.0.1"
version = "0.0.2"
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
Expand All @@ -18,6 +18,7 @@ opaque-debug = "0.3"

[dev-dependencies]
hex-literal = "0.2"
digest = { version = "0.9", features = ["dev"] }

[features]
asm = ["whirlpool/asm"]
Expand Down
5 changes: 3 additions & 2 deletions fsb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,15 @@ use alloc::vec;

#[macro_use]
mod macros;
mod pi;

pub use digest::{self, Digest};
use whirlpool::Whirlpool;

use core::convert::TryInto;

use crate::pi::PI;
// Double check this contains all values in the reference implementation
static PI: &[u8; 272384] = include_bytes!("pi.bin");

use block_buffer::BlockBuffer;
use digest::generic_array::GenericArray;
use digest::{BlockInput, FixedOutputDirty, Reset, Update};
Expand Down
5 changes: 2 additions & 3 deletions fsb/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,8 @@ macro_rules! fsb_impl {
impl Reset for $state {
fn reset(&mut self) {
self.buffer.reset();
for v in self.hash.iter_mut() {
*v = 0;
}
self.hash = [0u8; $r / 8];
self.bit_length = 0;
}
}
opaque_debug::implement!($state);
Expand Down
Binary file added fsb/src/pi.bin
Binary file not shown.
17,027 changes: 0 additions & 17,027 deletions fsb/src/pi.rs

This file was deleted.

2 changes: 2 additions & 0 deletions fsb/tests/data/fsb160.blb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
blobby1hellon�癎LF��|^�d��w�@�K+The quick brown fox jumps over the lazy dog�_n$��gS?
%#:�� �y>�tiriri tralala potompompom��/0��϶9d�m�V�$�
1 change: 1 addition & 0 deletions fsb/tests/data/fsb224.blb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
blobby1hello[���P����.r��i���yv�%7+The quick brown fox jumps over the lazy dogҍ���35��Ld��<ʨ��:�U�(tiriri tralala potompompom���Qix����y��2=Y����VV�#
2 changes: 2 additions & 0 deletions fsb/tests/data/fsb256.blb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
blobby1hello m�v�,��冨Yv�����\�v=��/(��+The quick brown fox jumps over the lazy dog �u)�Ů�j�3���K�)�
�ze4��$tiriri tralala potompompom ���R0Da�(7@z�k�K�X�P�d�y�/_+^
3 changes: 3 additions & 0 deletions fsb/tests/data/fsb384.blb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
blobby1hello0�M���&��kw�P�� ��6A&��j W
�qKɒE_�� ��P͹ +The quick brown fox jumps over the lazy dog0I���90��a�L�i\��k9�"��ܺD~��ͤj�A���_3�
�s�tiriri tralala potompompom0�����$��3V����k�K�D�X�����F���?��?O�
Expand Down
2 changes: 2 additions & 0 deletions fsb/tests/data/fsb512.blb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
blobby1hello@ k�v�r{���cC^�a�ܐN���X[eD/*:�:9y�%*�l��N�y�
���x�����Bl�����+The quick brown fox jumps over the lazy dog@o���0���z�\֢�a�h�6�4֮%iO�y �j��Ka� ���Wcv�6��;ZQ�!Xtiriri tralala potompompom@}�%]���߅'��UJS������>F���64�/�.�7n�w�J����+4�7�Q~��s
94 changes: 8 additions & 86 deletions fsb/tests/lib.rs
Original file line number Diff line number Diff line change
@@ -1,86 +1,8 @@
use hex_literal::hex;

use digest::Digest;
use fsb::*;

#[test]
fn main() {
let msg_1 = b"hello";
let msg_2 = b"The quick brown fox jumps over the lazy dog";
let msg_3 = b"tiriri tralala potompompom";

assert_eq!(
Fsb160::digest(msg_1)[..],
hex!("6e8ce7998e4c46a4ca7c5e8f6498a5778140d14b")[..],
);

assert_eq!(
Fsb160::digest(msg_2)[..],
hex!("a25f6e24c6fb67533f0a25233ac5cc09d5793e8a")[..]
);

assert_eq!(
Fsb160::digest(msg_3)[..],
hex!("bfbd2f301a8ffbcfb60f3964d96d07e6569824f9")[..]
);

assert_eq!(
Fsb224::digest(msg_1)[..],
hex!("5b04d5f3c350d00f8815f018d21a2e7289bc6993b4fa167976962537")[..]
);

assert_eq!(
Fsb224::digest(msg_2)[..],
hex!("1dd28d92cad63335fcca4c64a5e1133ccaa8c3e6083ad15591280701")[..]
);

assert_eq!(
Fsb224::digest(msg_3)[..],
hex!("bd9cc65169789ab20fbba27910a9f5323d0559f107eff3c55656dd23")[..]
);

assert_eq!(
Fsb256::digest(msg_1)[..],
hex!("0f036dc3761aed2cba9de586a85976eedde6fa8f115c0190763decc02f28edbc")[..]
);

assert_eq!(
Fsb256::digest(msg_2)[..],
hex!("a0751229aac5aeba6aeb1c0533988302e5084bb11029e7bb0ada7a653491df24")[..]
);

assert_eq!(
Fsb256::digest(msg_3)[..],
hex!("f997ac523044618f2837407ad76bf41a194bb558cf50ea1c64b379be2f5f2b5e")[..]
);

assert_eq!(
Fsb384::digest(msg_1)[..],
hex!("010d14a04da89df22685138b6b7795501ebdc109b6c714364126fcb46a0b570a9d714bc992455f8cf2099c8750cdb90b")[..]
);

assert_eq!(
Fsb384::digest(msg_2)[..],
hex!("4983ecfa3930e3cf61ac4c82695c01a394016b39cf22b5d6dcba447ef8cbcda46ac341ccf5835f331fed0abe73e9bf1c")[..]
);

assert_eq!(
Fsb384::digest(msg_3)[..],
hex!("0597e317f2a3f311db2485f0b8335607e6bcc6f918d07f6b0dc14bc044c558a9bcd0f5f346ad85bb043ff097f43f4f95")[..]
);

assert_eq!(
Fsb512::digest(msg_1)[..],
hex!("0c6bb476d9727b90a1f063435e8d611aacdc904e9680fe585b65442f2a3ac5043a3979ff252adf6cc9d34ef0b179a90ae2f2e8789f8797bff2426c90a58fb28b")[..]
);

assert_eq!(
Fsb512::digest(msg_2)[..],
hex!("6f87b9dc051330bfb0dd7ad35c05d6a2040e9a6110b06886368934d6ae25694fd9790b1bf1086af9da4b15619609b688fa576376f136adbd3b5a51ae1a1f2158")[..]
);

assert_eq!(
Fsb512::digest(msg_3)[..],
hex!("7dd5255dafac0796df851d278eb70f554a539cc3dfdfe0a3d73e46df1ab51c029d3634db022fcd032ee8376ea777e34af118821fb1ff2b34b7378e517eacdc73")[..]
);
}
use digest::dev::digest_test;
use digest::new_test;

new_test!(fsb160_main, "fsb160", fsb::Fsb160, digest_test);
new_test!(fsb224_main, "fsb224", fsb::Fsb224, digest_test);
new_test!(fsb256_main, "fsb256", fsb::Fsb256, digest_test);
new_test!(fsb384_main, "fsb384", fsb::Fsb384, digest_test);
new_test!(fsb512_main, "fsb512", fsb::Fsb512, digest_test);

0 comments on commit 1cb3dee

Please sign in to comment.