summaryrefslogtreecommitdiff
path: root/ckcapi.c
diff options
context:
space:
mode:
Diffstat (limited to 'ckcapi.c')
-rw-r--r--ckcapi.c128
1 files changed, 96 insertions, 32 deletions
diff --git a/ckcapi.c b/ckcapi.c
index 75c133a..b032c13 100644
--- a/ckcapi.c
+++ b/ckcapi.c
@@ -138,28 +138,39 @@ ckcapi_winerr_to_ckr(DWORD werr)
}
CK_RV
-ckcapi_return_data(CK_ATTRIBUTE_PTR attr, CK_VOID_PTR src, DWORD slen)
+ckcapi_return_data_raw(CK_VOID_PTR output, CK_ULONG_PTR n_output,
+ CK_VOID_PTR input, CK_ULONG n_input)
{
+ ASSERT(n_output);
+ ASSERT(input);
+
/* Just asking for the length */
- if(!attr->pValue)
+ if(!output)
{
- attr->ulValueLen = slen;
+ *n_output = n_input;
return CKR_OK;
}
/* Buffer is too short */
- if(slen > attr->ulValueLen)
+ if(n_input > *n_output)
{
- attr->ulValueLen = slen;
+ *n_output = n_input;
return CKR_BUFFER_TOO_SMALL;
}
- attr->ulValueLen = slen;
- memcpy(attr->pValue, src, slen);
+ *n_output = n_input;
+ memcpy(output, input, n_input);
return CKR_OK;
}
CK_RV
+ckcapi_return_data(CK_ATTRIBUTE_PTR attr, CK_VOID_PTR input, DWORD n_input)
+{
+ return ckcapi_return_data_raw(attr->pValue, &(attr->ulValueLen),
+ input, n_input);
+}
+
+CK_RV
ckcapi_return_string(CK_ATTRIBUTE_PTR attr, WCHAR* string)
{
DWORD error;
@@ -866,7 +877,7 @@ CC_C_EncryptUpdate(CK_SESSION_HANDLE session, CK_BYTE_PTR part,
ENTER(C_EncryptUpdate);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -877,7 +888,7 @@ CC_C_EncryptFinal(CK_SESSION_HANDLE session, CK_BYTE_PTR last_encrypted_part,
ENTER(C_EncryptFinal);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -885,22 +896,49 @@ static CK_RV
CC_C_DecryptInit(CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism,
CK_OBJECT_HANDLE key)
{
+ CkCapiObjectData* objdata;
+ CkCapiSession* sess;
+ CK_RV ret;
+
ENTER(C_DecryptInit);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
+ PREREQ(mechanism, CKR_ARGUMENTS_BAD);
+ PREREQ(key, CKR_ARGUMENTS_BAD);
- /* TODO: Implement this */
- RETURN(CKR_FUNCTION_NOT_SUPPORTED);
+ ret = ckcapi_session_get_lock_ref(session, 0, &sess);
+ if(ret == CKR_OK)
+ {
+ ret = ckcapi_session_get_object_data_for(sess, key, &objdata);
+ if(ret == CKR_OK)
+ ret = ckcapi_session_decrypt_init(sess, mechanism, objdata);
+
+ ckcapi_session_unref_unlock(sess);
+ }
+
+ RETURN(ret);
}
static CK_RV
CC_C_Decrypt(CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_data,
CK_ULONG encrypted_data_len, CK_BYTE_PTR data, CK_ULONG_PTR data_len)
{
+ CkCapiSession* sess;
+ CK_RV ret;
+
ENTER(C_Decrypt);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
+ PREREQ(encrypted_data, CKR_ARGUMENTS_BAD);
+ PREREQ(encrypted_data_len, CKR_ARGUMENTS_BAD);
- /* TODO: Implement this */
- RETURN(CKR_FUNCTION_NOT_SUPPORTED);
+ ret = ckcapi_session_get_lock_ref(session, 0, &sess);
+ if(ret == CKR_OK)
+ {
+ ret = ckcapi_session_decrypt(sess, encrypted_data, encrypted_data_len,
+ data, data_len);
+ ckcapi_session_unref_unlock(sess);
+ }
+
+ RETURN(ret);
}
static CK_RV
@@ -910,7 +948,7 @@ CC_C_DecryptUpdate(CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_part,
ENTER(C_DecryptUpdate);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: Implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -921,7 +959,7 @@ CC_C_DecryptFinal(CK_SESSION_HANDLE session, CK_BYTE_PTR pLastPart,
ENTER(C_DecryptFinal);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: Implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -931,7 +969,7 @@ CC_C_DigestInit(CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism)
ENTER(C_DigestInit);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: Implement this */
+ /* RSA/DSA mechs don't support digest. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -942,7 +980,7 @@ CC_C_Digest(CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len,
ENTER(C_Digest);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support digest. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -952,7 +990,7 @@ CC_C_DigestUpdate(CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len
ENTER(C_DigestUpdate);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support digest. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -962,7 +1000,7 @@ CC_C_DigestKey(CK_SESSION_HANDLE session, CK_OBJECT_HANDLE key)
ENTER(C_DigestKey);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support digest. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -973,7 +1011,7 @@ CC_C_DigestFinal(CK_SESSION_HANDLE session, CK_BYTE_PTR digest,
ENTER(C_DigestFinal);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support digest. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -981,22 +1019,48 @@ static CK_RV
CC_C_SignInit(CK_SESSION_HANDLE session, CK_MECHANISM_PTR mechanism,
CK_OBJECT_HANDLE key)
{
+ CkCapiObjectData* objdata;
+ CkCapiSession* sess;
+ CK_RV ret;
+
ENTER(C_SignInit);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
+ PREREQ(mechanism, CKR_ARGUMENTS_BAD);
+ PREREQ(key, CKR_ARGUMENTS_BAD);
- /* TODO: Implement this */
- RETURN(CKR_FUNCTION_NOT_SUPPORTED);
+ ret = ckcapi_session_get_lock_ref(session, 0, &sess);
+ if(ret == CKR_OK)
+ {
+ ret = ckcapi_session_get_object_data_for(sess, key, &objdata);
+ if(ret == CKR_OK)
+ ret = ckcapi_session_sign_init(sess, mechanism, objdata);
+
+ ckcapi_session_unref_unlock(sess);
+ }
+
+ RETURN(ret);
}
static CK_RV
CC_C_Sign(CK_SESSION_HANDLE session, CK_BYTE_PTR data, CK_ULONG data_len,
CK_BYTE_PTR signature, CK_ULONG_PTR signature_len)
{
+ CkCapiSession* sess;
+ CK_RV ret;
+
ENTER(C_Sign);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
+ PREREQ(data, CKR_ARGUMENTS_BAD);
+ PREREQ(data_len, CKR_ARGUMENTS_BAD);
- /* TODO: Implement this */
- RETURN(CKR_FUNCTION_NOT_SUPPORTED);
+ ret = ckcapi_session_get_lock_ref(session, 0, &sess);
+ if(ret == CKR_OK)
+ {
+ ret = ckcapi_session_sign(sess, data, data_len, signature, signature_len);
+ ckcapi_session_unref_unlock(sess);
+ }
+
+ RETURN(ret);
}
static CK_RV
@@ -1005,7 +1069,7 @@ CC_C_SignUpdate(CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len)
ENTER(C_SignUpdate);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: Implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -1016,7 +1080,7 @@ CC_C_SignFinal(CK_SESSION_HANDLE session, CK_BYTE_PTR signature,
ENTER(C_SignFinal);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: Implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -1070,7 +1134,7 @@ CC_C_VerifyUpdate(CK_SESSION_HANDLE session, CK_BYTE_PTR part, CK_ULONG part_len
ENTER(C_VerifyUpdate);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -1081,7 +1145,7 @@ CC_C_VerifyFinal(CK_SESSION_HANDLE session, CK_BYTE_PTR signature,
ENTER(C_VerifyFinal);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -1115,7 +1179,7 @@ CC_C_DigestEncryptUpdate(CK_SESSION_HANDLE session, CK_BYTE_PTR part,
ENTER(C_DigestEncryptUpdate);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -1127,7 +1191,7 @@ CC_C_DecryptDigestUpdate(CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_part,
ENTER(C_DecryptDigestUpdate);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -1139,7 +1203,7 @@ CC_C_SignEncryptUpdate(CK_SESSION_HANDLE session, CK_BYTE_PTR part,
ENTER(C_SignEncryptUpdate);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}
@@ -1151,7 +1215,7 @@ CC_C_DecryptVerifyUpdate(CK_SESSION_HANDLE session, CK_BYTE_PTR encrypted_part,
ENTER(C_DecryptVerifyUpdate);
PREREQ(cryptoki_initialized, CKR_CRYPTOKI_NOT_INITIALIZED);
- /* TODO: See if we need to implement this */
+ /* RSA/DSA mechs don't support incremental crypto operations. */
RETURN(CKR_FUNCTION_NOT_SUPPORTED);
}