Browse Source

z/OS support: Hashing bug

Trying to fix some issues with signature generation
master
David Lanzendörfer 11 months ago
parent
commit
bb9b0634d9
1 changed files with 29 additions and 2 deletions
  1. +29
    -2
      src/gskssl_crypto.c

+ 29
- 2
src/gskssl_crypto.c View File

@ -14,6 +14,7 @@
#endif
#include <strings.h>
#include <pthread.h>
#include <netpgp/crypto.h>
#include <netpgp/keyring.h>
@ -23,6 +24,8 @@
#include <netpgp/packet.h>
#include <netpgp/gskssl_glue.h>
pthread_mutex_t hashingmutex = PTHREAD_MUTEX_INITIALIZER;
static int
md5_init(pgp_hash_t *hash)
{
@ -115,9 +118,15 @@ pgp_hash_md5(pgp_hash_t *hash)
static int
sha1_init(pgp_hash_t *hash)
{
pthread_mutex_lock(&hashingmutex);
CK_RV rv = CKR_OK;
CK_MECHANISM mechanism;
if (pgp_get_debug_level(__FILE__)) {
fprintf(stderr, "sha1_init\n");
}
hash->session = malloc(sizeof(CK_SESSION_HANDLE));
rv = getSession(hash->session);
if( rv != CKR_OK) {
@ -147,7 +156,7 @@ sha1_add(pgp_hash_t *hash, const uint8_t *data, unsigned length)
}
rv = funcs->C_GetOperationState(*(hash->session), NULL_PTR, &len);
while( rv != CKR_OK) {}
//while( rv != CKR_OK) {}
rv = funcs->C_DigestUpdate(*(hash->session), (CK_BYTE_PTR)data, length);
if( rv != CKR_OK) {
@ -163,7 +172,7 @@ sha1_finish(pgp_hash_t *hash, uint8_t *out)
CK_ULONG l;
rv = funcs->C_GetOperationState(*(hash->session), NULL_PTR, &l);
while( rv != CKR_OK ) {}
//while( rv != CKR_OK ) {}
rv = funcs->C_DigestFinal(*(hash->session), out, &len);
if( rv != CKR_OK) {
@ -186,6 +195,8 @@ sha1_finish(pgp_hash_t *hash, uint8_t *out)
free(hash->session);
pthread_mutex_unlock(&hashingmutex);
return SHA_DIGEST_LENGTH;
}
@ -213,9 +224,14 @@ pgp_hash_sha1(pgp_hash_t *hash)
static int
sha256_init(pgp_hash_t *hash)
{
pthread_mutex_lock(&hashingmutex);
CK_RV rv = CKR_OK;
CK_MECHANISM mechanism;
if (pgp_get_debug_level(__FILE__)) {
fprintf(stderr, "sha256_init\n");
}
hash->session = malloc(sizeof(CK_SESSION_HANDLE));
rv = getSession(hash->session);
if( rv != CKR_OK) {
@ -238,10 +254,19 @@ static void
sha256_add(pgp_hash_t *hash, const uint8_t *data, unsigned length)
{
CK_RV rv;
CK_ULONG len;
if (pgp_get_debug_level(__FILE__)) {
hexdump(stderr, "sha256_add", (CK_BYTE_PTR)data, length);
}
rv = funcs->C_GetOperationState(*(hash->session), NULL_PTR, &len);
//while( rv != CKR_OK) {}
if ( rv == CKR_CRYPTOKI_NOT_INITIALIZED ) {
fprintf(stderr, "Cryptoki not yet initialized. Doing so now.\n");
sha256_init(hash);
}
rv = funcs->C_DigestUpdate( *(hash->session), (CK_BYTE_PTR)data, length);
if( rv != CKR_OK) {
fprintf(stderr, "C_DigestUpdate: rv = 0x%.8lX\n", rv);
@ -275,6 +300,8 @@ sha256_finish(pgp_hash_t *hash, uint8_t *out)
free(hash->session);
pthread_mutex_unlock(&hashingmutex);
return len;
}


Loading…
Cancel
Save