trivium fixed; further migrating to SCAL
This commit is contained in:
parent
12b222bf43
commit
2a5b018aa7
|
@ -134,7 +134,17 @@ uint8_t grain_enc(grain_ctx_t* ctx){
|
||||||
h = (pgm_read_byte(h_lut+(i/8)))>>(i%8);
|
h = (pgm_read_byte(h_lut+(i/8)))>>(i%8);
|
||||||
|
|
||||||
h ^= B(0) ^ B(1) ^ B(3) ^ B(9) ^ B(30) ^ B(42) ^ B(55);
|
h ^= B(0) ^ B(1) ^ B(3) ^ B(9) ^ B(30) ^ B(42) ^ B(55);
|
||||||
return h&1;
|
return (h&1);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t grain_getbyte(grain_ctx_t* ctx){
|
||||||
|
uint8_t i=0;
|
||||||
|
uint8_t r=0;
|
||||||
|
do{
|
||||||
|
r >>= 1;
|
||||||
|
r |= grain_enc(ctx)?0x80:0x00;
|
||||||
|
}while(++i<8);
|
||||||
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef GRAIN_REVERSEKEY
|
#ifdef GRAIN_REVERSEKEY
|
||||||
|
|
|
@ -35,7 +35,7 @@ typedef struct gain_ctx_st{
|
||||||
uint8_t nfsr[10];
|
uint8_t nfsr[10];
|
||||||
} grain_ctx_t;
|
} grain_ctx_t;
|
||||||
|
|
||||||
|
uint8_t grain_getbyte(grain_ctx_t* ctx);
|
||||||
uint8_t grain_enc(grain_ctx_t* ctx);
|
uint8_t grain_enc(grain_ctx_t* ctx);
|
||||||
void grain_init(const void* key, const void* iv, grain_ctx_t* ctx);
|
void grain_init(const void* key, const void* iv, grain_ctx_t* ctx);
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ STREAM_CIPHERS += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_DIR := grain/
|
$(ALGO_NAME)_DIR := grain/
|
||||||
$(ALGO_NAME)_OBJ := grain.o
|
$(ALGO_NAME)_OBJ := grain.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-grain-test.o $(CLI_STD) \
|
$(ALGO_NAME)_INCDIR := memxor/ scal/
|
||||||
nessie_stream_test.o nessie_common.o performance_test.o
|
$(ALGO_NAME)_TEST_BIN := main-grain-test.o $(CLI_STD) $(SCAL_STD) scal_grain.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
|
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@ STREAM_CIPHERS += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_DIR := mickey128/
|
$(ALGO_NAME)_DIR := mickey128/
|
||||||
$(ALGO_NAME)_OBJ := mickey128.o
|
$(ALGO_NAME)_OBJ := mickey128.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-mickey128-test.o $(CLI_STD) \
|
$(ALGO_NAME)_INCDIR := memxor/ scal/
|
||||||
nessie_stream_test.o nessie_common.o
|
$(ALGO_NAME)_TEST_BIN := main-mickey128-test.o $(CLI_STD) $(SCAL_STD) scal_mickey128.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
|
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -118,6 +118,9 @@ void long_block(scgen_ctx_t *ctx){
|
||||||
hook_str_ptr = (uint8_t*)hook_str_ptr + 2;
|
hook_str_ptr = (uint8_t*)hook_str_ptr + 2;
|
||||||
nessie_print_item(str, block, 64);
|
nessie_print_item(str, block, 64);
|
||||||
}
|
}
|
||||||
|
if(i%64==0){
|
||||||
|
NESSIE_SEND_ALIVE;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
strcpy_P(str, (PGM_VOID_P)pgm_read_word(hook_str_ptr));
|
strcpy_P(str, (PGM_VOID_P)pgm_read_word(hook_str_ptr));
|
||||||
nessie_print_item(str, xor_block, 64);
|
nessie_print_item(str, xor_block, 64);
|
||||||
|
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* scal_grain.c */
|
||||||
|
/*
|
||||||
|
This file is part of the AVR-Crypto-Lib.
|
||||||
|
Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "streamcipher_descriptor.h"
|
||||||
|
#include "keysize_descriptor.h"
|
||||||
|
|
||||||
|
#include "grain.h"
|
||||||
|
|
||||||
|
const char grain_str[] PROGMEM = "Grain";
|
||||||
|
|
||||||
|
const uint8_t grain_keysize_desc[] PROGMEM = {
|
||||||
|
KS_TYPE_LIST, 1, KS_INT(80),
|
||||||
|
KS_TYPE_TERMINATOR };
|
||||||
|
|
||||||
|
const uint8_t grain_ivsize_desc[] PROGMEM = {
|
||||||
|
KS_TYPE_LIST, 1, KS_INT(64),
|
||||||
|
KS_TYPE_TERMINATOR };
|
||||||
|
|
||||||
|
const scdesc_t grain_desc PROGMEM = {
|
||||||
|
SCDESC_TYPE_STREAMCIPHER, /* abstraction layer type designator */
|
||||||
|
SC_INIT_TYPE_2|SC_GEN_TYPE_1, /* flags*/
|
||||||
|
grain_str, /* name string pointer */
|
||||||
|
sizeof(grain_ctx_t), /* size of context */
|
||||||
|
8, /* blocksize */
|
||||||
|
{(void_fpt)grain_init}, /* init function pointer */
|
||||||
|
{(void_fpt)grain_getbyte}, /* key stream generator function pointer */
|
||||||
|
{(void_fpt)NULL}, /* key stream generator for random access function pointer */
|
||||||
|
(sc_free_fpt)NULL, /* free function pointer */
|
||||||
|
grain_keysize_desc, /* key size descriptor pointer */
|
||||||
|
grain_ivsize_desc /* iv size descriptor pointer */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* scal_grain.h */
|
||||||
|
/*
|
||||||
|
This file is part of the AVR-Crypto-Lib.
|
||||||
|
Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SCAL_GRAIN_H_
|
||||||
|
#define SCAL_GRAIN_H_
|
||||||
|
|
||||||
|
#include "streamcipher_descriptor.h"
|
||||||
|
|
||||||
|
extern const scdesc_t grain_desc;
|
||||||
|
|
||||||
|
#endif /* SCAL_GRAIN_H_ */
|
|
@ -0,0 +1,56 @@
|
||||||
|
/* scal_mickey128.c */
|
||||||
|
/*
|
||||||
|
This file is part of the AVR-Crypto-Lib.
|
||||||
|
Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include "streamcipher_descriptor.h"
|
||||||
|
#include "keysize_descriptor.h"
|
||||||
|
|
||||||
|
#include "mickey128.h"
|
||||||
|
|
||||||
|
const char mickey128_str[] PROGMEM = "Mickey128";
|
||||||
|
|
||||||
|
const uint8_t mickey128_keysize_desc[] PROGMEM = {
|
||||||
|
KS_TYPE_LIST, 1, KS_INT(128),
|
||||||
|
KS_TYPE_TERMINATOR };
|
||||||
|
|
||||||
|
const uint8_t mickey128_ivsize_desc[] PROGMEM = {
|
||||||
|
KS_TYPE_RANGE, KS_INT(0), KS_INT(128),
|
||||||
|
KS_TYPE_TERMINATOR };
|
||||||
|
|
||||||
|
const scdesc_t mickey128_desc PROGMEM = {
|
||||||
|
SCDESC_TYPE_STREAMCIPHER, /* abstraction layer type designator */
|
||||||
|
SC_INIT_TYPE_5|SC_GEN_TYPE_1, /* flags*/
|
||||||
|
mickey128_str, /* name string pointer */
|
||||||
|
sizeof(mickey128_ctx_t), /* size of context */
|
||||||
|
8, /* blocksize */
|
||||||
|
{(void_fpt)mickey128_init}, /* init function pointer */
|
||||||
|
{(void_fpt)mickey128_getbyte}, /* key stream generator function pointer */
|
||||||
|
{(void_fpt)NULL}, /* key stream generator for random access function pointer */
|
||||||
|
(sc_free_fpt)NULL, /* free function pointer */
|
||||||
|
mickey128_keysize_desc, /* key size descriptor pointer */
|
||||||
|
mickey128_ivsize_desc /* iv size descriptor pointer */
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
/* scal_mickey128.h */
|
||||||
|
/*
|
||||||
|
This file is part of the AVR-Crypto-Lib.
|
||||||
|
Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de)
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef SCAL_MICKEY128_H_
|
||||||
|
#define SCAL_MICKEY128_H_
|
||||||
|
|
||||||
|
#include "streamcipher_descriptor.h"
|
||||||
|
|
||||||
|
extern const scdesc_t mickey128_desc;
|
||||||
|
|
||||||
|
#endif /* SCAL_MICKEY128_H_ */
|
|
@ -32,7 +32,7 @@ const uint8_t trivium_keysize_desc[] PROGMEM = {
|
||||||
KS_TYPE_TERMINATOR };
|
KS_TYPE_TERMINATOR };
|
||||||
|
|
||||||
const uint8_t trivium_ivsize_desc[] PROGMEM = {
|
const uint8_t trivium_ivsize_desc[] PROGMEM = {
|
||||||
KS_TYPE_LIST, 2, KS_INT(32), KS_INT(80),
|
KS_TYPE_LIST, 3, KS_INT(32), KS_INT(64), KS_INT(80),
|
||||||
KS_TYPE_TERMINATOR };
|
KS_TYPE_TERMINATOR };
|
||||||
|
|
||||||
const scdesc_t trivium_desc PROGMEM = {
|
const scdesc_t trivium_desc PROGMEM = {
|
||||||
|
@ -40,9 +40,9 @@ const scdesc_t trivium_desc PROGMEM = {
|
||||||
SC_INIT_TYPE_5|SC_GEN_TYPE_1, /* flags*/
|
SC_INIT_TYPE_5|SC_GEN_TYPE_1, /* flags*/
|
||||||
trivium_str, /* name string pointer */
|
trivium_str, /* name string pointer */
|
||||||
sizeof(trivium_ctx_t), /* size of context */
|
sizeof(trivium_ctx_t), /* size of context */
|
||||||
1, /* blocksize */
|
8, /* blocksize */
|
||||||
{(void_fpt)trivium_init}, /* init function pointer */
|
{(void_fpt)trivium_init}, /* init function pointer */
|
||||||
{(void_fpt)trivium_enc}, /* key stream generator function pointer */
|
{(void_fpt)trivium_getbyte}, /* key stream generator function pointer */
|
||||||
{(void_fpt)NULL}, /* key stream generator for random access function pointer */
|
{(void_fpt)NULL}, /* key stream generator for random access function pointer */
|
||||||
(sc_free_fpt)NULL, /* free function pointer */
|
(sc_free_fpt)NULL, /* free function pointer */
|
||||||
trivium_keysize_desc, /* key size descriptor pointer */
|
trivium_keysize_desc, /* key size descriptor pointer */
|
||||||
|
|
|
@ -17,11 +17,11 @@
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef SCAL_ARCFOUR_H_
|
#ifndef SCAL_TRIVIUM_H_
|
||||||
#define SCAL_ARCFOUR_H_
|
#define SCAL_TRIVIUM_H_
|
||||||
|
|
||||||
#include "streamcipher_descriptor.h"
|
#include "streamcipher_descriptor.h"
|
||||||
|
|
||||||
extern const scdesc_t trivium_desc;
|
extern const scdesc_t trivium_desc;
|
||||||
|
|
||||||
#endif /* SCAL_ARCFOUR_H_ */
|
#endif /* SCAL_TRIVIUM_H_ */
|
||||||
|
|
|
@ -28,7 +28,9 @@
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
|
||||||
#include "grain.h"
|
#include "grain.h"
|
||||||
#include "nessie_stream_test.h"
|
#include "scal_grain.h"
|
||||||
|
#include "scal-basic.h"
|
||||||
|
#include "scal-nessie.h"
|
||||||
#include "performance_test.h"
|
#include "performance_test.h"
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -64,15 +66,7 @@ uint8_t grain_getbyte_dummy_rev(grain_ctx_t* ctx){
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_nessie_grain(void){
|
void testrun_nessie_grain(void){
|
||||||
nessie_stream_ctx.outsize_b = 8; /* actually unused */
|
scal_nessie_run(&grain_desc);
|
||||||
nessie_stream_ctx.keysize_b = 80; /* this is the one we have refrence vectors for */
|
|
||||||
nessie_stream_ctx.ivsize_b = 64;
|
|
||||||
nessie_stream_ctx.name = algo_name;
|
|
||||||
nessie_stream_ctx.ctx_size_B = sizeof(grain_ctx_t);
|
|
||||||
nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)grain_genctx_dummy;
|
|
||||||
nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)grain_getbyte_dummy_rev;
|
|
||||||
|
|
||||||
nessie_stream_run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,9 @@
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
|
||||||
#include "mickey128.h"
|
#include "mickey128.h"
|
||||||
#include "nessie_stream_test.h"
|
#include "scal_mickey128.h"
|
||||||
|
#include "scal-basic.h"
|
||||||
|
#include "scal-nessie.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -20,20 +22,9 @@ char* algo_name = "Mickey128";
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* additional validation-functions *
|
* additional validation-functions *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void mickey128_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){
|
|
||||||
mickey128_init(key, keysize_b, NULL, 0, ctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void testrun_nessie_mickey128(void){
|
void testrun_nessie_mickey128(void){
|
||||||
nessie_stream_ctx.outsize_b = 8; /* actually unused */
|
scal_nessie_run(&mickey128_desc);
|
||||||
nessie_stream_ctx.keysize_b = 128; /* this is the one we have refrence vectors for */
|
|
||||||
nessie_stream_ctx.ivsize_b = 0;
|
|
||||||
nessie_stream_ctx.name = algo_name;
|
|
||||||
nessie_stream_ctx.ctx_size_B = sizeof(mickey128_ctx_t);
|
|
||||||
nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)mickey128_genctx_dummy;
|
|
||||||
nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)mickey128_getbyte;
|
|
||||||
|
|
||||||
nessie_stream_run();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_ref_mickey128(void){
|
void testrun_ref_mickey128(void){
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
#include "trivium.h"
|
#include "trivium.h"
|
||||||
#include "scal_trivium.h"
|
#include "scal_trivium.h"
|
||||||
|
#include "scal-basic.h"
|
||||||
#include "scal-nessie.h"
|
#include "scal-nessie.h"
|
||||||
#include "performance_test.h"
|
#include "performance_test.h"
|
||||||
|
|
||||||
|
@ -61,10 +62,9 @@ void testrun_trivium(void){
|
||||||
cli_putstr_P(PSTR("\r\n IV = "));
|
cli_putstr_P(PSTR("\r\n IV = "));
|
||||||
cli_hexdump(iv, 4);
|
cli_hexdump(iv, 4);
|
||||||
cli_putstr_P(PSTR("\r\n Cipher = "));
|
cli_putstr_P(PSTR("\r\n Cipher = "));
|
||||||
cli_hexdump_block(buffer, 64, 4, 8);
|
cli_hexdump_block(buffer, 64, 4, 16);
|
||||||
scal_cipher_free(&ctx);
|
scal_cipher_free(&ctx);
|
||||||
key[0] = 0x00;
|
key[0] = 0x40;
|
||||||
key[9] = 0x80;
|
|
||||||
scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx);
|
scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx);
|
||||||
scal_cipher_gen_fillblock(buffer, 64, &ctx);
|
scal_cipher_gen_fillblock(buffer, 64, &ctx);
|
||||||
cli_putstr_P(PSTR("\r\nTest:\r\n Key = "));
|
cli_putstr_P(PSTR("\r\nTest:\r\n Key = "));
|
||||||
|
@ -72,7 +72,27 @@ void testrun_trivium(void){
|
||||||
cli_putstr_P(PSTR("\r\n IV = "));
|
cli_putstr_P(PSTR("\r\n IV = "));
|
||||||
cli_hexdump(iv, 4);
|
cli_hexdump(iv, 4);
|
||||||
cli_putstr_P(PSTR("\r\n Cipher = "));
|
cli_putstr_P(PSTR("\r\n Cipher = "));
|
||||||
cli_hexdump_block(buffer, 64, 4, 8);
|
cli_hexdump_block(buffer, 64, 4, 16);
|
||||||
|
scal_cipher_free(&ctx);
|
||||||
|
key[0] = 0x20;
|
||||||
|
scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx);
|
||||||
|
scal_cipher_gen_fillblock(buffer, 64, &ctx);
|
||||||
|
cli_putstr_P(PSTR("\r\nTest:\r\n Key = "));
|
||||||
|
cli_hexdump(key, 10);
|
||||||
|
cli_putstr_P(PSTR("\r\n IV = "));
|
||||||
|
cli_hexdump(iv, 4);
|
||||||
|
cli_putstr_P(PSTR("\r\n Cipher = "));
|
||||||
|
cli_hexdump_block(buffer, 64, 4, 16);
|
||||||
|
scal_cipher_free(&ctx);
|
||||||
|
key[0] = 0x10;
|
||||||
|
scal_cipher_init(&trivium_desc, key, 80, iv, 32, &ctx);
|
||||||
|
scal_cipher_gen_fillblock(buffer, 64, &ctx);
|
||||||
|
cli_putstr_P(PSTR("\r\nTest:\r\n Key = "));
|
||||||
|
cli_hexdump(key, 10);
|
||||||
|
cli_putstr_P(PSTR("\r\n IV = "));
|
||||||
|
cli_hexdump(iv, 4);
|
||||||
|
cli_putstr_P(PSTR("\r\n Cipher = "));
|
||||||
|
cli_hexdump_block(buffer, 64, 4, 16);
|
||||||
scal_cipher_free(&ctx);
|
scal_cipher_free(&ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -28,9 +28,10 @@
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "trivium.h"
|
#include "trivium.h"
|
||||||
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
#define G(i) ((((*ctx)[(i)/8])>>(((i)%8)))&1)
|
#define G(i) ((((*ctx)[(i)/8])>>(((i)%8)))&1)
|
||||||
#define S(i,v) ((*ctx)[(i)/8] = ((*ctx)[(i)/8] & ~(1<<((i)%8))) | ((v)<<((i)%8)))
|
#define S(i,v) ((*ctx)[(i)/8] = (((*ctx)[(i)/8]) & (uint8_t)~(1<<((i)%8))) | ((v)<<((i)%8)))
|
||||||
uint8_t trivium_enc(trivium_ctx_t* ctx){
|
uint8_t trivium_enc(trivium_ctx_t* ctx){
|
||||||
uint8_t t1,t2,t3,z;
|
uint8_t t1,t2,t3,z;
|
||||||
|
|
||||||
|
@ -57,25 +58,55 @@ uint8_t trivium_enc(trivium_ctx_t* ctx){
|
||||||
return z?0x080:0x00;
|
return z?0x080:0x00;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
uint8_t trivium_getbyte(trivium_ctx_t *ctx){
|
||||||
|
uint8_t r=0, i=0;
|
||||||
|
do{
|
||||||
|
r>>=1;
|
||||||
|
r |= trivium_enc(ctx);
|
||||||
|
}while(++i<8);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
#define KEYSIZE_B ((keysize_b+7)/8)
|
#define KEYSIZE_B ((keysize_b+7)/8)
|
||||||
#define IVSIZE_B ((ivsize_b +7)/8)
|
#define IVSIZE_B ((ivsize_b +7)/8)
|
||||||
|
|
||||||
|
static const uint8_t rev_table[16] PROGMEM = {
|
||||||
|
0x00, 0x08, 0x04, 0x0C, /* 0000 1000 0100 1100 */
|
||||||
|
0x02, 0x0A, 0x06, 0x0E, /* 0010 1010 0110 1110 */
|
||||||
|
0x01, 0x09, 0x05, 0x0D, /* 0001 1001 0101 1101 */
|
||||||
|
0x03, 0x0B, 0x07, 0x0F /* 0011 1011 0111 1111 */
|
||||||
|
};
|
||||||
|
|
||||||
void trivium_init(const void* key, uint16_t keysize_b,
|
void trivium_init(const void* key, uint16_t keysize_b,
|
||||||
const void* iv, uint16_t ivsize_b,
|
const void* iv, uint16_t ivsize_b,
|
||||||
trivium_ctx_t* ctx){
|
trivium_ctx_t* ctx){
|
||||||
uint16_t i;
|
uint16_t i;
|
||||||
uint8_t c1=0,c2;
|
uint8_t c1,c2;
|
||||||
|
uint8_t t1,t2;
|
||||||
memset((*ctx)+KEYSIZE_B, 0, 35-KEYSIZE_B);
|
memset((*ctx)+KEYSIZE_B, 0, 35-KEYSIZE_B);
|
||||||
memcpy((*ctx), key, KEYSIZE_B);
|
c2=0;
|
||||||
memcpy((*ctx)+12, iv, IVSIZE_B); /* iv0 is at s96, must shift to s93 */
|
c1=KEYSIZE_B;
|
||||||
|
do{
|
||||||
|
t1 = ((uint8_t*)key)[--c1];
|
||||||
|
t2 = (pgm_read_byte(&(rev_table[t1&0x0f]))<<4)|(pgm_read_byte(&(rev_table[t1>>4])));
|
||||||
|
(*ctx)[c2++] = t2;
|
||||||
|
}while(c1!=0);
|
||||||
|
|
||||||
|
c2=12;
|
||||||
|
c1=IVSIZE_B;
|
||||||
|
do{
|
||||||
|
t1 = ((uint8_t*)iv)[--c1];
|
||||||
|
t2 = (pgm_read_byte(&(rev_table[t1&0x0f]))<<4)|(pgm_read_byte(&(rev_table[t1>>4])));
|
||||||
|
(*ctx)[c2++] = t2;
|
||||||
|
}while(c1!=0);
|
||||||
|
|
||||||
for(i=12+IVSIZE_B; i>10; --i){
|
for(i=12+IVSIZE_B; i>10; --i){
|
||||||
c2=(((*ctx)[i])<<5);
|
c2=(((*ctx)[i])<<5);
|
||||||
(*ctx)[i] = (((*ctx)[i])>>3)|c1;
|
(*ctx)[i] = (((*ctx)[i])>>3)|c1;
|
||||||
c1=c2;
|
c1=c2;
|
||||||
}
|
}
|
||||||
(*ctx)[35] |= 0xE0;
|
|
||||||
|
(*ctx)[35] = 0xE0;
|
||||||
|
|
||||||
for(i=0; i<4*288; ++i){
|
for(i=0; i<4*288; ++i){
|
||||||
trivium_enc(ctx);
|
trivium_enc(ctx);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
typedef uint8_t trivium_ctx_t[36]; /* 288bit */
|
typedef uint8_t trivium_ctx_t[36]; /* 288bit */
|
||||||
|
|
||||||
uint8_t trivium_enc(trivium_ctx_t* ctx);
|
uint8_t trivium_enc(trivium_ctx_t* ctx);
|
||||||
|
uint8_t trivium_getbyte(trivium_ctx_t* ctx);
|
||||||
void trivium_init(const void* key, uint16_t keysize_b,
|
void trivium_init(const void* key, uint16_t keysize_b,
|
||||||
const void* iv, uint16_t ivsize_b,
|
const void* iv, uint16_t ivsize_b,
|
||||||
trivium_ctx_t* ctx);
|
trivium_ctx_t* ctx);
|
||||||
|
|
Loading…
Reference in New Issue