Consistently return -1 on failure

This commit is contained in:
Joost Rijneveld 2017-11-01 14:33:07 +01:00
parent a95aaf0b37
commit b9b84b9f9e
No known key found for this signature in database
GPG Key ID: A4FE39CF49CBC553
5 changed files with 22 additions and 22 deletions

2
hash.c
View File

@ -38,7 +38,7 @@ static int core_hash(const xmss_params *params,
shake256(out, 64, in, inlen); shake256(out, 64, in, inlen);
} }
else { else {
return 1; return -1;
} }
return 0; return 0;
} }

View File

@ -174,7 +174,7 @@ int xmss_parse_oid(xmss_params *params, const uint32_t oid)
break; break;
default: default:
return 1; return -1;
} }
switch (oid) { switch (oid) {
case 0x01000001: case 0x01000001:
@ -198,7 +198,7 @@ int xmss_parse_oid(xmss_params *params, const uint32_t oid)
break; break;
default: default:
return 1; return -1;
} }
switch (oid) { switch (oid) {
case 0x01000001: case 0x01000001:
@ -223,7 +223,7 @@ int xmss_parse_oid(xmss_params *params, const uint32_t oid)
break; break;
default: default:
return 1; return -1;
} }
params->d = 1; params->d = 1;
params->tree_height = params->full_height / params->d; params->tree_height = params->full_height / params->d;
@ -289,7 +289,7 @@ int xmssmt_parse_oid(xmss_params *params, const uint32_t oid)
break; break;
default: default:
return 1; return -1;
} }
switch (oid) { switch (oid) {
case 0x01000001: case 0x01000001:
@ -333,7 +333,7 @@ int xmssmt_parse_oid(xmss_params *params, const uint32_t oid)
break; break;
default: default:
return 1; return -1;
} }
switch (oid) { switch (oid) {
case 0x01000001: case 0x01000001:
@ -387,7 +387,7 @@ int xmssmt_parse_oid(xmss_params *params, const uint32_t oid)
break; break;
default: default:
return 1; return -1;
} }
switch (oid) { switch (oid) {
case 0x01000001: case 0x01000001:
@ -441,7 +441,7 @@ int xmssmt_parse_oid(xmss_params *params, const uint32_t oid)
break; break;
default: default:
return 1; return -1;
} }
params->tree_height = params->full_height / params->d; params->tree_height = params->full_height / params->d;

View File

