mirror of
https://github.com/cryb-to/cryb-to.git
synced 2024-12-18 02:24:54 +00:00
Merge pull request #9 from cryb-to/cryb-cipher
Fix counter increment in Salsa and ChaCha.
This commit is contained in:
commit
c365b9762a
2 changed files with 4 additions and 6 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue