Move ull-byte-conversions to separate utils file

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

View File

@ -2,8 +2,8 @@ CC = /usr/bin/gcc
CFLAGS = -Wall -g -O3 -Wextra -Wpedantic CFLAGS = -Wall -g -O3 -Wextra -Wpedantic
LDLIBS = -lcrypto LDLIBS = -lcrypto
SOURCES = params.c hash.c fips202.c hash_address.c randombytes.c wots.c xmss.c xmss_core.c xmss_commons.c SOURCES = params.c hash.c fips202.c hash_address.c randombytes.c wots.c xmss.c xmss_core.c xmss_commons.c utils.c
HEADERS = params.h hash.h fips202.h hash_address.h randombytes.h wots.h xmss.h xmss_core.h xmss_commons.h HEADERS = params.h hash.h fips202.h hash_address.h randombytes.h wots.h xmss.h xmss_core.h xmss_commons.h utils.h
SOURCES_FAST = $(subst xmss_core.c,xmss_core_fast.c,$(SOURCES)) SOURCES_FAST = $(subst xmss_core.c,xmss_core_fast.c,$(SOURCES))
HEADERS_FAST = $(subst xmss_core.c,xmss_core_fast.c,$(HEADERS)) HEADERS_FAST = $(subst xmss_core.c,xmss_core_fast.c,$(HEADERS))

2
hash.c
View File

@ -3,7 +3,7 @@
#include <openssl/sha.h> #include <openssl/sha.h>
#include "hash_address.h" #include "hash_address.h"
#include "xmss_commons.h" #include "utils.h"
#include "params.h" #include "params.h"
#include "hash.h" #include "hash.h"
#include "fips202.h" #include "fips202.h"

30
utils.c Normal file
View File

@ -0,0 +1,30 @@
#include "utils.h"
/**
* Converts the value of 'in' to 'outlen' bytes in big-endian byte order.
*/
void ull_to_bytes(unsigned char *out, unsigned int outlen,
unsigned long long in)
{
int i;
/* Iterate over out in decreasing order, for big-endianness. */
for (i = outlen - 1; i >= 0; i--) {
out[i] = in & 0xff;
in = in >> 8;
}
}
/**
* Converts the inlen bytes in 'in' from big-endian byte order to an integer.
*/
unsigned long long bytes_to_ull(const unsigned char *in, unsigned int inlen)
{
unsigned long long retval = 0;
unsigned int i;
for (i = 0; i < inlen; i++) {
retval |= ((unsigned long long)in[i]) << (8*(inlen - 1 - i));
}
return retval;
}

15
utils.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef XMSS_UTILS_H
#define XMSS_UTILS_H
/**
* Converts the value of 'in' to 'outlen' bytes in big-endian byte order.
*/
void ull_to_bytes(unsigned char *out, unsigned int outlen,
unsigned long long in);
/**
* Converts the inlen bytes in 'in' from big-endian byte order to an integer.
*/
unsigned long long bytes_to_ull(const unsigned char *in, unsigned int inlen);
#endif

2
wots.c
View File

@ -1,7 +1,7 @@
#include <stdint.h> #include <stdint.h>
#include <string.h> #include <string.h>
#include "xmss_commons.h" #include "utils.h"
#include "hash.h" #include "hash.h"
#include "wots.h" #include "wots.h"
#include "hash_address.h" #include "hash_address.h"

View File

@ -6,37 +6,9 @@
#include "hash_address.h" #include "hash_address.h"
#include "params.h" #include "params.h"
#include "wots.h" #include "wots.h"
#include "utils.h"
#include "xmss_commons.h" #include "xmss_commons.h"
/**
* Converts the value of 'in' to 'outlen' bytes in big-endian byte order.
*/
void ull_to_bytes(unsigned char *out, unsigned int outlen,
unsigned long long in)
{
int i;
/* Iterate over out in decreasing order, for big-endianness. */
for (i = outlen - 1; i >= 0; i--) {
out[i] = in & 0xff;
in = in >> 8;
}
}
/**
* Converts the inlen bytes in 'in' from big-endian byte order to an integer.
*/
unsigned long long bytes_to_ull(const unsigned char *in, unsigned int inlen)
{
unsigned long long retval = 0;
unsigned int i;
for (i = 0; i < inlen; i++) {
retval |= ((unsigned long long)in[i]) << (8*(inlen - 1 - i));
}
return retval;
}
/** /**
* Computes the leaf at a given address. First generates the WOTS key pair, * Computes the leaf at a given address. First generates the WOTS key pair,
* then computes leaf using l_tree. As this happens position independent, we * then computes leaf using l_tree. As this happens position independent, we

View File

@ -4,17 +4,6 @@
#include <stdint.h> #include <stdint.h>
#include "params.h" #include "params.h"
/**
* Converts the value of 'in' to 'len' bytes in big-endian byte order.
*/
void ull_to_bytes(unsigned char *out, unsigned int outlen,
unsigned long long in);
/**
* Converts the inlen bytes in 'in' from big-endian byte order to an integer.
*/
unsigned long long bytes_to_ull(const unsigned char *in, unsigned int inlen);
/** /**
* Computes the leaf at a given address. First generates the WOTS key pair, * Computes the leaf at a given address. First generates the WOTS key pair,
* then computes leaf using l_tree. As this happens position independent, we * then computes leaf using l_tree. As this happens position independent, we

View File

@ -7,6 +7,7 @@
#include "params.h" #include "params.h"
#include "randombytes.h" #include "randombytes.h"
#include "wots.h" #include "wots.h"
#include "utils.h"
#include "xmss_commons.h" #include "xmss_commons.h"
#include "xmss_core.h" #include "xmss_core.h"

View File

@ -7,6 +7,7 @@
#include "params.h" #include "params.h"
#include "randombytes.h" #include "randombytes.h"
#include "wots.h" #include "wots.h"
#include "utils.h"
#include "xmss_commons.h" #include "xmss_commons.h"
#include "xmss_core.h" #include "xmss_core.h"