diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2020-08-14 11:50:38 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2020-08-14 11:50:38 +0200 |
commit | 19582261b8dea2b348e5c503fc0f5ee180b7c9b9 (patch) | |
tree | 4b17f199ad3c18dea2d108408ef4591439661c8a | |
parent | b9593c117c02219248727b664475027d6c4d50d5 (diff) |
openpgp: Fix the expected maximum overhead of the Padmé scheme.
- We observe a slightly higher maximum overhead than what the paper
suggests, but it is still easily within the 12% claimed in the
paper's abstract.
- Fixes #541.
-rw-r--r-- | openpgp/src/serialize/stream/padding.rs | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/openpgp/src/serialize/stream/padding.rs b/openpgp/src/serialize/stream/padding.rs index 2ccf4882..b92f913c 100644 --- a/openpgp/src/serialize/stream/padding.rs +++ b/openpgp/src/serialize/stream/padding.rs @@ -354,10 +354,20 @@ mod test { (c - p) / p } + /// Experimentally, we observe the maximum overhead to be ~11.63% + /// when padding 129 bytes to 144. + const MAX_OVERHEAD: f32 = 0.1163; + #[test] fn padme_max_overhead() { + // The paper says the maximum multiplicative overhead is + // 11.(11)% when padding 9 bytes to 10. assert!(0.111 < padme_multiplicative_overhead(9)); assert!(padme_multiplicative_overhead(9) < 0.112); + + // Contrary to that, we observe the maximum overhead to be + // ~11.63% when padding 129 bytes to 144. + assert!(padme_multiplicative_overhead(129) < MAX_OVERHEAD); } quickcheck! { @@ -372,10 +382,12 @@ mod test { let s = e.log2().floor() + 1.; // # of bits to represent e let max_overhead = (2.0_f32.powf(e-s) - 1.) / l_; - assert!(o < 0.112); + assert!(o < MAX_OVERHEAD, + "padme({}) => {}: overhead {} exceeds maximum overhead {}", + l, padme(l.into()), o, MAX_OVERHEAD); assert!(o <= max_overhead, - "padme({}): overhead {} exceeds maximum overhead {}", - l, o, max_overhead); + "padme({}) => {}: overhead {} exceeds maximum overhead {}", + l, padme(l.into()), o, max_overhead); true } } |