Skip to content

Commit dee131d

Browse files
committed
rsa: Move some compliance comments to the appropriate place.
These comments make more sense in the new location. They should have been moved in an earlier refactoring.
1 parent 4d41150 commit dee131d

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

src/rsa/base/public_key.rs

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,6 @@ impl<'a> ValidatedInput<'a> {
3939
n_max_bits: bits::BitLength,
4040
e_min_value: PublicExponent,
4141
) -> Result<Self, error::KeyRejected> {
42-
let n =
43-
public_modulus::ValidatedInput::from_be_bytes(components.n, n_min_bits..=n_max_bits)?;
44-
let e_input = components.e.into();
45-
let e = PublicExponent::from_be_bytes(e_input, e_min_value)?;
46-
Ok(Self { n, e, e_input })
47-
}
48-
49-
pub fn n(&self) -> &public_modulus::ValidatedInput<'_> {
50-
&self.n
51-
}
52-
53-
pub(in super::super) fn e_input(&self) -> untrusted::Input<'_> {
54-
self.e_input
55-
}
56-
57-
pub(in super::super) fn build(&self, cpu_features: cpu::Features) -> PublicKey {
5842
// This is an incomplete implementation of NIST SP800-56Br1 Section
5943
// 6.4.2.2, "Partial Public-Key Validation for RSA." That spec defers
6044
// to NIST SP800-89 Section 5.3.3, "(Explicit) Partial Public Key
@@ -64,16 +48,33 @@ impl<'a> ValidatedInput<'a> {
6448
// and one set lettered. TODO: Document this in the end-user
6549
// documentation for RSA keys.
6650

67-
let n = self.n.build(cpu_features);
68-
6951
// If `n` is less than `e` then somebody has probably accidentally swapped
7052
// them. The largest acceptable `e` is smaller than the smallest acceptable
7153
// `n`, so no additional checks need to be done.
7254

7355
// XXX: Steps 4 & 5 / Steps d, e, & f are not implemented. This is also the
7456
// case in most other commonly-used crypto libraries.
7557

76-
PublicKey { n, e: self.e }
58+
let n =
59+
public_modulus::ValidatedInput::from_be_bytes(components.n, n_min_bits..=n_max_bits)?;
60+
let e_input = components.e.into();
61+
let e = PublicExponent::from_be_bytes(e_input, e_min_value)?;
62+
Ok(Self { n, e, e_input })
63+
}
64+
65+
pub fn n(&self) -> &public_modulus::ValidatedInput<'_> {
66+
&self.n
67+
}
68+
69+
pub(in super::super) fn e_input(&self) -> untrusted::Input<'_> {
70+
self.e_input
71+
}
72+
73+
pub(in super::super) fn build(&self, cpu_features: cpu::Features) -> PublicKey {
74+
PublicKey {
75+
n: self.n.build(cpu_features),
76+
e: self.e,
77+
}
7778
}
7879
}
7980

0 commit comments

Comments
 (0)