@ -33,26 +33,26 @@ typedef struct {
/** /**
* Accepts strings such as "XMSS-SHA2_10_256" * Accepts strings such as "XMSS-SHA2_10_256"
* and outputs OIDs such as 0x01000001. * and outputs OIDs such as 0x01000001.
* Returns 1 when the parameter set is not found, 0 otherwise * Returns -1 when the parameter set is not found, 0 otherwise
*/ */
int xmss_str_to_oid(uint32_t *oid, const char* s); int xmss_str_to_oid(uint32_t *oid, const char* s);
/** /**
* Accepts takes strings such as "XMSSMT-SHA2_20/2_256" * Accepts takes strings such as "XMSSMT-SHA2_20/2_256"
* and outputs OIDs such as 0x01000001. * and outputs OIDs such as 0x01000001.
* Returns 1 when the parameter set is not found, 0 otherwise * Returns -1 when the parameter set is not found, 0 otherwise
*/ */
int xmssmt_str_to_oid(uint32_t *oid, const char* s); int xmssmt_str_to_oid(uint32_t *oid, const char* s);
/** /**
* Accepts OIDs such as 0x01000001, and configures params accordingly. * Accepts OIDs such as 0x01000001, and configures params accordingly.
* Returns 1 when the OID is not found, 0 otherwise. * Returns -1 when the OID is not found, 0 otherwise.
*/ */
int xmss_parse_oid(xmss_params *params, const uint32_t oid); int xmss_parse_oid(xmss_params *params, const uint32_t oid);
/** /**
* Accepts OIDs such as 0x01000001, and configures params accordingly. * Accepts OIDs such as 0x01000001, and configures params accordingly.
* Returns 1 when the OID is not found, 0 otherwise. * Returns -1 when the OID is not found, 0 otherwise.
*/ */
int xmssmt_parse_oid(xmss_params *params, const uint32_t oid); int xmssmt_parse_oid(xmss_params *params, const uint32_t oid);

12
xmss.c
View File

@ -13,7 +13,7 @@ int xmss_keypair(unsigned char *pk, unsigned char *sk, const uint32_t oid)
unsigned int i; unsigned int i;
if (xmss_parse_oid(&params, oid)) { if (xmss_parse_oid(&params, oid)) {
return 1; return -1;
} }
for (i = 0; i < XMSS_OID_LEN; i++) { for (i = 0; i < XMSS_OID_LEN; i++) {
pk[i] = (oid >> (8 * i)) & 0xFF; pk[i] = (oid >> (8 * i)) & 0xFF;
@ -37,7 +37,7 @@ int xmss_sign(unsigned char *sk,
oid |= sk[i] << (i * 8); oid |= sk[i] << (i * 8);
} }
if (xmss_parse_oid(&params, oid)) { if (xmss_parse_oid(&params, oid)) {
return 1; return -1;
} }
return xmss_core_sign(&params, sk + XMSS_OID_LEN, sm, smlen, m, mlen); return xmss_core_sign(&params, sk + XMSS_OID_LEN, sm, smlen, m, mlen);
} }
@ -54,7 +54,7 @@ int xmss_sign_open(unsigned char *m, unsigned long long *mlen,
oid |= pk[i] << (i * 8); oid |= pk[i] << (i * 8);
} }
if (xmss_parse_oid(&params, oid)) { if (xmss_parse_oid(&params, oid)) {
return 1; return -1;
} }
return xmss_core_sign_open(&params, m, mlen, sm, smlen, pk + XMSS_OID_LEN); return xmss_core_sign_open(&params, m, mlen, sm, smlen, pk + XMSS_OID_LEN);
} }
@ -65,7 +65,7 @@ int xmssmt_keypair(unsigned char *pk, unsigned char *sk, const uint32_t oid)
unsigned int i; unsigned int i;
if (xmssmt_parse_oid(&params, oid)) { if (xmssmt_parse_oid(&params, oid)) {
return 1; return -1;
} }
for (i = 0; i < XMSS_OID_LEN; i++) { for (i = 0; i < XMSS_OID_LEN; i++) {
pk[i] = (oid >> (8 * i)) & 0xFF; pk[i] = (oid >> (8 * i)) & 0xFF;
@ -86,7 +86,7 @@ int xmssmt_sign(unsigned char *sk,
oid |= sk[i] << (i * 8); oid |= sk[i] << (i * 8);
} }
if (xmssmt_parse_oid(&params, oid)) { if (xmssmt_parse_oid(&params, oid)) {
return 1; return -1;
} }
return xmssmt_core_sign(&params, sk + XMSS_OID_LEN, sm, smlen, m, mlen); return xmssmt_core_sign(&params, sk + XMSS_OID_LEN, sm, smlen, m, mlen);
} }
@ -103,7 +103,7 @@ int xmssmt_sign_open(unsigned char *m, unsigned long long *mlen,
oid |= pk[i] << (i * 8); oid |= pk[i] << (i * 8);
} }
if (xmssmt_parse_oid(&params, oid)) { if (xmssmt_parse_oid(&params, oid)) {
return 1; return -1;
} }
return xmssmt_core_sign_open(&params, m, mlen, sm, smlen, pk + XMSS_OID_LEN); return xmssmt_core_sign_open(&params, m, mlen, sm, smlen, pk + XMSS_OID_LEN);
} }

View File

@ -328,8 +328,8 @@ static void treehash_update(const xmss_params *params,
} }
/** /**
* Performs one treehash update on the instance that needs it the most. * Performs treehash updates on the instance that needs it the most.
* Returns 1 if such an instance was not found * Returns the updated number of available updates.
**/ **/
static char bds_treehash_update(const xmss_params *params, static char bds_treehash_update(const xmss_params *params,
bds_state *state, unsigned int updates, bds_state *state, unsigned int updates,
@ -370,7 +370,7 @@ static char bds_treehash_update(const xmss_params *params,
/** /**
* Updates the state (typically NEXT_i) by adding a leaf and updating the stack * Updates the state (typically NEXT_i) by adding a leaf and updating the stack
* Returns 1 if all leaf nodes have already been processed * Returns -1 if all leaf nodes have already been processed
**/ **/
static char bds_state_update(const xmss_params *params, static char bds_state_update(const xmss_params *params,
bds_state *state, const unsigned char *sk_seed, bds_state *state, const unsigned char *sk_seed,
@ -384,7 +384,7 @@ static char bds_state_update(const xmss_params *params,
unsigned int nodeh; unsigned int nodeh;
int idx = state->next_leaf; int idx = state->next_leaf;
if (idx == 1 << params->tree_height) { if (idx == 1 << params->tree_height) {
return 1; return -1;
} }
// only copy layer and tree address parts // only copy layer and tree address parts