Resolve type coercions

This commit is contained in:
Joost Rijneveld 2019-04-06 14:18:55 +02:00
parent a14dcefb32
commit a300190d5b
No known key found for this signature in database
GPG Key ID: A4FE39CF49CBC553
5 changed files with 16 additions and 16 deletions

View File

@ -12,11 +12,11 @@ void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_prf_addr(
void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_gen_message_random( void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_gen_message_random(
unsigned char *R, unsigned char *R,
const unsigned char *sk_prf, const unsigned char *optrand, const unsigned char *sk_prf, const unsigned char *optrand,
const unsigned char *m, unsigned long long mlen); const unsigned char *m, size_t mlen);
void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_hash_message( void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_hash_message(
unsigned char *digest, uint64_t *tree, uint32_t *leaf_idx, unsigned char *digest, uint64_t *tree, uint32_t *leaf_idx,
const unsigned char *R, const unsigned char *pk, const unsigned char *R, const unsigned char *pk,
const unsigned char *m, unsigned long long mlen); const unsigned char *m, size_t mlen);
#endif #endif

View File

@ -35,7 +35,7 @@ void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_prf_addr(
void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_gen_message_random( void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_gen_message_random(
unsigned char *R, unsigned char *R,
const unsigned char *sk_prf, const unsigned char *optrand, const unsigned char *sk_prf, const unsigned char *optrand,
const unsigned char *m, unsigned long long mlen) { const unsigned char *m, size_t mlen) {
uint64_t s_inc[26]; uint64_t s_inc[26];
shake256_inc_init(s_inc); shake256_inc_init(s_inc);
@ -54,7 +54,7 @@ void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_gen_message_random(
void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_hash_message( void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_hash_message(
unsigned char *digest, uint64_t *tree, uint32_t *leaf_idx, unsigned char *digest, uint64_t *tree, uint32_t *leaf_idx,
const unsigned char *R, const unsigned char *pk, const unsigned char *R, const unsigned char *pk,
const unsigned char *m, unsigned long long mlen) { const unsigned char *m, size_t mlen) {
#define SPX_TREE_BITS (SPX_TREE_HEIGHT * (SPX_D - 1)) #define SPX_TREE_BITS (SPX_TREE_HEIGHT * (SPX_D - 1))
#define SPX_TREE_BYTES ((SPX_TREE_BITS + 7) / 8) #define SPX_TREE_BYTES ((SPX_TREE_BITS + 7) / 8)
#define SPX_LEAF_BITS SPX_TREE_HEIGHT #define SPX_LEAF_BITS SPX_TREE_HEIGHT
@ -84,7 +84,7 @@ void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_hash_message(
*tree &= (~(uint64_t)0) >> (64 - SPX_TREE_BITS); *tree &= (~(uint64_t)0) >> (64 - SPX_TREE_BITS);
bufp += SPX_TREE_BYTES; bufp += SPX_TREE_BYTES;
*leaf_idx = PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_bytes_to_ull( *leaf_idx = (uint32_t)PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_bytes_to_ull(
bufp, SPX_LEAF_BYTES); bufp, SPX_LEAF_BYTES);
*leaf_idx &= (~(uint32_t)0) >> (32 - SPX_LEAF_BITS); *leaf_idx &= (~(uint32_t)0) >> (32 - SPX_LEAF_BITS);
} }

View File

@ -135,7 +135,7 @@ int PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_crypto_sign_signature(
unsigned char optrand[SPX_N]; unsigned char optrand[SPX_N];
unsigned char mhash[SPX_FORS_MSG_BYTES]; unsigned char mhash[SPX_FORS_MSG_BYTES];
unsigned char root[SPX_N]; unsigned char root[SPX_N];
unsigned long long i; uint32_t i;
uint64_t tree; uint64_t tree;
uint32_t idx_leaf; uint32_t idx_leaf;
uint32_t wots_addr[8] = {0}; uint32_t wots_addr[8] = {0};

View File

@ -1,21 +1,21 @@
#include <stddef.h>
#include <string.h> #include <string.h>
#include "utils.h"
#include "address.h" #include "address.h"
#include "hash.h" #include "hash.h"
#include "params.h" #include "params.h"
#include "thash.h" #include "thash.h"
#include "utils.h"
/** /**
* Converts the value of 'in' to 'outlen' bytes in big-endian byte order. * Converts the value of 'in' to 'outlen' bytes in big-endian byte order.
*/ */
void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_ull_to_bytes( void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_ull_to_bytes(
unsigned char *out, unsigned int outlen, unsigned long long in) { unsigned char *out, size_t outlen, unsigned long long in) {
int i;
/* Iterate over out in decreasing order, for big-endianness. */ /* Iterate over out in decreasing order, for big-endianness. */
for (i = outlen - 1; i >= 0; i--) { for (size_t i = outlen; i > 0; i--) {
out[i] = in & 0xff; out[i - 1] = in & 0xff;
in = in >> 8; in = in >> 8;
} }
} }
@ -24,11 +24,10 @@ void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_ull_to_bytes(
* Converts the inlen bytes in 'in' from big-endian byte order to an integer. * Converts the inlen bytes in 'in' from big-endian byte order to an integer.
*/ */
unsigned long long PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_bytes_to_ull( unsigned long long PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_bytes_to_ull(
const unsigned char *in, unsigned int inlen) { const unsigned char *in, size_t inlen) {
unsigned long long retval = 0; unsigned long long retval = 0;
unsigned int i;
for (i = 0; i < inlen; i++) { for (size_t i = 0; i < inlen; i++) {
retval |= ((unsigned long long)in[i]) << (8 * (inlen - 1 - i)); retval |= ((unsigned long long)in[i]) << (8 * (inlen - 1 - i));
} }
return retval; return retval;

View File

@ -2,19 +2,20 @@
#define SPX_UTILS_H #define SPX_UTILS_H
#include "params.h" #include "params.h"
#include <stddef.h>
#include <stdint.h> #include <stdint.h>
/** /**
* Converts the value of 'in' to 'outlen' bytes in big-endian byte order. * Converts the value of 'in' to 'outlen' bytes in big-endian byte order.
*/ */
void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_ull_to_bytes( void PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_ull_to_bytes(
unsigned char *out, unsigned int outlen, unsigned long long in); unsigned char *out, size_t outlen, unsigned long long in);
/** /**
* Converts the inlen bytes in 'in' from big-endian byte order to an integer. * Converts the inlen bytes in 'in' from big-endian byte order to an integer.
*/ */
unsigned long long PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_bytes_to_ull( unsigned long long PQCLEAN_SPHINCSSHAKE256128FSIMPLE_CLEAN_bytes_to_ull(
const unsigned char *in, unsigned int inlen); const unsigned char *in, size_t inlen);
/** /**
* Computes a root node given a leaf and an auth path. * Computes a root node given a leaf and an auth path.