pkcs11: We have to create our own hashes for some signature schemes.

This commit is contained in:
Tobias Brunner
2011-11-02 20:27:55 +01:00
parent 30a3ede8ce
commit fd48b220ed
4 changed files with 81 additions and 12 deletions
@@ -204,8 +204,10 @@ METHOD(public_key_t, verify, bool,
CK_MECHANISM_PTR mechanism;
CK_SESSION_HANDLE session;
CK_RV rv;
hash_algorithm_t hash_alg;
chunk_t hash = chunk_empty;
mechanism = pkcs11_signature_scheme_to_mech(scheme);
mechanism = pkcs11_signature_scheme_to_mech(scheme, &hash_alg);
if (!mechanism)
{
DBG1(DBG_LIB, "signature scheme %N not supported",
@@ -230,8 +232,21 @@ METHOD(public_key_t, verify, bool,
DBG1(DBG_LIB, "C_VerifyInit() failed: %N", ck_rv_names, rv);
return FALSE;
}
if (hash_alg != HASH_UNKNOWN)
{
hasher_t *hasher = lib->crypto->create_hasher(lib->crypto, hash_alg);
if (!hasher)
{
this->lib->f->C_CloseSession(session);
return FALSE;
}
hasher->allocate_hash(hasher, data, &hash);
hasher->destroy(hasher);
data = hash;
}
rv = this->lib->f->C_Verify(session, data.ptr, data.len, sig.ptr, sig.len);
this->lib->f->C_CloseSession(session);
chunk_free(&hash);
if (rv != CKR_OK)
{
DBG1(DBG_LIB, "C_Verify() failed: %N", ck_rv_names, rv);