Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
{"$comment":"This file only protects against accidental modifications. It is not a security mechanism and does not protect against malicious changes.","files":{".cargo_vcs_info.json":"5450a83cfe0af1058b39b762599d6f723406373431afc6d492f42cc18ab53755","CHANGELOG.md":"515a21a127e7fdd18a9b372c0b70c31b9694c732ed54fd223bca03250b1199a1","Cargo.lock":"8485d13d33edf05a6c7cd1c425dcf83e877fb4c92b8743926f46746a2b8454b2","Cargo.toml":"98856c5ab681142c6199ab7c5375731444cb7e0c6b7de54754e60d86ffe81f6a","Cargo.toml.orig":"d64b41df830dfae6cd9f1e33404d9d4a60f4ac65a6dad301ef58d2e6993b6fcd","LICENSE-APACHE":"59013a5c8d3a19c26a457579105915a5d51bb0c09d579f8cdedf12e4203c3018","LICENSE-MIT":"d288f9c9b4590446ec18c22ead8f8b5a12a3d4025b68f62dc9015063eb9cca69","README.md":"888ed3a0087a6307c119cbf1517edb07b510a69600431e0376f2652d50a70644","benches/mod.rs":"ecb5e2dd2f9c65bd034edb93060d005a2e73ba4d02a6dab5088aa3dab36aa579","src/errors.rs":"3726025c89f0b236ab1c33f9f22ce4765282f77f1aa9117132bb1cad9f9d899b","src/hmac_impl.rs":"bf4a2c9632ce498a8ef3a4b147447c3fd449d7de273c61192311741358cbf6c1","src/lib.rs":"11749cd8d24cd23569770f6b442ab537285139b8b7d103ab2d3abac0e5c892de","tests/data/rfc5869_sha1.blb":"074edf62b4feeba7f98faeed282b1276cb75fbad2e3bafc5c1de23d32dfba82c","tests/data/rfc5869_sha256.blb":"c00cdd6b39d34b800bbb5081a8f4139e3dd550683d077ffa525e8cd87e389961","tests/data/wycheproof_sha1.blb":"e1d9df8ed19aeea433f57153cd2b053e5c79aa7dcc10d941412757185cee1141","tests/data/wycheproof_sha256.blb":"f705b50364411b3add9c23ba1d989c281bad8336abb3e2399e8368839847974a","tests/data/wycheproof_sha384.blb":"161f61483386c00a6e5c886c364a1da9a12f51db8c7db6778e7bce48ee670e1c","tests/data/wycheproof_sha512.blb":"45d4e987601f0fcb2a9221a8d6543f55f2bbf90227b779a89dc08b89709080ed","tests/rfc5869.rs":"b23e218da8388b188317ce10588940a31913eed646e0e388107c89a5355d4428","tests/tests.rs":"9c2e0056af44f3a5af588d0096be579004f953c50ed84175d744f83ee037126b","tests/wycheproof.rs":"dc828fc4c1f78c34e332a6b9bf102dc6aaf323e10d4800a8b5b0f71670331971"},"package":"4aaa26c720c68b866f2c96ef5c1264b3e6f473fe5d4ce61cd44bbe913e553018"}
+6
View File
@@ -0,0 +1,6 @@
{
"git": {
"sha1": "bfb3b209abeeaa02277935b167e06bac320b2773"
},
"path_in_vcs": "hkdf"
}
+138
View File
@@ -0,0 +1,138 @@
# Changelog
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.13.0 (2026-03-30)
### Added
- New `Hkdf` and `HkdfExtract` type aliases for `GenericHkdf` and `GenericHkdfExtract` ([#155])
- Implement `kdf::Kdf` for `GenericHkdfExtract` ([#173])
### Changed
- Bump MSRV to 1.85 and edition to 2024 ([#114])
- Bump `hmac` dependency to v0.13
- Use `digest::EagerHash` ([#148])
- Unseal `HmacImpl` trait ([#154])
- Rename `Hkdf` and `HkdfExtract` to `GenericHkdf` and `GenericHkdfExtract` respectively ([#155])
- Use simplified `H: HmacImpl` bounds ([#155])
### Removed
- `std` crate feature ([#105])
[#105]: https://github.com/RustCrypto/KDFs/pull/105
[#114]: https://github.com/RustCrypto/KDFs/pull/114
[#148]: https://github.com/RustCrypto/KDFs/pull/148
[#154]: https://github.com/RustCrypto/KDFs/pull/154
[#155]: https://github.com/RustCrypto/KDFs/pull/155
[#173]: https://github.com/RustCrypto/KDFs/pull/173
## 0.12.3 (2022-02-17)
### Fixed
- Minimal versions build ([#63])
[#63]: https://github.com/RustCrypto/KDFs/pull/63
## 0.12.2 (2022-01-27)
### Fixed
- Re-export `InvalidLength` and `InvalidPrkLength` ([#59])
[#59]: https://github.com/RustCrypto/KDFs/pull/59
## 0.12.1 (2022-01-27) [YANKED]
### Added
- Ability to switch HMAC implementation to `SimpleHmac` with respective `SimpleHkdfExtract` and `SimpleHkdf` aliases ([#57])
[#57]: https://github.com/RustCrypto/KDFs/pull/55
## 0.12.0 (2021-12-07)
### Changed
- Bump `hmac` crate dependency to v0.12 and `digest` to v0.10 ([#52])
[#52]: https://github.com/RustCrypto/KDFs/pull/52
## 0.11.0 (2021-04-29)
### Added
- Wycheproof HKDF test vectors ([#49])
### Changed
- Bump `hmac` crate dependency to v0.11 ([#50])
### Fixed
- HKDF-Extract with empty salt ([#46])
[#46]: https://github.com/RustCrypto/KDFs/pull/46
[#49]: https://github.com/RustCrypto/KDFs/pull/49
[#50]: https://github.com/RustCrypto/KDFs/pull/50
## 0.10.0 (2020-10-26)
### Changed
- Bump `hmac` dependency to v0.10 ([#40])
[#40]: https://github.com/RustCrypto/KDFs/pull/40
## 0.9.0 (2020-06-22)
### Added
- Multipart features for HKDF-Extract and HKDF-Expand ([#34])
### Changed
- Bump `digest` v0.9; `hmac` v0.9 ([#35])
[#34]: https://github.com/RustCrypto/KDFs/pull/34
[#35]: https://github.com/RustCrypto/KDFs/pull/35
## 0.8.0 (2019-07-26)
### Added
- `Hkdf::from_prk()`, `Hkdf::extract()`
## 0.7.1 (2019-07-15)
## 0.7.0 (2018-10-16)
### Changed
- Update digest to 0.8
- Refactor for API changes
### Removed
- Redundant `generic-array` crate.
## 0.6.0 (2018-08-20)
### Changed
- The `expand` signature has changed.
### Removed
- `std` requirement
## 0.5.0 (2018-05-20)
### Fixed
- Omitting HKDF salt.
### Removed
- Deprecated interface
## 0.4.0 (2018-03-20
### Added
- Benchmarks
- derive `Clone`
### Changed
- RFC-inspired interface
- Reduce heap allocation
- Bump deps: hex-0.3
### Removed
- Unnecessary mut
## 0.3.0 (2017-11-29)
### Changed
- update dependencies: digest-0.7, hmac-0.5
## 0.2.0 (2017-09-21)
### Fixed
- Support for rustc 1.20.0
## 0.1.2 (2017-09-21)
### Fixed
- Support for rustc 1.5.0
## 0.1.0 (2017-09-21)
- Initial release
+144
View File
@@ -0,0 +1,144 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 4
[[package]]
name = "blobby"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "89af0b093cc13baa4e51e64e65ec2422f7e73aea0e612e5ad3872986671622f1"
[[package]]
name = "block-buffer"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdd35008169921d80bc60d3d0ab416eecb028c4cd653352907921d95084790be"
dependencies = [
"hybrid-array",
]
[[package]]
name = "cfg-if"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
[[package]]
name = "cmov"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de0758edba32d61d1fd9f4d69491b47604b91ee2f7e6b33de7e54ca4ebe55dc3"
[[package]]
name = "cpufeatures"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201"
dependencies = [
"libc",
]
[[package]]
name = "crypto-common"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77727bb15fa921304124b128af125e7e3b968275d1b108b379190264f4423710"
dependencies = [
"hybrid-array",
]
[[package]]
name = "ctutils"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1005a6d4446f5120ef475ad3d2af2b30c49c2c9c6904258e3bb30219bebed5e4"
dependencies = [
"cmov",
]
[[package]]
name = "digest"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4850db49bf08e663084f7fb5c87d202ef91a3907271aff24a94eb97ff039153c"
dependencies = [
"block-buffer",
"crypto-common",
"ctutils",
]
[[package]]
name = "hex-literal"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e712f64ec3850b98572bffac52e2c6f282b29fe6c5fa6d42334b30be438d95c1"
[[package]]
name = "hkdf"
version = "0.13.0"
dependencies = [
"blobby",
"hex-literal",
"hmac",
"kdf",
"sha1",
"sha2",
]
[[package]]
name = "hmac"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6303bc9732ae41b04cb554b844a762b4115a61bfaa81e3e83050991eeb56863f"
dependencies = [
"digest",
]
[[package]]
name = "hybrid-array"
version = "0.4.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8655f91cd07f2b9d0c24137bd650fe69617773435ee5ec83022377777ce65ef1"
dependencies = [
"typenum",
]
[[package]]
name = "kdf"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fb9652713a34bd7a2f539adcab233163943bed9c685970db62eb3cb264d625a1"
[[package]]
name = "libc"
version = "0.2.183"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
[[package]]
name = "sha1"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "aacc4cc499359472b4abe1bf11d0b12e688af9a805fa5e3016f9a386dc2d0214"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "sha2"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "446ba717509524cb3f22f17ecc096f10f4822d76ab5c0b9822c5f9c284e825f4"
dependencies = [
"cfg-if",
"cpufeatures",
"digest",
]
[[package]]
name = "typenum"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "562d481066bde0658276a35467c4af00bdc6ee726305698a55b86e61d7ad82bb"
+122
View File
@@ -0,0 +1,122 @@
# THIS FILE IS AUTOMATICALLY GENERATED BY CARGO
#
# When uploading crates to the registry Cargo will automatically
# "normalize" Cargo.toml files for maximal compatibility
# with all versions of Cargo and also rewrite `path` dependencies
# to registry (e.g., crates.io) dependencies.
#
# If you are reading this file be aware that the original Cargo.toml
# will likely look very different (and much more reasonable).
# See Cargo.toml.orig for the original contents.
[package]
edition = "2024"
rust-version = "1.85"
name = "hkdf"
version = "0.13.0"
authors = ["RustCrypto Developers"]
build = false
autolib = false
autobins = false
autoexamples = false
autotests = false
autobenches = false
description = "HMAC-based Extract-and-Expand Key Derivation Function (HKDF)"
homepage = "https://github.com/RustCrypto/KDFs/"
readme = "README.md"
keywords = [
"crypto",
"HKDF",
"KDF",
]
categories = [
"cryptography",
"no-std",
]
license = "MIT OR Apache-2.0"
repository = "https://github.com/RustCrypto/KDFs/"
resolver = "2"
[package.metadata.docs.rs]
all-features = true
[lib]
name = "hkdf"
path = "src/lib.rs"
[[test]]
name = "rfc5869"
path = "tests/rfc5869.rs"
[[test]]
name = "tests"
path = "tests/tests.rs"
[[test]]
name = "wycheproof"
path = "tests/wycheproof.rs"
[[bench]]
name = "mod"
path = "benches/mod.rs"
[dependencies.hmac]
version = "0.13"
[dependencies.kdf]
version = "0.1"
optional = true
[dev-dependencies.blobby]
version = "0.4"
[dev-dependencies.hex-literal]
version = "1"
[dev-dependencies.sha1]
version = "0.11"
default-features = false
[dev-dependencies.sha2]
version = "0.11"
default-features = false
[lints.clippy]
borrow_as_ptr = "warn"
cast_lossless = "warn"
cast_possible_truncation = "warn"
cast_possible_wrap = "warn"
cast_precision_loss = "warn"
cast_sign_loss = "warn"
checked_conversions = "warn"
doc_markdown = "warn"
from_iter_instead_of_collect = "warn"
implicit_saturating_sub = "warn"
manual_assert = "warn"
map_unwrap_or = "warn"
missing_errors_doc = "warn"
missing_panics_doc = "warn"
mod_module_files = "warn"
must_use_candidate = "warn"
needless_range_loop = "allow"
ptr_as_ptr = "warn"
redundant_closure_for_method_calls = "warn"
ref_as_ptr = "warn"
return_self_not_must_use = "warn"
semicolon_if_nothing_returned = "warn"
std_instead_of_alloc = "warn"
std_instead_of_core = "warn"
trivially_copy_pass_by_ref = "warn"
undocumented_unsafe_blocks = "warn"
unnecessary_safety_comment = "warn"
unwrap_used = "warn"
[lints.rust]
missing_copy_implementations = "warn"
missing_debug_implementations = "warn"
missing_docs = "warn"
trivial_casts = "warn"
trivial_numeric_casts = "warn"
unsafe_code = "forbid"
unused_lifetimes = "warn"
unused_qualifications = "warn"
+31
View File
@@ -0,0 +1,31 @@
[package]
name = "hkdf"
version = "0.13.0"
authors = ["RustCrypto Developers"]
license = "MIT OR Apache-2.0"
homepage = "https://github.com/RustCrypto/KDFs/"
repository = "https://github.com/RustCrypto/KDFs/"
description = "HMAC-based Extract-and-Expand Key Derivation Function (HKDF)"
keywords = ["crypto", "HKDF", "KDF"]
categories = ["cryptography", "no-std"]
readme = "README.md"
edition = "2024"
rust-version = "1.85"
[dependencies]
hmac = "0.13"
# optional dependencies
kdf = { version = "0.1", optional = true }
[dev-dependencies]
blobby = "0.4"
hex-literal = "1"
sha1 = { version = "0.11", default-features = false }
sha2 = { version = "0.11", default-features = false }
[lints]
workspace = true
[package.metadata.docs.rs]
all-features = true
+201
View File
@@ -0,0 +1,201 @@
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
file or class name and description of purpose be included on the
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
+26
View File
@@ -0,0 +1,26 @@
Copyright (c) 2015-2018 Vlad Filippov
Copyright (c) 2018-2021 RustCrypto Developers
Permission is hereby granted, free of charge, to any
person obtaining a copy of this software and associated
documentation files (the "Software"), to deal in the
Software without restriction, including without
limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software
is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice
shall be included in all copies or substantial portions
of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
+118
View File
@@ -0,0 +1,118 @@
# [RustCrypto]: HKDF
[![crate][crate-image]][crate-link]
[![Docs][docs-image]][docs-link]
![Apache2/MIT licensed][license-image]
![Rust Version][rustc-image]
[![Project Chat][chat-image]][chat-link]
[![Build Status][build-image]][build-link]
Pure Rust implementation of the [HMAC-based Extract-and-Expand Key Derivation Function (HKDF)](https://tools.ietf.org/html/rfc5869) generic over hash function.
# Usage
The most common way to use HKDF is as follows: you provide the Initial Key Material (IKM) and an optional salt, then you expand it (perhaps multiple times) into some Output Key Material (OKM) bound to an "info" context string.
```rust
use sha2::Sha256;
use hkdf::Hkdf;
use hex_literal::hex;
let ikm = hex!("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
let salt = hex!("000102030405060708090a0b0c");
let info = hex!("f0f1f2f3f4f5f6f7f8f9");
let hk = Hkdf::<Sha256>::new(Some(&salt[..]), &ikm);
let mut okm = [0u8; 42];
hk.expand(&info, &mut okm)
.expect("42 is a valid length for Sha256 to output");
let expected = hex!("
3cb25f25faacd57a90434f64d0362f2a
2d2d0a90cf1a5a4c5db02d56ecc4c5bf
34007208d5b887185865
");
assert_eq!(okm, expected);
```
Normally the PRK (Pseudo-Random Key) remains hidden within the HKDF object, but if you need to access it, use `Hkdf::extract` instead of `Hkdf::new`.
```rust
use sha2::Sha256;
use hkdf::Hkdf;
use hex_literal::hex;
let ikm = hex!("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
let salt = hex!("000102030405060708090a0b0c");
let (prk, hk) = Hkdf::<Sha256>::extract(Some(&salt[..]), &ikm);
let expected = hex!("
077709362c2e32df0ddc3f0dc47bba63
90b6c73bb50f9c3122ec844ad7c2b3e5
");
assert_eq!(prk[..], expected[..]);
```
If you already have a strong key to work from (uniformly-distributed and
long enough), you can save a tiny amount of time by skipping the extract
step. In this case, you pass a Pseudo-Random Key (PRK) into the
`Hkdf::from_prk` constructor, then use the resulting `Hkdf` object
as usual.
```rust
use sha2::Sha256;
use hkdf::Hkdf;
use hex_literal::hex;
let salt = hex!("000102030405060708090a0b0c");
let info = hex!("f0f1f2f3f4f5f6f7f8f9");
let prk = hex!("
077709362c2e32df0ddc3f0dc47bba63
90b6c73bb50f9c3122ec844ad7c2b3e5
");
let hk = Hkdf::<Sha256>::from_prk(&prk).expect("PRK should be large enough");
let mut okm = [0u8; 42];
hk.expand(&info, &mut okm)
.expect("42 is a valid length for Sha256 to output");
let expected = hex!("
3cb25f25faacd57a90434f64d0362f2a
2d2d0a90cf1a5a4c5db02d56ecc4c5bf
34007208d5b887185865
");
assert_eq!(okm, expected);
```
## 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/hkdf.svg
[crate-link]: https://crates.io/crates/hkdf
[docs-image]: https://docs.rs/hkdf/badge.svg
[docs-link]: https://docs.rs/hkdf/
[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg
[rustc-image]: https://img.shields.io/badge/rustc-1.85+-blue.svg
[chat-image]: https://img.shields.io/badge/zulip-join_chat-blue.svg
[chat-link]: https://rustcrypto.zulipchat.com/#narrow/stream/260043-KDFs
[build-image]: https://github.com/RustCrypto/KDFs/workflows/hkdf/badge.svg?branch=master&event=push
[build-link]: https://github.com/RustCrypto/KDFs/actions?query=workflow:hkdf
[//]: # (links)
[RustCrypto]: https://github.com/RustCrypto
+27
View File
@@ -0,0 +1,27 @@
#![feature(test)]
extern crate test;
use test::Bencher;
type HkdfSha256 = hkdf::Hkdf<sha2::Sha256>;
#[bench]
fn hkdf_sha256_10(b: &mut Bencher) {
let mut okm = vec![0u8; 10];
b.iter(|| HkdfSha256::new(Some(&[]), &[]).expand(&[], &mut okm));
b.bytes = okm.len() as u64;
}
#[bench]
fn hkdf_sha256_1024(b: &mut Bencher) {
let mut okm = vec![0u8; 1024];
b.iter(|| HkdfSha256::new(Some(&[]), &[]).expand(&[], &mut okm));
b.bytes = okm.len() as u64;
}
#[bench]
fn hkdf_sha256_8000(b: &mut Bencher) {
let mut okm = vec![0u8; 8000];
b.iter(|| HkdfSha256::new(Some(&[]), &[]).expand(&[], &mut okm));
b.bytes = okm.len() as u64;
}
+25
View File
@@ -0,0 +1,25 @@
use core::fmt;
/// Error that is returned when supplied pseudorandom key (PRK) is not long enough.
#[derive(Copy, Clone, Debug)]
pub struct InvalidPrkLength;
impl fmt::Display for InvalidPrkLength {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
f.write_str("invalid pseudorandom key length, too short")
}
}
impl core::error::Error for InvalidPrkLength {}
/// Structure for `InvalidLength`, used for output error handling.
#[derive(Copy, Clone, Debug)]
pub struct InvalidLength;
impl fmt::Display for InvalidLength {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
f.write_str("invalid number of blocks, too large output")
}
}
impl core::error::Error for InvalidLength {}
+56
View File
@@ -0,0 +1,56 @@
use hmac::digest::{
Digest, FixedOutput, KeyInit, Output, Update,
block_api::{BlockSizeUser, OutputSizeUser},
};
use hmac::{EagerHash, Hmac, SimpleHmac};
/// Trait representing a HMAC implementation.
///
/// Most users should use [`Hmac`] or [`SimpleHmac`].
pub trait HmacImpl: Clone + OutputSizeUser {
/// Create new HMAC state with the given key.
fn new_from_slice(key: &[u8]) -> Self;
/// Update HMAC state.
fn update(&mut self, data: &[u8]);
/// Finalize the HMAC state and get generated tag.
fn finalize(self) -> Output<Self>;
}
impl<H: EagerHash> HmacImpl for Hmac<H> {
#[inline(always)]
fn new_from_slice(key: &[u8]) -> Self {
KeyInit::new_from_slice(key).expect("HMAC can take a key of any size")
}
#[inline(always)]
fn update(&mut self, data: &[u8]) {
Update::update(self, data);
}
#[inline(always)]
fn finalize(self) -> Output<Self> {
self.finalize_fixed()
}
}
impl<H> HmacImpl for SimpleHmac<H>
where
H: Digest + BlockSizeUser + Clone,
{
#[inline(always)]
fn new_from_slice(key: &[u8]) -> Self {
KeyInit::new_from_slice(key).expect("HMAC can take a key of any size")
}
#[inline(always)]
fn update(&mut self, data: &[u8]) {
Update::update(self, data);
}
#[inline(always)]
fn finalize(self) -> Output<H> {
self.finalize_fixed()
}
}
+177
View File
@@ -0,0 +1,177 @@
#![no_std]
#![doc = include_str!("../README.md")]
#![doc(
html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg",
html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/6ee8e381/logo.svg"
)]
#![cfg_attr(docsrs, feature(doc_cfg))]
use hmac::{
Hmac, SimpleHmac,
digest::{Output, OutputSizeUser, array::typenum::Unsigned},
};
mod errors;
mod hmac_impl;
pub use errors::{InvalidLength, InvalidPrkLength};
pub use hmac;
pub use hmac_impl::HmacImpl;
#[cfg(feature = "kdf")]
pub use kdf::{self, Kdf};
/// [`GenericHkdfExtract`] variant which uses [`Hmac`] for the underlying HMAC implementation.
pub type HkdfExtract<H> = GenericHkdfExtract<Hmac<H>>;
/// [`GenericHkdf`] variant which uses [`Hmac`] for the underlying HMAC implementation.
pub type Hkdf<H> = GenericHkdf<Hmac<H>>;
/// [`GenericHkdfExtract`] variant which uses [`SimpleHmac`] for the underlying HMAC implementation.
pub type SimpleHkdfExtract<H> = GenericHkdfExtract<SimpleHmac<H>>;
/// [`GenericHkdf`] variant which uses [`SimpleHmac`] for the underlying HMAC implementation.
pub type SimpleHkdf<H> = GenericHkdf<SimpleHmac<H>>;
/// Structure representing the streaming context of an HKDF-Extract operation.
///
/// This type is generic over HMAC implementation. Most users should use
/// [`HkdfExtract`] or [`SimpleHkdfExtract`] type aliases.
#[derive(Clone, Debug)]
pub struct GenericHkdfExtract<H: HmacImpl> {
hmac: H,
}
impl<H: HmacImpl> GenericHkdfExtract<H> {
/// Initiates the HKDF-Extract context with the given optional salt
#[must_use]
pub fn new(salt: Option<&[u8]>) -> Self {
let default_salt = Output::<H>::default();
let salt = salt.unwrap_or(&default_salt);
let hmac = H::new_from_slice(salt);
Self { hmac }
}
/// Feeds in additional input key material to the HKDF-Extract context
pub fn input_ikm(&mut self, ikm: &[u8]) {
self.hmac.update(ikm);
}
/// Completes the HKDF-Extract operation, returning both the generated pseudorandom key and
/// `Hkdf` struct for expanding.
#[allow(clippy::missing_panics_doc, reason = "PRK size is correct")]
pub fn finalize(self) -> (Output<H>, GenericHkdf<H>) {
let prk = self.hmac.finalize();
let hkdf = GenericHkdf::<H>::from_prk(&prk).expect("PRK size is correct");
(prk, hkdf)
}
}
#[cfg(feature = "kdf")]
impl<H: HmacImpl> Kdf for GenericHkdfExtract<H> {
fn derive_key(&self, secret: &[u8], info: &[u8], out: &mut [u8]) -> kdf::Result<()> {
let mut extract = self.clone();
extract.input_ikm(secret);
let (_, hkdf) = extract.finalize();
hkdf.expand(info, out).map_err(|_| kdf::Error)
}
}
/// Structure representing the HKDF, capable of HKDF-Expand and HKDF-Extract operations.
/// Recommendations for the correct usage of the parameters can be found in the
/// [crate root](index.html#usage).
///
/// This type is generic over HMAC implementation. Most users should use
/// [`Hkdf`] or [`SimpleHkdf`] type aliases.
#[derive(Clone, Debug)]
pub struct GenericHkdf<H: HmacImpl> {
hmac: H,
}
impl<H: HmacImpl> GenericHkdf<H> {
/// Convenience method for [`extract`][Hkdf::extract] when the generated
/// pseudorandom key can be ignored and only HKDF-Expand operation is needed. This is the most
/// common constructor.
#[must_use]
pub fn new(salt: Option<&[u8]>, ikm: &[u8]) -> Self {
let (_, hkdf) = Self::extract(salt, ikm);
hkdf
}
/// Create `Hkdf` from an already cryptographically strong pseudorandom key
/// as per section 3.3 from RFC5869.
///
/// # Errors
/// Returns [`InvalidPrkLength`] if `prk` is shorter than the output size of `H`.
pub fn from_prk(prk: &[u8]) -> Result<Self, InvalidPrkLength> {
// section 2.3 specifies that `prk` must be "at least HashLen octets"
let hash_len = <H as OutputSizeUser>::OutputSize::to_usize();
if prk.len() < hash_len {
return Err(InvalidPrkLength);
}
let hmac = H::new_from_slice(prk);
Ok(Self { hmac })
}
/// The RFC5869 HKDF-Extract operation returning both the generated
/// pseudorandom key and `Hkdf` struct for expanding.
#[must_use]
pub fn extract(salt: Option<&[u8]>, ikm: &[u8]) -> (Output<H>, Self) {
let mut extract_ctx = GenericHkdfExtract::<H>::new(salt);
extract_ctx.input_ikm(ikm);
extract_ctx.finalize()
}
/// The RFC5869 HKDF-Expand operation. This is equivalent to calling
/// [`expand`][Hkdf::extract] with the `info` argument set equal to the
/// concatenation of all the elements of `info_components`.
///
/// # Errors
/// Returns [`InvalidLength`] in the event `okm` is too large.
#[allow(clippy::missing_panics_doc, reason = "expect should not fail")]
pub fn expand_multi_info(
&self,
info_components: &[&[u8]],
okm: &mut [u8],
) -> Result<(), InvalidLength> {
let mut prev: Option<Output<H>> = None;
let chunk_len = <H as OutputSizeUser>::OutputSize::USIZE;
if okm.len() > chunk_len * 255 {
return Err(InvalidLength);
}
for (block_n, block) in okm.chunks_mut(chunk_len).enumerate() {
let mut hmac = self.hmac.clone();
if let Some(ref prev) = prev {
hmac.update(prev);
};
// Feed in the info components in sequence. This is equivalent to feeding in the
// concatenation of all the info components
for info in info_components {
hmac.update(info);
}
hmac.update(&[u8::try_from(block_n).expect("should convert") + 1]);
let output = hmac.finalize();
let block_len = block.len();
block.copy_from_slice(&output[..block_len]);
prev = Some(output);
}
Ok(())
}
/// The RFC5869 HKDF-Expand operation
///
/// If you don't have any `info` to pass, use an empty slice.
///
/// # Errors
/// Returns [`InvalidLength`] in the event `okm` is too large.
pub fn expand(&self, info: &[u8], okm: &mut [u8]) -> Result<(), InvalidLength> {
self.expand_multi_info(&[info], okm)
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+54
View File
@@ -0,0 +1,54 @@
//! Test vectors from <https://tools.ietf.org/html/rfc5869>.
#![allow(clippy::unwrap_used, reason = "tests")]
use hkdf::{GenericHkdf, HmacImpl};
use hmac::{Hmac, SimpleHmac};
#[derive(Copy, Clone, Debug)]
struct TestVector {
ikm: &'static [u8],
salt: &'static [u8],
info: &'static [u8],
prk: &'static [u8],
okm: &'static [u8],
}
fn test<H: HmacImpl>(tvs: &[TestVector]) {
let mut buf = [0u8; 128];
for tv in tvs {
let salt = if tv.salt.is_empty() {
None
} else {
Some(tv.salt)
};
let (prk2, hkdf) = GenericHkdf::<H>::extract(salt, tv.ikm);
let okm_dst = &mut buf[..tv.okm.len()];
assert!(hkdf.expand(tv.info, okm_dst).is_ok());
assert_eq!(prk2[..], tv.prk[..]);
assert_eq!(okm_dst, tv.okm);
okm_dst.fill(0);
let hkdf = GenericHkdf::<H>::from_prk(tv.prk).unwrap();
assert!(hkdf.expand(tv.info, okm_dst).is_ok());
assert_eq!(okm_dst, tv.okm);
}
}
macro_rules! new_test {
($name:ident, $hash:ty) => {
#[test]
fn $name() {
blobby::parse_into_structs!(
include_bytes!(concat!("data/", stringify!($name), ".blb"));
static TEST_VECTORS: &[TestVector { ikm, salt, info, prk, okm }];
);
test::<Hmac<$hash>>(TEST_VECTORS);
test::<SimpleHmac<$hash>>(TEST_VECTORS);
}
};
}
new_test!(rfc5869_sha1, sha1::Sha1);
new_test!(rfc5869_sha256, sha2::Sha256);
+192
View File
@@ -0,0 +1,192 @@
//! Integration tests.
use core::iter;
use hex_literal::hex;
use hkdf::{Hkdf, HkdfExtract, SimpleHkdfExtract};
use sha1::Sha1;
use sha2::Sha256;
const MAX_SHA256_LENGTH: usize = 255 * (256 / 8); // =8160
static COMPONENTS: &[&[u8]] = &[
b"09090909090909090909090909090909090909090909",
b"8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a8a",
b"0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0",
b"4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4c4",
b"1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d1d",
];
#[test]
fn test_lengths() {
let hkdf = Hkdf::<Sha256>::new(None, &[]);
let mut longest = vec![0u8; MAX_SHA256_LENGTH];
assert!(hkdf.expand(&[], &mut longest).is_ok());
// Runtime is O(length), so exhaustively testing all legal lengths
// would take too long (at least without --release). Only test a
// subset: the first 500, the last 10, and every 100th in between.
let range = 500..MAX_SHA256_LENGTH - 10;
let lengths = (0..MAX_SHA256_LENGTH + 1).filter(|len| !range.contains(len) || *len % 100 == 0);
for length in lengths {
let mut okm = vec![0u8; length];
assert!(hkdf.expand(&[], &mut okm).is_ok());
assert_eq!(okm.len(), length);
assert_eq!(okm[..], longest[..length]);
}
}
#[test]
fn test_max_length() {
let hkdf = Hkdf::<Sha256>::new(Some(&[]), &[]);
let mut okm = vec![0u8; MAX_SHA256_LENGTH];
assert!(hkdf.expand(&[], &mut okm).is_ok());
}
#[test]
fn test_max_length_exceeded() {
let hkdf = Hkdf::<Sha256>::new(Some(&[]), &[]);
let mut okm = vec![0u8; MAX_SHA256_LENGTH + 1];
assert!(hkdf.expand(&[], &mut okm).is_err());
}
#[test]
fn test_unsupported_length() {
let hkdf = Hkdf::<Sha256>::new(Some(&[]), &[]);
let mut okm = vec![0u8; 90000];
assert!(hkdf.expand(&[], &mut okm).is_err());
}
#[test]
fn test_prk_too_short() {
use sha2::digest::Digest;
let output_len = Sha256::output_size();
let prk = vec![0; output_len - 1];
assert!(Hkdf::<Sha256>::from_prk(&prk).is_err());
}
#[test]
#[rustfmt::skip]
fn test_derive_sha1_with_none() {
let ikm = hex!("0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c0c");
let salt = None;
let info = hex!("");
let (prk, hkdf) = Hkdf::<Sha1>::extract(salt, &ikm[..]);
let mut okm = [0u8; 42];
assert!(hkdf.expand(&info[..], &mut okm).is_ok());
assert_eq!(
prk[..],
hex!("2adccada18779e7c2077ad2eb19d3f3e731385dd")[..]
);
assert_eq!(
okm[..],
hex!("
2c91117204d745f3500d636a62f64f0a
b3bae548aa53d423b0d1f27ebba6f5e5
673a081d70cce7acfc48
")[..],
);
}
#[test]
fn test_expand_multi_info() {
let info_components = COMPONENTS;
let (_, hkdf_ctx) = Hkdf::<Sha256>::extract(None, b"some ikm here");
// Compute HKDF-Expand on the concatenation of all the info components
let mut oneshot_res = [0u8; 16];
hkdf_ctx
.expand(&info_components.concat(), &mut oneshot_res)
.unwrap();
// Now iteratively join the components of info_components until it's all 1 component. The value
// of HKDF-Expand should be the same throughout
let mut num_concatted = 0;
let mut info_head = Vec::new();
while num_concatted < info_components.len() {
info_head.extend(info_components[num_concatted]);
// Build the new input to be the info head followed by the remaining components
let input: Vec<&[u8]> = iter::once(info_head.as_slice())
.chain(info_components.iter().cloned().skip(num_concatted + 1))
.collect();
// Compute and compare to the one-shot answer
let mut multipart_res = [0u8; 16];
hkdf_ctx
.expand_multi_info(&input, &mut multipart_res)
.unwrap();
assert_eq!(multipart_res, oneshot_res);
num_concatted += 1;
}
}
#[test]
fn test_extract_streaming() {
let ikm_components = COMPONENTS;
let salt = b"mysalt";
// Compute HKDF-Extract on the concatenation of all the IKM components
let (oneshot_res, _) = Hkdf::<Sha256>::extract(Some(&salt[..]), &ikm_components.concat());
// Now iteratively join the components of ikm_components until it's all 1 component. The value
// of HKDF-Extract should be the same throughout
let mut num_concatted = 0;
let mut ikm_head = Vec::new();
while num_concatted < ikm_components.len() {
ikm_head.extend(ikm_components[num_concatted]);
// Make a new extraction context and build the new input to be the IKM head followed by the
// remaining components
let mut extract_ctx = HkdfExtract::<Sha256>::new(Some(&salt[..]));
let input = iter::once(ikm_head.as_slice())
.chain(ikm_components.iter().cloned().skip(num_concatted + 1));
// Stream in the IKM input in the chunks specified
for ikm in input {
extract_ctx.input_ikm(ikm);
}
// Finalize and compare to the one-shot answer
let (multipart_res, _) = extract_ctx.finalize();
assert_eq!(multipart_res, oneshot_res);
num_concatted += 1;
}
let mut num_concatted = 0;
let mut ikm_head = Vec::new();
while num_concatted < ikm_components.len() {
ikm_head.extend(ikm_components[num_concatted]);
// Make a new extraction context and build the new input to be the IKM head followed by the
// remaining components
let mut extract_ctx = SimpleHkdfExtract::<Sha256>::new(Some(&salt[..]));
let input = iter::once(ikm_head.as_slice())
.chain(ikm_components.iter().cloned().skip(num_concatted + 1));
// Stream in the IKM input in the chunks specified
for ikm in input {
extract_ctx.input_ikm(ikm);
}
// Finalize and compare to the one-shot answer
let (multipart_res, _) = extract_ctx.finalize();
assert_eq!(multipart_res, oneshot_res);
num_concatted += 1;
}
}
#[test]
fn test_debug_impls() {
fn needs_debug<T: core::fmt::Debug>() {}
needs_debug::<Hkdf<Sha256>>();
needs_debug::<HkdfExtract<Sha256>>();
}
+52
View File
@@ -0,0 +1,52 @@
//! Wycheproof test vectors.
use hkdf::{GenericHkdf, HmacImpl};
use hmac::{Hmac, SimpleHmac};
#[derive(Copy, Clone, Debug)]
struct TestVector {
ikm: &'static [u8],
salt: &'static [u8],
info: &'static [u8],
okm: &'static [u8],
}
fn test<H: HmacImpl>(test_vectors: &[TestVector]) {
let mut buf = [0u8; 1 << 14];
for (i, tv) in test_vectors.iter().enumerate() {
let prk = GenericHkdf::<H>::new(Some(tv.salt), tv.ikm);
let okm_dst = &mut buf[..tv.okm.len()];
let mut err = None;
if prk.expand(tv.info, okm_dst).is_err() {
err = Some("prk expand");
}
if okm_dst != tv.okm {
err = Some("mismatch in okm");
}
if let Some(err_desc) = err {
panic!("Failed test #{i}: {err_desc}\nTest vector:\t{tv:#?}");
}
}
}
macro_rules! new_test {
($name:ident, $hash:ty) => {
#[test]
fn $name() {
blobby::parse_into_structs!(
include_bytes!(concat!("data/", stringify!($name), ".blb"));
static TEST_VECTORS: &[TestVector { ikm, salt, info, okm }];
);
test::<Hmac<$hash>>(TEST_VECTORS);
test::<SimpleHmac<$hash>>(TEST_VECTORS);
}
};
}
new_test!(wycheproof_sha1, sha1::Sha1);
new_test!(wycheproof_sha256, sha2::Sha256);
new_test!(wycheproof_sha384, sha2::Sha384);
new_test!(wycheproof_sha512, sha2::Sha512);