diff options
author | Paul Selkirk <paul@psgd.org> | 2018-08-12 15:01:06 -0400 |
---|---|---|
committer | Paul Selkirk <paul@psgd.org> | 2018-08-12 15:01:06 -0400 |
commit | 7537c3a6f3c50301f220a0f1500afda904b4a2cf (patch) | |
tree | 85b68dcbfaa29116321c09aaabd27a4539b91425 | |
parent | 91658ababd0f3d902c3c40673640b6a8f90c648c (diff) |
Clean up builds for *BSD/clang.
Move lm[ot]s_algorithm_t definitions to hal.h, prefix all public symbols with 'hal_'.
Remove some unused functions.
Wrap hal_pkey_slot_t initializers in an extra set of curly braces.
Remove an unused-argument kludge (x=x;) because gcc doesn't care, and clang complains.
Make timersub a proper macro.
Add some casts to printf arguments, because !@#$ printf formats.
-rw-r--r-- | hal.h | 22 | ||||
-rw-r--r-- | hal_internal.h | 4 | ||||
-rw-r--r-- | hashsig.c | 110 | ||||
-rw-r--r-- | hashsig.h | 31 | ||||
-rw-r--r-- | rpc_api.c | 4 | ||||
-rw-r--r-- | rpc_client.c | 4 | ||||
-rw-r--r-- | rpc_client_daemon.c | 1 | ||||
-rw-r--r-- | rpc_pkey.c | 4 | ||||
-rw-r--r-- | tests/test-rpc_hashsig.c | 79 |
9 files changed, 128 insertions, 131 deletions
@@ -815,16 +815,30 @@ extern hal_error_t hal_rpc_pkey_generate_ec(const hal_client_handle_t client, const hal_curve_name_t curve, const hal_key_flags_t flags); -typedef enum lmots_algorithm_type lmots_algorithm_t; -typedef enum lms_algorithm_type lms_algorithm_t; +typedef enum lmots_algorithm_type { + hal_lmots_reserved = 0, + hal_lmots_sha256_n32_w1 = 1, + hal_lmots_sha256_n32_w2 = 2, + hal_lmots_sha256_n32_w4 = 3, + hal_lmots_sha256_n32_w8 = 4 +} hal_lmots_algorithm_t; + +typedef enum lms_algorithm_type { + hal_lms_reserved = 0, + hal_lms_sha256_n32_h5 = 5, + hal_lms_sha256_n32_h10 = 6, + hal_lms_sha256_n32_h15 = 7, + hal_lms_sha256_n32_h20 = 8, + hal_lms_sha256_n32_h25 = 9 +} hal_lms_algorithm_t; extern hal_error_t hal_rpc_pkey_generate_hashsig(const hal_client_handle_t client, const hal_session_handle_t session, hal_pkey_handle_t *pkey, hal_uuid_t *name, const size_t hss_levels, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type, + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type, const hal_key_flags_t flags); extern hal_error_t hal_rpc_pkey_close(const hal_pkey_handle_t pkey); diff --git a/hal_internal.h b/hal_internal.h index 94546c3..15f4c79 100644 --- a/hal_internal.h +++ b/hal_internal.h @@ -310,8 +310,8 @@ typedef struct { hal_pkey_handle_t *pkey, hal_uuid_t *name, const size_t hss_levels, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type, + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type, const hal_key_flags_t flags); hal_error_t (*close)(const hal_pkey_handle_t pkey); @@ -116,38 +116,39 @@ static inline hal_error_t hal_asn1_decode_size_t(size_t *np, const uint8_t * con } } -static inline hal_error_t hal_asn1_encode_lms_algorithm(const lms_algorithm_t type, uint8_t *der, size_t *der_len, const size_t der_max) +static inline hal_error_t hal_asn1_encode_lms_algorithm(const hal_lms_algorithm_t type, uint8_t *der, size_t *der_len, const size_t der_max) { return hal_asn1_encode_uint32((const uint32_t)type, der, der_len, der_max); } -static inline hal_error_t hal_asn1_decode_lms_algorithm(lms_algorithm_t *type, const uint8_t * const der, size_t *der_len, const size_t der_max) +static inline hal_error_t hal_asn1_decode_lms_algorithm(hal_lms_algorithm_t *type, const uint8_t * const der, size_t *der_len, const size_t der_max) { uint32_t n; hal_error_t err; if ((err = hal_asn1_decode_uint32(&n, der, der_len, der_max)) == HAL_OK) - *type = (lms_algorithm_t)n; + *type = (hal_lms_algorithm_t)n; return err; } -static inline hal_error_t hal_asn1_encode_lmots_algorithm(const lmots_algorithm_t type, uint8_t *der, size_t *der_len, const size_t der_max) +static inline hal_error_t hal_asn1_encode_lmots_algorithm(const hal_lmots_algorithm_t type, uint8_t *der, size_t *der_len, const size_t der_max) { return hal_asn1_encode_uint32((const uint32_t)type, der, der_len, der_max); } -static inline hal_error_t hal_asn1_decode_lmots_algorithm(lmots_algorithm_t *type, const uint8_t * const der, size_t *der_len, const size_t der_max) +static inline hal_error_t hal_asn1_decode_lmots_algorithm(hal_lmots_algorithm_t *type, const uint8_t * const der, size_t *der_len, const size_t der_max) { uint32_t n; hal_error_t err; if ((err = hal_asn1_decode_uint32(&n, der, der_len, der_max)) == HAL_OK) - *type = (lmots_algorithm_t)n; + *type = (hal_lmots_algorithm_t)n; return err; } +#if 0 /* currently unused */ static inline hal_error_t hal_asn1_encode_uuid(const hal_uuid_t * const data, uint8_t *der, size_t *der_len, const size_t der_max) { return hal_asn1_encode_octet_string((const uint8_t * const)data, sizeof(hal_uuid_t), der, der_len, der_max); @@ -157,6 +158,7 @@ static inline hal_error_t hal_asn1_decode_uuid(hal_uuid_t *data, const uint8_t * { return hal_asn1_decode_octet_string((uint8_t *)data, sizeof(hal_uuid_t), der, der_len, der_max); } +#endif static inline hal_error_t hal_asn1_encode_bytestring16(const bytestring16 * const data, uint8_t *der, size_t *der_len, const size_t der_max) { @@ -185,14 +187,14 @@ static inline hal_error_t hal_asn1_decode_bytestring32(bytestring32 *data, const */ typedef const struct lmots_parameter_set { - lmots_algorithm_t type; + hal_lmots_algorithm_t type; size_t n, w, p, ls; } lmots_parameter_t; static lmots_parameter_t lmots_parameters[] = { - { lmots_sha256_n32_w1, 32, 1, 265, 7 }, - { lmots_sha256_n32_w2, 32, 2, 133, 6 }, - { lmots_sha256_n32_w4, 32, 4, 67, 4 }, - { lmots_sha256_n32_w8, 32, 8, 34, 0 }, + { hal_lmots_sha256_n32_w1, 32, 1, 265, 7 }, + { hal_lmots_sha256_n32_w2, 32, 2, 133, 6 }, + { hal_lmots_sha256_n32_w4, 32, 4, 67, 4 }, + { hal_lmots_sha256_n32_w8, 32, 8, 34, 0 }, }; typedef struct lmots_key { @@ -204,12 +206,12 @@ typedef struct lmots_key { bytestring32 K; } lmots_key_t; -static inline lmots_parameter_t *lmots_select_parameter_set(const lmots_algorithm_t lmots_type) +static inline lmots_parameter_t *lmots_select_parameter_set(const hal_lmots_algorithm_t lmots_type) { - if (lmots_type < lmots_sha256_n32_w1 || lmots_type > lmots_sha256_n32_w8) + if (lmots_type < hal_lmots_sha256_n32_w1 || lmots_type > hal_lmots_sha256_n32_w8) return NULL; else - return &lmots_parameters[lmots_type - lmots_sha256_n32_w1]; + return &lmots_parameters[lmots_type - hal_lmots_sha256_n32_w1]; } static inline size_t lmots_private_key_len(lmots_parameter_t * const lmots) @@ -218,11 +220,13 @@ static inline size_t lmots_private_key_len(lmots_parameter_t * const lmots) return 2 * sizeof(uint32_t) + sizeof(bytestring16) + (lmots->p * lmots->n); } +#if 0 /* currently unused */ static inline size_t lmots_public_key_len(lmots_parameter_t * const lmots) { /* u32str(type) || I || u32str(q) || K */ return 2 * sizeof(uint32_t) + sizeof(bytestring16) + lmots->n; } +#endif static inline size_t lmots_signature_len(lmots_parameter_t * const lmots) { @@ -453,7 +457,7 @@ static hal_error_t lmots_public_key_candidate(const lmots_key_t * const key, // b. if sigtype is not equal to pubtype, return INVALID - if ((lmots_algorithm_t)sigtype != key->lmots->type) + if ((hal_lmots_algorithm_t)sigtype != key->lmots->type) return HAL_ERROR_INVALID_SIGNATURE; // c. set n and p according to the pubtype and Table 1; if the @@ -629,7 +633,7 @@ static hal_error_t lmots_private_key_from_der(lmots_key_t *key, // u32str(lmots_type) || I || u32str(q) || K || x[0] || x[1] || ... || x[p-1] - lmots_algorithm_t lmots_type; + hal_lmots_algorithm_t lmots_type; check(hal_asn1_decode_lmots_algorithm(&lmots_type, d, &len, vlen)); d += len; vlen -= len; key->lmots = lmots_select_parameter_set(lmots_type); check(hal_asn1_decode_bytestring16(&key->I, d, &len, vlen)); d += len; vlen -= len; @@ -655,15 +659,15 @@ static hal_error_t lmots_private_key_from_der(lmots_key_t *key, */ typedef const struct lms_parameter_set { - lms_algorithm_t type; + hal_lms_algorithm_t type; size_t m, h; } lms_parameter_t; static lms_parameter_t lms_parameters[] = { - { lms_sha256_n32_h5, 32, 5 }, - { lms_sha256_n32_h10, 32, 10 }, - { lms_sha256_n32_h15, 32, 15 }, - { lms_sha256_n32_h20, 32, 20 }, - { lms_sha256_n32_h25, 32, 25 }, + { hal_lms_sha256_n32_h5, 32, 5 }, + { hal_lms_sha256_n32_h10, 32, 10 }, + { hal_lms_sha256_n32_h15, 32, 15 }, + { hal_lms_sha256_n32_h20, 32, 20 }, + { hal_lms_sha256_n32_h25, 32, 25 }, }; typedef struct lms_key { @@ -682,12 +686,12 @@ typedef struct lms_key { size_t signature_len; } lms_key_t; -static inline lms_parameter_t *lms_select_parameter_set(const lms_algorithm_t lms_type) +static inline lms_parameter_t *lms_select_parameter_set(const hal_lms_algorithm_t lms_type) { - if (lms_type < lms_sha256_n32_h5 || lms_type > lms_sha256_n32_h25) + if (lms_type < hal_lms_sha256_n32_h5 || lms_type > hal_lms_sha256_n32_h25) return NULL; else - return &lms_parameters[lms_type - lms_sha256_n32_h5]; + return &lms_parameters[lms_type - hal_lms_sha256_n32_h5]; } static inline size_t lms_public_key_len(lms_parameter_t * const lms) @@ -796,7 +800,7 @@ static hal_error_t lms_generate(lms_key_t *key) static hal_error_t lms_delete(const lms_key_t * const key) { - hal_pkey_slot_t slot = {0}; + hal_pkey_slot_t slot = {{0}}; hal_ks_t *ks = (key->level == 0) ? hal_ks_token : hal_ks_volatile; /* delete the lmots keys */ @@ -959,7 +963,7 @@ static hal_error_t lms_public_key_candidate(const lms_key_t * const key, // c. if otssigtype is not the OTS typecode from the public key, return INVALID - if ((lmots_algorithm_t)otssigtype != key->lmots->type) + if ((hal_lmots_algorithm_t)otssigtype != key->lmots->type) return HAL_ERROR_INVALID_SIGNATURE; // d. set n, p according to otssigtype and Table 1; if the @@ -982,7 +986,7 @@ static hal_error_t lms_public_key_candidate(const lms_key_t * const key, // f. if sigtype is not the LM typecode from the public key, return INVALID - if ((lms_algorithm_t)sigtype != key->lms->type) + if ((hal_lms_algorithm_t)sigtype != key->lms->type) return HAL_ERROR_INVALID_SIGNATURE; // g. set m, h according to sigtype and Table 2 @@ -1148,10 +1152,10 @@ static hal_error_t lms_private_key_from_der(lms_key_t *key, // u32str(lms_type) || u32str(lmots_type) || I || q - lms_algorithm_t lms_type; + hal_lms_algorithm_t lms_type; check(hal_asn1_decode_lms_algorithm(&lms_type, d, &n, vlen)); d += n; vlen -= n; key->lms = lms_select_parameter_set(lms_type); - lmots_algorithm_t lmots_type; + hal_lmots_algorithm_t lmots_type; check(hal_asn1_decode_lmots_algorithm(&lmots_type, d, &n, vlen)); d += n; vlen -= n; key->lmots = lmots_select_parameter_set(lmots_type); check(hal_asn1_decode_bytestring16(&key->I, d, &n, vlen)); d += n; vlen -= n; @@ -1192,11 +1196,13 @@ const size_t hal_hashsig_key_t_size = sizeof(hss_key_t); static hss_key_t *hss_keys = NULL; +#if 0 /* currently unused */ static inline size_t hss_public_key_len(lms_parameter_t * const lms) { /* L || pub[0] */ return sizeof(uint32_t) + lms_public_key_len(lms); } +#endif static inline size_t hss_signature_len(const size_t L, lms_parameter_t * const lms, lmots_parameter_t * const lmots) { @@ -1205,8 +1211,8 @@ static inline size_t hss_signature_len(const size_t L, lms_parameter_t * const l } size_t hal_hashsig_signature_len(const size_t L, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type) + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type) { lms_parameter_t * const lms = lms_select_parameter_set(lms_type); if (lms == NULL) @@ -1219,7 +1225,7 @@ size_t hal_hashsig_signature_len(const size_t L, return hss_signature_len(L, lms, lmots); } -size_t hal_hashsig_lmots_private_key_len(const lmots_algorithm_t lmots_type) +size_t hal_hashsig_lmots_private_key_len(const hal_lmots_algorithm_t lmots_type) { lmots_parameter_t * const lmots = lmots_select_parameter_set(lmots_type); if (lmots == NULL) @@ -1243,8 +1249,8 @@ static inline void *gnaw(uint8_t **mem, size_t *len, const size_t size) static hal_error_t hss_alloc(hal_hashsig_key_t **key_, const size_t L, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type) + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type) { if (key_ == NULL) return HAL_ERROR_BAD_ARGUMENTS; @@ -1329,8 +1335,8 @@ static hal_error_t hss_alloc(hal_hashsig_key_t **key_, hal_error_t hal_hashsig_key_gen(hal_core_t *core, hal_hashsig_key_t **key_, const size_t L, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type) + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type) { /* hss_alloc does most of the checks */ @@ -1520,8 +1526,6 @@ hal_error_t hal_hashsig_verify(hal_core_t *core, if (key == NULL || key->type != HAL_KEY_TYPE_HASHSIG_PUBLIC || msg == NULL || sig == NULL) return HAL_ERROR_BAD_ARGUMENTS; - core = core; - // To verify a signature sig and message using the public key pub, the // following steps are performed: // @@ -1567,7 +1571,7 @@ hal_error_t hal_hashsig_verify(hal_core_t *core, /* read lmots_type out of the ots_signature */ uint32_t lmots_type; check(hal_xdr_decode_int_peek(&sigptr, siglim, &lmots_type)); - lmots_parameter_t *lmots = lmots_select_parameter_set((lmots_algorithm_t)lmots_type); + lmots_parameter_t *lmots = lmots_select_parameter_set((hal_lmots_algorithm_t)lmots_type); if (lmots == NULL) return HAL_ERROR_INVALID_SIGNATURE; /* skip over ots_signature */ @@ -1575,7 +1579,7 @@ hal_error_t hal_hashsig_verify(hal_core_t *core, /* read lms_type after ots_signature */ uint32_t lms_type; check(hal_xdr_decode_int(&sigptr, siglim, &lms_type)); - lms_parameter_t *lms = lms_select_parameter_set((lms_algorithm_t)lms_type); + lms_parameter_t *lms = lms_select_parameter_set((hal_lms_algorithm_t)lms_type); if (lms == NULL) return HAL_ERROR_INVALID_SIGNATURE; /* skip over the path elements of the lms signature */ @@ -1587,11 +1591,11 @@ hal_error_t hal_hashsig_verify(hal_core_t *core, /* parse the signed public key */ check(hal_xdr_decode_int(&sigptr, siglim, &lms_type)); - pub.lms = lms_select_parameter_set((lmots_algorithm_t)lms_type); + pub.lms = lms_select_parameter_set((hal_lms_algorithm_t)lms_type); if (pub.lms == NULL) return HAL_ERROR_INVALID_SIGNATURE; check(hal_xdr_decode_int(&sigptr, siglim, &lmots_type)); - pub.lmots = lmots_select_parameter_set((lmots_algorithm_t)lmots_type); + pub.lmots = lmots_select_parameter_set((hal_lmots_algorithm_t)lmots_type); if (pub.lmots == NULL) return HAL_ERROR_INVALID_SIGNATURE; check(hal_xdr_decode_bytestring16(&sigptr, siglim, &pub.I)); @@ -1688,10 +1692,10 @@ hal_error_t hal_hashsig_private_key_from_der(hal_hashsig_key_t **key_, size_t n; check(hal_asn1_decode_size_t(&key->L, d, &n, vlen)); d += n; vlen -= n; - lms_algorithm_t lms_type; + hal_lms_algorithm_t lms_type; check(hal_asn1_decode_lms_algorithm(&lms_type, d, &n, vlen)); d += n; vlen -= n; key->lms = lms_select_parameter_set(lms_type); - lmots_algorithm_t lmots_type; + hal_lmots_algorithm_t lmots_type; check(hal_asn1_decode_lmots_algorithm(&lmots_type, d, &n, vlen)); d += n; vlen -= n; key->lmots = lmots_select_parameter_set(lmots_type); check(hal_asn1_decode_bytestring16(&key->I, d, &n, vlen)); d += n; vlen -= n; @@ -1789,8 +1793,8 @@ hal_error_t hal_hashsig_public_key_from_der(hal_hashsig_key_t **key_, // L || u32str(lms_type) || u32str(lmots_type) || I || T[1] - lms_algorithm_t lms_type; - lmots_algorithm_t lmots_type; + hal_lms_algorithm_t lms_type; + hal_lmots_algorithm_t lmots_type; check(hal_asn1_decode_size_t(&key->L, d, &len, pubkey_end - d)); d += len; check(hal_asn1_decode_lms_algorithm(&lms_type, d, &len, pubkey_end - d)); d += len; @@ -1810,8 +1814,8 @@ hal_error_t hal_hashsig_public_key_from_der(hal_hashsig_key_t **key_, hal_error_t hal_hashsig_key_load_public(hal_hashsig_key_t **key_, void *keybuf, const size_t keybuf_len, const size_t L, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type, + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type, const uint8_t * const I, const size_t I_len, const uint8_t * const T1, const size_t T1_len) { @@ -1890,8 +1894,8 @@ hal_error_t hal_hashsig_public_key_der_to_xdr(const uint8_t * const der, const s // L || u32str(lms_type) || u32str(lmots_type) || I || T[1] size_t L; - lms_algorithm_t lms_type; - lmots_algorithm_t lmots_type; + hal_lms_algorithm_t lms_type; + hal_lmots_algorithm_t lmots_type; bytestring16 I; bytestring32 T1; @@ -1927,7 +1931,7 @@ hal_error_t hal_hashsig_ks_init(void) const hal_session_handle_t session = { HAL_HANDLE_NONE }; hal_uuid_t prev_name = {{0}}; unsigned len; - hal_pkey_slot_t slot = {0}; + hal_pkey_slot_t slot = {{0}}; uint8_t der[HAL_KS_WRAPPED_KEYSIZE]; size_t der_len; @@ -1945,7 +1949,7 @@ hal_error_t hal_hashsig_ks_init(void) } /* Make sure we have the lms key */ - hal_pkey_slot_t lms_slot = {0}; + hal_pkey_slot_t lms_slot = {{0}}; lms_key_t lms_key; memcpy(&lms_slot.name, &key->I, sizeof(lms_slot.name)); if (hal_ks_fetch(hal_ks_token, &lms_slot, der, &der_len, sizeof(der)) != HAL_OK || @@ -35,23 +35,6 @@ #ifndef _HAL_HASHSIG_H_ #define _HAL_HASHSIG_H_ -typedef enum lmots_algorithm_type { - lmots_reserved = 0, - lmots_sha256_n32_w1 = 1, - lmots_sha256_n32_w2 = 2, - lmots_sha256_n32_w4 = 3, - lmots_sha256_n32_w8 = 4 -} lmots_algorithm_t; - -typedef enum lms_algorithm_type { - lms_reserved = 0, - lms_sha256_n32_h5 = 5, - lms_sha256_n32_h10 = 6, - lms_sha256_n32_h15 = 7, - lms_sha256_n32_h20 = 8, - lms_sha256_n32_h25 = 9 -} lms_algorithm_t; - typedef struct hal_hashsig_key hal_hashsig_key_t; extern const size_t hal_hashsig_key_t_size; @@ -59,8 +42,8 @@ extern const size_t hal_hashsig_key_t_size; extern hal_error_t hal_hashsig_key_gen(hal_core_t *core, hal_hashsig_key_t **key_, const size_t hss_levels, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type); + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type); extern hal_error_t hal_hashsig_key_delete(const hal_hashsig_key_t * const key); @@ -95,8 +78,8 @@ extern hal_error_t hal_hashsig_verify(hal_core_t *core, extern hal_error_t hal_hashsig_key_load_public(hal_hashsig_key_t **key_, void *keybuf, const size_t keybuf_len, const size_t L, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type, + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type, const uint8_t * const I, const size_t I_len, const uint8_t * const T1, const size_t T1_len); @@ -105,10 +88,10 @@ extern hal_error_t hal_hashsig_key_load_public_xdr(hal_hashsig_key_t **key_, const uint8_t * const xdr, const size_t xdr_len); extern size_t hal_hashsig_signature_len(const size_t L, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type); + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type); -extern size_t hal_hashsig_lmots_private_key_len(const lmots_algorithm_t lmots_type); +extern size_t hal_hashsig_lmots_private_key_len(const hal_lmots_algorithm_t lmots_type); extern hal_error_t hal_hashsig_public_key_der_to_xdr(const uint8_t * const der, const size_t der_len, uint8_t * const xdr, size_t * const xdr_len , const size_t xdr_max); @@ -278,8 +278,8 @@ hal_error_t hal_rpc_pkey_generate_hashsig(const hal_client_handle_t client, hal_pkey_handle_t *pkey, hal_uuid_t *name, const size_t hss_levels, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type, + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type, const hal_key_flags_t flags) { if (pkey == NULL || name == NULL || !check_pkey_flags(flags)) diff --git a/rpc_client.c b/rpc_client.c index e97289e..eb3333e 100644 --- a/rpc_client.c +++ b/rpc_client.c @@ -548,8 +548,8 @@ static hal_error_t pkey_remote_generate_hashsig(const hal_client_handle_t client hal_pkey_handle_t *pkey, hal_uuid_t *name, const size_t hss_levels, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type, + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type, const hal_key_flags_t flags) { uint8_t outbuf[nargs(7)], *optr = outbuf, *olimit = outbuf + sizeof(outbuf); diff --git a/rpc_client_daemon.c b/rpc_client_daemon.c index 1c506eb..d47ac7d 100644 --- a/rpc_client_daemon.c +++ b/rpc_client_daemon.c @@ -37,6 +37,7 @@ #include <netinet/in.h> #include <unistd.h> #include <sys/un.h> +#include <sys/socket.h> #include "hal.h" #include "hal_internal.h" @@ -530,8 +530,8 @@ static hal_error_t pkey_local_generate_hashsig(const hal_client_handle_t client, hal_pkey_handle_t *pkey, hal_uuid_t *name, const size_t hss_levels, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type, + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type, const hal_key_flags_t flags) { hal_assert(pkey != NULL && name != NULL); diff --git a/tests/test-rpc_hashsig.c b/tests/test-rpc_hashsig.c index 8cd2897..8b9e509 100644 --- a/tests/test-rpc_hashsig.c +++ b/tests/test-rpc_hashsig.c @@ -52,22 +52,17 @@ #include "test-hashsig.h" #include <sys/time.h> -/* not included in my glibc, sigh... */ -/* But it's a macro on *BSD including MacOS so don't conflict with that. */ + #ifndef timersub -void timersub(struct timeval *a, struct timeval *b, struct timeval *res) -{ - res->tv_sec = a->tv_sec - b->tv_sec; - res->tv_usec = a->tv_usec - b->tv_usec; - if (res->tv_usec < 0) { - res->tv_usec += 1000000; - --res->tv_sec; - } - if (res->tv_usec > 1000000) { - res->tv_usec -= 1000000; - ++res->tv_sec; - } -} +#define timersub(a, b, res) \ + do { \ + (res)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ + (res)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ + if ((res)->tv_usec < 0) { \ + (res)->tv_usec += 1000000; \ + --(res)->tv_sec; \ + } \ + } while (0) #endif static int debug = 0; @@ -172,36 +167,36 @@ static void hexdump(const char * const label, const uint8_t * const buf, const s printf("\n"); } -static inline size_t lms_type_to_h(const lms_algorithm_t lms_type) +static inline size_t lms_type_to_h(const hal_lms_algorithm_t lms_type) { switch (lms_type) { - case lms_sha256_n32_h5: return 5; - case lms_sha256_n32_h10: return 10; - case lms_sha256_n32_h15: return 15; - case lms_sha256_n32_h20: return 20; - case lms_sha256_n32_h25: return 25; + case hal_lms_sha256_n32_h5: return 5; + case hal_lms_sha256_n32_h10: return 10; + case hal_lms_sha256_n32_h15: return 15; + case hal_lms_sha256_n32_h20: return 20; + case hal_lms_sha256_n32_h25: return 25; default: return 0; } } -static inline size_t lmots_type_to_w(const lmots_algorithm_t lmots_type) +static inline size_t lmots_type_to_w(const hal_lmots_algorithm_t lmots_type) { switch (lmots_type) { - case lmots_sha256_n32_w1: return 1; - case lmots_sha256_n32_w2: return 2; - case lmots_sha256_n32_w4: return 4; - case lmots_sha256_n32_w8: return 8; + case hal_lmots_sha256_n32_w1: return 1; + case hal_lmots_sha256_n32_w2: return 2; + case hal_lmots_sha256_n32_w4: return 4; + case hal_lmots_sha256_n32_w8: return 8; default: return 0; } } -static inline size_t lmots_type_to_p(const lmots_algorithm_t lmots_type) +static inline size_t lmots_type_to_p(const hal_lmots_algorithm_t lmots_type) { switch (lmots_type) { - case lmots_sha256_n32_w1: return 265; - case lmots_sha256_n32_w2: return 133; - case lmots_sha256_n32_w4: return 67; - case lmots_sha256_n32_w8: return 34; + case hal_lmots_sha256_n32_w1: return 265; + case hal_lmots_sha256_n32_w2: return 133; + case hal_lmots_sha256_n32_w4: return 67; + case hal_lmots_sha256_n32_w8: return 34; default: return 0; } } @@ -227,7 +222,7 @@ static hal_error_t dump_hss_signature(const uint8_t * const sig, const size_t le uint32_t lmots_type; if ((err = hal_xdr_decode_int(&sigptr, siglim, &lmots_type)) != HAL_OK) return err; hexdump("C", sigptr, 32); sigptr += 32; - size_t p = lmots_type_to_p((const lmots_algorithm_t)lmots_type); + size_t p = lmots_type_to_p((const hal_lmots_algorithm_t)lmots_type); for (size_t j = 0; j < p; ++j) { char label[16]; sprintf(label, "y[%lu]", j); @@ -238,7 +233,7 @@ static hal_error_t dump_hss_signature(const uint8_t * const sig, const size_t le hexdump("lms type", sigptr, 4); uint32_t lms_type; if ((err = hal_xdr_decode_int(&sigptr, siglim, &lms_type)) != HAL_OK) return err; - size_t h = lms_type_to_h((const lms_algorithm_t)lms_type); + size_t h = lms_type_to_h((const hal_lms_algorithm_t)lms_type); for (size_t j = 0; j < h; ++j) { char label[16]; sprintf(label, "path[%lu]", j); @@ -264,8 +259,8 @@ static hal_error_t dump_hss_signature(const uint8_t * const sig, const size_t le } static int test_hashsig_sign(const size_t L, - const lms_algorithm_t lms_type, - const lmots_algorithm_t lmots_type, + const hal_lms_algorithm_t lms_type, + const hal_lmots_algorithm_t lmots_type, size_t iterations, int save, int keep) { @@ -315,8 +310,8 @@ static int test_hashsig_sign(const size_t L, timersub(&tv_end, &tv_start, &tv_diff); long per_key = (tv_diff.tv_sec * 1000000 + tv_diff.tv_usec) / (L * (1 << h)); printf("Info: %ldm%ld.%03lds to generate key (%ld.%03lds per lmots key)\n", - tv_diff.tv_sec / 60, tv_diff.tv_sec % 60, tv_diff.tv_usec / 1000, - per_key / 1000000, (per_key % 1000000) / 1000); + (long)tv_diff.tv_sec / 60, (long)tv_diff.tv_sec % 60, (long)tv_diff.tv_usec / 1000, + (long)per_key / 1000000, ((long)per_key % 1000000) / 1000); } uint8_t public_der[hal_rpc_pkey_get_public_key_len(private_key)]; @@ -385,8 +380,8 @@ static int test_hashsig_sign(const size_t L, timersub(&tv_end, &tv_start, &tv_diff); long per_sig = (tv_diff.tv_sec * 1000000 + tv_diff.tv_usec) / i; printf("Info: %ldm%ld.%03lds to generate %d signatures (%ld.%03lds per signature)\n", - tv_diff.tv_sec / 60, tv_diff.tv_sec % 60, tv_diff.tv_usec / 1000, i, - per_sig / 1000000, (per_sig % 1000000) / 1000); + (long)tv_diff.tv_sec / 60, (long)tv_diff.tv_sec % 60, (long)tv_diff.tv_usec / 1000, i, + (long)per_sig / 1000000, ((long)per_sig % 1000000) / 1000); } if (info) @@ -398,7 +393,7 @@ static int test_hashsig_sign(const size_t L, gettimeofday(&tv_end, NULL); timersub(&tv_end, &tv_start, &tv_diff); printf("Info: %ldm%ld.%03lds to verify 1 signature\n", - tv_diff.tv_sec / 60, tv_diff.tv_sec % 60, tv_diff.tv_usec / 1000); + (long)tv_diff.tv_sec / 60, (long)tv_diff.tv_sec % 60, (long)tv_diff.tv_usec / 1000); } } @@ -579,8 +574,8 @@ Numeric arguments can be a single number or a range, e.g. '1..4'\n"; /* A test to key exhaustion would be of the form '-n max' */ if (L_lo > 0) { for (size_t L = L_lo; L <= L_hi; ++L) { - for (lms_algorithm_t lms_type = lms_lo; lms_type <= lms_hi; ++lms_type) { - for (lmots_algorithm_t lmots_type = lmots_lo; lmots_type <= lmots_hi; ++lmots_type) { + for (hal_lms_algorithm_t lms_type = lms_lo; lms_type <= lms_hi; ++lms_type) { + for (hal_lmots_algorithm_t lmots_type = lmots_lo; lmots_type <= lmots_hi; ++lmots_type) { ok &= test_hashsig_sign(L, lms_type, lmots_type, iterations, save, keep); } } |