diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 17:39:49 +0000 |
commit | a0aa2307322cd47bbf416810ac0292925e03be87 (patch) | |
tree | 37076262a026c4b48c8a0e84f44ff9187556ca35 /rust/vendor/ghash | |
parent | Initial commit. (diff) | |
download | suricata-a0aa2307322cd47bbf416810ac0292925e03be87.tar.xz suricata-a0aa2307322cd47bbf416810ac0292925e03be87.zip |
Adding upstream version 1:7.0.3.upstream/1%7.0.3
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | rust/vendor/ghash/.cargo-checksum.json | 1 | ||||
-rw-r--r-- | rust/vendor/ghash/CHANGELOG.md | 87 | ||||
-rw-r--r-- | rust/vendor/ghash/Cargo.toml | 41 | ||||
-rw-r--r-- | rust/vendor/ghash/LICENSE-APACHE | 201 | ||||
-rw-r--r-- | rust/vendor/ghash/LICENSE-MIT | 25 | ||||
-rw-r--r-- | rust/vendor/ghash/README.md | 63 | ||||
-rw-r--r-- | rust/vendor/ghash/benches/ghash.rs | 32 | ||||
-rw-r--r-- | rust/vendor/ghash/src/lib.rs | 108 | ||||
-rw-r--r-- | rust/vendor/ghash/tests/lib.rs | 27 |
9 files changed, 585 insertions, 0 deletions
diff --git a/rust/vendor/ghash/.cargo-checksum.json b/rust/vendor/ghash/.cargo-checksum.json new file mode 100644 index 0000000..a916c48 --- /dev/null +++ b/rust/vendor/ghash/.cargo-checksum.json @@ -0,0 +1 @@ +{"files":{"CHANGELOG.md":"b204237047523c5401ce493787a2d5601df5a2003fba8a3403cccc29fcee4bf6","Cargo.toml":"31fdefab189e3b9a6f72b980edca6a5ac59f0037fc4a06eb621af93a74b6e341","LICENSE-APACHE":"a9040321c3712d8fd0b09cf52b17445de04a23a10165049ae187cd39e5c86be5","LICENSE-MIT":"c0fabcc308b450cb6fe62c9f56fae6abbeb9768eb80d992484c857d744846c2e","README.md":"d3caede2dd415fb9e7854d2413845b514aa9cdc9fafbf142cfcadf8172d82234","benches/ghash.rs":"e335a1ab94cf670e861a708ea0f5535e0e32139789e4f10b1a45e8d9e7b2bcc3","src/lib.rs":"76ccafb97a6c44c14a27bc69efac988fd6f060f298b0f890df07cb831a530f69","tests/lib.rs":"145be0c569804200a4cbdf34f029faf3c99a6300876f582ba891ba86328db7fd"},"package":"1583cc1656d7839fd3732b80cf4f38850336cdb9b8ded1cd399ca62958de3c99"}
\ No newline at end of file diff --git a/rust/vendor/ghash/CHANGELOG.md b/rust/vendor/ghash/CHANGELOG.md new file mode 100644 index 0000000..1422eb0 --- /dev/null +++ b/rust/vendor/ghash/CHANGELOG.md @@ -0,0 +1,87 @@ +# 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.4.4 (2021-08-27) +### Changed +- Relax `zeroize` constraints ([#141]) + +[#141]: https://github.com/RustCrypto/universal-hashes/pull/141 + +## 0.4.3 (2021-07-20) +### Changed +- Pin `zeroize` dependency to v1.3 ([#134]) + +[#134]: https://github.com/RustCrypto/universal-hashes/pull/134 + +## 0.4.2 (2021-05-31) +### Added +- Nightly-only ARMv8 intrinsics support gated under the `armv8` feature ([#126]) + +[#126]: https://github.com/RustCrypto/universal-hashes/pull/126 + +## 0.4.1 (2021-05-05) +### Added +- `force-soft` feature ([#121]) + +[#121]: https://github.com/RustCrypto/universal-hashes/pull/121 + +## 0.4.0 (2021-04-29) +### Changed +- Bump `polyval` crate dependency to v0.5; MSRV 1.49+ ([#114], [#119]) + +[#114]: https://github.com/RustCrypto/universal-hashes/pull/114 +[#119]: https://github.com/RustCrypto/universal-hashes/pull/119 + +## 0.3.1 (2020-12-26) +### Added +- `Debug` impl using `opaque-debug` ([#105]) + +### Changed +- Use `polyval::mulx` ([#109]) + +[#105]: https://github.com/RustCrypto/universal-hashes/pull/105 +[#109]: https://github.com/RustCrypto/universal-hashes/pull/109 + +## 0.3.0 (2020-06-06) +### Changed +- Bump `polyval` dependency to v0.4 ([#59]) +- Bump `universal-hash` dependency to v0.4; MSRV 1.41 ([#52], [#57]) +- Rename `result` methods to to `finalize` ([#56]) + +[#59]: https://github.com/RustCrypto/universal-hashes/pull/59 +[#57]: https://github.com/RustCrypto/universal-hashes/pull/57 +[#56]: https://github.com/RustCrypto/universal-hashes/pull/56 +[#52]: https://github.com/RustCrypto/universal-hashes/pull/52 + +## 0.2.3 (2019-11-14) +### Changed +- Upgrade to `zeroize` 1.0 ([#33]) + +[#33]: https://github.com/RustCrypto/universal-hashes/pull/33 + +## 0.2.2 (2019-10-06) +### Fixed +- Revert mulX_POLYVAL changes from [#28] ([#31]) + +[#31]: https://github.com/RustCrypto/universal-hashes/pull/31 + +## 0.2.1 (2019-10-05) +### Changed +- Upgrade to `polyval` v0.3 ([#28], [#29]) + +[#29]: https://github.com/RustCrypto/universal-hashes/pull/29 +[#28]: https://github.com/RustCrypto/universal-hashes/pull/28 + +## 0.2.0 (2019-10-04) +### Changed +- Upgrade to `polyval` v0.2 and `universal-hash` crate v0.3 ([#22]) + +[#22]: https://github.com/RustCrypto/universal-hashes/pull/22 + +## 0.1.0 (2019-09-19) + +- Initial release diff --git a/rust/vendor/ghash/Cargo.toml b/rust/vendor/ghash/Cargo.toml new file mode 100644 index 0000000..e82ec25 --- /dev/null +++ b/rust/vendor/ghash/Cargo.toml @@ -0,0 +1,41 @@ +# 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 believe there's an error in this file please file an +# issue against the rust-lang/cargo repository. If you're +# editing this file be aware that the upstream Cargo.toml +# will likely look very different (and much more reasonable) + +[package] +edition = "2018" +name = "ghash" +version = "0.4.4" +authors = ["RustCrypto Developers"] +description = "Universal hash over GF(2^128) useful for constructing a Message Authentication Code (MAC),\nas in the AES-GCM authenticated encryption cipher.\n" +documentation = "https://docs.rs/ghash" +readme = "README.md" +keywords = ["aes-gcm", "crypto", "universal-hashing"] +categories = ["cryptography", "no-std"] +license = "Apache-2.0 OR MIT" +repository = "https://github.com/RustCrypto/universal-hashes" +[dependencies.opaque-debug] +version = "0.3" + +[dependencies.polyval] +version = "0.5.1" + +[dependencies.zeroize] +version = ">=1, <1.4" +optional = true +default-features = false +[dev-dependencies.hex-literal] +version = "0.3" + +[features] +armv8 = ["polyval/armv8"] +force-soft = ["polyval/force-soft"] +std = ["polyval/std"] diff --git a/rust/vendor/ghash/LICENSE-APACHE b/rust/vendor/ghash/LICENSE-APACHE new file mode 100644 index 0000000..78173fa --- /dev/null +++ b/rust/vendor/ghash/LICENSE-APACHE @@ -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. diff --git a/rust/vendor/ghash/LICENSE-MIT b/rust/vendor/ghash/LICENSE-MIT new file mode 100644 index 0000000..51e2859 --- /dev/null +++ b/rust/vendor/ghash/LICENSE-MIT @@ -0,0 +1,25 @@ +Copyright (c) 2019 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. diff --git a/rust/vendor/ghash/README.md b/rust/vendor/ghash/README.md new file mode 100644 index 0000000..847e4f3 --- /dev/null +++ b/rust/vendor/ghash/README.md @@ -0,0 +1,63 @@ +# RustCrypto: GHASH + +[![crate][crate-image]][crate-link] +[![Docs][docs-image]][docs-link] +![Apache2/MIT licensed][license-image] +![Rust Version][rustc-image] +[![Build Status][build-image]][build-link] + +[GHASH][1] is a [universal hash function][2] which operates over GF(2^128) and +can be used for constructing a [Message Authentication Code (MAC)][3]. + +Its primary intended use is for implementing [AES-GCM][4]. + +[Documentation][docs-link] + +## Security Notes + +This crate has received one [security audit by NCC Group][5], with no significant +findings. We would like to thank [MobileCoin][6] for funding the audit. + +All implementations contained in the crate are designed to execute in constant +time, either by relying on hardware intrinsics (i.e. AVX2 on x86/x86_64), or +using a portable implementation which is only constant time on processors which +implement constant-time multiplication. + +It is not suitable for use on processors with a variable-time multiplication +operation (e.g. short circuit on multiply-by-zero / multiply-by-one, such as +certain 32-bit PowerPC CPUs and some non-ARM microcontrollers). + +## 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/ghash.svg +[crate-link]: https://crates.io/crates/ghash +[docs-image]: https://docs.rs/ghash/badge.svg +[docs-link]: https://docs.rs/ghash/ +[license-image]: https://img.shields.io/badge/license-Apache2.0/MIT-blue.svg +[rustc-image]: https://img.shields.io/badge/rustc-1.49+-blue.svg +[build-image]: https://github.com/RustCrypto/universal-hashes/workflows/ghash/badge.svg?branch=master&event=push +[build-link]: https://github.com/RustCrypto/universal-hashes/actions?query=workflow%3Aghash + +[//]: # (footnotes) + +[1]: https://en.wikipedia.org/wiki/Galois/Counter_Mode#Mathematical_basis +[2]: https://en.wikipedia.org/wiki/Universal_hashing +[3]: https://en.wikipedia.org/wiki/Message_authentication_code +[4]: https://en.wikipedia.org/wiki/Galois/Counter_Mode +[5]: https://research.nccgroup.com/2020/02/26/public-report-rustcrypto-aes-gcm-and-chacha20poly1305-implementation-review/ +[6]: https://www.mobilecoin.com/ diff --git a/rust/vendor/ghash/benches/ghash.rs b/rust/vendor/ghash/benches/ghash.rs new file mode 100644 index 0000000..4427b1a --- /dev/null +++ b/rust/vendor/ghash/benches/ghash.rs @@ -0,0 +1,32 @@ +#![feature(test)] + +extern crate test; + +use ghash::{ + universal_hash::{NewUniversalHash, UniversalHash}, + GHash, +}; +use test::Bencher; + +// TODO(tarcieri): move this into the `universal-hash` crate +macro_rules! bench { + ($name:ident, $bs:expr) => { + #[bench] + fn $name(b: &mut Bencher) { + let key = Default::default(); + let mut m = GHash::new(&key); + let data = [0; $bs]; + + b.iter(|| { + m.update_padded(&data); + }); + + b.bytes = $bs; + } + }; +} + +bench!(bench1_10, 10); +bench!(bench2_100, 100); +bench!(bench3_1000, 1000); +bench!(bench3_10000, 10000); diff --git a/rust/vendor/ghash/src/lib.rs b/rust/vendor/ghash/src/lib.rs new file mode 100644 index 0000000..2c8fba2 --- /dev/null +++ b/rust/vendor/ghash/src/lib.rs @@ -0,0 +1,108 @@ +//! **GHASH**: universal hash over GF(2^128) used by AES-GCM for message +//! authentication (i.e. GMAC). +//! +//! ## Implementation Notes +//! +//! The implementation of GHASH found in this crate internally uses the +//! [`polyval`] crate, which provides a similar universal hash function used by +//! AES-GCM-SIV (RFC 8452). +//! +//! By implementing GHASH in terms of POLYVAL, the two universal hash functions +//! can share a common core, meaning any optimization work (e.g. CPU-specific +//! SIMD implementations) which happens upstream in the `polyval` crate +//! benefits GHASH as well. +//! +//! From RFC 8452 Appendix A: +//! <https://tools.ietf.org/html/rfc8452#appendix-A> +//! +//! > GHASH and POLYVAL both operate in GF(2^128), although with different +//! > irreducible polynomials: POLYVAL works modulo x^128 + x^127 + x^126 + +//! > x^121 + 1 and GHASH works modulo x^128 + x^7 + x^2 + x + 1. Note +//! > that these irreducible polynomials are the "reverse" of each other. +//! +//! [`polyval`]: https://github.com/RustCrypto/universal-hashes/tree/master/polyval + +#![no_std] +#![doc( + html_logo_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", + html_favicon_url = "https://raw.githubusercontent.com/RustCrypto/media/8f1a9894/logo.svg", + html_root_url = "https://docs.rs/ghash/0.4.3" +)] +#![warn(missing_docs, rust_2018_idioms)] + +pub use polyval::universal_hash; + +use polyval::Polyval; +use universal_hash::{consts::U16, NewUniversalHash, UniversalHash}; + +#[cfg(feature = "zeroize")] +use zeroize::Zeroize; + +/// GHASH keys (16-bytes) +pub type Key = universal_hash::Key<GHash>; + +/// GHASH blocks (16-bytes) +pub type Block = universal_hash::Block<GHash>; + +/// GHASH tags (16-bytes) +pub type Tag = universal_hash::Output<GHash>; + +/// **GHASH**: universal hash over GF(2^128) used by AES-GCM. +/// +/// GHASH is a universal hash function used for message authentication in +/// the AES-GCM authenticated encryption cipher. +#[derive(Clone)] +pub struct GHash(Polyval); + +impl NewUniversalHash for GHash { + type KeySize = U16; + + /// Initialize GHASH with the given `H` field element + #[inline] + fn new(h: &Key) -> Self { + let mut h = *h; + h.reverse(); + + #[allow(unused_mut)] + let mut h_polyval = polyval::mulx(&h); + + #[cfg(feature = "zeroize")] + h.zeroize(); + + #[allow(clippy::let_and_return)] + let result = GHash(Polyval::new(&h_polyval)); + + #[cfg(feature = "zeroize")] + h_polyval.zeroize(); + + result + } +} + +impl UniversalHash for GHash { + type BlockSize = U16; + + /// Input a field element `X` to be authenticated + #[inline] + fn update(&mut self, x: &Block) { + let mut x = *x; + x.reverse(); + self.0.update(&x); + } + + /// Reset internal state + #[inline] + fn reset(&mut self) { + self.0.reset(); + } + + /// Get GHASH output + #[inline] + fn finalize(self) -> Tag { + let mut output = self.0.finalize().into_bytes(); + output.reverse(); + Tag::new(output) + } +} + +opaque_debug::implement!(GHash); diff --git a/rust/vendor/ghash/tests/lib.rs b/rust/vendor/ghash/tests/lib.rs new file mode 100644 index 0000000..2a4a74d --- /dev/null +++ b/rust/vendor/ghash/tests/lib.rs @@ -0,0 +1,27 @@ +use ghash::{ + universal_hash::{NewUniversalHash, UniversalHash}, + GHash, +}; +use hex_literal::hex; + +// +// Test vectors for GHASH from RFC 8452 Appendix A +// <https://tools.ietf.org/html/rfc8452#appendix-A> +// + +const H: [u8; 16] = hex!("25629347589242761d31f826ba4b757b"); +const X_1: [u8; 16] = hex!("4f4f95668c83dfb6401762bb2d01a262"); +const X_2: [u8; 16] = hex!("d1a24ddd2721d006bbe45f20d3c9f362"); + +/// GHASH(H, X_1, X_2) +const GHASH_RESULT: [u8; 16] = hex!("bd9b3997046731fb96251b91f9c99d7a"); + +#[test] +fn ghash_test_vector() { + let mut ghash = GHash::new(&H.into()); + ghash.update(&X_1.into()); + ghash.update(&X_2.into()); + + let result = ghash.finalize(); + assert_eq!(&GHASH_RESULT[..], result.into_bytes().as_slice()); +} |