Merge pull request #9 from cryb-to/cryb-cipher

Fix counter increment in Salsa and ChaCha.
This commit is contained in:
Dag-Erling Smørgrav 2017-04-22 03:33:01 +02:00 committed by GitHub
commit c365b9762a
2 changed files with 4 additions and 6 deletions

View File

@ -137,7 +137,6 @@ size_t
chacha_encrypt(chacha_ctx *ctx, const void *vpt, uint8_t *ct, size_t len)
{
const uint8_t *pt = vpt;
uint64_t ctr;
uint32_t mix[16];
uint8_t ks[64];
unsigned int b, i;
@ -164,8 +163,8 @@ chacha_encrypt(chacha_ctx *ctx, const void *vpt, uint8_t *ct, size_t len)
for (i = 0; i < 64 && i < len; ++i)
*ct++ = *pt++ ^ ks[i];
}
ctr = le64dec(ctx->state + 12);
le64enc(ctx->state + 12, ++ctr);
if (++ctx->state[12] == 0)
++ctx->state[13];
}
return (len);
}

View File

@ -137,7 +137,6 @@ size_t
salsa_encrypt(salsa_ctx *ctx, const void *vpt, uint8_t *ct, size_t len)
{
const uint8_t *pt = vpt;
uint64_t ctr;
uint32_t mix[16];
uint8_t ks[64];
unsigned int b, i;
@ -164,8 +163,8 @@ salsa_encrypt(salsa_ctx *ctx, const void *vpt, uint8_t *ct, size_t len)
for (i = 0; i < 64 && i < len; ++i)
*ct++ = *pt++ ^ ks[i];
}
ctr = le64dec(ctx->state + 12);
le64enc(ctx->state + 12, ++ctr);
if (++ctx->state[12] == 0)
++ctx->state[13];
}
return (len);
}