RSA: Move rsa::keypair::Components to rsa::KeyPairComponents.

Take a step towards flattening (and simplifying) the public API of
the RSA submodule. This is done as a separate step from the rest of
the work so that the Git history will correctly reflect that signing.rs
gets renamed to keypair.rs, with only minimial modifications, in the
next commit. (If this were merged with the following commit, then Git
would report the new keypair.rs as a new file without any history from
signing.rs.)
This commit is contained in:
Brian Smith 2021-09-28 11:53:10 -07:00
parent 6cde4b8142
commit 88c281e3ea
4 changed files with 13 additions and 16 deletions

View File

@ -60,9 +60,11 @@ enum N {}
unsafe impl bigint::PublicModulus for N {}
pub mod keypair;
mod keypair_components;
pub mod public;
pub(crate) mod verification;
pub(crate) mod signing;
pub use self::keypair_components::KeyPairComponents;

View File

@ -1,5 +0,0 @@
//! Low-level RSA key pair (private key) API.
pub(crate) mod components;
pub use components::Components;

View File

@ -1,10 +1,10 @@
use super::super::public;
use super::public;
/// RSA key pair components.
#[derive(Clone, Copy)]
pub struct Components<Public, Private = Public> {
pub struct KeyPairComponents<Public, Private = Public> {
/// The public key components.
pub public_key: super::super::public::Components<Public>,
pub public_key: super::public::Components<Public>,
/// The private exponent.
pub d: Private,
@ -25,7 +25,7 @@ pub struct Components<Public, Private = Public> {
pub qInv: Private,
}
impl<Public, Private> core::fmt::Debug for Components<Public, Private>
impl<Public, Private> core::fmt::Debug for KeyPairComponents<Public, Private>
where
public::Components<Public>: core::fmt::Debug,
{

View File

@ -12,7 +12,7 @@
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
use super::{keypair::Components, padding::RsaEncoding, public, N};
use super::{padding::RsaEncoding, public, KeyPairComponents, N};
/// RSA PKCS#1 1.5 signatures.
use crate::{
@ -155,7 +155,7 @@ impl RsaKeyPair {
let dQ = nonnegative_integer(input)?;
let qInv = nonnegative_integer(input)?;
let components = Components {
let components = KeyPairComponents {
public_key: super::public::Components { n, e },
d,
p,
@ -214,13 +214,13 @@ impl RsaKeyPair {
/// validating a key pair for use by some other system; that other
/// system must check the value of `d` itself if `d` is to be used.
pub fn from_components<Public, Private>(
components: &Components<Public, Private>,
components: &KeyPairComponents<Public, Private>,
) -> Result<Self, KeyRejected>
where
Public: AsRef<[u8]>,
Private: AsRef<[u8]>,
{
let components = Components {
let components = KeyPairComponents {
public_key: public::Components {
n: components.public_key.n.as_ref(),
e: components.public_key.e.as_ref(),
@ -236,7 +236,7 @@ impl RsaKeyPair {
}
fn from_components_(
&Components {
&KeyPairComponents {
public_key,
d,
p,
@ -244,7 +244,7 @@ impl RsaKeyPair {
dP,
dQ,
qInv,
}: &Components<&[u8]>,
}: &KeyPairComponents<&[u8]>,
cpu_features: cpu::Features,
) -> Result<Self, KeyRejected> {
let d = untrusted::Input::from(d);