-
Notifications
You must be signed in to change notification settings - Fork 82
Closed
Description
This OAEP code complies but then throws the Pkcs11(ArgumentsBad) error for any parameters set.
I am using softhsm2.
Here is the code
use cryptoki::context::{CInitializeArgs, Pkcs11};
use cryptoki::mechanism::{Mechanism, MechanismType};
use cryptoki::mechanism::rsa::{PkcsMgfType, PkcsOaepParams, PkcsOaepSource};
use cryptoki::object::Attribute;
use cryptoki::session::UserType;
use std::error::Error;
use cryptoki::types::AuthPin;
const PKCS11_LIB_PATH: &str = "PATH";
const SLOT_ID: u64 = SLOT;
fn main() -> Result<(), Box<dyn Error>> {
let context = Pkcs11::new(PKCS11_LIB_PATH)?;
context.initialize(CInitializeArgs::OsThreads)?;
let session = context.open_rw_session(SLOT_ID.try_into()?)?;
session.login(UserType::User, Some(&AuthPin::new("PIN".into()))).expect("Invalid PIN");
let pub_key_template = [Attribute::ModulusBits(2048.into())];
let (publickey, _privkey) = session.generate_key_pair(&Mechanism::RsaPkcsKeyPairGen,
&pub_key_template, &[])?;
let oaep=PkcsOaepParams::new(MechanismType::SHA1 ,PkcsMgfType::MGF1_SHA1, PkcsOaepSource::empty());
let encrypt_mechanism: Mechanism = Mechanism::RsaPkcsOaep(oaep);
session.encrypt(&encrypt_mechanism, publickey, b"Test")?;
Ok(())
}
Which results in the error: Error: Pkcs11(ArgumentsBad).
I tried the same code without using OAEP and it works as well, So i presume it is an issue with OAEP Padding.
Thank you
Metadata
Metadata
Assignees
Labels
No labels