ENCRYPTO_utils
ENCRYPTO_utils copied to clipboard
Non-threadsafe function `hash_ctr`
Hi,
Recently I continuously get calculation error from ABY and I believe such error is caused by a non-threadsafe function at ENCRYPTO_utils/crypto/crypto.cpp.
I pasted the code block below for convenience.
void crypto::hash_ctr(uint8_t* resbuf, uint32_t noutbytes, uint8_t* inbuf, uint32_t ninbytes, uint64_t ctr) {
uint8_t* tmpbuf = (uint8_t*) malloc(ninbytes + sizeof(uint64_t));
memcpy(tmpbuf, &ctr, sizeof(uint64_t));
memcpy(tmpbuf + sizeof(uint64_t), inbuf, ninbytes);
hash_routine(resbuf, noutbytes, tmpbuf, ninbytes+sizeof(uint64_t), sha_hash_buf);
free(tmpbuf);
}
Changing to the following sovles the issue,
void crypto::hash_ctr(uint8_t* resbuf, uint32_t noutbytes, uint8_t* inbuf, uint32_t ninbytes, uint64_t ctr) {
uint8_t* hash_buf = (uint8_t*) malloc(get_hash_bytes());
uint8_t* tmpbuf = (uint8_t*) malloc(ninbytes + sizeof(uint64_t));
memcpy(tmpbuf, &ctr, sizeof(uint64_t));
memcpy(tmpbuf + sizeof(uint64_t), inbuf, ninbytes);
hash_routine(resbuf, noutbytes, tmpbuf, ninbytes+sizeof(uint64_t), hash_buf);
free(tmpbuf);
free(hash_buf);
}
I've also opened an issue in ABY: https://github.com/encryptogroup/ABY/issues/152 Thanks, Jamie