Skip to content

Commit

Permalink
FSB hash function (#256)
Browse files Browse the repository at this point in the history
  • Loading branch information
iquerejeta authored Jul 18, 2021
1 parent 59269ed commit a1e8900
Show file tree
Hide file tree
Showing 10 changed files with 17,617 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/workspace.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
- uses: actions/checkout@v1
- uses: actions-rs/toolchain@v1
with:
toolchain: 1.41.0 # MSRV
toolchain: 1.47.0
components: clippy
profile: minimal
override: true
Expand Down
11 changes: 11 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]
members = [
"fsb",
"blake2",
"gost94",
"groestl",
Expand Down
3 changes: 3 additions & 0 deletions fsb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/target
.idea
Cargo.lock
20 changes: 20 additions & 0 deletions fsb/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "fsb"
version = "0.1.0"
description = "FSB hash function"
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
readme = "README.md"
edition = "2018"
repository = "https://github.com/RustCrypto/hashes"
keywords = ["crypto", "fsb", "hash", "digest"]
categories = ["cryptography", "no-std"]

[dependencies]
whirlpool = { version = "0.9", path = "../whirlpool", default-features = false }
digest = "0.9"
block-buffer = { version = "0.9", features = ["block-padding"] }
opaque-debug = "0.3"

[dev-dependencies]
hex-literal = "0.2"
56 changes: 56 additions & 0 deletions fsb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# RustCrypto: FSB

[![crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
[![Build Status][build-image]][build-link]
![Apache2/MIT licensed][license-image]
![Rust Version][rustc-image]
[![Project Chat][chat-image]][chat-link]

Pure Rust implementation of the [FSB hash function][1] family.

[Documentation][docs-link]

## Minimum Supported Rust Version

Rust **1.41** or higher.

Minimum supported Rust version can be changed in the future, but it will be
done with a minor version bump.

## SemVer Policy

- All on-by-default features of this library are covered by SemVer
- MSRV is considered exempt from SemVer as noted above

## License

Licensed under either of:

* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
* [MIT license](http://opensource.org/licenses/MIT)

at your option.

### Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you, as defined in the Apache-2.0 license, shall be
dual licensed as above, without any additional terms or conditions.

[//]: # (badges)

[crate-image]: https://img.shields.io/crates/v/fsb.svg
[crate-link]: https://crates.io/crates/fsb
[docs-image]: https://docs.rs/fsb/badge.svg
[docs-link]: https://docs.rs/fsb/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260041-hashes
[rustc-image]: https://img.shields.io/badge/rustc-1.41+-blue.svg
[build-image]: https://github.com/RustCrypto/hashes/workflows/fsb/badge.svg?branch=master
[build-link]: https://github.com/RustCrypto/hashes/actions?query=workflow%3Afsb

[//]: # (general links)

[1]: https://www.paris.inria.fr/secret/CBCrypto/index.php?pg=fsb
75 changes: 75 additions & 0 deletions fsb/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
//! An implementation of the [FSB][1] cryptographic hash algorithms.
//! The FSB hash function was one of the submissions to SHA-3,
//! the cryptographic hash algorithm competition organized by the NIST.
//!
//! There are 5 standard versions of the FSB hash function:
//!
//! * `FSB-160`
//! * `FSB-224`
//! * `FSB-256`
//! * `FSB-384`
//! * `FSB-512`
//!
//! # Examples
//!
//! Output size of FSB-256 is fixed, so its functionality is usually
//! accessed via the `Digest` trait:
//!
//! ```
//! use hex_literal::hex;
//! use fsb::{Digest, Fsb256};
//!
//! // create a FSB-256 object
//! let mut hasher = Fsb256::new();
//!
//! // write input message
//! hasher.update(b"hello");
//!
//! // read hash digest
//! let result = hasher.finalize();
//!
//! assert_eq!(result[..], hex!("
//! 0f036dc3761aed2cba9de586a85976eedde6fa8f115c0190763decc02f28edbc
//! ")[..]);
//! ```
//! Also see [RustCrypto/hashes][2] readme.
//!
//! [1]: https://www.paris.inria.fr/secret/CBCrypto/index.php?pg=fsb
//! [2]: https://github.com/RustCrypto/hashes
// #![no_std]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/meta/master/logo.svg"
)]
#![deny(unsafe_code)]
#![warn(missing_docs, rust_2018_idioms)]

#![allow(non_snake_case)]

#[cfg(feature = "std")]
extern crate std;

#[cfg(not(feature = "std"))]
extern crate alloc;
use alloc::vec;

#[macro_use]
mod macros;
mod pi;

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

use core::convert::TryInto;

use block_buffer::BlockBuffer;
use digest::{generic_array::GenericArray};
use digest::{BlockInput, FixedOutputDirty, Reset, Update};
use crate::pi::PI;

fsb_impl!(Fsb160, 160, U60, U20, 5 << 18, 80, 640, 653, 1120, "FSB-160 hash function.");
fsb_impl!(Fsb224, 224, U84, U28, 7 << 18, 112, 896, 907, 1568, "FSB-224 hash function.");
fsb_impl!(Fsb256, 256, U96, U32, 1 << 21, 128, 1024, 1061, 1792, "FSB-256 hash function.");
fsb_impl!(Fsb384, 384, U115, U48, 23 << 16, 184, 1472, 1483, 2392, "FSB-384 hash function.");
fsb_impl!(Fsb512, 512, U155, U64, 31 << 16, 248, 1984, 1987, 3224, "FSB-512 hash function.");
Loading

0 comments on commit a1e8900

Please sign in to comment.