]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
+trivium
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Mon, 14 Apr 2008 18:36:02 +0000 (18:36 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Mon, 14 Apr 2008 18:36:02 +0000 (18:36 +0000)
Makefile
main-noekeon-test.c
main-trivium-test.c [new file with mode: 0644]
trivium.c [new file with mode: 0644]
trivium.h [new file with mode: 0644]
trivium.mk [new file with mode: 0644]

index 0eab89b310a03797c45794f64f2789cf30a9095f..9026dc4f38c30c833bf5d616bd0cc6275ccac12f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -140,7 +140,7 @@ $(foreach algo, $(ALGORITHMS), $(eval $(call SIZE_TEMPLATE, $(call lc,$(algo)),
 define FLASH_TEMPLATE
 $(1)_FLASH: $(2)
        @echo "[flash]: $(2)"
-       $(FLASHCMD)$(call first,$(2))
+       @$(FLASHCMD)$(call first,$(2))
 endef
 
 $(foreach algo, $(ALGORITHMS),$(eval $(call FLASH_TEMPLATE, $(algo), \
index c7b21e722872b023048adcaf855ef67f060fb6aa..b5965ecc59fd2d782cfa73e968b5c89625e87bc1 100644 (file)
@@ -188,6 +188,7 @@ void testrun_performance_noekeon(void){
        uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
        ultoa((unsigned long)t, str, 10);
        uart_putstr(str);
+       
        uart_putstr_P(PSTR("\r\n"));
 }
 /*****************************************************************************
diff --git a/main-trivium-test.c b/main-trivium-test.c
new file mode 100644 (file)
index 0000000..7e3faa2
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Mickey128 test-suit
+ * 
+*/
+
+#include "config.h"
+#include "serial-tools.h"
+#include "uart.h"
+#include "debug.h"
+#include "cli.h"
+
+#include "trivium.h"
+#include "nessie_stream_test.h"
+#include "performance_test.h"
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+char* cipher_name = "Trivium";
+
+/*****************************************************************************
+ *  additional validation-functions                                                                                     *
+ *****************************************************************************/
+void trivium_genctx_dummy(uint8_t* key, uint16_t keysize_b, void* ctx){
+       uint32_t iv=0;
+       trivium_init(key, 80, &iv, 32, ctx);
+}
+
+uint8_t trivium_getbyte_dummy(trivium_ctx_t* ctx){
+       uint8_t i,ret=0;
+       for(i=0; i<8; ++i){
+               ret<<=1;
+               ret |= trivium_enc(ctx);
+       }
+       return ret;
+}
+
+void testrun_nessie_trivium(void){
+       nessie_stream_ctx.outsize_b =   8; /* actually unused */
+       nessie_stream_ctx.keysize_b =  80; /* this is the one we have refrence vectors for */
+       nessie_stream_ctx.ivsize_b  =  32;
+       nessie_stream_ctx.name = cipher_name;
+       nessie_stream_ctx.ctx_size_B = sizeof(trivium_ctx_t);
+       nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)trivium_genctx_dummy;
+       nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)trivium_getbyte_dummy;
+       
+       nessie_stream_run();    
+}
+
+void testrun_performance_trivium(void){
+       uint16_t i,c;
+       uint64_t t;
+       char str[16];
+       uint8_t key[10], iv[10];
+       trivium_ctx_t ctx;
+       
+       calibrateTimer();
+       getOverhead(&c, &i);
+       uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
+       utoa(c, str, 10);
+       uart_putstr_P(PSTR("\r\n\tconst overhead:     "));
+       uart_putstr(str);
+       utoa(i, str, 10);
+       uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
+       uart_putstr(str);       
+       
+       memset(key,  0, 10);
+       memset(iv,  0, 10);
+       
+       startTimer(1);
+       trivium_init(key, 80, iv, 80, &ctx);
+       t = stopTimer();
+       uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
+       ultoa((unsigned long)t, str, 10);
+       uart_putstr(str);       
+       
+       startTimer(1);
+       trivium_enc(&ctx);
+       t = stopTimer();
+       uart_putstr_P(PSTR("\r\n\tencrypt time: "));
+       ultoa((unsigned long)t, str, 10);
+       uart_putstr(str);       
+       
+       uart_putstr_P(PSTR("\r\n"));
+}
+
+/*****************************************************************************
+ *  main                                                                                                                                        *
+ *****************************************************************************/
+
+typedef void(*void_fpt)(void);
+
+int main (void){
+       char  str[20];
+       DEBUG_INIT();
+       uart_putstr("\r\n");
+
+       uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
+       uart_putstr(cipher_name);
+       uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
+
+       PGM_P    u   = PSTR("nessie\0test\0performance\0");
+       void_fpt v[] = {testrun_nessie_trivium, testrun_nessie_trivium, testrun_performance_trivium};
+
+       while(1){ 
+               if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
+               if(execcommand_d0_P(str, u, v)<0){
+                       uart_putstr_P(PSTR("\r\nunknown command\r\n"));
+               }
+               continue;
+       error:
+               uart_putstr("ERROR\r\n");
+       }       
+}
diff --git a/trivium.c b/trivium.c
new file mode 100644 (file)
index 0000000..cd89b56
--- /dev/null
+++ b/trivium.c
@@ -0,0 +1,66 @@
+/**
+ * 
+ * author: Daniel Otte
+ * email:  daniel.otte@rub.de
+ * license: GPLv3
+ * 
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include "trivium.h"
+
+#define S(i) ((((*ctx)[(i)/8])>>((i)%8))&1)
+uint8_t trivium_enc(trivium_ctx_t* ctx){
+       uint8_t t1,t2,t3,z;
+       
+       t1 = S(65)  ^ S(92);
+       t2 = S(161) ^ S(176);
+       t3 = S(242) ^ S(287);
+       z  = t1^t2^t3;
+       t1 ^= (S(90)  & S(91))  ^ S(170);
+       t2 ^= (S(174) & S(175)) ^ S(263);
+       t3 ^= (S(285) & S(286)) ^ S(68);
+       
+       /* shift whole state and insert ts later */
+       uint8_t i,c1=0,c2;
+       for(i=0; i<36; ++i){
+               c2=(((*ctx)[i])>>7);
+               (*ctx)[i] = (((*ctx)[i])<<1)|c1;
+               c1=c2;
+       }
+       /* insert ts */
+       (*ctx)[0] = (((*ctx)[0])&0xFE)| t3; /* s0*/
+       (*ctx)[93/8] = (((*ctx)[93/8])& (~(1<<(93%8)))) | (t1<<(93%8)); /* s93 */
+       (*ctx)[177/8] = (((*ctx)[177/8])& (~(1<<(177%8)))) | (t2<<(177%8));/* s177 */
+       
+       return z;
+}
+
+#define KEYSIZE_B ((keysize_b+7)/8)
+#define IVSIZE_B  ((ivsize_b +7)/8)
+
+void trivium_init(const void* key, uint8_t keysize_b, 
+                  const void* iv,  uint8_t ivsize_b,
+                  trivium_ctx_t* ctx){
+       uint16_t i;
+       uint8_t c1=0,c2;
+
+       memset((*ctx)+KEYSIZE_B, 0, 35-KEYSIZE_B);
+       memcpy((*ctx), key, KEYSIZE_B);
+       memcpy((*ctx)+12, iv, IVSIZE_B); /* iv0 is at s96, must shift to s93 */
+       
+       for(i=12+IVSIZE_B; i>10; --i){
+               c2=(((*ctx)[i])<<5);
+               (*ctx)[i] = (((*ctx)[i])>>3)|c1;
+               c1=c2;
+       }
+       (*ctx)[35]=0xE0;
+       
+       for(i=0; i<4*288; ++i){
+               trivium_enc(ctx);
+       }
+}
+
+
diff --git a/trivium.h b/trivium.h
new file mode 100644 (file)
index 0000000..6cef51c
--- /dev/null
+++ b/trivium.h
@@ -0,0 +1,11 @@
+#ifndef TRIVIUM_H_
+#define TRIVIUM_H_
+
+typedef uint8_t trivium_ctx_t[36]; /* 288bit */
+
+uint8_t trivium_enc(trivium_ctx_t* ctx);
+void trivium_init(const void* key, uint8_t keysize_b, 
+                  const void* iv,  uint8_t ivsize_b,
+                  trivium_ctx_t* ctx);
+
+#endif /*TRIVIUM_H_*/
diff --git a/trivium.mk b/trivium.mk
new file mode 100644 (file)
index 0000000..e2e3484
--- /dev/null
@@ -0,0 +1,13 @@
+# Makefile for Trivium
+ALGO_NAME := TRIVIUM
+
+# comment out the following line for removement of Trivium from the build process
+STREAM_CIPHERS += $(ALGO_NAME)
+
+$(ALGO_NAME)_OBJ      := trivium.o
+$(ALGO_NAME)_TEST_BIN := main-trivium-test.o debug.o uart.o serial-tools.o \
+                         nessie_stream_test.o nessie_common.o trivium.o cli.o \
+                        performance_test.o
+$(ALGO_NAME)_NESSIE_TEST      := "nessie"
+$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
+