Make addr type switching not zero out remainder
This behavior was completely unpredictable from the function name, in particular when comparing it to other set_*_addr functions.
This commit is contained in:
parent
51790b9d57
commit
42a2e8aa83
@ -13,12 +13,7 @@ void set_tree_addr(uint32_t addr[8], uint64_t tree)
|
|||||||
|
|
||||||
void set_type(uint32_t addr[8], uint32_t type)
|
void set_type(uint32_t addr[8], uint32_t type)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
|
|
||||||
addr[3] = type;
|
addr[3] = type;
|
||||||
for (i = 4; i < 8; i++) {
|
|
||||||
addr[i] = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void set_key_and_mask(uint32_t addr[8], uint32_t key_and_mask)
|
void set_key_and_mask(uint32_t addr[8], uint32_t key_and_mask)
|
||||||
|
@ -218,16 +218,16 @@ static void treehash_init(const xmss_params *params,
|
|||||||
{
|
{
|
||||||
unsigned int idx = index;
|
unsigned int idx = index;
|
||||||
// use three different addresses because at this point we use all three formats in parallel
|
// use three different addresses because at this point we use all three formats in parallel
|
||||||
uint32_t ots_addr[8];
|
uint32_t ots_addr[8] = {0};
|
||||||
uint32_t ltree_addr[8];
|
uint32_t ltree_addr[8] = {0};
|
||||||
uint32_t node_addr[8];
|
uint32_t node_addr[8] = {0};
|
||||||
// only copy layer and tree address parts
|
// only copy layer and tree address parts
|
||||||
memcpy(ots_addr, addr, 12);
|
copy_subtree_addr(ots_addr, addr);
|
||||||
// type = ots
|
// type = ots
|
||||||
set_type(ots_addr, 0);
|
set_type(ots_addr, 0);
|
||||||
memcpy(ltree_addr, addr, 12);
|
copy_subtree_addr(ltree_addr, addr);
|
||||||
set_type(ltree_addr, 1);
|
set_type(ltree_addr, 1);
|
||||||
memcpy(node_addr, addr, 12);
|
copy_subtree_addr(node_addr, addr);
|
||||||
set_type(node_addr, 2);
|
set_type(node_addr, 2);
|
||||||
|
|
||||||
uint32_t lastnode, i;
|
uint32_t lastnode, i;
|
||||||
@ -287,16 +287,16 @@ static void treehash_update(const xmss_params *params,
|
|||||||
const unsigned char *pub_seed,
|
const unsigned char *pub_seed,
|
||||||
const uint32_t addr[8])
|
const uint32_t addr[8])
|
||||||
{
|
{
|
||||||
uint32_t ots_addr[8];
|
uint32_t ots_addr[8] = {0};
|
||||||
uint32_t ltree_addr[8];
|
uint32_t ltree_addr[8] = {0};
|
||||||
uint32_t node_addr[8];
|
uint32_t node_addr[8] = {0};
|
||||||
// only copy layer and tree address parts
|
// only copy layer and tree address parts
|
||||||
memcpy(ots_addr, addr, 12);
|
copy_subtree_addr(ots_addr, addr);
|
||||||
// type = ots
|
// type = ots
|
||||||
set_type(ots_addr, 0);
|
set_type(ots_addr, 0);
|
||||||
memcpy(ltree_addr, addr, 12);
|
copy_subtree_addr(ltree_addr, addr);
|
||||||
set_type(ltree_addr, 1);
|
set_type(ltree_addr, 1);
|
||||||
memcpy(node_addr, addr, 12);
|
copy_subtree_addr(node_addr, addr);
|
||||||
set_type(node_addr, 2);
|
set_type(node_addr, 2);
|
||||||
|
|
||||||
set_ltree_addr(ltree_addr, treehash->next_idx);
|
set_ltree_addr(ltree_addr, treehash->next_idx);
|
||||||
@ -378,9 +378,9 @@ static char bds_state_update(const xmss_params *params,
|
|||||||
const unsigned char *pub_seed,
|
const unsigned char *pub_seed,
|
||||||
const uint32_t addr[8])
|
const uint32_t addr[8])
|
||||||
{
|
{
|
||||||
uint32_t ltree_addr[8];
|
uint32_t ltree_addr[8] = {0};
|
||||||
uint32_t node_addr[8];
|
uint32_t node_addr[8] = {0};
|
||||||
uint32_t ots_addr[8];
|
uint32_t ots_addr[8] = {0};
|
||||||
|
|
||||||
unsigned int nodeh;
|
unsigned int nodeh;
|
||||||
int idx = state->next_leaf;
|
int idx = state->next_leaf;
|
||||||
@ -389,12 +389,12 @@ static char bds_state_update(const xmss_params *params,
|
|||||||
}
|
}
|
||||||
|
|
||||||
// only copy layer and tree address parts
|
// only copy layer and tree address parts
|
||||||
memcpy(ots_addr, addr, 12);
|
copy_subtree_addr(ots_addr, addr);
|
||||||
// type = ots
|
// type = ots
|
||||||
set_type(ots_addr, 0);
|
set_type(ots_addr, 0);
|
||||||
memcpy(ltree_addr, addr, 12);
|
copy_subtree_addr(ltree_addr, addr);
|
||||||
set_type(ltree_addr, 1);
|
set_type(ltree_addr, 1);
|
||||||
memcpy(node_addr, addr, 12);
|
copy_subtree_addr(node_addr, addr);
|
||||||
set_type(node_addr, 2);
|
set_type(node_addr, 2);
|
||||||
|
|
||||||
set_ots_addr(ots_addr, idx);
|
set_ots_addr(ots_addr, idx);
|
||||||
@ -447,16 +447,17 @@ static void bds_round(const xmss_params *params,
|
|||||||
unsigned int offset, rowidx;
|
unsigned int offset, rowidx;
|
||||||
unsigned char buf[2 * params->n];
|
unsigned char buf[2 * params->n];
|
||||||
|
|
||||||
uint32_t ots_addr[8];
|
uint32_t ots_addr[8] = {0};
|
||||||
uint32_t ltree_addr[8];
|
uint32_t ltree_addr[8] = {0};
|
||||||
uint32_t node_addr[8];
|
uint32_t node_addr[8] = {0};
|
||||||
|
|
||||||
// only copy layer and tree address parts
|
// only copy layer and tree address parts
|
||||||
memcpy(ots_addr, addr, 12);
|
copy_subtree_addr(ots_addr, addr);
|
||||||
// type = ots
|
// type = ots
|
||||||
set_type(ots_addr, 0);
|
set_type(ots_addr, 0);
|
||||||
memcpy(ltree_addr, addr, 12);
|
copy_subtree_addr(ltree_addr, addr);
|
||||||
set_type(ltree_addr, 1);
|
set_type(ltree_addr, 1);
|
||||||
memcpy(node_addr, addr, 12);
|
copy_subtree_addr(node_addr, addr);
|
||||||
set_type(node_addr, 2);
|
set_type(node_addr, 2);
|
||||||
|
|
||||||
for (i = 0; i < params->tree_height; i++) {
|
for (i = 0; i < params->tree_height; i++) {
|
||||||
@ -524,7 +525,7 @@ unsigned long long xmss_core_sk_bytes(const xmss_params *params)
|
|||||||
int xmss_core_keypair(const xmss_params *params,
|
int xmss_core_keypair(const xmss_params *params,
|
||||||
unsigned char *pk, unsigned char *sk)
|
unsigned char *pk, unsigned char *sk)
|
||||||
{
|
{
|
||||||
uint32_t addr[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint32_t addr[8] = {0};
|
||||||
|
|
||||||
// TODO refactor BDS state not to need separate treehash instances
|
// TODO refactor BDS state not to need separate treehash instances
|
||||||
bds_state state;
|
bds_state state;
|
||||||
@ -607,7 +608,7 @@ int xmss_core_sign(const xmss_params *params,
|
|||||||
unsigned char R[params->n];
|
unsigned char R[params->n];
|
||||||
unsigned char msg_h[params->n];
|
unsigned char msg_h[params->n];
|
||||||
unsigned char ots_seed[params->n];
|
unsigned char ots_seed[params->n];
|
||||||
uint32_t ots_addr[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint32_t ots_addr[8] = {0};
|
||||||
|
|
||||||
// ---------------------------------
|
// ---------------------------------
|
||||||
// Message Hashing
|
// Message Hashing
|
||||||
@ -712,7 +713,7 @@ int xmssmt_core_keypair(const xmss_params *params,
|
|||||||
unsigned char *pk, unsigned char *sk)
|
unsigned char *pk, unsigned char *sk)
|
||||||
{
|
{
|
||||||
unsigned char ots_seed[params->n];
|
unsigned char ots_seed[params->n];
|
||||||
uint32_t addr[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint32_t addr[8] = {0};
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
unsigned char *wots_sigs;
|
unsigned char *wots_sigs;
|
||||||
|
|
||||||
@ -785,8 +786,8 @@ int xmssmt_core_sign(const xmss_params *params,
|
|||||||
unsigned char R[params->n];
|
unsigned char R[params->n];
|
||||||
unsigned char msg_h[params->n];
|
unsigned char msg_h[params->n];
|
||||||
unsigned char ots_seed[params->n];
|
unsigned char ots_seed[params->n];
|
||||||
uint32_t addr[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint32_t addr[8] = {0};
|
||||||
uint32_t ots_addr[8] = {0, 0, 0, 0, 0, 0, 0, 0};
|
uint32_t ots_addr[8] = {0};
|
||||||
unsigned char idx_bytes_32[32];
|
unsigned char idx_bytes_32[32];
|
||||||
|
|
||||||
unsigned char *wots_sigs;
|
unsigned char *wots_sigs;
|
||||||
|
Loading…
Reference in New Issue
Block a user