Skip to content

Commit

Permalink
rsa: deprecate accidentally-exposed API.
Browse files Browse the repository at this point in the history
  • Loading branch information
briansmith committed Mar 9, 2025
1 parent 52b239c commit 6af531f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/rsa/keypair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

use super::{
padding::RsaEncoding, KeyPairComponents, PublicExponent, PublicKey, PublicKeyComponents, N,
padding::{self, RsaEncoding},
KeyPairComponents, PublicExponent, PublicKey, PublicKeyComponents, N,
};

/// RSA PKCS#1 1.5 signatures.
Expand Down Expand Up @@ -546,7 +547,13 @@ impl KeyPair {

// Use the output buffer as the scratch space for the signature to
// reduce the required stack space.
padding_alg.encode(m_hash, signature, self.public().inner().n().len_bits(), rng)?;
padding::encode(
padding_alg,
m_hash,
signature,
self.public().inner().n().len_bits(),
rng,
)?;

// RFC 8017 Section 5.1.2: RSADP, using the Chinese Remainder Theorem
// with Garner's algorithm.
Expand Down
13 changes: 13 additions & 0 deletions src/rsa/padding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,23 @@ pub trait Padding: 'static + Sync + crate::sealed::Sealed + core::fmt::Debug {
fn digest_alg(&self) -> &'static digest::Algorithm;
}

pub(super) fn encode(
encoding: &dyn RsaEncoding,
m_hash: digest::Digest,
m_out: &mut [u8],
mod_bits: bits::BitLength,
rng: &dyn rand::SecureRandom,
) -> Result<(), error::Unspecified> {
#[allow(deprecated)]
encoding.encode(m_hash, m_out, mod_bits, rng)
}

/// An RSA signature encoding as described in [RFC 3447 Section 8].
///
/// [RFC 3447 Section 8]: https://tools.ietf.org/html/rfc3447#section-8
#[cfg(feature = "alloc")]
pub trait RsaEncoding: Padding {
#[deprecated(note = "internal API that will be removed")]
#[doc(hidden)]
fn encode(
&self,
Expand Down Expand Up @@ -153,6 +165,7 @@ mod test {

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

Expand Down

0 comments on commit 6af531f

Please sign in to comment.