|
@@ -9,7 +9,7 @@ |
|
|
#include "utils_hash.h" |
|
|
#include "utils_hash.h" |
|
|
|
|
|
|
|
|
static inline |
|
|
static inline |
|
|
int _hash( unsigned char *digest, const unsigned char *m, unsigned long long mlen ) { |
|
|
|
|
|
|
|
|
int _hash( unsigned char *digest, const unsigned char *m, size_t mlen ) { |
|
|
// #if 32 == _HASH_LEN |
|
|
// #if 32 == _HASH_LEN |
|
|
sha256(digest, m, mlen); |
|
|
sha256(digest, m, mlen); |
|
|
// #elif 48 == _HASH_LEN |
|
|
// #elif 48 == _HASH_LEN |
|
@@ -23,20 +23,20 @@ int _hash( unsigned char *digest, const unsigned char *m, unsigned long long mle |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
static inline |
|
|
static inline |
|
|
int expand_hash( unsigned char *digest, unsigned n_digest, const unsigned char *hash ) { |
|
|
|
|
|
|
|
|
int expand_hash(unsigned char *digest, size_t n_digest, const unsigned char *hash) { |
|
|
if ( _HASH_LEN >= n_digest ) { |
|
|
if ( _HASH_LEN >= n_digest ) { |
|
|
for (unsigned i = 0; i < n_digest; i++) { |
|
|
|
|
|
|
|
|
for (size_t i = 0; i < n_digest; i++) { |
|
|
digest[i] = hash[i]; |
|
|
digest[i] = hash[i]; |
|
|
} |
|
|
} |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
for (unsigned i = 0; i < _HASH_LEN; i++) { |
|
|
|
|
|
|
|
|
for (size_t i = 0; i < _HASH_LEN; i++) { |
|
|
digest[i] = hash[i]; |
|
|
digest[i] = hash[i]; |
|
|
} |
|
|
} |
|
|
n_digest -= _HASH_LEN; |
|
|
n_digest -= _HASH_LEN; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while ( _HASH_LEN <= n_digest ) { |
|
|
|
|
|
|
|
|
while (_HASH_LEN <= n_digest ) { |
|
|
_hash( digest + _HASH_LEN, digest, _HASH_LEN ); |
|
|
_hash( digest + _HASH_LEN, digest, _HASH_LEN ); |
|
|
|
|
|
|
|
|
n_digest -= _HASH_LEN; |
|
|
n_digest -= _HASH_LEN; |
|
@@ -45,18 +45,20 @@ int expand_hash( unsigned char *digest, unsigned n_digest, const unsigned char * |
|
|
unsigned char temp[_HASH_LEN]; |
|
|
unsigned char temp[_HASH_LEN]; |
|
|
if ( n_digest ) { |
|
|
if ( n_digest ) { |
|
|
_hash( temp, digest, _HASH_LEN ); |
|
|
_hash( temp, digest, _HASH_LEN ); |
|
|
for (unsigned i = 0; i < n_digest; i++) { |
|
|
|
|
|
|
|
|
for (size_t i = 0; i < n_digest; i++) { |
|
|
digest[_HASH_LEN + i] = temp[i]; |
|
|
digest[_HASH_LEN + i] = temp[i]; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
int PQCLEAN_RAINBOWIACLASSIC_CLEAN_hash_msg( unsigned char *digest, unsigned len_digest, const unsigned char *m, unsigned long long mlen ) { |
|
|
|
|
|
|
|
|
int PQCLEAN_RAINBOWIACLASSIC_CLEAN_hash_msg(unsigned char *digest, |
|
|
|
|
|
size_t len_digest, |
|
|
|
|
|
const unsigned char *m, |
|
|
|
|
|
size_t mlen) { |
|
|
unsigned char buf[_HASH_LEN]; |
|
|
unsigned char buf[_HASH_LEN]; |
|
|
_hash( buf, m, mlen ); |
|
|
|
|
|
|
|
|
|
|
|
return expand_hash( digest, len_digest, buf ); |
|
|
|
|
|
|
|
|
_hash(buf, m, mlen); |
|
|
|
|
|
return expand_hash(digest, len_digest, buf); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|