From d30c444305b4fcde74fb39b065a9f716540f9592 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Mon, 8 Dec 2008 20:18:26 +0000 Subject: Hook in the RSA mechanism to the PKCS#11 calls. --- ckcapi-rsa.c | 11 +++++++++++ ckcapi-rsa.h | 3 +++ ckcapi.c | 32 ++++++++++++++++++++------------ 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/ckcapi-rsa.c b/ckcapi-rsa.c index 0d4e75d..122ac53 100644 --- a/ckcapi-rsa.c +++ b/ckcapi-rsa.c @@ -403,3 +403,14 @@ ckcapi_rsa_pkcs_decrypt_cleanup(void* operation) { /* Nothing to do */ } + +void +ckcapi_rsa_pkcs_get_info (CK_MECHANISM_TYPE mech, CK_MECHANISM_INFO_PTR info) +{ + ASSERT(mech == CKM_RSA_PKCS); + ASSERT(info != NULL); + + info->ulMinKeySize = 384; + info->ulMaxKeySize = 16384; + info->flags = 0; +} diff --git a/ckcapi-rsa.h b/ckcapi-rsa.h index 4e00133..d410cc1 100644 --- a/ckcapi-rsa.h +++ b/ckcapi-rsa.h @@ -38,4 +38,7 @@ CK_RV ckcapi_rsa_pkcs_decrypt_perform (CK_BYTE_PTR encdata, CK_ULONG n_enc void ckcapi_rsa_pkcs_decrypt_cleanup (void* operation); +void ckcapi_rsa_pkcs_get_info (CK_MECHANISM_TYPE mech, + CK_MECHANISM_INFO_PTR info); + #endif /* CKCAPI_RSA_H */ diff --git a/ckcapi.c b/ckcapi.c index 38654e9..1bc6dd9 100644 --- a/ckcapi.c +++ b/ckcapi.c @@ -24,6 +24,7 @@ #include "ckcapi.h" #include "ckcapi-object.h" #include "ckcapi-session.h" +#include "ckcapi-rsa.h" #include "ckcapi-token.h" /* Warns about all the raw string usage in this file */ @@ -49,6 +50,10 @@ static HANDLE global_mutex = NULL; #define MAX_PIN_LEN 256 #define MIN_PIN_LEN 1 +static CK_MECHANISM_TYPE all_mechanisms[] = { + CKM_RSA_PKCS +}; + /* ------------------------------------------------------------------- * MODULE GLOBAL FUNCTIONS */ @@ -491,6 +496,8 @@ static CK_RV CC_C_GetMechanismList(CK_SLOT_ID id, CK_MECHANISM_TYPE_PTR mechanism_list, CK_ULONG_PTR count) { + CK_ULONG n_mechs; + ENTER(C_GetMechanismList); PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED); PREREQ(count, CKR_ARGUMENTS_BAD); @@ -498,22 +505,23 @@ CC_C_GetMechanismList(CK_SLOT_ID id, CK_MECHANISM_TYPE_PTR mechanism_list, if(!ckcapi_token_is_valid(id)) RETURN(CKR_SLOT_ID_INVALID); - /* TODO: Eventually we'll return stuff here */ - /* mechanism_list[0] = CKM_RSA_PKCS; */ + n_mechs = sizeof(all_mechanisms) / sizeof(all_mechanisms[0]); if(mechanism_list == NULL) { - *count = 0; + *count = n_mechs; RETURN(CKR_OK); } - if(*count < 0) + if(*count < n_mechs) { - *count = 0; + *count = n_mechs; RETURN(CKR_BUFFER_TOO_SMALL); } - *count = 0; + memcpy(mechanism_list, all_mechanisms, + n_mechs * sizeof(CK_MECHANISM_TYPE)); + *count = n_mechs; RETURN(CKR_OK); } @@ -528,13 +536,13 @@ CC_C_GetMechanismInfo(CK_SLOT_ID id, CK_MECHANISM_TYPE type, if(!ckcapi_token_is_valid(id)) RETURN(CKR_SLOT_ID_INVALID); - /* TODO: Eventually we'll return stuff here */ - RETURN(CKR_MECHANISM_INVALID); + if(type == CKM_RSA_PKCS) + { + ckcapi_rsa_pkcs_get_info(type, info); + RETURN(CKR_OK); + } - /* info->ulMinKeySize = 384; - info->ulMaxKeySize = 16384; - info->flags = 0; - RETURN(CKR_OK);*/ + RETURN(CKR_MECHANISM_INVALID); } static CK_RV -- cgit v1.2.3