Skip to content

Commit 32029ac

Browse files
authored
sha1: switch name from sha-1 to sha1 (#350)
1 parent b13d772 commit 32029ac

File tree

5 files changed

+45
-121
lines changed

5 files changed

+45
-121
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Additionally all crates do not require the standard library (i.e. `no_std` capab
2222
| [MD4] | [`md4`] | [![crates.io](https://img.shields.io/crates/v/md4.svg)](https://crates.io/crates/md4) | [![Documentation](https://docs.rs/md4/badge.svg)](https://docs.rs/md4) | ![MSRV 1.41][msrv-1.41] | :broken_heart: |
2323
| [MD5] | [`md-5`] [:exclamation:] | [![crates.io](https://img.shields.io/crates/v/md-5.svg)](https://crates.io/crates/md-5) | [![Documentation](https://docs.rs/md-5/badge.svg)](https://docs.rs/md-5) | ![MSRV 1.41][msrv-1.41] | :broken_heart: |
2424
| [RIPEMD] | [`ripemd`] | [![crates.io](https://img.shields.io/crates/v/ripemd.svg)](https://crates.io/crates/ripemd) | [![Documentation](https://docs.rs/ripemd/badge.svg)](https://docs.rs/ripemd) | ![MSRV 1.41][msrv-1.41] | :green_heart: |
25-
| [SHA-1] | [`sha-1`] [:exclamation:] | [![crates.io](https://img.shields.io/crates/v/sha-1.svg)](https://crates.io/crates/sha-1) | [![Documentation](https://docs.rs/sha-1/badge.svg)](https://docs.rs/sha-1) | ![MSRV 1.41][msrv-1.41] | :broken_heart: |
25+
| [SHA-1] | [`sha1`] | [![crates.io](https://img.shields.io/crates/v/sha1.svg)](https://crates.io/crates/sha1) | [![Documentation](https://docs.rs/sha1/badge.svg)](https://docs.rs/sha1) | ![MSRV 1.41][msrv-1.41] | :broken_heart: |
2626
| [SHA-2] | [`sha2`] | [![crates.io](https://img.shields.io/crates/v/sha2.svg)](https://crates.io/crates/sha2) | [![Documentation](https://docs.rs/sha2/badge.svg)](https://docs.rs/sha2) | ![MSRV 1.41][msrv-1.41] | :green_heart: |
2727
| [SHA-3] (Keccak) | [`sha3`] | [![crates.io](https://img.shields.io/crates/v/sha3.svg)](https://crates.io/crates/sha3) | [![Documentation](https://docs.rs/sha3/badge.svg)](https://docs.rs/sha3) | ![MSRV 1.41][msrv-1.41] | :green_heart: |
2828
| [SHABAL] | [`shabal`] | [![crates.io](https://img.shields.io/crates/v/shabal.svg)](https://crates.io/crates/shabal) | [![Documentation](https://docs.rs/shabal/badge.svg)](https://docs.rs/shabal) | ![MSRV 1.41][msrv-1.41] | :green_heart: |
@@ -31,17 +31,21 @@ Additionally all crates do not require the standard library (i.e. `no_std` capab
3131
| [Tiger] | [`tiger`] | [![crates.io](https://img.shields.io/crates/v/tiger.svg)](https://crates.io/crates/tiger) | [![Documentation](https://docs.rs/tiger/badge.svg)](https://docs.rs/tiger) | ![MSRV 1.41][msrv-1.41] | :green_heart: |
3232
| [Whirlpool] | [`whirlpool`] | [![crates.io](https://img.shields.io/crates/v/whirlpool.svg)](https://crates.io/crates/whirlpool) | [![Documentation](https://docs.rs/whirlpool/badge.svg)](https://docs.rs/whirlpool) | ![MSRV 1.41][msrv-1.41] | :green_heart: |
3333

34-
NOTE: the [BLAKE3 crate](https://github.com/BLAKE3-team/BLAKE3) implements the `digest` traits used by the rest of the hashes in this repository, but is maintained by the BLAKE3 team.
34+
NOTE: the [`blake3`] crate implements the `digest` traits used by the rest of the hashes in this repository, but is maintained by the BLAKE3 team.
3535

3636
[Security]: https://en.wikipedia.org/wiki/Hash_function_security_summary
3737
[:exclamation:]: #crate-names
3838

3939
### Crate Names
4040

4141
Whenever possible crates are published under the the same name as the crate folder.
42-
Owners of `md5` and `sha1` declined ([1](https://github.com/stainless-steel/md5/pull/2), [2](https://github.com/mitsuhiko/rust-sha1/issues/17)) to participate in this project.
43-
Those crates do not implement the [`digest`] traits, so they are not interoperable with the RustCrypto ecosystem.
44-
This is why crates marked by :exclamation: are published under `md-5` and `sha-1` names, but the libraries themselves are named as `md5` and `sha1`, i.e. inside `use` statements you should use `sha1`/`md5`, not `sha_1`/`md_5`.
42+
Owners of `md5` [declined](https://github.com/stainless-steel/md5/pull/) to participate in this project.
43+
This crate does not implement the [`digest`] traits, so it is not interoperable with the RustCrypto ecosystem.
44+
This is why we publish our MD5 implementation as `md-5` and mark it with the :exclamation: mark.
45+
Note that the library itselv is named as `md5`, i.e. inside `use` statements you should use `md5`, not `md_5`.
46+
47+
The SHA-1 implementation was previosuly published as `sha-1`, but migrated to `sha1` since v0.10.0.
48+
`sha-1` will continue to recieve v0.10.x patch updates, but will be deprecated after `sha1` v0.11 release.
4549

4650
### Security Level Legend
4751

@@ -92,12 +96,22 @@ hasher.update(data);
9296
hasher.update("String data");
9397
// Note that calling `finalize()` consumes hasher
9498
let hash = hasher.finalize();
95-
println!("Result: {:x}", hash);
99+
println!("Binary hash: {:?}", hash);
96100
```
97101

98102
In this example `hash` has type `GenericArray<u8, U32>`, which is a generic alternative to `[u8; 32]` defined in the [`generic-array`] crate.
103+
If you need to serialize hash value into string, you can use crates like [`base16ct`] and [`base64ct`]:
104+
```rust
105+
use base64ct::{Base64, Encoding};
106+
107+
let base64_hash = Base64::encode_string(&hash);
108+
println!("Base64-encoded hash: {}", hex_hash);
99109

100-
Alternatively, you can use a chained approach, which is equivalent to the previous example:
110+
let hex_hash = base16ct::lower::encode_string(&hash);
111+
println!("Hex-encoded hash: {}", hex_hash);
112+
```
113+
114+
Instead of calling `update`, you also can use a chained approach:
101115

102116
```rust
103117
use sha2::{Sha256, Digest};
@@ -106,16 +120,14 @@ let hash = Sha256::new()
106120
.chain_update(b"Hello world!")
107121
.chain_update("String data")
108122
.finalize();
109-
println!("Result: {:x}", hash);
110123
```
111124

112-
If a complete message is available, then you also can use the convenience [`Digest::digest`] method:
125+
If a complete message is available, then you can use the convenience [`Digest::digest`] method:
113126

114127
```rust
115128
use sha2::{Sha256, Digest};
116129

117130
let hash = Sha256::digest(b"my message");
118-
println!("Result: {:x}", hash);
119131
```
120132

121133
### Hashing `Read`able Objects
@@ -130,9 +142,6 @@ let mut file = fs::File::open(&path)?;
130142
let mut hasher = Sha256::new();
131143
let n = io::copy(&mut file, &mut hasher)?;
132144
let hash = hasher.finalize();
133-
134-
println!("Bytes processed: {}", n);
135-
println!("Hash value: {:x}", hash);
136145
```
137146

138147
### Hash-based Message Authentication Code (HMAC)
@@ -176,10 +185,10 @@ fn dyn_hash(hasher: &mut dyn DynDigest, data: &[u8]) -> Box<[u8]> {
176185
let mut sha256_hasher = Sha256::default();
177186
let mut sha512_hasher = Sha512::default();
178187

179-
let res1 = dyn_hash(&mut sha256_hasher, b"foo");
180-
let res2 = dyn_hash(&mut sha256_hasher, b"bar");
181-
let res3 = dyn_hash(&mut sha512_hasher, b"foo");
182-
let res4 = dyn_hash(&mut sha512_hasher, b"bar");
188+
let hash1 = dyn_hash(&mut sha256_hasher, b"foo");
189+
let hash2 = dyn_hash(&mut sha256_hasher, b"bar");
190+
let hash3 = dyn_hash(&mut sha512_hasher, b"foo");
191+
let hash4 = dyn_hash(&mut sha512_hasher, b"bar");
183192
```
184193

185194
## License
@@ -215,7 +224,7 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
215224
[`md4`]: ./md4
216225
[`md-5`]: ./md-5
217226
[`ripemd`]: ./ripemd
218-
[`sha-1`]: ./sha1
227+
[`sha1`]: ./sha1
219228
[`sha2`]: ./sha2
220229
[`sha3`]: ./sha3
221230
[`shabal`]: ./shabal
@@ -227,6 +236,9 @@ Unless you explicitly state otherwise, any contribution intentionally submitted
227236
[//]: # (footnotes)
228237

229238
[1]: https://en.wikipedia.org/wiki/Cryptographic_hash_function
239+
[`blake3`]: https://github.com/BLAKE3-team/BLAKE3
240+
[`base16ct`]: https://docs.rs/base16ct
241+
[`base64ct`]: https://docs.rs/base64ct
230242
[`digest`]: https://docs.rs/digest
231243
[`Digest`]: https://docs.rs/digest/0.10.0/digest/trait.Digest.html
232244
[`Digest::digest`]: https://docs.rs/digest/0.10.0/digest/trait.Digest.html#tymethod.digest

sha1/CHANGELOG.md

Lines changed: 3 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -5,101 +5,8 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8-
## 0.10.0 (2021-12-07)
8+
## 0.10.0 (2022-01-17)
99
### Changed
10-
- Update to `digest` v0.10 ([#217])
10+
- The crate is transferred to the RustCrypto organization. New implementation is identical to the `sha-1 v0.10.0` crate and expressed in terms of traits from the `digest` crate. ([#350])
1111

12-
[#217]: https://github.com/RustCrypto/hashes/pull/217
13-
14-
## 0.9.8 (2021-08-27)
15-
### Changed
16-
- Bump `cpufeatures` dependency to 0.2 ([#306])
17-
18-
[#306]: https://github.com/RustCrypto/hashes/pull/306
19-
20-
## 0.9.7 (2021-07-18)
21-
### Changed
22-
- Make `aarch64` CPU feature detection OS-independent ([#276])
23-
- Bump `sha1-asm` to v0.5; support ARMv8 Crypto Extensions on Apple targets ([#289])
24-
25-
[#276]: https://github.com/RustCrypto/hashes/pull/276
26-
[#289]: https://github.com/RustCrypto/hashes/pull/289
27-
28-
## 0.9.6 (2021-05-11)
29-
### Changed
30-
- Use `cpufeatures` to detect intrinsics support on `aarch64` targets ([#268])
31-
32-
[#268]: https://github.com/RustCrypto/hashes/pull/268
33-
34-
## 0.9.5 (2021-05-05)
35-
### Changed
36-
- Switch from `cpuid-bool` to `cpufeatures` ([#263])
37-
38-
[#263]: https://github.com/RustCrypto/hashes/pull/263
39-
40-
## 0.9.4 (2021-02-16)
41-
### Added
42-
- Expose compression function under the `compress` feature flag. ([#238])
43-
44-
[#238]: https://github.com/RustCrypto/hashes/pull/238
45-
46-
## 0.9.3 (2021-02-01)
47-
### Changed
48-
- Use SHA1 intrinsics when `asm` feature is enabled. ([#225])
49-
50-
[#225]: https://github.com/RustCrypto/hashes/pull/225
51-
52-
## 0.9.2 (2020-11-04)
53-
### Added
54-
- `force-soft` feature to enforce use of software implementation. ([#203])
55-
56-
### Changed
57-
- `cfg-if` dependency updated to v1.0. ([#197])
58-
59-
[#197]: https://github.com/RustCrypto/hashes/pull/197
60-
[#203]: https://github.com/RustCrypto/hashes/pull/203
61-
62-
## 0.9.1 (2020-06-24)
63-
### Added
64-
- x86 hardware acceleration via SHA extension instrinsics. ([#167])
65-
66-
[#167]: https://github.com/RustCrypto/hashes/pull/167
67-
68-
## 0.9.0 (2020-06-09)
69-
### Changed
70-
- Update to `digest` v0.9 release; MSRV 1.41+ ([#155])
71-
- Use new `*Dirty` traits from the `digest` crate ([#153])
72-
- Bump `block-buffer` to v0.8 release ([#151])
73-
- Rename `*result*` to `finalize` ([#148])
74-
- Upgrade to Rust 2018 edition ([#132])
75-
- Use `libc` for `aarch64` consts ([#94])
76-
- Allow compile-time detection of crypto on `aarch64` ([#94])
77-
78-
[#155]: https://github.com/RustCrypto/hashes/pull/155
79-
[#153]: https://github.com/RustCrypto/hashes/pull/153
80-
[#151]: https://github.com/RustCrypto/hashes/pull/151
81-
[#148]: https://github.com/RustCrypto/hashes/pull/148
82-
[#132]: https://github.com/RustCrypto/hashes/pull/132
83-
[#94]: https://github.com/RustCrypto/hashes/pull/94
84-
85-
## 0.8.2 (2020-01-06)
86-
87-
## 0.8.1 (2018-11-14)
88-
89-
## 0.8.0 (2018-10-02)
90-
91-
## 0.7.0 (2017-11-15)
92-
93-
## 0.4.1 (2017-06-13)
94-
95-
## 0.4.0 (2017-06-12)
96-
97-
## 0.3.4 (2017-06-04)
98-
99-
## 0.3.3 (2017-05-09)
100-
101-
## 0.3.2 (2017-05-02)
102-
103-
## 0.3.1 (2017-04-18)
104-
105-
## 0.3.0 (2017-04-06)
12+
[#350]: https://github.com/RustCrypto/hashes/pull/350

sha1/Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,17 @@
11
[package]
2-
name = "sha-1"
2+
name = "sha1"
33
version = "0.10.0" # Also update html_root_url in lib.rs when bumping this
4+
# on v0.10.x releases also release the sha-1 crate as well
45
description = "SHA-1 hash function"
56
authors = ["RustCrypto Developers"]
67
license = "MIT OR Apache-2.0"
78
readme = "README.md"
89
edition = "2018"
9-
documentation = "https://docs.rs/sha-1"
10+
documentation = "https://docs.rs/sha1"
1011
repository = "https://github.com/RustCrypto/hashes"
1112
keywords = ["crypto", "sha1", "hash", "digest"]
1213
categories = ["cryptography", "no-std"]
1314

14-
[lib]
15-
name = "sha1"
16-
1715
[dependencies]
1816
digest = "0.10"
1917
cfg-if = "1.0"

sha1/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,23 @@
2929
//!
3030
//! Also see [RustCrypto/hashes][3] readme.
3131
//!
32+
//! # Note for users of `sha1 v0.6`
33+
//!
34+
//! This crate has been transferred to the RustCrypto organization and uses
35+
//! implementation previously published as the `sha-1` crate. The previous
36+
//! zero dependencies version is now published as the [`sha1_smoll`] crate.
37+
//!
3238
//! [1]: https://en.wikipedia.org/wiki/SHA-1
3339
//! [2]: https://sha-mbles.github.io/
3440
//! [3]: https://github.com/RustCrypto/hashes
41+
//! [`sha1_smoll`]: https://github.com/mitsuhiko/sha1-smol/
3542
3643
#![no_std]
3744
#![cfg_attr(docsrs, feature(doc_cfg))]
3845
#![doc(
3946
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
4047
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
41-
html_root_url = "https://docs.rs/sha-1/0.10.0"
48+
html_root_url = "https://docs.rs/sha1/0.10.0"
4249
)]
4350
#![warn(missing_docs, rust_2018_idioms)]
4451

0 commit comments

Comments
 (0)