Skip to content

Commit f5a07e6

Browse files
authored
Use README as crate docs (#537)
1 parent 414eca5 commit f5a07e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+823
-1117
lines changed

Cargo.lock

Lines changed: 5 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ The SHA-1 implementation was previously published as `sha-1`, but migrated to `s
6767

6868
MSRV bumps are considered breaking changes and will be performed only with minor version bump.
6969

70-
## Usage
70+
## Examples
7171

7272
Let us demonstrate how to use crates in this repository using SHA-2 as an example.
7373

@@ -215,10 +215,10 @@ let hash2_1 = use_hasher(&mut *hasher2, b"foo");
215215

216216
## License
217217

218-
All crates licensed under either of
218+
All crates in this repository are licensed under either of
219219

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

223223
at your option.
224224

ascon-hash/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ ascon = { version = "0.4", default-features = false }
2222
[dev-dependencies]
2323
spectral = { version = "0.6", default-features = false }
2424
hex = "0.4"
25+
hex-literal = "0.4"
2526

2627
[features]
2728
default = ["std"]

ascon-hash/LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Copyright (c) 2022-2023 Sebastian Ramacher <[email protected]>
2-
Copyright (c) 2023 The RustCrypto Project Developers
2+
Copyright (c) 2023-2024 The RustCrypto Project Developers
33

44
Permission is hereby granted, free of charge, to any
55
person obtaining a copy of this software and associated

ascon-hash/README.md

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,40 @@ Pure Rust implementation of the lightweight cryptographic hash functions
1111
[AsconHash and AsconAHash][1] and the extendable output functions (XOF) AsconXOF
1212
and AsconAXOF.
1313

14-
[Documentation][docs-link]
15-
1614
## Security Notes
1715

1816
No security audits of this crate have ever been performed.
1917

2018
USE AT YOUR OWN RISK!
2119

20+
## Examples
21+
Fixed output size hashing:
22+
```rust
23+
use ascon_hash::{AsconHash, Digest};
24+
use hex_literal::hex;
25+
26+
let mut hasher = AsconHash::new();
27+
hasher.update(b"some bytes");
28+
let hash = hasher.finalize();
29+
30+
assert_eq!(hash, hex!("b742ca75e57038757059cccc6874714f9dbd7fc5924a7df4e316594fd1426ca8"));
31+
```
32+
33+
XOF hashing:
34+
```rust
35+
use ascon_hash::{AsconXof, ExtendableOutput, Update, XofReader};
36+
use hex_literal::hex;
37+
38+
let mut xof = AsconXof::default();
39+
xof.update(b"some bytes");
40+
let mut reader = xof.finalize_xof();
41+
let mut dst = [0u8; 5];
42+
reader.read(&mut dst);
43+
assert_eq!(dst, hex!("c21972fde9"));
44+
```
45+
46+
Also, see the [examples section] in the RustCrypto/hashes readme.
47+
2248
## Minimum Supported Rust Version
2349

2450
This crate requires **Rust 1.71** at a minimum.
@@ -28,10 +54,10 @@ version bump.
2854

2955
## License
3056

31-
Licensed under either of:
57+
The crate is licensed under either of:
3258

33-
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
34-
* [MIT license](http://opensource.org/licenses/MIT)
59+
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
60+
* [MIT license](http://opensource.org/licenses/MIT)
3561

3662
at your option.
3763

@@ -57,3 +83,4 @@ dual licensed as above, without any additional terms or conditions.
5783
[//]: # (general links)
5884

5985
[1]: https://ascon.iaik.tugraz.at
86+
[examples section]: https://github.com/RustCrypto/hashes#Examples

ascon-hash/src/lib.rs

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
// Copyright 2022-2023 Sebastian Ramacher
2-
// SPDX-License-Identifier: Apache-2.0 OR MIT
3-
41
#![no_std]
52
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
63
#![doc = include_str!("../README.md")]
@@ -10,30 +7,6 @@
107
)]
118
#![warn(missing_docs)]
129

13-
//! ## Usage (Hashing)
14-
//!
15-
//! ```
16-
//! use ascon_hash::{AsconHash, Digest}; // Or `AsconAHash`
17-
//!
18-
//! let mut hasher = AsconHash::new();
19-
//! hasher.update(b"some bytes");
20-
//! let digest = hasher.finalize();
21-
//! assert_eq!(&digest[..], b"\xb7\x42\xca\x75\xe5\x70\x38\x75\x70\x59\xcc\xcc\x68\x74\x71\x4f\x9d\xbd\x7f\xc5\x92\x4a\x7d\xf4\xe3\x16\x59\x4f\xd1\x42\x6c\xa8");
22-
//! ```
23-
//!
24-
//! ## Usage (XOF)
25-
//!
26-
//! ```
27-
//! use ascon_hash::{AsconXof, ExtendableOutput, Update, XofReader};
28-
//!
29-
//! let mut xof = AsconXof::default();
30-
//! xof.update(b"some bytes");
31-
//! let mut reader = xof.finalize_xof();
32-
//! let mut dst = [0u8; 5];
33-
//! reader.read(&mut dst);
34-
//! assert_eq!(&dst, b"\xc2\x19\x72\xfd\xe9");
35-
//! ```
36-
3710
use core::marker::PhantomData;
3811

3912
use ascon::{pad, State};

belt-hash/LICENSE-MIT

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2022 Artyom Pavlov
1+
Copyright (c) 2022-2024 The RustCrypto Project Developers
22

33
Permission is hereby granted, free of charge, to any
44
person obtaining a copy of this software and associated

belt-hash/README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,19 @@
99

1010
Pure Rust implementation of the [BelT] hash function specified in [STB 34.101.31-2020].
1111

12-
[Documentation][docs-link]
12+
## Examples
13+
```rust
14+
use belt_hash::{BeltHash, Digest};
15+
use hex_literal::hex;
16+
17+
let mut hasher = BeltHash::new();
18+
hasher.update(b"hello world");
19+
let hash = hasher.finalize();
20+
21+
assert_eq!(hash, hex!("afb175816416fbadad4629ecbd78e1887789881f2d2e5b80c22a746b7ac7ba88"));
22+
```
23+
24+
Also, see the [examples section] in the RustCrypto/hashes readme.
1325

1426
## Minimum Supported Rust Version
1527

@@ -25,10 +37,10 @@ done with a minor version bump.
2537

2638
## License
2739

28-
Licensed under either of:
40+
The crate is licensed under either of:
2941

30-
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
31-
* [MIT license](http://opensource.org/licenses/MIT)
42+
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
43+
* [MIT license](http://opensource.org/licenses/MIT)
3244

3345
at your option.
3446

@@ -55,3 +67,4 @@ dual licensed as above, without any additional terms or conditions.
5567

5668
[BelT]: https://ru.wikipedia.org/wiki/BelT
5769
[STB 34.101.31-2020]: http://apmi.bsu.by/assets/files/std/belt-spec371.pdf
70+
[examples section]: https://github.com/RustCrypto/hashes#Examples

belt-hash/src/lib.rs

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,6 @@
1-
//! Pure Rust implementation of the [BelT] hash function specified in
2-
//! [STB 34.101.31-2020].
3-
//!
4-
//! # Usage
5-
//!
6-
//! ```rust
7-
//! use belt_hash::{BeltHash, Digest};
8-
//! use hex_literal::hex;
9-
//!
10-
//! // create a BelT hasher instance
11-
//! let mut hasher = BeltHash::new();
12-
//!
13-
//! // process input message
14-
//! hasher.update(b"hello world");
15-
//!
16-
//! // acquire hash digest in the form of Array,
17-
//! // which in this case is equivalent to [u8; 32]
18-
//! let result = hasher.finalize();
19-
//! let expected = hex!(
20-
//! "afb175816416fbadad4629ecbd78e1887789881f2d2e5b80c22a746b7ac7ba88"
21-
//! );
22-
//! assert_eq!(result[..], expected[..]);
23-
//! ```
24-
//!
25-
//! Also see [examples] in the RustCrypto/hashes readme.
26-
//!
27-
//! [BelT]: https://ru.wikipedia.org/wiki/BelT
28-
//! [STB 34.101.31-2020]: http://apmi.bsu.by/assets/files/std/belt-spec371.pdf
29-
//! [examples]: https://github.com/RustCrypto/hashes#usage
301
#![no_std]
2+
#![doc = include_str!("../README.md")]
3+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
314
#![doc(
325
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
336
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
@@ -52,6 +25,9 @@ use digest::{
5225
};
5326

5427
const U32_MASK: u128 = (1 << 32) - 1;
28+
const H0: [u32; 8] = [
29+
0xC8BA94B1, 0x3BF5080A, 0x8E006D36, 0xE45D4A58, 0x9DFA0485, 0xACC7B61B, 0xC2722E25, 0x0DCEFD02,
30+
];
5531

5632
/// Core BelT hasher state.
5733
#[derive(Clone)]
@@ -128,11 +104,7 @@ impl Default for BeltHashCore {
128104
Self {
129105
r: 0,
130106
s: [0; 4],
131-
#[rustfmt::skip]
132-
h: [
133-
0xC8BA94B1, 0x3BF5080A, 0x8E006D36, 0xE45D4A58,
134-
0x9DFA0485, 0xACC7B61B, 0xC2722E25, 0x0DCEFD02,
135-
],
107+
h: H0,
136108
}
137109
}
138110
}

belt-hash/tests/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,7 @@ fn belt_rand() {
1111
let mut h = BeltHash::new();
1212
feed_rand_16mib(&mut h);
1313
assert_eq!(
14-
h.finalize()[..],
15-
hex!(
16-
"a45053f80827d530008198c8185aa507"
17-
"403b4a21f591579f07c34358e5991754"
18-
)[..]
14+
h.finalize(),
15+
hex!("a45053f80827d530008198c8185aa507403b4a21f591579f07c34358e5991754")
1916
);
2017
}

blake2/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ hex-literal = "0.4"
2323
default = ["std"]
2424
std = ["digest/std"]
2525
reset = [] # Enable reset functionality
26-
simd = []
27-
simd_opt = ["simd"]
28-
simd_asm = ["simd_opt"]
26+
#simd = []
27+
#simd_opt = ["simd"]
28+
#simd_asm = ["simd_opt"]
2929
size_opt = [] # Optimize for code size. Removes some `inline(always)`

blake2/LICENSE-MIT

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
Copyright (c) 2015-2016 The blake2-rfc Developers, Cesar Barros
22
Copyright (c) 2017 Artyom Pavlov
3+
Copyright (c) 2017-2024 The RustCrypto Project Developers
34

45
Permission is hereby granted, free of charge, to any
56
person obtaining a copy of this software and associated

blake2/README.md

Lines changed: 65 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,67 @@
77
![Rust Version][rustc-image]
88
[![Project Chat][chat-image]][chat-link]
99

10-
Pure Rust implementation of the [BLAKE2 hash function][1] family.
10+
Pure Rust implementation of the [BLAKE2] hash function family.
1111

12-
[Documentation][docs-link]
12+
## Examples
13+
14+
### Fixed output size
15+
16+
```rust
17+
use blake2::{Blake2b512, Blake2s256, Digest};
18+
use hex_literal::hex;
19+
20+
// create a Blake2b512 object
21+
let mut hasher = Blake2b512::new();
22+
23+
// write input message
24+
hasher.update(b"hello world");
25+
26+
// read hash digest and consume hasher
27+
let res = hasher.finalize();
28+
assert_eq!(res, hex!(
29+
"021ced8799296ceca557832ab941a50b4a11f83478cf141f51f933f653ab9fbc"
30+
"c05a037cddbed06e309bf334942c4e58cdf1a46e237911ccd7fcf9787cbc7fd0"
31+
));
32+
33+
// same example for Blake2s256:
34+
let mut hasher = Blake2s256::new();
35+
hasher.update(b"hello world");
36+
let res = hasher.finalize();
37+
assert_eq!(res, hex!("9aec6806794561107e594b1f6a8a6b0c92a0cba9acf5e5e93cca06f781813b0b"));
38+
```
39+
40+
Also, see the [examples section] in the RustCrypto/hashes readme.
41+
42+
### Variable output size
43+
44+
This implementation supports run and compile time variable sizes.
45+
46+
Output size set at run time:
47+
```rust
48+
use blake2::Blake2bVar;
49+
use blake2::digest::{Update, VariableOutput};
50+
use hex_literal::hex;
51+
52+
let mut hasher = Blake2bVar::new(10).unwrap();
53+
hasher.update(b"my_input");
54+
let mut buf = [0u8; 10];
55+
hasher.finalize_variable(&mut buf).unwrap();
56+
assert_eq!(buf, hex!("2cc55c84e416924e6400"));
57+
```
58+
59+
Output size set at compile time:
60+
```rust
61+
use blake2::{Blake2b, Digest, digest::consts::U10};
62+
use hex_literal::hex;
63+
64+
type Blake2b80 = Blake2b<U10>;
65+
66+
let mut hasher = Blake2b80::new();
67+
hasher.update(b"my_input");
68+
let res = hasher.finalize();
69+
assert_eq!(res, hex!("2cc55c84e416924e6400"));
70+
```
1371

1472
## Minimum Supported Rust Version
1573

@@ -25,10 +83,10 @@ done with a minor version bump.
2583

2684
## License
2785

28-
Licensed under either of:
86+
The crate is licensed under either of:
2987

30-
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
31-
* [MIT license](http://opensource.org/licenses/MIT)
88+
* [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0)
89+
* [MIT license](http://opensource.org/licenses/MIT)
3290

3391
at your option.
3492

@@ -53,4 +111,5 @@ dual licensed as above, without any additional terms or conditions.
53111

54112
[//]: # (general links)
55113

56-
[1]: https://blake2.net/
114+
[BLAKE2]: https://blake2.net/
115+
[examples section]: https://github.com/RustCrypto/hashes#Examples

0 commit comments

Comments
 (0)