mirror of
https://github.com/ntop/n2n.git
synced 2024-09-20 00:51:10 +02:00
reworked cc20
This commit is contained in:
parent
91ca25baa2
commit
87ee4d6fa7
32
src/cc20.c
32
src/cc20.c
|
@ -96,7 +96,16 @@ static void chacha20_init_block(cc20_context_t *ctx, const uint8_t nonce[]) {
|
||||||
x[a] += x[b]; x[d] = ROL32(x[d] ^ x[a], 16); \
|
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[c] += x[d]; x[b] = ROL32(x[b] ^ x[c], 12); \
|
||||||
x[a] += x[b]; x[d] = ROL32(x[d] ^ x[a], 8); \
|
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[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) {
|
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++)
|
for(i = 0; i < 16; i++)
|
||||||
ctx->keystream32[i] = ctx->state[i];
|
ctx->keystream32[i] = ctx->state[i];
|
||||||
|
|
||||||
for(i = 0; i < 10; i++) {
|
// 10 double rounds
|
||||||
CHACHA20_QUARTERROUND(ctx->keystream32, 0, 4, 8, 12)
|
CHACHA20_DOUBLE_ROUND;
|
||||||
CHACHA20_QUARTERROUND(ctx->keystream32, 1, 5, 9, 13)
|
CHACHA20_DOUBLE_ROUND;
|
||||||
CHACHA20_QUARTERROUND(ctx->keystream32, 2, 6, 10, 14)
|
CHACHA20_DOUBLE_ROUND;
|
||||||
CHACHA20_QUARTERROUND(ctx->keystream32, 3, 7, 11, 15)
|
CHACHA20_DOUBLE_ROUND;
|
||||||
CHACHA20_QUARTERROUND(ctx->keystream32, 0, 5, 10, 15)
|
CHACHA20_DOUBLE_ROUND;
|
||||||
CHACHA20_QUARTERROUND(ctx->keystream32, 1, 6, 11, 12)
|
CHACHA20_DOUBLE_ROUND;
|
||||||
CHACHA20_QUARTERROUND(ctx->keystream32, 2, 7, 8, 13)
|
CHACHA20_DOUBLE_ROUND;
|
||||||
CHACHA20_QUARTERROUND(ctx->keystream32, 3, 4, 9, 14)
|
CHACHA20_DOUBLE_ROUND;
|
||||||
}
|
CHACHA20_DOUBLE_ROUND;
|
||||||
|
CHACHA20_DOUBLE_ROUND;
|
||||||
|
|
||||||
for(i = 0; i < 16; i++)
|
for(i = 0; i < 16; i++)
|
||||||
ctx->keystream32[i] += ctx->state[i];
|
ctx->keystream32[i] += ctx->state[i];
|
||||||
|
|
|
@ -164,7 +164,6 @@ static void help() {
|
||||||
printf("-r | Enable packet forwarding through n2n community.\n");
|
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("-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("-A2 ... -A5 or -A | Choose a cipher for payload encryption, requires a key: -A2 = Twofish (default),\n");
|
||||||
printf(" | "
|
|
||||||
printf(" | -A3 or -A (deprecated) = AES, "
|
printf(" | -A3 or -A (deprecated) = AES, "
|
||||||
"-A4 = ChaCha20, "
|
"-A4 = ChaCha20, "
|
||||||
"-A5 = Speck-CTR.\n");
|
"-A5 = Speck-CTR.\n");
|
||||||
|
|
|
@ -63,7 +63,6 @@ static void parseArgs(int argc, char * argv[]) {
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
uint8_t pktbuf[N2N_PKT_BUF_SIZE];
|
uint8_t pktbuf[N2N_PKT_BUF_SIZE];
|
||||||
n2n_trans_op_t transop_null, transop_tf;
|
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_aes;
|
||||||
n2n_trans_op_t transop_cc20;
|
n2n_trans_op_t transop_cc20;
|
||||||
|
|
||||||
|
@ -80,7 +79,7 @@ int main(int argc, char * argv[]) {
|
||||||
/* Init transopts */
|
/* Init transopts */
|
||||||
n2n_transop_null_init(&conf, &transop_null);
|
n2n_transop_null_init(&conf, &transop_null);
|
||||||
n2n_transop_tf_init(&conf, &transop_tf);
|
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_aes_init(&conf, &transop_aes);
|
||||||
n2n_transop_cc20_init(&conf, &transop_cc20);
|
n2n_transop_cc20_init(&conf, &transop_cc20);
|
||||||
n2n_transop_speck_init(&conf, &transop_speck);
|
n2n_transop_speck_init(&conf, &transop_speck);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user