Factor RsaPublicKeyComponents
out of rsa::verification
.
This commit is contained in:
parent
796323f56b
commit
d32c304b3d
@ -227,6 +227,8 @@ include = [
|
||||
"src/rsa/convert_nist_rsa_test_vectors.py",
|
||||
"src/rsa.rs",
|
||||
"src/rsa/padding.rs",
|
||||
"src/rsa/public.rs",
|
||||
"src/rsa/public/components.rs",
|
||||
"src/rsa/random.rs",
|
||||
"src/rsa/rsa_pss_padding_tests.txt",
|
||||
"src/rsa/signature_rsa_example_private_key.der",
|
||||
|
@ -60,6 +60,8 @@ enum N {}
|
||||
|
||||
unsafe impl bigint::PublicModulus for N {}
|
||||
|
||||
pub mod public;
|
||||
|
||||
pub(crate) mod verification;
|
||||
|
||||
pub(crate) mod signing;
|
||||
|
19
src/rsa/public.rs
Normal file
19
src/rsa/public.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright 2021 Brian Smith.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
//! Low-level RSA public key API.
|
||||
|
||||
pub(crate) mod components;
|
||||
|
||||
pub use components::Components;
|
37
src/rsa/public/components.rs
Normal file
37
src/rsa/public/components.rs
Normal file
@ -0,0 +1,37 @@
|
||||
// Copyright 2015-2021 Brian Smith.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
|
||||
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
||||
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
|
||||
// SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
||||
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
|
||||
// OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
||||
// CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
/// RSA public key components
|
||||
#[derive(Debug)]
|
||||
pub struct Components<B: AsRef<[u8]> + core::fmt::Debug> {
|
||||
/// The public modulus, encoded in big-endian bytes without leading zeros.
|
||||
pub n: B,
|
||||
|
||||
/// The public exponent, encoded in big-endian bytes without leading zeros.
|
||||
pub e: B,
|
||||
}
|
||||
|
||||
impl<B: Copy> Copy for Components<B> where B: AsRef<[u8]> + core::fmt::Debug {}
|
||||
|
||||
impl<B: Clone> Clone for Components<B>
|
||||
where
|
||||
B: AsRef<[u8]> + core::fmt::Debug,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
n: self.n.clone(),
|
||||
e: self.e.clone(),
|
||||
}
|
||||
}
|
||||
}
|
@ -208,7 +208,16 @@ rsa_params!(
|
||||
`ring::signature`'s module-level documentation for more details."
|
||||
);
|
||||
|
||||
/// Low-level API for the verification of RSA signatures.
|
||||
pub use super::public::Components as RsaPublicKeyComponents;
|
||||
|
||||
impl<B> super::public::Components<B>
|
||||
where
|
||||
B: AsRef<[u8]> + core::fmt::Debug,
|
||||
{
|
||||
/// Verifies that `signature` is a valid signature of `message` using `self`
|
||||
/// as the public key. `params` determine what algorithm parameters
|
||||
/// (padding, digest algorithm, key length range, etc.) are used in the
|
||||
/// verification.
|
||||
///
|
||||
/// When the public key is in DER-encoded PKCS#1 ASN.1 format, it is
|
||||
/// recommended to use `ring::signature::verify()` with
|
||||
@ -225,37 +234,6 @@ rsa_params!(
|
||||
// testing `verify_rsa` directly, but the testing work for RSA PKCS#1
|
||||
// verification was done during the implementation of
|
||||
// `signature::VerificationAlgorithm`, before `verify_rsa` was factored out).
|
||||
#[derive(Debug)]
|
||||
pub struct RsaPublicKeyComponents<B: AsRef<[u8]> + core::fmt::Debug> {
|
||||
/// The public modulus, encoded in big-endian bytes without leading zeros.
|
||||
pub n: B,
|
||||
|
||||
/// The public exponent, encoded in big-endian bytes without leading zeros.
|
||||
pub e: B,
|
||||
}
|
||||
|
||||
impl<B: Copy> Copy for RsaPublicKeyComponents<B> where B: AsRef<[u8]> + core::fmt::Debug {}
|
||||
|
||||
impl<B: Clone> Clone for RsaPublicKeyComponents<B>
|
||||
where
|
||||
B: AsRef<[u8]> + core::fmt::Debug,
|
||||
{
|
||||
fn clone(&self) -> Self {
|
||||
Self {
|
||||
n: self.n.clone(),
|
||||
e: self.e.clone(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<B> RsaPublicKeyComponents<B>
|
||||
where
|
||||
B: AsRef<[u8]> + core::fmt::Debug,
|
||||
{
|
||||
/// Verifies that `signature` is a valid signature of `message` using `self`
|
||||
/// as the public key. `params` determine what algorithm parameters
|
||||
/// (padding, digest algorithm, key length range, etc.) are used in the
|
||||
/// verification.
|
||||
pub fn verify(
|
||||
&self,
|
||||
params: &RsaParameters,
|
||||
|
Loading…
x
Reference in New Issue
Block a user