mirror of
https://github.com/GrapheneOS/hardened_malloc.git
synced 2025-06-03 05:32:03 -04:00
drop 128-bit keys from ChaCha implementation
This commit is contained in:
parent
b52d9ca831
commit
433af6d4ba
3 changed files with 16 additions and 25 deletions
27
chacha.c
27
chacha.c
|
@ -41,30 +41,21 @@ Public domain.
|
|||
c = PLUS(c,d); b = ROTATE(XOR(b,c), 7);
|
||||
|
||||
static const char sigma[16] = "expand 32-byte k";
|
||||
static const char tau[16] = "expand 16-byte k";
|
||||
|
||||
void chacha_keysetup(chacha_ctx *x,const u8 *k,u32 kbits)
|
||||
void chacha_keysetup(chacha_ctx *x,const u8 *k)
|
||||
{
|
||||
const char *constants;
|
||||
|
||||
x->input[0] = U8TO32_LITTLE(sigma + 0);
|
||||
x->input[1] = U8TO32_LITTLE(sigma + 4);
|
||||
x->input[2] = U8TO32_LITTLE(sigma + 8);
|
||||
x->input[3] = U8TO32_LITTLE(sigma + 12);
|
||||
x->input[4] = U8TO32_LITTLE(k + 0);
|
||||
x->input[5] = U8TO32_LITTLE(k + 4);
|
||||
x->input[6] = U8TO32_LITTLE(k + 8);
|
||||
x->input[7] = U8TO32_LITTLE(k + 12);
|
||||
if (kbits == 256) { /* recommended */
|
||||
k += 16;
|
||||
constants = sigma;
|
||||
} else { /* kbits == 128 */
|
||||
constants = tau;
|
||||
}
|
||||
x->input[8] = U8TO32_LITTLE(k + 0);
|
||||
x->input[9] = U8TO32_LITTLE(k + 4);
|
||||
x->input[10] = U8TO32_LITTLE(k + 8);
|
||||
x->input[11] = U8TO32_LITTLE(k + 12);
|
||||
x->input[0] = U8TO32_LITTLE(constants + 0);
|
||||
x->input[1] = U8TO32_LITTLE(constants + 4);
|
||||
x->input[2] = U8TO32_LITTLE(constants + 8);
|
||||
x->input[3] = U8TO32_LITTLE(constants + 12);
|
||||
x->input[8] = U8TO32_LITTLE(k + 16);
|
||||
x->input[9] = U8TO32_LITTLE(k + 20);
|
||||
x->input[10] = U8TO32_LITTLE(k + 24);
|
||||
x->input[11] = U8TO32_LITTLE(k + 28);
|
||||
}
|
||||
|
||||
void chacha_ivsetup(chacha_ctx *x,const u8 *iv)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue