From 59d304027ce101143d9f54d2b97ef7d3301af290 Mon Sep 17 00:00:00 2001 From: Joost Rijneveld Date: Thu, 26 Oct 2017 16:54:06 +0200 Subject: [PATCH] Let xmss_core decide on secret key size This allows different backends to store additional state information in the secret key while the rest of the codebase remains agnostic. In particular, this prepares for a common xmss_core.h API for both the standard and the BDS-traversal-based implementations. --- params.c | 6 ++++-- params.h | 2 +- xmss_core.c | 20 ++++++++++++++++++++ xmss_core.h | 14 ++++++++++++++ xmss_core_fast.c | 20 ++++++++++++++++++++ xmss_core_fast.h | 15 +++++++++++++++ 6 files changed, 74 insertions(+), 3 deletions(-) diff --git a/params.c b/params.c index 1053301..5191e4a 100644 --- a/params.c +++ b/params.c @@ -1,6 +1,8 @@ #include #include + #include "params.h" +#include "xmss_core.h" int xmss_str_to_oid(uint32_t *oid, const char *s) { @@ -237,7 +239,7 @@ int xmss_parse_oid(xmss_params *params, const uint32_t oid) + params->d * params->wots_sig_bytes + params->full_height * params->n); params->pk_bytes = 2 * params->n; - params->sk_bytes = 4 * params->n + params->index_bytes; + params->sk_bytes = xmss_core_sk_bytes(params); // TODO figure out sensible and legal values for this based on the above params->bds_k = 0; @@ -455,7 +457,7 @@ int xmssmt_parse_oid(xmss_params *params, const uint32_t oid) + params->d * params->wots_sig_bytes + params->full_height * params->n); params->pk_bytes = 2 * params->n; - params->sk_bytes = 4 * params->n + params->index_bytes; + params->sk_bytes = xmssmt_core_sk_bytes(params); // TODO figure out sensible and legal values for this based on the above params->bds_k = 0; diff --git a/params.h b/params.h index 9155bcb..48478c7 100644 --- a/params.h +++ b/params.h @@ -26,7 +26,7 @@ typedef struct { unsigned int index_bytes; unsigned int sig_bytes; unsigned int pk_bytes; - unsigned int sk_bytes; + unsigned long long sk_bytes; unsigned int bds_k; } xmss_params; diff --git a/xmss_core.c b/xmss_core.c index 64bd32e..fda01c3 100644 --- a/xmss_core.c +++ b/xmss_core.c @@ -84,6 +84,16 @@ static void treehash(const xmss_params *params, memcpy(root, stack, params->n); } +/** + * Given a set of parameters, this function returns the size of the secret key. + * This is implementation specific, as varying choices in tree traversal will + * result in varying requirements for state storage. + */ +unsigned long long xmss_core_sk_bytes(const xmss_params *params) +{ + return params->index_bytes + 4 * params->n; +} + /* * Generates a XMSS key pair for a given parameter set. * Format sk: [(32bit) index || SK_SEED || SK_PRF || PUB_SEED || root] @@ -114,6 +124,16 @@ int xmss_core_sign(const xmss_params *params, return xmssmt_core_sign(params, sk, sm, smlen, m, mlen); } +/** + * Given a set of parameters, this function returns the size of the secret key. + * This is implementation specific, as varying choices in tree traversal will + * result in varying requirements for state storage. + */ +unsigned long long xmssmt_core_sk_bytes(const xmss_params *params) +{ + return params->index_bytes + 4 * params->n; +} + /* * Generates a XMSSMT key pair for a given parameter set. * Format sk: [(ceil(h/8) bit) index || SK_SEED || SK_PRF || PUB_SEED] diff --git a/xmss_core.h b/xmss_core.h index e670dd8..251183b 100644 --- a/xmss_core.h +++ b/xmss_core.h @@ -3,6 +3,13 @@ #include "params.h" +/** + * Given a set of parameters, this function returns the size of the secret key. + * This is implementation specific, as varying choices in tree traversal will + * result in varying requirements for state storage. + */ +unsigned long long xmss_core_sk_bytes(const xmss_params *params); + /* * Generates a XMSS key pair for a given parameter set. * Format sk: [(32bit) index || SK_SEED || SK_PRF || PUB_SEED || root] @@ -29,6 +36,13 @@ int xmss_core_sign_open(const xmss_params *params, const unsigned char *sm, unsigned long long smlen, const unsigned char *pk); +/** + * Given a set of parameters, this function returns the size of the secret key. + * This is implementation specific, as varying choices in tree traversal will + * result in varying requirements for state storage. + */ +unsigned long long xmssmt_core_sk_bytes(const xmss_params *params); + /* * Generates a XMSSMT key pair for a given parameter set. * Format sk: [(ceil(h/8) bit) index || SK_SEED || SK_PRF || PUB_SEED] diff --git a/xmss_core_fast.c b/xmss_core_fast.c index 9971805..64e06c1 100644 --- a/xmss_core_fast.c +++ b/xmss_core_fast.c @@ -344,6 +344,16 @@ static void bds_round(const xmss_params *params, } } +/** + * Given a set of parameters, this function returns the size of the secret key. + * This is implementation specific, as varying choices in tree traversal will + * result in varying requirements for state storage. + */ +unsigned long long xmss_core_sk_bytes(const xmss_params *params) +{ + return params->index_bytes + 4 * params->n; +} + /* * Generates a XMSS key pair for a given parameter set. * Format sk: [(32bit) idx || SK_SEED || SK_PRF || PUB_SEED || root] @@ -483,6 +493,16 @@ int xmss_core_sign(const xmss_params *params, return 0; } +/** + * Given a set of parameters, this function returns the size of the secret key. + * This is implementation specific, as varying choices in tree traversal will + * result in varying requirements for state storage. + */ +unsigned long long xmssmt_core_sk_bytes(const xmss_params *params) +{ + return params->index_bytes + 4 * params->n; +} + /* * Generates a XMSSMT key pair for a given parameter set. * Format sk: [(ceil(h/8) bit) idx || SK_SEED || SK_PRF || PUB_SEED || root] diff --git a/xmss_core_fast.h b/xmss_core_fast.h index 767dedd..699ed9e 100644 --- a/xmss_core_fast.h +++ b/xmss_core_fast.h @@ -31,6 +31,14 @@ void xmss_set_bds_state(bds_state *state, unsigned char *stack, unsigned char *auth, unsigned char *keep, treehash_inst *treehash, unsigned char *retain, int next_leaf); + +/** + * Given a set of parameters, this function returns the size of the secret key. + * This is implementation specific, as varying choices in tree traversal will + * result in varying requirements for state storage. + */ +unsigned long long xmss_core_sk_bytes(const xmss_params *params); + /** * Generates a XMSS key pair for a given parameter set. * Format sk: [(32bit) idx || SK_SEED || SK_PRF || PUB_SEED || root] @@ -58,6 +66,13 @@ int xmss_core_sign_open(const xmss_params *params, const unsigned char *sm, unsigned long long smlen, const unsigned char *pk); +/** + * Given a set of parameters, this function returns the size of the secret key. + * This is implementation specific, as varying choices in tree traversal will + * result in varying requirements for state storage. + */ +unsigned long long xmssmt_core_sk_bytes(const xmss_params *params); + /* * Generates a XMSSMT key pair for a given parameter set. * Format sk: [(ceil(h/8) bit) idx || SK_SEED || SK_PRF || PUB_SEED || root]