Skip to content

Commit 9225ab4

Browse files
authored
Use #![doc = include_str!("../README.md")] in all crates (#191)
1 parent 05c5beb commit 9225ab4

13 files changed

Lines changed: 224 additions & 296 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
3737
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
3838
[deps-image]: https://deps.rs/repo/github/RustCrypto/MACs/status.svg
3939
[deps-link]: https://deps.rs/repo/github/RustCrypto/MACs
40-
[msrv-1.85]: https://img.shields.io/badge/rustc-1.85.0+-blue.svg
40+
[msrv-1.85]: https://img.shields.io/badge/rustc-1.85+-blue.svg
4141

4242
[//]: # (crates)
4343

belt-mac/README.md

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

10-
Pure Rust implementation of [`belt-mac`].
10+
Pure Rust implementation of [`belt-mac`][1].
1111

1212
# Example
1313
```rust
@@ -31,18 +31,6 @@ mac.update(b"input message");
3131
mac.verify(&tag_bytes).unwrap();
3232
```
3333

34-
## Minimum Supported Rust Version
35-
36-
Rust **1.81** or higher.
37-
38-
Minimum supported Rust version can be changed in the future, but it will be
39-
done with a minor version bump.
40-
41-
## SemVer Policy
42-
43-
- All on-by-default features of this library are covered by SemVer
44-
- MSRV is considered exempt from SemVer as noted above
45-
4634
## License
4735

4836
Licensed under either of:
@@ -65,12 +53,12 @@ dual licensed as above, without any additional terms or conditions.
6553
[docs-image]: https://docs.rs/belt-mac/badge.svg
6654
[docs-link]: https://docs.rs/belt-mac/
6755
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
68-
[rustc-image]: https://img.shields.io/badge/rustc-1.81+-blue.svg
56+
[rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
6957
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
7058
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260044-MACs
7159
[build-image]: https://github.com/RustCrypto/MACs/workflows/belt-mac/badge.svg?branch=master&event=push
7260
[build-link]: https://github.com/RustCrypto/MACs/actions?query=workflow%3Abelt-mac
7361

7462
[//]: # (general links)
7563

76-
[belt-mac]: https://apmi.bsu.by/assets/files/std/belt-spec371.pdf
64+
[1]: https://apmi.bsu.by/assets/files/std/belt-spec371.pdf

belt-mac/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg",
55
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg"
66
)]
7-
#![forbid(unsafe_code)]
87
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
8+
#![forbid(unsafe_code)]
99
#![warn(missing_docs)]
1010

1111
pub use digest::{self, KeyInit, Mac};

cbc-mac/README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,28 @@
77
![Rust Version][rustc-image]
88
[![Project Chat][chat-image]][chat-link]
99

10-
Pure Rust implementation of the [Cipher Block Chaining Message Authentication Code (CBC-MAC)][CBC-MAC].
10+
Generic implementation of [Cipher Block Chaining Message Authentication Code (CBC-MAC)][CBC-MAC].
1111

12-
[Documentation][docs-link]
12+
**WARNING!** The algorithm has known weaknesses in case of variable-length
13+
messages. See the linked Wikipedia article for more information.
1314

14-
## Minimum Supported Rust Version
15+
## Examples
1516

16-
Rust **1.81** or higher.
17+
```rust
18+
use cbc_mac::{digest::KeyInit, CbcMac, Mac};
19+
use des::Des;
20+
use hex_literal::hex;
1721

18-
Minimum supported Rust version can be changed in the future, but it will be
19-
done with a minor version bump.
22+
// CBC-MAC with the DES block cipher is equivalent to DAA
23+
type Daa = CbcMac<Des>;
2024

21-
## SemVer Policy
22-
23-
- All on-by-default features of this library are covered by SemVer
24-
- MSRV is considered exempt from SemVer as noted above
25+
// test from FIPS 113
26+
let key = hex!("0123456789ABCDEF");
27+
let mut mac = Daa::new_from_slice(&key).unwrap();
28+
mac.update(b"7654321 Now is the time for ");
29+
let correct = hex!("F1D30F6849312CA4");
30+
mac.verify_slice(&correct).unwrap();
31+
```
2532

2633
## License
2734

@@ -45,7 +52,7 @@ dual licensed as above, without any additional terms or conditions.
4552
[docs-image]: https://docs.rs/cbc-mac/badge.svg
4653
[docs-link]: https://docs.rs/cbc-mac/
4754
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
48-
[rustc-image]: https://img.shields.io/badge/rustc-1.81+-blue.svg
55+
[rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
4956
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
5057
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260044-MACs
5158
[build-image]: https://github.com/RustCrypto/MACs/workflows/cbc-mac/badge.svg?branch=master&event=push

cbc-mac/src/lib.rs

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,11 @@
1-
//! [Cipher Block Chaining Message Authentication Code (CBC-MAC)][CBC-MAC]
2-
//! implemented in pure Rust and generic over block cipher.
3-
//!
4-
//! **WARNING!** The algorithm has known weaknesses in case of variable-length
5-
//! messages. See the linked Wikipedia article for more information.
6-
//!
7-
//! # Examples
8-
//!
9-
//! ```
10-
//! use cbc_mac::{digest::KeyInit, CbcMac, Mac};
11-
//! use des::Des;
12-
//! use hex_literal::hex;
13-
//!
14-
//! // CBC-MAC with the DES block cipher is equivalent to DAA
15-
//! type Daa = CbcMac<Des>;
16-
//!
17-
//! // test from FIPS 113
18-
//! let key = hex!("0123456789ABCDEF");
19-
//! let mut mac = Daa::new_from_slice(&key).unwrap();
20-
//! mac.update(b"7654321 Now is the time for ");
21-
//! let correct = hex!("F1D30F6849312CA4");
22-
//! mac.verify_slice(&correct).unwrap();
23-
//! ```
24-
//!
25-
//! [CBC-MAC]: https://en.wikipedia.org/wiki/CBC-MAC
26-
271
#![no_std]
2+
#![doc = include_str!("../README.md")]
283
#![doc(
294
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg",
305
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg"
316
)]
327
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
33-
#![deny(unsafe_code)]
8+
#![forbid(unsafe_code)]
349
#![warn(missing_docs)]
3510

