RustCrypto/RSA

PSS signatures: Could not find 'sha2' in rsa

NikolaWissenklaus opened this issue · 1 comments

When using the code below, the error "could not find 'sha2' in rsa" occurs.

use rsa::RsaPrivateKey;
use rsa::pss::{BlindedSigningKey, VerifyingKey};
use rsa::signature::{Keypair,RandomizedSigner, SignatureEncoding, Verifier};
use rsa::sha2::{Digest, Sha256};

let mut rng = rand::thread_rng();

let bits = 2048;
let private_key = RsaPrivateKey::new(&mut rng, bits).expect("failed to generate a key");
let signing_key = BlindedSigningKey::::new(private_key);
let verifying_key = signing_key.verifying_key();

// Sign
let data = b"hello world";
let signature = signing_key.sign_with_rng(&mut rng, data);
assert_ne!(signature.to_bytes().as_ref(), data);

// Verify
verifying_key.verify(data, &signature).expect("failed to verify");

As noted in the docs:

https://docs.rs/rsa/latest/rsa/#pss-signatures

Note: requires sha2 feature of rsa crate is enabled.

The next release will eliminate the need to enable a feature.