Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Non-threadsafe function hash_ctr #22

Open
Jamie-Cui opened this issue Nov 20, 2019 · 0 comments
Open

Non-threadsafe function hash_ctr #22

Jamie-Cui opened this issue Nov 20, 2019 · 0 comments

Comments

@Jamie-Cui
Copy link

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: encryptogroup/ABY#152
Thanks,
Jamie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant