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

Code review #1506

Merged
merged 5 commits into from
Jan 31, 2016
Merged

Code review #1506

merged 5 commits into from
Jan 31, 2016

Conversation

kpp
Copy link
Contributor

@kpp kpp commented Jan 24, 2016

fix: compare sensitive data with sodium_memcmp
fix: replace memset with sodium_memzero for sensitive data
fix: make increment_nonce & increment_nonce_number independent of user-controlled input
fix: make crypto_core more stable agains null ptr dereference

fix: update apt before installing anything
add: comments about hairy code

@towlie
Copy link

towlie commented Jan 24, 2016

This breaks compatibility with vanilla NaCl https://nacl.cr.yp.to/
Which is something @irungentoo doesn't want?

@kpp
Copy link
Contributor Author

kpp commented Jan 24, 2016

@towlie , do you have any idea how to make memset be non-optimized (and deleted) by compiler? Only sodium_memzero is safe to clear sensitive data before free it. NaCl does not have such function, Sodium does.
@irungentoo , what do you prefer? memset or sodium_memzero?

@GrayHatter
Copy link
Collaborator

@kpp toxcore has never been shy to write it's own wrappers for functions. Why not create a tox_wrapper_memzero function and then #ifdef depending on if you're using NaCL or libsodium?

@kpp
Copy link
Contributor Author

kpp commented Jan 24, 2016

@GrayHatter I did not find a similar function in NaCl. Maybe you can do that? Or do you propose me to write something like:

#ifdef USE_SODIUM
sodium_memzero(ptr, size);
#else
memset(ptr, 0, size);
#endif

I will not do that, because that will be unsafe.

@kpp kpp closed this Jan 24, 2016
@kpp kpp reopened this Jan 24, 2016
@GrayHatter
Copy link
Collaborator

@kpp less safe than it is right now?

@mrkiko
Copy link

mrkiko commented Jan 26, 2016

I was thinking about libbsd and their explicit_bzero.

@alexbakker
Copy link
Contributor

@irungentoo any comments?

@irungentoo
Copy link
Owner

A bit paranoid but that's fine.

I just need to check if using public_key_cmp everywhere doesn't slow down the code too much.

@kpp
Copy link
Contributor Author

kpp commented Jan 27, 2016

I just need to check if using public_key_cmp everywhere doesn't slow down the code too much.

@irungentoo Well, asymptotic complexity of comparing public keys using memcmp is O(N), using public_key_cmp is ~N, so there are such public keys that in the worst case compares with memcmp as "slow" as they are compared with public_key_cmp. There must be no slow down.

@irungentoo irungentoo merged commit 23b0c9c into irungentoo:master Jan 31, 2016
uint_fast16_t carry = 0U;
for (; i != 0; --i) {
carry += (uint_fast16_t) nonce[i] + (uint_fast16_t) num_as_nonce[i];
nonce[i] = (unsigned char) carry;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed it already but here the array indexes should have been i - 1.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I will fix it in 1-2 days

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@irungentoo thank you. That was a bad bug. I wrote unit tests for that case. See PR.

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

Successfully merging this pull request may close these issues.

None yet

7 participants