Browse Source

reworked cc20

pull/400/head
Logan007 4 years ago
parent
commit
87ee4d6fa7
  1. 36
      src/cc20.c
  2. 1
      src/edge.c
  3. 3
      tools/benchmark.c

36
src/cc20.c

@ -92,11 +92,20 @@ static void chacha20_init_block(cc20_context_t *ctx, const uint8_t nonce[]) {
}
#define ROL32(x,r) (((x)<<(r))|((x)>>(32-(r))))
#define CHACHA20_QUARTERROUND(x, a, b, c, d) \
#define CHACHA20_QUARTERROUND(x, a, b, c, d) \
x[a] += x[b]; x[d] = ROL32(x[d] ^ x[a], 16); \
x[c] += x[d]; x[b] = ROL32(x[b] ^ x[c], 12); \
x[a] += x[b]; x[d] = ROL32(x[d] ^ x[a], 8); \
x[c] += x[d]; x[b] = ROL32(x[b] ^ x[c], 7);
x[a] += x[b]; x[d] = ROL32(x[d] ^ x[a], 8); \
x[c] += x[d]; x[b] = ROL32(x[b] ^ x[c], 7)
#define CHACHA20_DOUBLE_ROUND \
CHACHA20_QUARTERROUND(ctx->keystream32, 0, 4, 8, 12); \
CHACHA20_QUARTERROUND(ctx->keystream32, 1, 5, 9, 13); \
CHACHA20_QUARTERROUND(ctx->keystream32, 2, 6, 10, 14); \
CHACHA20_QUARTERROUND(ctx->keystream32, 3, 7, 11, 15); \
CHACHA20_QUARTERROUND(ctx->keystream32, 0, 5, 10, 15); \
CHACHA20_QUARTERROUND(ctx->keystream32, 1, 6, 11, 12); \
CHACHA20_QUARTERROUND(ctx->keystream32, 2, 7, 8, 13); \
CHACHA20_QUARTERROUND(ctx->keystream32, 3, 4, 9, 14)
static void chacha20_block_next(cc20_context_t *ctx) {
@ -105,16 +114,17 @@ static void chacha20_block_next(cc20_context_t *ctx) {
for(i = 0; i < 16; i++)
ctx->keystream32[i] = ctx->state[i];
for(i = 0; i < 10; i++) {
CHACHA20_QUARTERROUND(ctx->keystream32, 0, 4, 8, 12)
CHACHA20_QUARTERROUND(ctx->keystream32, 1, 5, 9, 13)
CHACHA20_QUARTERROUND(ctx->keystream32, 2, 6, 10, 14)
CHACHA20_QUARTERROUND(ctx->keystream32, 3, 7, 11, 15)
CHACHA20_QUARTERROUND(ctx->keystream32, 0, 5, 10, 15)
CHACHA20_QUARTERROUND(ctx->keystream32, 1, 6, 11, 12)
CHACHA20_QUARTERROUND(ctx->keystream32, 2, 7, 8, 13)
CHACHA20_QUARTERROUND(ctx->keystream32, 3, 4, 9, 14)
}
// 10 double rounds
CHACHA20_DOUBLE_ROUND;
CHACHA20_DOUBLE_ROUND;
CHACHA20_DOUBLE_ROUND;
CHACHA20_DOUBLE_ROUND;
CHACHA20_DOUBLE_ROUND;
CHACHA20_DOUBLE_ROUND;
CHACHA20_DOUBLE_ROUND;
CHACHA20_DOUBLE_ROUND;
CHACHA20_DOUBLE_ROUND;
CHACHA20_DOUBLE_ROUND;
for(i = 0; i < 16; i++)
ctx->keystream32[i] += ctx->state[i];

1
src/edge.c

@ -164,7 +164,6 @@ static void help() {
printf("-r | Enable packet forwarding through n2n community.\n");
printf("-A1 | Disable payload encryption. Do not use with key (defaulting to Twofish then).\n");
printf("-A2 ... -A5 or -A | Choose a cipher for payload encryption, requires a key: -A2 = Twofish (default),\n");
printf(" | "
printf(" | -A3 or -A (deprecated) = AES, "
"-A4 = ChaCha20, "
"-A5 = Speck-CTR.\n");

3
tools/benchmark.c

@ -63,7 +63,6 @@ static void parseArgs(int argc, char * argv[]) {
int main(int argc, char * argv[]) {
uint8_t pktbuf[N2N_PKT_BUF_SIZE];
n2n_trans_op_t transop_null, transop_tf;
n2n_trans_op_t transop_aes_cbc;
n2n_trans_op_t transop_aes;
n2n_trans_op_t transop_cc20;
@ -80,7 +79,7 @@ int main(int argc, char * argv[]) {
/* Init transopts */
n2n_transop_null_init(&conf, &transop_null);
n2n_transop_tf_init(&conf, &transop_tf);
n2n_transop_aes_cbc_init(&conf, &transop_aes_cbc);
n2n_transop_aes_init(&conf, &transop_aes);
n2n_transop_aes_init(&conf, &transop_aes);
n2n_transop_cc20_init(&conf, &transop_cc20);
n2n_transop_speck_init(&conf, &transop_speck);

Loading…
Cancel
Save