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

Bug in poly1305-donna-16.h #2

Closed
Gammatester opened this issue Aug 5, 2015 · 4 comments
Closed

Bug in poly1305-donna-16.h #2

Gammatester opened this issue Aug 5, 2015 · 4 comments

Comments

@Gammatester
Copy link

The code in poly1305-donna-16.h failed to pass the selftest and most of the test vectors from
http://tools.ietf.org/html/rfc7539. See my post and the answer at http://stackoverflow.com/questions/31806863/verification-of-poly1305-donna-16-h-code.

dchest added a commit to dchest/tweetnacl-js that referenced this issue Mar 28, 2016
There is a bug in fast version, which was ported from
16-bit Poly1305-donna, where the bug comes from:
floodyberry/poly1305-donna#2

Until we figure out the source of bug, return nacl-fast version to match
the original nacl version.
@dchest
Copy link

dchest commented Mar 28, 2016

Test that fails is:

    /* generates a final value of (2^130 - 2) == 3 */
    static const unsigned char wrap_key[32] = {
        0x02,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    };

    static const unsigned char wrap_msg[16] = {
        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,
        0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff
    };

    static const unsigned char wrap_mac[16] = {
        0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
        0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
    };

@floodyberry
Copy link
Owner

Sorry about not updating for so long! This should be fixed now. The issue was not properly detecting if st->h was >= 2^130 - 5, coupled with believing my own README and defining POLY1305_16BITS instead of POLY1305_16BIT and not catching the failure. The chance of the bug affecting anything in the real world is essentially zero luckily, but it's good to have it fixed.

@dchest
Copy link

dchest commented Mar 29, 2016

Thanks a lot!

@Gammatester
Copy link
Author

Thank you! I just compiled and ran it under with GCC 4.7.3 and MS VC 6 and got

poly1305 self test: successful
sample mac is ddb9da7ddd5e52792730ed5cda5f90a4 (correct)

I will add a comment to the stackoverflow question.

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

3 participants