From 02bfcc3b75ef17a2dbae08ca582988aa7d19eb9b Mon Sep 17 00:00:00 2001 From: Daniel Micay Date: Tue, 9 Apr 2019 01:29:25 -0400 Subject: [PATCH] chacha: add constant for number of rounds --- chacha.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/chacha.c b/chacha.c index 1ada59c..541a7ac 100644 --- a/chacha.c +++ b/chacha.c @@ -4,6 +4,9 @@ #include "chacha.h" +// ChaCha8 +static const unsigned rounds = 8; + #define U8C(v) (v##U) #define U32C(v) (v##U) @@ -108,7 +111,7 @@ void chacha_keystream_bytes(chacha_ctx *x, u8 *c, u32 bytes) { u32 x13 = j13; u32 x14 = j14; u32 x15 = j15; - for (unsigned i = 8; i > 0; i -= 2) { + for (unsigned i = rounds; i > 0; i -= 2) { QUARTERROUND(x0, x4, x8, x12) QUARTERROUND(x1, x5, x9, x13) QUARTERROUND(x2, x6, x10, x14)