Skip to content

Commit bdf93cd

Browse files
committed
dbl: seal the Dbl trait and tweak docs
1 parent 8c5ddd4 commit bdf93cd

3 files changed

Lines changed: 19 additions & 8 deletions

File tree

dbl/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
### Changed
99
- Migrated from `generic-array` to `hybrid-array` ([#944])
1010
- Edition changed to 2024 and MSRV bumped to 1.85 ([#1149])
11+
- Seal the `Dbl` trait ([#1198])
1112

1213
[#944]: https://github.com/RustCrypto/utils/pull/944
1314
[#1149]: https://github.com/RustCrypto/utils/pull/1149
15+
[#1198]: https://github.com/RustCrypto/utils/pull/1198

dbl/README.md

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

10-
Double operation in Galois Field GF(2^128) as used by e.g. CMAC/PMAC.
11-
12-
Also known as "multiply-by-x", the operation is performed in the finite field
13-
represented using the primitive polynomial x^128 + x^7 + x^2 + x + 1.
10+
Double operation (a.k.a. "multiply-by-x") in Galois Field `GF(2^128)` using
11+
the lexicographically first polynomial among the irreducible degree `n` polynomials
12+
having a minimum number of coefficients.
1413

1514
## License
1615

dbl/src/lib.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@ const C64: u64 = 0b1_1011;
1313
const C128: u64 = 0b1000_0111;
1414
const C256: u64 = 0b100_0010_0101;
1515

16-
/// Double and inverse double over GF(2^n).
16+
mod sealed {
17+
pub trait Sealed {}
18+
}
19+
20+
/// Double and inverse double over `GF(2^n)` with the lexicographically first polynomial
21+
/// among the irreducible degree `n` polynomials having a minimum number of coefficients.
1722
///
18-
/// This trait is implemented for 64, 128 and 256 bit block sizes. Big-endian
19-
/// order is used.
20-
pub trait Dbl {
23+
/// This trait is implemented using big-endian byte order for 64, 128 and 256 bit block sizes.
24+
pub trait Dbl: sealed::Sealed {
2125
/// Double block. (alternatively: multiply block by x)
2226
///
2327
/// If most significant bit of the block equals to zero will return
@@ -59,6 +63,8 @@ impl Dbl for Array<u8, U8> {
5963
}
6064
}
6165

66+
impl sealed::Sealed for Array<u8, U8> {}
67+
6268
impl Dbl for Array<u8, U16> {
6369
#[inline]
6470
fn dbl(self) -> Self {
@@ -104,6 +110,8 @@ impl Dbl for Array<u8, U16> {
104110
}
105111
}
106112

113+
impl sealed::Sealed for Array<u8, U16> {}
114+
107115
impl Dbl for Array<u8, U32> {
108116
#[inline]
109117
fn dbl(self) -> Self {
@@ -169,3 +177,5 @@ impl Dbl for Array<u8, U32> {
169177
res
170178
}
171179
}
180+
181+
impl sealed::Sealed for Array<u8, U32> {}

0 commit comments

Comments
 (0)