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.master
@@ -1,6 +1,8 @@ | |||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "params.h" | #include "params.h" | ||||
#include "xmss_core.h" | |||||
int xmss_str_to_oid(uint32_t *oid, const char *s) | 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->d * params->wots_sig_bytes | ||||
+ params->full_height * params->n); | + params->full_height * params->n); | ||||
params->pk_bytes = 2 * 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 | // TODO figure out sensible and legal values for this based on the above | ||||
params->bds_k = 0; | 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->d * params->wots_sig_bytes | ||||
+ params->full_height * params->n); | + params->full_height * params->n); | ||||
params->pk_bytes = 2 * 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 | // TODO figure out sensible and legal values for this based on the above | ||||
params->bds_k = 0; | params->bds_k = 0; | ||||
@@ -26,7 +26,7 @@ typedef struct { | |||||
unsigned int index_bytes; | unsigned int index_bytes; | ||||
unsigned int sig_bytes; | unsigned int sig_bytes; | ||||
unsigned int pk_bytes; | unsigned int pk_bytes; | ||||
unsigned int sk_bytes; | |||||
unsigned long long sk_bytes; | |||||
unsigned int bds_k; | unsigned int bds_k; | ||||
} xmss_params; | } xmss_params; | ||||
@@ -84,6 +84,16 @@ static void treehash(const xmss_params *params, | |||||
memcpy(root, stack, params->n); | 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. | * Generates a XMSS key pair for a given parameter set. | ||||
* Format sk: [(32bit) index || SK_SEED || SK_PRF || PUB_SEED || root] | * 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); | 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. | * Generates a XMSSMT key pair for a given parameter set. | ||||
* Format sk: [(ceil(h/8) bit) index || SK_SEED || SK_PRF || PUB_SEED] | * Format sk: [(ceil(h/8) bit) index || SK_SEED || SK_PRF || PUB_SEED] | ||||
@@ -3,6 +3,13 @@ | |||||
#include "params.h" | #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. | * Generates a XMSS key pair for a given parameter set. | ||||
* Format sk: [(32bit) index || SK_SEED || SK_PRF || PUB_SEED || root] | * 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 *sm, unsigned long long smlen, | ||||
const unsigned char *pk); | 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. | * Generates a XMSSMT key pair for a given parameter set. | ||||
* Format sk: [(ceil(h/8) bit) index || SK_SEED || SK_PRF || PUB_SEED] | * Format sk: [(ceil(h/8) bit) index || SK_SEED || SK_PRF || PUB_SEED] | ||||
@@ -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. | * Generates a XMSS key pair for a given parameter set. | ||||
* Format sk: [(32bit) idx || SK_SEED || SK_PRF || PUB_SEED || root] | * 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; | 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. | * Generates a XMSSMT key pair for a given parameter set. | ||||
* Format sk: [(ceil(h/8) bit) idx || SK_SEED || SK_PRF || PUB_SEED || root] | * Format sk: [(ceil(h/8) bit) idx || SK_SEED || SK_PRF || PUB_SEED || root] | ||||
@@ -31,6 +31,14 @@ void xmss_set_bds_state(bds_state *state, unsigned char *stack, | |||||
unsigned char *auth, unsigned char *keep, | unsigned char *auth, unsigned char *keep, | ||||
treehash_inst *treehash, unsigned char *retain, | treehash_inst *treehash, unsigned char *retain, | ||||
int next_leaf); | 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. | * Generates a XMSS key pair for a given parameter set. | ||||
* Format sk: [(32bit) idx || SK_SEED || SK_PRF || PUB_SEED || root] | * 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 *sm, unsigned long long smlen, | ||||
const unsigned char *pk); | 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. | * Generates a XMSSMT key pair for a given parameter set. | ||||
* Format sk: [(ceil(h/8) bit) idx || SK_SEED || SK_PRF || PUB_SEED || root] | * Format sk: [(ceil(h/8) bit) idx || SK_SEED || SK_PRF || PUB_SEED || root] | ||||