Browse Source

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.
master
Joost Rijneveld 7 years ago
parent
commit
59d304027c
No known key found for this signature in database GPG Key ID: A4FE39CF49CBC553
6 changed files with 74 additions and 3 deletions
  1. +4
    -2
      params.c
  2. +1
    -1
      params.h
  3. +20
    -0
      xmss_core.c
  4. +14
    -0
      xmss_core.h
  5. +20
    -0
      xmss_core_fast.c
  6. +15
    -0
      xmss_core_fast.h

+ 4
- 2
params.c View File

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


+ 1
- 1
params.h View File

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



+ 20
- 0
xmss_core.c View File

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


+ 14
- 0
xmss_core.h View File

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


+ 20
- 0
xmss_core_fast.c View File

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


+ 15
- 0
xmss_core_fast.h View File

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


Loading…
Cancel
Save