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

Fix ChaChaPoly for big-endian processors. #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/crypto/chacha/chacha.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,18 @@

void chacha_keysetup(chacha_ctx *x, const uint8_t *k, uint32_t kbits)
{
static const char tag128[] = "expand 16-byte k";
static const char tag256[] = "expand 32-byte k";
static const uint8_t tag128[] = "expand 16-byte k";
static const uint8_t tag256[] = "expand 32-byte k";
if (kbits == 256) {
memcpy(x->input, tag256, 16);
#ifdef USE_VECTOR_MATH
x->input[0] = fromLittleVec(tag256);
x->input[1] = fromLittleVec(k);
x->input[2] = fromLittleVec(k + 16);
#else
x->input[0] = fromLittle(tag256);
x->input[1] = fromLittle(tag256+4);
x->input[2] = fromLittle(tag256+8);
x->input[3] = fromLittle(tag256+12);
x->input[4] = fromLittle(k);
x->input[5] = fromLittle(k + 4);
x->input[6] = fromLittle(k + 8);
Expand All @@ -91,10 +95,14 @@ void chacha_keysetup(chacha_ctx *x, const uint8_t *k, uint32_t kbits)
x->input[11] = fromLittle(k + 28);
#endif
} else {
memcpy(x->input, tag128, 16);
#ifdef USE_VECTOR_MATH
x->input[0] = fromLittleVec(tag128);
x->input[2] = x->input[1] = fromLittleVec(k);
#else
x->input[0] = fromLittle(tag128);
x->input[1] = fromLittle(tag128+4);
x->input[2] = fromLittle(tag128+8);
x->input[3] = fromLittle(tag128+12);
x->input[8] = x->input[4] = fromLittle(k);
x->input[9] = x->input[5] = fromLittle(k + 4);
x->input[10] = x->input[6] = fromLittle(k + 8);
Expand Down