Skip to content

Commit

Permalink
fixup pss
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Gautier <[email protected]>
  • Loading branch information
baloo committed Nov 28, 2023
1 parent b00e7c5 commit 819a72b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 23 deletions.
5 changes: 2 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ members = ["cryptoki", "cryptoki-sys", "cryptoki-rustcrypto"]
[patch.crates-io]
# https://github.com/RustCrypto/formats/pull/1269
spki = { git = "https://github.com/baloo/formats.git", branch = "baloo/spki/from_key" }
# https://github.com/RustCrypto/RSA/pull/393
rsa = { git = "https://github.com/baloo/RSA.git", branch = "baloo/pkcs+pss/alg-id" }
2 changes: 1 addition & 1 deletion cryptoki-rustcrypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ p224 = { version = "0.13.2", features = ["pkcs8"] }
p256 = { version = "0.13.2", features = ["pkcs8"] }
p384 = { version = "0.13.0", features = ["pkcs8"] }
k256 = { version = "0.13.2", features = ["pkcs8"] }
rsa = "0.9"
rsa = "0.9.5"
signature = { version = "2.2.0", features = ["digest"] }
sha1 = { version = "0.10", features = ["oid"] }
sha2 = { version = "0.10", features = ["oid"] }
Expand Down
21 changes: 2 additions & 19 deletions cryptoki-rustcrypto/src/rsa/pss.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use der::{asn1::ObjectIdentifier, oid::AssociatedOid, Any, AnyRef};
use rsa::{
pkcs1::{self, RsaPssParams},
pkcs8::{self},
pss::{Signature, VerifyingKey},
pss::{get_default_pss_signature_algo_id, Signature, VerifyingKey},
};
use signature::digest::Digest;
use spki::{
Expand All @@ -22,7 +22,6 @@ pub struct Signer<D: DigestSigning, S: SessionLike> {
session: S,
private_key: ObjectHandle,
verifying_key: VerifyingKey<D>,
salt_len: usize,
}

impl<D: DigestSigning, S: SessionLike> Signer<D, S> {
Expand Down Expand Up @@ -64,13 +63,11 @@ impl<D: DigestSigning, S: SessionLike> Signer<D, S> {
let public_key = read_key(&session, template)?;

let verifying_key = VerifyingKey::new(public_key);
let salt_len = <D as Digest>::output_size();

Ok(Self {
session,
private_key,
verifying_key,
salt_len,
})
}

Expand Down Expand Up @@ -109,20 +106,6 @@ impl<D: DigestSigning, S: SessionLike> signature::Signer<Signature> for Signer<D

impl<D: DigestSigning, S: SessionLike> DynSignatureAlgorithmIdentifier for Signer<D, S> {
fn signature_algorithm_identifier(&self) -> pkcs8::spki::Result<AlgorithmIdentifierOwned> {
get_pss_signature_algo_id::<D>(self.salt_len as u8)
get_default_pss_signature_algo_id::<D>()
}
}

fn get_pss_signature_algo_id<D>(salt_len: u8) -> pkcs8::spki::Result<AlgorithmIdentifierOwned>
where
D: Digest + AssociatedOid,
{
const ID_RSASSA_PSS: ObjectIdentifier = ObjectIdentifier::new_unwrap("1.2.840.113549.1.1.10");

let pss_params = RsaPssParams::new::<D>(salt_len);

Ok(AlgorithmIdentifierOwned {
oid: ID_RSASSA_PSS,
parameters: Some(Any::encode_from(&pss_params)?),
})
}

0 comments on commit 819a72b

Please sign in to comment.