3611
pub use digest::{self, KeyInit, Mac};

cmac/README.md

Lines changed: 35 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,45 @@
77
![Rust Version][rustc-image]
88
[![Project Chat][chat-image]][chat-link]
99

10-
Pure Rust implementation of the [Cipher-based Message Authentication Code (CMAC)][1].
10+
Generic implementation of [Cipher-based Message Authentication Code (CMAC)][1],
11+
otherwise known as OMAC1.
1112

12-
[Documentation][docs-link]
13+
## Examples
14+
We will use AES-128 block cipher from the [`aes`] crate.
1315

14-
## Minimum Supported Rust Version
16+
To get the authentication code:
1517

16-
Rust **1.81** or higher.
18+
```rust
19+
use aes::Aes128;
20+
use cmac::{digest::KeyInit, Cmac, Mac};
1721

18-
Minimum supported Rust version can be changed in the future, but it will be
19-
done with a minor version bump.
22+
// Create `Mac` trait implementation, namely CMAC-AES128
23+
let mut mac = Cmac::<Aes128>::new_from_slice(b"very secret key.").unwrap();
24+
mac.update(b"input message");
2025

21-
## SemVer Policy
26+
// `result` has type `Output` which is a thin wrapper around array of
27+
// bytes for providing constant time equality check
28+
let result = mac.finalize();
29+
// To get underlying array use the `into_bytes` method, but be careful,
30+
// since incorrect use of the tag value may permit timing attacks which
31+
// defeat the security provided by the `Output` wrapper
32+
let tag_bytes = result.into_bytes();
33+
```
2234

23-
- All on-by-default features of this library are covered by SemVer
24-
- MSRV is considered exempt from SemVer as noted above
35+
To verify the message:
36+
37+
```rust
38+
use aes::Aes128;
39+
use cmac::{digest::KeyInit, Cmac, Mac};
40+
41+
let mut mac = Cmac::<Aes128>::new_from_slice(b"very secret key.").unwrap();
42+
43+
mac.update(b"input message");
44+
45+
# let tag_bytes = mac.clone().finalize().into_bytes();
46+
// `verify` will return `Ok(())` if tag is correct, `Err(MacError)` otherwise
47+
mac.verify(&tag_bytes).unwrap();
48+
```
2549

2650
## License
2751

