[Cryptech-Commits] [sw/pkcs11] 03/14: Merge branch 'master' into ecdsa

git at cryptech.is git at cryptech.is
Mon Sep 14 21:43:54 UTC 2015


This is an automated email from the git hooks/post-receive script.

sra at hactrn.net pushed a commit to branch ecdsa
in repository sw/pkcs11.

commit 22a1a599999109e797fa340c462b7a0f874cbb37
Merge: 92325a4 fc8c37c
Author: Rob Austein <sra at hactrn.net>
Date:   Tue Sep 8 16:04:49 2015 -0400

    Merge branch 'master' into ecdsa

 pkcs11.c | 122 ++++++++++++++++++++++++++++++++++++++++++++++++++-------------
 1 file changed, 98 insertions(+), 24 deletions(-)

diff --cc pkcs11.c
index ff5304a,9d61927..36ecefc
--- a/pkcs11.c
+++ b/pkcs11.c
@@@ -165,6 -158,10 +158,10 @@@ typedef struct p11_session 
    CK_OBJECT_HANDLE
      sign_key_handle,                    /* Key  for C_Sign*() */
      verify_key_handle;                  /* Key  for C_Verify() */
+   hal_hash_state_t
 -    digest_state,                       /* Hash state for C_Digest*() */
 -    sign_digest_state,                  /* Hash state for C_Sign*() */
 -    verify_digest_state;                /* Hash state for C_Verify*() */
++    *digest_state,                      /* Hash state for C_Digest*() */
++    *sign_digest_state,                 /* Hash state for C_Sign*() */
++    *verify_digest_state;               /* Hash state for C_Verify*() */
  } p11_session_t;
  
  /*
@@@ -3293,6 -3039,9 +3292,9 @@@ CK_RV C_Digest(CK_SESSION_HANDLE hSessi
    if (session->digest_descriptor == NULL)
      lose(CKR_OPERATION_NOT_INITIALIZED);
  
 -  if (session->digest_state.state != NULL)
++  if (session->digest_state != NULL)
+     lose(CKR_OPERATION_ACTIVE);
+ 
    rv = *pulDigestLen < session->digest_descriptor->digest_length ? CKR_BUFFER_TOO_SMALL : CKR_OK;
  
    *pulDigestLen = session->digest_descriptor->digest_length;
@@@ -3322,6 -3071,94 +3324,94 @@@
    mutex_unlock_return_with_rv(rv, p11_global_mutex);
  }
  
+ CK_RV C_DigestUpdate(CK_SESSION_HANDLE hSession,
+                      CK_BYTE_PTR pPart,
+                      CK_ULONG ulPartLen)
+ {
+   ENTER_PUBLIC_FUNCTION(C_DigestUpdate);
+ 
+   p11_session_t *session;
+   CK_RV rv = CKR_OK;
+ 
+   mutex_lock_or_return_failure(p11_global_mutex);
+ 
+   if ((session = p11_session_find(hSession)) == NULL)
+     lose(CKR_SESSION_HANDLE_INVALID);
+ 
+   if (pPart == NULL)
+     lose(CKR_ARGUMENTS_BAD);
+ 
+   if (session->digest_descriptor == NULL)
+     lose(CKR_OPERATION_NOT_INITIALIZED);
+ 
+   if (!session->digest_descriptor->can_restore_state)
+     lose(CKR_FUNCTION_FAILED);
+ 
 -  if (session->digest_state.state == NULL) {
++  if (session->digest_state == NULL) {
+     hal_error_t err = hal_hash_initialize(session->digest_descriptor,
+                                           &session->digest_state, NULL, 0);
+     if (err == HAL_ERROR_ALLOCATION_FAILURE)
+       lose(CKR_HOST_MEMORY);
+     else if (err != HAL_OK)
+       lose(CKR_FUNCTION_FAILED);    
+   }
+ 
+   if (!hal_check(hal_hash_update(session->digest_state, pPart, ulPartLen)))
+     lose(CKR_FUNCTION_FAILED);
+ 
+   return mutex_unlock(p11_global_mutex);
+ 
+  fail:
+   if (session != NULL) {
+     hal_hash_cleanup(&session->digest_state);
+     session->digest_descriptor = NULL;
+   }
+   mutex_unlock_return_with_rv(rv, p11_global_mutex);
+ }
+ 
+ CK_RV C_DigestFinal(CK_SESSION_HANDLE hSession,
+                     CK_BYTE_PTR pDigest,
+                     CK_ULONG_PTR pulDigestLen)
+ {
+   ENTER_PUBLIC_FUNCTION(C_DigestFinal);
+ 
+   p11_session_t *session;
+   CK_RV rv = CKR_OK;
+ 
+   mutex_lock_or_return_failure(p11_global_mutex);
+ 
+   if ((session = p11_session_find(hSession)) == NULL)
+     lose(CKR_SESSION_HANDLE_INVALID);
+ 
+   if (pulDigestLen == NULL)
+     lose(CKR_ARGUMENTS_BAD);
+ 
 -  if (session->digest_descriptor == NULL || session->digest_state.state == NULL)
++  if (session->digest_descriptor == NULL || session->digest_state == NULL)
+     lose(CKR_OPERATION_NOT_INITIALIZED);
+ 
+   rv = *pulDigestLen < session->digest_descriptor->digest_length ? CKR_BUFFER_TOO_SMALL : CKR_OK;
+ 
+   *pulDigestLen = session->digest_descriptor->digest_length;
+ 
+   if (pDigest == NULL)
+     return mutex_unlock(p11_global_mutex);
+ 
+   if (rv == CKR_BUFFER_TOO_SMALL)
+     lose(CKR_BUFFER_TOO_SMALL);
+ 
+   if (!hal_check(hal_hash_finalize(session->digest_state, pDigest, *pulDigestLen)))
+     lose(CKR_FUNCTION_FAILED);
+ 
+   rv = CKR_OK;                  /* Fall through */
+ 
+  fail:
+   if (session != NULL) {
+     hal_hash_cleanup(&session->digest_state);
+     session->digest_descriptor = NULL;
+   }
+   mutex_unlock_return_with_rv(rv, p11_global_mutex);
+ }
+ 
  CK_RV C_SignInit(CK_SESSION_HANDLE hSession,
                   CK_MECHANISM_PTR pMechanism,
                   CK_OBJECT_HANDLE hKey)



More information about the Commits mailing list