Consistently return -1 on failure

This commit is contained in:
Joost Rijneveld 2017-11-01 14:33:07 +01:00
bovenliggende a95aaf0b37
commit b9b84b9f9e
Geen bekende sleutel gevonden voor deze handtekening in de database
GPG sleutel-ID: A4FE39CF49CBC553
5 gewijzigde bestanden met toevoegingen van 22 en 22 verwijderingen

2
hash.c
Bestand weergeven

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

Bestand weergeven

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

Bestand weergeven

@ -33,26 +33,26 @@ typedef struct {
/**
* Accepts strings such as "XMSS-SHA2_10_256"
* 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);
/**
* Accepts takes strings such as "XMSSMT-SHA2_20/2_256"
* 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);
/**
* 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);
/**
* 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);

12
xmss.c
Bestand weergeven

@ -13,7 +13,7 @@ int xmss_keypair(unsigned char *pk, unsigned char *sk, const uint32_t oid)
unsigned int i;
if (xmss_parse_oid(&params, oid)) {
return 1;
return -1;
}
for (i = 0; i < XMSS_OID_LEN; i++) {
pk[i] = (oid >> (8 * i)) & 0xFF;
@ -37,7 +37,7 @@ int xmss_sign(unsigned char *sk,
oid |= sk[i] << (i * 8);
}
if (xmss_parse_oid(&params, oid)) {
return 1;
return -1;
}
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);
}
if (xmss_parse_oid(&params, oid)) {
return 1;
return -1;
}
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;
if (xmssmt_parse_oid(&params, oid)) {
return 1;
return -1;
}
for (i = 0; i < XMSS_OID_LEN; i++) {
pk[i] = (oid >> (8 * i)) & 0xFF;
@ -86,7 +86,7 @@ int xmssmt_sign(unsigned char *sk,
oid |= sk[i] << (i * 8);
}
if (xmssmt_parse_oid(&params, oid)) {
return 1;
return -1;
}
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);
}
if (xmssmt_parse_oid(&params, oid)) {
return 1;
return -1;
}
return xmssmt_core_sign_open(&params, m, mlen, sm, smlen, pk + XMSS_OID_LEN);
}

Bestand weergeven

@ -328,8 +328,8 @@ static void treehash_update(const xmss_params *params,
}
/**
* Performs one treehash update on the instance that needs it the most.
* Returns 1 if such an instance was not found
* Performs treehash updates on the instance that needs it the most.
* Returns the updated number of available updates.
**/
static char bds_treehash_update(const xmss_params *params,
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
* 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,
bds_state *state, const unsigned char *sk_seed,
@ -384,7 +384,7 @@ static char bds_state_update(const xmss_params *params,
unsigned int nodeh;
int idx = state->next_leaf;
if (idx == 1 << params->tree_height) {
return 1;
return -1;
}
// only copy layer and tree address parts