@ -564,11 +564,7 @@ void slow_hash_free_state(void)
* @ param length the length in bytes of the data
* @ param length the length in bytes of the data
* @ param hash a pointer to a buffer in which the final 256 bit hash will be stored
* @ param hash a pointer to a buffer in which the final 256 bit hash will be stored
*/
*/
void cn_slow_hash ( const void * data , size_t length , char * hash , int variant ) {
void cn_slow_hash ( const void * data , size_t length , char * hash , int variant , int prehashed )
cn_slow_hash_pre ( data , length , hash , variant , false ) ;
}
void cn_slow_hash_pre ( const void * data , size_t length , char * hash , int variant , bool prehashed )
{
{
RDATA_ALIGN16 uint8_t expandedKey [ 240 ] ; /* These buffers are aligned to use later with SSE functions */
RDATA_ALIGN16 uint8_t expandedKey [ 240 ] ; /* These buffers are aligned to use later with SSE functions */
@ -909,7 +905,7 @@ STATIC INLINE void aes_pseudo_round_xor(const uint8_t *in, uint8_t *out, const u
}
}
}
}
void cn_slow_hash ( const void * data , size_t length , char * hash , int variant )
void cn_slow_hash ( const void * data , size_t length , char * hash , int variant , int prehashed )
{
{
RDATA_ALIGN16 uint8_t expandedKey [ 240 ] ;
RDATA_ALIGN16 uint8_t expandedKey [ 240 ] ;
RDATA_ALIGN16 uint8_t hp_state [ MEMORY ] ;
RDATA_ALIGN16 uint8_t hp_state [ MEMORY ] ;
@ -932,7 +928,11 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant)
/* CryptoNight Step 1: Use Keccak1600 to initialize the 'state' (and 'text') buffers from the data. */
/* CryptoNight Step 1: Use Keccak1600 to initialize the 'state' (and 'text') buffers from the data. */
if ( prehashed ) {
memcpy ( & state . hs , data , length ) ;
} else {
hash_process ( & state . hs , data , length ) ;
hash_process ( & state . hs , data , length ) ;
}
memcpy ( text , state . init , INIT_SIZE_BYTE ) ;
memcpy ( text , state . init , INIT_SIZE_BYTE ) ;
VARIANT1_INIT64 ( ) ;
VARIANT1_INIT64 ( ) ;
@ -1105,7 +1105,7 @@ STATIC INLINE void xor_blocks(uint8_t* a, const uint8_t* b)
U64 ( a ) [ 1 ] ^ = U64 ( b ) [ 1 ] ;
U64 ( a ) [ 1 ] ^ = U64 ( b ) [ 1 ] ;
}
}
void cn_slow_hash ( const void * data , size_t length , char * hash , int variant )
void cn_slow_hash ( const void * data , size_t length , char * hash , int variant , int prehashed )
{
{
uint8_t text [ INIT_SIZE_BYTE ] ;
uint8_t text [ INIT_SIZE_BYTE ] ;
uint8_t a [ AES_BLOCK_SIZE ] ;
uint8_t a [ AES_BLOCK_SIZE ] ;
@ -1131,7 +1131,11 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant)
long_state = ( uint8_t * ) malloc ( MEMORY ) ;
long_state = ( uint8_t * ) malloc ( MEMORY ) ;
# endif
# endif
if ( prehashed ) {
memcpy ( & state . hs , data , length ) ;
} else {
hash_process ( & state . hs , data , length ) ;
hash_process ( & state . hs , data , length ) ;
}
memcpy ( text , state . init , INIT_SIZE_BYTE ) ;
memcpy ( text , state . init , INIT_SIZE_BYTE ) ;
VARIANT1_INIT64 ( ) ;
VARIANT1_INIT64 ( ) ;
@ -1289,7 +1293,7 @@ union cn_slow_hash_state {
} ;
} ;
# pragma pack(pop)
# pragma pack(pop)
void cn_slow_hash ( const void * data , size_t length , char * hash , int variant ) {
void cn_slow_hash ( const void * data , size_t length , char * hash , int variant , int prehashed ) {
uint8_t long_state [ MEMORY ] ;
uint8_t long_state [ MEMORY ] ;
union cn_slow_hash_state state ;
union cn_slow_hash_state state ;
uint8_t text [ INIT_SIZE_BYTE ] ;
uint8_t text [ INIT_SIZE_BYTE ] ;
@ -1301,7 +1305,11 @@ void cn_slow_hash(const void *data, size_t length, char *hash, int variant) {
uint8_t aes_key [ AES_KEY_SIZE ] ;
uint8_t aes_key [ AES_KEY_SIZE ] ;
oaes_ctx * aes_ctx ;
oaes_ctx * aes_ctx ;
if ( prehashed ) {
memcpy ( & state . hs , data , length ) ;
} else {
hash_process ( & state . hs , data , length ) ;
hash_process ( & state . hs , data , length ) ;
}
memcpy ( text , state . init , INIT_SIZE_BYTE ) ;
memcpy ( text , state . init , INIT_SIZE_BYTE ) ;
memcpy ( aes_key , state . hs . b , AES_KEY_SIZE ) ;
memcpy ( aes_key , state . hs . b , AES_KEY_SIZE ) ;
aes_ctx = ( oaes_ctx * ) oaes_alloc ( ) ;
aes_ctx = ( oaes_ctx * ) oaes_alloc ( ) ;