Skip to content

Commit 6af531f

Browse files
committed
rsa: deprecate accidentally-exposed API.
1 parent 52b239c commit 6af531f

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

src/rsa/keypair.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1414

1515
use super::{
16-
padding::RsaEncoding, KeyPairComponents, PublicExponent, PublicKey, PublicKeyComponents, N,
16+
padding::{self, RsaEncoding},
17+
KeyPairComponents, PublicExponent, PublicKey, PublicKeyComponents, N,
1718
};
1819

1920
/// RSA PKCS#1 1.5 signatures.
@@ -546,7 +547,13 @@ impl KeyPair {
546547

547548
// Use the output buffer as the scratch space for the signature to
548549
// reduce the required stack space.
549-
padding_alg.encode(m_hash, signature, self.public().inner().n().len_bits(), rng)?;
550+
padding::encode(
551+
padding_alg,
552+
m_hash,
553+
signature,
554+
self.public().inner().n().len_bits(),
555+
rng,
556+
)?;
550557

551558
// RFC 8017 Section 5.1.2: RSADP, using the Chinese Remainder Theorem
552559
// with Garner's algorithm.

src/rsa/padding.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,23 @@ pub trait Padding: 'static + Sync + crate::sealed::Sealed + core::fmt::Debug {
3030
fn digest_alg(&self) -> &'static digest::Algorithm;
3131
}
3232

33+
pub(super) fn encode(
34+
encoding: &dyn RsaEncoding,
35+
m_hash: digest::Digest,
36+
m_out: &mut [u8],
37+
mod_bits: bits::BitLength,
38+
rng: &dyn rand::SecureRandom,
39+
) -> Result<(), error::Unspecified> {
40+
#[allow(deprecated)]
41+
encoding.encode(m_hash, m_out, mod_bits, rng)
42+
}
43+
3344
/// An RSA signature encoding as described in [RFC 3447 Section 8].
3445
///
3546
/// [RFC 3447 Section 8]: https://tools.ietf.org/html/rfc3447#section-8
3647
#[cfg(feature = "alloc")]
3748
pub trait RsaEncoding: Padding {
49+
#[deprecated(note = "internal API that will be removed")]
3850
#[doc(hidden)]
3951
fn encode(
4052
&self,
@@ -153,6 +165,7 @@ mod test {
153165

154166
let mut m_out = vec![0u8; bit_len.as_usize_bytes_rounded_up()];
155167
let digest = digest::digest(alg.digest_alg(), &msg);
168+
#[allow(deprecated)]
156169
alg.encode(digest, &mut m_out, bit_len, &rng).unwrap();
157170
assert_eq!(m_out, encoded);
158171

0 commit comments

Comments
 (0)