@@ -45,7 +69,7 @@ dual licensed as above, without any additional terms or conditions.
4569
[docs-image]: https://docs.rs/cmac/badge.svg
4670
[docs-link]: https://docs.rs/cmac/
4771
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
48-
[rustc-image]: https://img.shields.io/badge/rustc-1.81+-blue.svg
72+
[rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
4973
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
5074
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260044-MACs
5175
[build-image]: https://github.com/RustCrypto/MACs/workflows/cmac/badge.svg?branch=master&event=push
@@ -54,3 +78,4 @@ dual licensed as above, without any additional terms or conditions.
5478
[//]: # (general links)
5579

5680
[1]: https://en.wikipedia.org/wiki/One-key_MAC
81+
[`aes`]: https://docs.rs/aes

cmac/src/lib.rs

Lines changed: 1 addition & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,5 @@
1-
//! Generic implementation of [Cipher-based Message Authentication Code (CMAC)][1],
2-
//! otherwise known as OMAC1.
3-
//!
4-
//! # Examples
5-
//! We will use AES-128 block cipher from [aes](https://docs.rs/aes) crate.
6-
//!
7-
//! To get the authentication code:
8-
//!
9-
//! ```rust
10-
//! use aes::Aes128;
11-
//! use cmac::{digest::KeyInit, Cmac, Mac};
12-
//!
13-
//! // Create `Mac` trait implementation, namely CMAC-AES128
14-
//! let mut mac = Cmac::<Aes128>::new_from_slice(b"very secret key.").unwrap();
15-
//! mac.update(b"input message");
16-
//!
17-
//! // `result` has type `Output` which is a thin wrapper around array of
18-
//! // bytes for providing constant time equality check
19-
//! let result = mac.finalize();
20-
//! // To get underlying array use the `into_bytes` method, but be careful,
21-
//! // since incorrect use of the tag value may permit timing attacks which
22-
//! // defeat the security provided by the `Output` wrapper
23-
//! let tag_bytes = result.into_bytes();
24-
//! ```
25-
//!
26-
//! To verify the message:
27-
//!
28-
//! ```rust
29-
//! # use aes::Aes128;
30-
//! # use cmac::{digest::KeyInit, Cmac, Mac};
31-
//! let mut mac = Cmac::<Aes128>::new_from_slice(b"very secret key.").unwrap();
32-
//!
33-
//! mac.update(b"input message");
34-
//!
35-
//! # let tag_bytes = mac.clone().finalize().into_bytes();
36-
//! // `verify` will return `Ok(())` if tag is correct, `Err(MacError)` otherwise
37-
//! mac.verify(&tag_bytes).unwrap();
38-
//! ```
39-
//!
40-
//! [1]: https://en.wikipedia.org/wiki/One-key_MAC
41-
421
#![no_std]
2+
#![doc = include_str!("../README.md")]
433
#![doc(
444
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg",
455
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/26acc39f/logo.svg"

hmac/README.md

Lines changed: 95 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,92 @@
77
![Rust Version][rustc-image]
88
[![Project Chat][chat-image]][chat-link]
99

10-
Pure Rust implementation of the [Hash-based Message Authentication Code (HMAC)][1].
10+
Generic implementation of [Hash-based Message Authentication Code (HMAC)][1].
1111

12-
[Documentation][docs-link]
12+
To use it you will need a cryptographic hash function implementation which
13+
implements the [`digest`] crate traits. You can find compatible crates
14+
(e.g. [`sha2`]) in the [`RustCrypto/hashes`] repository.
1315

14-
## Minimum Supported Rust Version
16+
This crate provides four HMAC implementations: [`Hmac`], [`HmacReset`],
17+
[`SimpleHmac`], and [`SimpleHmacReset`].
1518

16-
Rust **1.81** or higher.
19+
The first two types are buffered wrappers around block-level
20+
[`block_api::HmacCore`] and [`block_api::HmacResetCore`] types respectively.
21+
Internally they uses efficient state representation, but work only with
22+
hash functions which expose block-level API and consume blocks eagerly
23+
(e.g. they will not work with the BLAKE2 family of hash functions).
1724

18-
Minimum supported Rust version can be changed in the future, but it will be
19-
done with a minor version bump.
25+
On the other hand, [`SimpleHmac`] and [`SimpleHmacReset`] are a bit less
26+
efficient, but work with all hash functions which implement
27+
the [`Digest`] trait.
2028

21-
## SemVer Policy
29+
[`Hmac`] and [`SimpleHmac`] do not support resetting MAC state (i.e. they
30+
do not implement the [`Reset`] and [`FixedOutputReset`] traits). Use
31+
[`HmacReset`] or [`SimpleHmacReset`] if you want to reuse MAC state.
2232

23-
- All on-by-default features of this library are covered by SemVer
24-
- MSRV is considered exempt from SemVer as noted above
33+
## Examples
34+
35+
Let us demonstrate how to use HMAC using the SHA-256 hash function
36+
implemented in the [`sha2`] crate.
37+
38+
In the following examples [`Hmac`] is interchangeable with [`SimpleHmac`].
39+
40+
To get authentication code:
41+
42+
```rust
43+
use sha2::Sha256;
44+
use hmac::{Hmac, KeyInit, Mac};
45+
use hex_literal::hex;
46+
47+
// Create alias for HMAC-SHA256
48+
type HmacSha256 = Hmac<Sha256>;
49+
50+
let mut mac = HmacSha256::new_from_slice(b"my secret and secure key")
51+
.expect("HMAC can take key of any size");
52+
mac.update(b"input message");
53+
54+
// `result` has type `CtOutput` which is a thin wrapper around array of
55+
// bytes for providing constant time equality check
56+
let result = mac.finalize();
57+
// To get underlying array use `into_bytes`, but be careful, since
58+
// incorrect use of the code value may permit timing attacks which defeats
59+
// the security provided by the `CtOutput`
60+
let code_bytes = result.into_bytes();
61+
let expected = hex!("
62+
97d2a569059bbcd8ead4444ff99071f4
63+
c01d005bcefe0d3567e1be628e5fdcd9
64+
");
65+
assert_eq!(code_bytes[..], expected[..]);
66+
```
67+
68+
To verify the message:
69+
70+
```rust
71+
use sha2::Sha256;
72+
use hmac::{Hmac, KeyInit, Mac};
73+
use hex_literal::hex;
74+
75+
type HmacSha256 = Hmac<Sha256>;
76+
77+
let mut mac = HmacSha256::new_from_slice(b"my secret and secure key")
78+
.expect("HMAC can take key of any size");
79+
80+
mac.update(b"input message");
81+
82+
let code_bytes = hex!("
83+
97d2a569059bbcd8ead4444ff99071f4
84+
c01d005bcefe0d3567e1be628e5fdcd9
85+
");
86+
// `verify_slice` will return `Ok(())` if code is correct, `Err(MacError)` otherwise
87+
mac.verify_slice(&code_bytes[..]).unwrap();
88+
```
89+
90+
## Block and input sizes
91+
92+
Usually it is assumed that block size is larger than output size. Due to the
93+
generic nature of the implementation, we must handle cases when this assumption
94+
does not hold. This is done by truncating hash output to the hash
95+
block size if needed.
2596

2697
## License
2798

@@ -47,10 +118,24 @@ dual licensed as above, without any additional terms or conditions.
47118
[build-image]: https://github.com/RustCrypto/MACs/actions/workflows/hmac.yml/badge.svg
48119
[build-link]: https://github.com/RustCrypto/MACs/actions/workflows/hmac.yml
49120
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
50-
[rustc-image]: https://img.shields.io/badge/rustc-1.81+-blue.svg
121+
[rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
51122
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
52123
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260044-MACs
53124

54125
[//]: # (general links)
55126

56127
[1]: https://en.wikipedia.org/wiki/HMAC
128+
[`digest`]: https://docs.rs/digest
129+
[`sha2`]: https://docs.rs/sha2
130+
[`RustCrypto/hashes`]: https://github.com/RustCrypto/hashes
131+
132+
[//]: # (intra-crate links)
133+
[`Reset`]: https://docs.rs/digest/latest/digest/trait.Reset.html
134+
[`Digest`]: https://docs.rs/digest/latest/digest/trait.Digest.html
135+
[`FixedOutputReset`]: https://docs.rs/digest/latest/digest/trait.FixedOutputReset.html
136+
[`Hmac`]: https://docs.rs/hmac/latest/hmac/struct.Hmac.html
137+
[`HmacReset`]: https://docs.rs/hmac/latest/hmac/struct.HmacReset.html
138+
[`SimpleHmac`]: https://docs.rs/hmac/latest/hmac/struct.SimpleHmac.html
139+
[`SimpleHmacReset`]: https://docs.rs/hmac/latest/hmac/struct.SimpleHmacReset.html
140+
[`block_api::HmacCore`]: https://docs.rs/hmac/latest/hmac/block_api/struct.HmacCore.html
141+
[`block_api::HmacResetCore`]: https://docs.rs/hmac/latest/hmac/block_api/struct.HmacResetCore.html

0 commit comments

Comments
 (0)