aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--hal.h5
-rw-r--r--rpc_api.c12
-rw-r--r--rpc_pkey.c8
3 files changed, 14 insertions, 11 deletions
diff --git a/hal.h b/hal.h
index cd3b9c0..9f25e62 100644
--- a/hal.h
+++ b/hal.h
@@ -4,7 +4,7 @@
* Memory map, access functions, and HAL for Cryptech cores.
*
* Authors: Joachim Strombergson, Paul Selkirk, Rob Austein
- * Copyright (c) 2015, NORDUnet A/S All rights reserved.
+ * Copyright (c) 2015-2016, NORDUnet A/S All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
@@ -227,6 +227,7 @@ typedef struct hal_hash_driver hal_hash_driver_t;
*/
typedef enum {
+ hal_digest_algorithm_none,
hal_digest_algorithm_sha1,
hal_digest_algorithm_sha256,
hal_digest_algorithm_sha512_224,
@@ -544,6 +545,8 @@ extern hal_error_t hal_ecdsa_verify(const hal_core_t *core,
* mechanism, not the server (HSM) side.
*/
+#define HAL_HANDLE_NONE (0)
+
typedef struct { uint32_t handle; } hal_client_handle_t;
typedef struct { uint32_t handle; } hal_session_handle_t;
diff --git a/rpc_api.c b/rpc_api.c
index a903f57..b2701a5 100644
--- a/rpc_api.c
+++ b/rpc_api.c
@@ -36,7 +36,7 @@
#include "hal.h"
#include "hal_internal.h"
-const hal_hash_handle_t hal_hash_handle_none = {0};
+const hal_hash_handle_t hal_hash_handle_none = {HAL_HANDLE_NONE};
static inline int check_pkey_type(const hal_key_type_t type)
{
@@ -155,7 +155,7 @@ hal_error_t hal_rpc_hash_get_digest_algorithm_id(const hal_digest_algorithm_t al
hal_error_t hal_rpc_hash_get_algorithm(const hal_hash_handle_t hash, hal_digest_algorithm_t *alg)
{
- if (hash.handle == hal_hash_handle_none.handle || alg == NULL)
+ if (hash.handle == HAL_HANDLE_NONE || alg == NULL)
return HAL_ERROR_BAD_ARGUMENTS;
return hal_rpc_hash_dispatch->get_algorithm(hash, alg);
}
@@ -174,7 +174,7 @@ hal_error_t hal_rpc_hash_initialize(const hal_client_handle_t client,
hal_error_t hal_rpc_hash_update(const hal_hash_handle_t hash,
const uint8_t * data, const size_t length)
{
- if (hash.handle == hal_hash_handle_none.handle || data == NULL)
+ if (hash.handle == HAL_HANDLE_NONE || data == NULL)
return HAL_ERROR_BAD_ARGUMENTS;
if (length == 0)
return HAL_OK;
@@ -184,7 +184,7 @@ hal_error_t hal_rpc_hash_update(const hal_hash_handle_t hash,
hal_error_t hal_rpc_hash_finalize(const hal_hash_handle_t hash,
uint8_t *digest, const size_t length)
{
- if (hash.handle == hal_hash_handle_none.handle || digest == NULL || length == 0)
+ if (hash.handle == HAL_HANDLE_NONE || digest == NULL || length == 0)
return HAL_ERROR_BAD_ARGUMENTS;
return hal_rpc_hash_dispatch->finalize(hash, digest, length);
}
@@ -290,7 +290,7 @@ hal_error_t hal_rpc_pkey_sign(const hal_session_handle_t session,
uint8_t * signature, size_t *signature_len, const size_t signature_max)
{
if (signature == NULL || signature_len == NULL || signature_max == 0 ||
- (hash.handle == hal_hash_handle_none.handle) == (input == NULL || input_len == 0))
+ (hash.handle == HAL_HANDLE_NONE) == (input == NULL || input_len == 0))
return HAL_ERROR_BAD_ARGUMENTS;
return hal_rpc_pkey_dispatch->sign(session, pkey, hash, input, input_len, signature, signature_len, signature_max);
}
@@ -302,7 +302,7 @@ hal_error_t hal_rpc_pkey_verify(const hal_session_handle_t session,
const uint8_t * const signature, const size_t signature_len)
{
if (signature == NULL || signature_len == 0 ||
- (hash.handle == hal_hash_handle_none.handle) == (input == NULL || input_len == 0))
+ (hash.handle == HAL_HANDLE_NONE) == (input == NULL || input_len == 0))
return HAL_ERROR_BAD_ARGUMENTS;
return hal_rpc_pkey_dispatch->verify(session, pkey, hash, input, input_len, signature, signature_len);
}
diff --git a/rpc_pkey.c b/rpc_pkey.c
index 96680ed..3ae8f2a 100644
--- a/rpc_pkey.c
+++ b/rpc_pkey.c
@@ -565,7 +565,7 @@ static hal_error_t sign_rsa(uint8_t *keybuf, const size_t keybuf_len,
hal_error_t err;
assert(signature != NULL && signature_len != NULL);
- assert((hash.handle == hal_hash_handle_none.handle) != (input == NULL || input_len == 0));
+ assert((hash.handle == HAL_HANDLE_NONE) != (input == NULL || input_len == 0));
if ((err = hal_rsa_private_key_from_der(&key, keybuf, keybuf_len, der, der_len)) != HAL_OK ||
(err = hal_rsa_key_get_modulus(key, NULL, signature_len, 0)) != HAL_OK)
@@ -597,7 +597,7 @@ static hal_error_t sign_ecdsa(uint8_t *keybuf, const size_t keybuf_len,
hal_error_t err;
assert(signature != NULL && signature_len != NULL);
- assert((hash.handle == hal_hash_handle_none.handle) != (input == NULL || input_len == 0));
+ assert((hash.handle == HAL_HANDLE_NONE) != (input == NULL || input_len == 0));
if ((err = hal_ecdsa_private_key_from_der(&key, keybuf, keybuf_len, der, der_len)) != HAL_OK)
return err;
@@ -686,7 +686,7 @@ static hal_error_t verify_rsa(uint8_t *keybuf, const size_t keybuf_len, const ha
hal_error_t err;
assert(signature != NULL && signature_len > 0);
- assert((hash.handle == hal_hash_handle_none.handle) != (input == NULL || input_len == 0));
+ assert((hash.handle == HAL_HANDLE_NONE) != (input == NULL || input_len == 0));
switch (type) {
case HAL_KEY_TYPE_RSA_PRIVATE:
@@ -733,7 +733,7 @@ static hal_error_t verify_ecdsa(uint8_t *keybuf, const size_t keybuf_len, const
hal_error_t err;
assert(signature != NULL && signature_len > 0);
- assert((hash.handle == hal_hash_handle_none.handle) != (input == NULL || input_len == 0));
+ assert((hash.handle == HAL_HANDLE_NONE) != (input == NULL || input_len == 0));
switch (type) {
case HAL_KEY_TYPE_EC_PRIVATE: