Skip to content

Commit

Permalink
signature: ECDSA OSSL_FUNC_SIGNATURE_DIGEST_SIGN_INIT
Browse files Browse the repository at this point in the history
Signed-off-by: Tomás González <[email protected]>
  • Loading branch information
tgonzalezorlandoarm committed May 14, 2024
1 parent 6bf3f07 commit d2ba7a9
Showing 1 changed file with 22 additions and 2 deletions.
24 changes: 22 additions & 2 deletions parsec-openssl-provider/src/signature/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,36 @@ unsafe extern "C" fn parsec_provider_signature_digest_sign_init(
let prov_key = Arc::from_raw(provkey as *const RwLock<ParsecProviderKeyObject>);

reader_sig_ctx.keyobj = Some(prov_key.clone());
let key_data = match reader_sig_ctx.keyobj {
None => {
return Err("Key Object not set. This should be done through sign_init()".into())
}
Some(ref keyobj) => keyobj.read().unwrap(),
};

let key_name = match key_data.get_key_name() {
None => return Err("Key name not set in the Key Object".into()),
Some(ref name) => name,
};
// Currently we only support SHA256 hash function.
// Return error if any other function is selected.
if let Ok(hash_function) = CStr::from_ptr(mdname).to_str() {
if hash_function != "SHA256" && hash_function != "SHA2-256" {
return Err("Invalid hash function".into());
}
}

Ok(parsec_provider_signature_set_params(ctx, params))
let key_attributes = key_data
.get_provctx()
.get_client()
.key_attributes(key_name)
.map_err(|e| format!("Failed to get specified key's attributes: {}", e))?;
match key_attributes.key_type {
Type::RsaKeyPair => Ok(parsec_provider_signature_set_params(ctx, params)),
Type::EccKeyPair {
curve_family: EccFamily::SecpR1,
} => Ok(parsec_provider_signature_ecdsa_set_params(ctx, params)),
_ => Err("Key type not recognized".to_string().into()),
}
});

match result {
Expand Down

0 comments on commit d2ba7a9

Please sign in to comment.