summaryrefslogtreecommitdiff
path: root/ckcapi-key.c
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2008-12-04 18:59:50 +0000
committerStef Walter <stef@memberwebs.com>2008-12-04 18:59:50 +0000
commitd611032e1e5b4e2261625ee924071e9713320837 (patch)
tree66683785a16c02975b675017f460eb9ed14e799d /ckcapi-key.c
parentb00eb56b7ffe5019bb33ad399d351b90f4715132 (diff)
Implement RSA Sign and Decrypt operations. Not tested.
Diffstat (limited to 'ckcapi-key.c')
-rw-r--r--ckcapi-key.c92
1 files changed, 64 insertions, 28 deletions
diff --git a/ckcapi-key.c b/ckcapi-key.c
index 1ce057c..88e769e 100644
--- a/ckcapi-key.c
+++ b/ckcapi-key.c
@@ -98,6 +98,40 @@ typedef struct _KeyObjectData
KeyObjectData;
static CK_RV
+load_key_handle (CkCapiObjectData* objdata, HCRYPTKEY* ret_key)
+{
+ KeyObjectData* kdata = (KeyObjectData*)objdata;
+ HCRYPTPROV prov;
+ HCRYPTKEY key;
+ DWORD error;
+
+ ASSERT(kdata);
+
+ if(!CryptAcquireContextW(&prov, kdata->prov_info->pwszContainerName,
+ kdata->prov_info->pwszProvName,
+ kdata->prov_info->dwProvType, 0))
+ {
+ return ckcapi_winerr_to_ckr(GetLastError());
+ }
+
+ if(!CryptGetUserKey(prov, kdata->prov_info->dwKeySpec, &key))
+ {
+ error = GetLastError();
+ CryptReleaseContext(prov, 0);
+ return ckcapi_winerr_to_ckr(error);
+ }
+
+ if(ret_key)
+ *ret_key = key;
+ else
+ CryptDestroyKey(key);
+
+ CryptReleaseContext(prov, 0);
+ return CKR_OK;
+}
+
+
+static CK_RV
load_raw_public_key(KeyObjectData* kdata)
{
BOOL success = FALSE;
@@ -108,7 +142,7 @@ load_raw_public_key(KeyObjectData* kdata)
ASSERT(kdata);
ASSERT(!kdata->raw_public_key.pbData);
- ret = ckcapi_key_object_data_get_handles(&kdata->base, NULL, &key);
+ ret = load_key_handle(&kdata->base, &key);
if(ret != CKR_OK)
return ret;
@@ -994,40 +1028,42 @@ ckcapi_key_find(CkCapiSession* sess, CK_OBJECT_CLASS cls,
return ret;
}
-CK_RV
-ckcapi_key_object_data_get_handles (CkCapiObjectData* objdata, HCRYPTPROV* ret_prov,
- HCRYPTKEY* ret_key)
+DWORD
+ckcapi_key_object_data_get_bits(CkCapiObjectData* objdata)
{
- KeyObjectData* kdata = (KeyObjectData*)objdata;
- HCRYPTPROV prov;
- HCRYPTKEY key;
- DWORD error;
+ KeyObjectData* kdata;
+ PUBLICKEYSTRUC* header;
+ RSAPUBKEY* pubkey;
+ CK_RV ret;
- ASSERT(kdata);
+ ASSERT(objdata);
- if(!CryptAcquireContextW(&prov, kdata->prov_info->pwszContainerName,
- kdata->prov_info->pwszProvName,
- kdata->prov_info->dwProvType, 0))
+ kdata = (KeyObjectData*)objdata;
+
+ if(!kdata->raw_public_key.pbData)
{
- return ckcapi_winerr_to_ckr(GetLastError());
+ ret = load_raw_public_key(kdata);
+ if(ret != CKR_OK)
+ return ret;
}
- if(!CryptGetUserKey(prov, kdata->prov_info->dwKeySpec, &key))
- {
- error = GetLastError();
- CryptReleaseContext(prov, 0);
- return ckcapi_winerr_to_ckr(error);
- }
+ header = (PUBLICKEYSTRUC*)kdata->raw_public_key.pbData;
+ if(!header->bType == PUBLICKEYBLOB)
+ return 0;
- if(ret_key)
- *ret_key = key;
- else
- CryptDestroyKey(key);
+ pubkey = (RSAPUBKEY*)(header + 1);
+ if(!pubkey->magic == 0x31415352)
+ return 0;
- if(ret_prov)
- *ret_prov = prov;
- else
- CryptReleaseContext(prov, 0);
+ return pubkey->bitlen;
+}
- return CKR_OK;
+CRYPT_KEY_PROV_INFO*
+ckcapi_key_object_data_get_prov_info(CkCapiObjectData* objdata)
+{
+ KeyObjectData* kdata;
+
+ ASSERT(objdata);
+ kdata = (KeyObjectData*)objdata;
+ return kdata->prov_info;
}