aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2016-11-20 21:15:13 -0500
committerRob Austein <sra@hactrn.net>2016-11-20 21:15:13 -0500
commitf4b6098c2359a75cc16275aad7ba2bf001261dea (patch)
tree6e9d6d617436efab7a79ec49d446987146dd5b87
parent306c1dec5eb20da03bc9569aab83ae97a2ca9e7a (diff)
Move UUID utilities to hal.h; change attribute values to (const void *).
-rw-r--r--hal.h25
-rw-r--r--hal_internal.h18
-rw-r--r--ks_attribute.c2
-rw-r--r--rpc_server.c8
4 files changed, 29 insertions, 24 deletions
diff --git a/hal.h b/hal.h
index df330ae..ee27649 100644
--- a/hal.h
+++ b/hal.h
@@ -39,6 +39,7 @@
#include <stdint.h>
#include <sys/types.h>
#include <stdlib.h>
+#include <string.h>
/*
* A handy macro from cryptlib.
@@ -567,6 +568,26 @@ extern hal_error_t hal_ecdsa_verify(const hal_core_t *core,
const uint8_t * const signature, const size_t signature_len);
/*
+ * UUID stuff. All UUIDs we use (or are likely to use) are type 4 "random" UUIDs
+ */
+
+typedef struct { uint8_t uuid[16]; } hal_uuid_t;
+
+#define HAL_UUID_TEXT_SIZE (sizeof("00112233-4455-6677-8899-aabbccddeeff"))
+
+static inline int hal_uuid_cmp(const hal_uuid_t * const a, const hal_uuid_t * const b)
+{
+ return memcmp(a, b, sizeof(hal_uuid_t));
+}
+
+extern hal_error_t hal_uuid_gen(hal_uuid_t *uuid);
+
+extern hal_error_t hal_uuid_parse(hal_uuid_t *uuid, const char * const string);
+
+extern hal_error_t hal_uuid_format(const hal_uuid_t * const uuid,
+ char *buffer, const size_t buffer_len);
+
+/*
* Higher level RPC-based mechanism for working with HSM at arm's
* length, using handles instead of direct access to the cores.
*
@@ -689,8 +710,6 @@ extern hal_error_t hal_rpc_hash_finalize(const hal_hash_handle_t hash,
* a session handle and which ones don't...).
*/
-typedef struct { uint8_t uuid[16]; } hal_uuid_t;
-
typedef struct { uint32_t handle; } hal_pkey_handle_t;
typedef uint32_t hal_key_flags_t;
@@ -762,7 +781,7 @@ extern hal_error_t hal_rpc_pkey_verify(const hal_pkey_handle_t pkey,
typedef struct {
uint32_t type;
size_t length;
- const uint8_t *value;
+ const void *value;
} hal_rpc_pkey_attribute_t;
extern hal_error_t hal_rpc_pkey_match(const hal_client_handle_t client,
diff --git a/hal_internal.h b/hal_internal.h
index 0794d37..88424cf 100644
--- a/hal_internal.h
+++ b/hal_internal.h
@@ -286,24 +286,6 @@ extern hal_error_t hal_rpc_pkcs1_construct_digestinfo(const hal_hash_handle_t ha
const size_t digest_info_max);
/*
- * UUID stuff. All UUIDs we use (or are likely to use) are type 4 "random" UUIDs
- * Some of this may need to move to hal.h.
- */
-
-#define HAL_UUID_TEXT_SIZE (sizeof("00112233-4455-6677-8899-aabbccddeeff"))
-
-static inline int hal_uuid_cmp(const hal_uuid_t * const a, const hal_uuid_t * const b)
-{
- return memcmp(a, b, sizeof(hal_uuid_t));
-}
-
-extern hal_error_t hal_uuid_gen(hal_uuid_t *uuid);
-
-extern hal_error_t hal_uuid_parse(hal_uuid_t *uuid, const char * const string);
-
-extern hal_error_t hal_uuid_format(const hal_uuid_t * const uuid, char *buffer, const size_t buffer_len);
-
-/*
* CRC-32 stuff (for flash keystore, etc). Dunno if we want a Verilog
* implementation of this, or if it would even be faster than doing it
* the main CPU taking I/O overhead and so forth into account.
diff --git a/ks_attribute.c b/ks_attribute.c
index 53cd6bf..2621ed7 100644
--- a/ks_attribute.c
+++ b/ks_attribute.c
@@ -129,7 +129,7 @@ hal_error_t hal_ks_attribute_delete(uint8_t *bytes, const size_t bytes_len,
return HAL_OK;
const size_t delete_length = hal_ks_attribute_header_size + attributes[i].length;
- const size_t delete_offset = attributes[i].value - hal_ks_attribute_header_size - bytes;
+ const size_t delete_offset = (uint8_t*) attributes[i].value - hal_ks_attribute_header_size - bytes;
if (delete_offset + delete_length > *total_len)
return HAL_ERROR_IMPOSSIBLE;
diff --git a/rpc_server.c b/rpc_server.c
index ae891a4..f4f2a06 100644
--- a/rpc_server.c
+++ b/rpc_server.c
@@ -661,9 +661,11 @@ static hal_error_t pkey_match(const uint8_t **iptr, const uint8_t * const ilimit
for (int i = 0; i < attributes_len; i++) {
hal_rpc_pkey_attribute_t *a = &attributes[i];
+ const uint8_t *value;
uint32_t value_len;
check(hal_xdr_decode_int(iptr, ilimit, &a->type));
- check(hal_xdr_decode_buffer_in_place(iptr, ilimit, &a->value, &value_len));
+ check(hal_xdr_decode_buffer_in_place(iptr, ilimit, &value, &value_len));
+ a->value = value;
a->length = value_len;
}
@@ -712,9 +714,11 @@ static hal_error_t pkey_set_attributes(const uint8_t **iptr, const uint8_t * con
for (int i = 0; i < attributes_len; i++) {
hal_rpc_pkey_attribute_t *a = &attributes[i];
+ const uint8_t *value;
uint32_t value_len;
check(hal_xdr_decode_int(iptr, ilimit, &a->type));
- check(hal_xdr_decode_buffer_in_place(iptr, ilimit, &a->value, &value_len));
+ check(hal_xdr_decode_buffer_in_place(iptr, ilimit, &value, &value_len));
+ a->value = value;
a->length = value_len;
}