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.
Этот коммит содержится в:
Joost Rijneveld 2017-10-26 16:54:06 +02:00
родитель 1b16921e3e
Коммит 59d304027c
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: A4FE39CF49CBC553
6 изменённых файлов: 74 добавлений и 3 удалений

Просмотреть файл

@ -1,6 +1,8 @@
#include <stdint.h>
#include <string.h>
#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;

Просмотреть файл

@ -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;

Просмотреть файл

@ -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]

Просмотреть файл

@ -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]

Просмотреть файл

@ -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]

Просмотреть файл

@ -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]