# @echo " $(ALGORITHMS_TEST_BIN)"
# @echo " ALGORITHMS_TEST_TARGET_ELF:"
# @echo " $(ALGORITHMS_TEST_TARGET_ELF)"
+ @echo " targets:"
+ @echo " all - all algorithm cores"
+ @echo " cores - all algorithm cores"
+ @echo " listings - all algorithm core listings"
+ @echo " tests - all algorithm test programs"
+ @echo " stats - all algorithm size statistics"
+ @echo " blockciphers - all blockcipher cores"
+ @echo " streamciphers - all streamcipher cores"
+ @echo " hashes - all hash cores"
+ @echo " macs - all MAC cores"
+ @echo " prngs - all PRNG cores"
+ @echo " all_testrun - testrun all algorithms"
+ @echo " docu - build doxygen documentation"
+ @echo " clean - remove a lot of builded files"
+ @echo " xclean - also remove dependency files"
+ @echo " *_TEST_BIN - build test program"
+ @echo " *_TESTRUN - run nessie test"
+ @echo " *_OBJ - build algorithm core"
+ @echo " *_FLASH - flash test program"
+ @echo " *_LIST - build assembler listing"
#-------------------------------------------------------------------------------
define TESTRUN_TEMPLATE
$(1)_TESTRUN: $(1)_FLASH
@echo "[test]: $(1)"
- $(RUBY) get_test.rb $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
+ $(RUBY) $(GET_TEST) $(TESTPORT) $(TESTPORTBAUDR) 8 1 nessie $(TESTLOG_DIR)$(TESTPREFIX) $(2)
endef
$(foreach algo, $(ALGORITHMS),$(eval $(call TESTRUN_TEMPLATE, $(algo), $(call lc,$(algo)) )))
-ALL_TESTRUN: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
+all_testrun: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
#-------------------------------------------------------------------------------
docu:
doxygen
+make.dump: Makefile
+ $(MAKE) -p -B -n -f $^ > $@
+
+make.dot: make.dump
+ $(MAKE2GRAPH) $^ > $@
+
+make.png: make.dot
+ $(TWOPI) -Tpng -o $@ $^
+
+make.svg: make.dot
+ $(TWOPI) -Tsvg -o $@ $^
+
+.PHONY: make-info
+make-info: make.png make.svg
# Rules for building the .text rom images
#uisp -dprog=bsd -dlpt=/dev/parport1 --upload if=$(PRG).hex
ERASECMD =
TESTPORT = /dev/ttyUSB1
-TESTPORTBAUDR = 9600
+TESTPORTBAUDR = 38400
TESTLOG_DIR = testlog/
TESTPREFIX = nessie-
LIST_DIR = listings/
OBJDUMP = avr-objdump
SIZE = avr-size
RUBY = ruby
+GET_TEST = host/get_test.rb
+MAKE = make
+MAKE2GRAPH = ~/bin/make2graph.rb
+TWOPI = twopi
-void cast5_init(void* key, uint8_t keylength_b, cast5_ctx_t* s){
+void cast5_init(const void* key, uint8_t keylength_b, cast5_ctx_t* s){
/* we migth return if the key is valid and if setup was sucessfull */
uint32_t x[4], z[4];
#define BPX ((uint8_t*)&(x[0]))
#else
- return (((pgm_read_dword(&s1[((uint8_t*)&t)[IA]] ) ^ pgm_read_dword(&s2[((uint8_t*)&t)[IB]] ))
- - pgm_read_dword(&s3[((uint8_t*)&t)[IC]] )) + pgm_read_dword(&s4[((uint8_t*)&t)[ID]]));
+ return ((( pgm_read_dword(&s1[((uint8_t*)&t)[IA]])
+ ^ pgm_read_dword(&s2[((uint8_t*)&t)[IB]]) )
+ - pgm_read_dword(&s3[((uint8_t*)&t)[IC]]) )
+ + pgm_read_dword(&s4[((uint8_t*)&t)[ID]]) );
#endif
}
return (((ia - ib) + ic) ^ id);
#else
- return (((pgm_read_dword(&s1[((uint8_t*)&t)[IA]])
- - pgm_read_dword(&s2[((uint8_t*)&t)[IB]]) )
+ return ((( pgm_read_dword(&s1[((uint8_t*)&t)[IA]])
+ - pgm_read_dword(&s2[((uint8_t*)&t)[IB]]) )
+ pgm_read_dword(&s3[((uint8_t*)&t)[IC]]) )
^ pgm_read_dword(&s4[((uint8_t*)&t)[ID]]) );
uart_putstr("\r\n\tID="); uart_hexdump(&id, 4);
return (((ia + ib) ^ ic) - id);
#else
- return ((pgm_read_dword(&s1[((uint8_t*)&t)[IA]] ) + pgm_read_dword(&s2[((uint8_t*)&t)[IB]] ))
- ^ pgm_read_dword(&s3[((uint8_t*)&t)[IC]] )) - pgm_read_dword(&s4[((uint8_t*)&t)[ID]] );
+ return (( pgm_read_dword(&s1[((uint8_t*)&t)[IA]] )
+ + pgm_read_dword(&s2[((uint8_t*)&t)[IB]] ))
+ ^ pgm_read_dword(&s3[((uint8_t*)&t)[IC]] ))
+ - pgm_read_dword(&s4[((uint8_t*)&t)[ID]] );
#endif
}
*
* A variable of this type may hold a keyschedule for the CAST-5 cipher.
* This context is regulary generated by the
- * cast5_init(uint8_t* key, uint8_t keylength_b, cast5_ctx_t* s) funtion.
+ * cast5_init(uint8_t* key, uint8_t keylength_b, cast5_ctx_t* s) function.
*/
typedef struct cast5_ctx_st{
uint32_t mask[16];
* \param keylength_b length of the key in bits (maximum 128 bits)
* \param s pointer to the context
*/
-void cast5_init(void* key, uint8_t keylength_b, cast5_ctx_t* s);
+void cast5_init(const void* key, uint8_t keylength_b, cast5_ctx_t* s);
/** \fn void cast5_enc(void* block, const cast5_ctx_t *s);
* \brief encrypt a block with the CAST-5 algorithm
/* uart.[ch] defines */
#define UART_INTERRUPT 1
-#define UART_BAUD_RATE 9600
+#define UART_BAUD_RATE 38400
#define UART_RXBUFSIZE 16
#define UART_TXBUFSIZE 16
#define UART_LINE_BUFFER_SIZE 40
--- /dev/null
+# Makefile for noekeon
+ALGO_NAME := OMAC_NOEKEON
+
+# comment out the following line for removement of noekeon from the build process
+MACS += $(ALGO_NAME)
+
+
+$(ALGO_NAME)_OBJ := noekeon_asm.o omac_noekeon.o memxor.o
+$(ALGO_NAME)_TEST_BIN := main-omac-noekeon-test.o debug.o uart.o serial-tools.o \
+ nessie_mac_test.o nessie_common.o cli.o performance_test.o
+$(ALGO_NAME)_NESSIE_TEST := test nessie
+$(ALGO_NAME)_PERFORMANCE_TEST := performance
+
--- /dev/null
+# Makefile for noekeon
+ALGO_NAME := OMAC_NOEKEON_C
+
+# comment out the following line for removement of noekeon from the build process
+MACS += $(ALGO_NAME)
+
+
+$(ALGO_NAME)_OBJ := noekeon_asm.o omac_noekeon_C.o memxor.o
+$(ALGO_NAME)_TEST_BIN := main-omac-noekeon-test.o debug.o uart.o serial-tools.o \
+ nessie_mac_test.o nessie_common.o cli.o performance_test.o
+$(ALGO_NAME)_NESSIE_TEST := test nessie
+$(ALGO_NAME)_PERFORMANCE_TEST := performance
+
--- /dev/null
+# Makefile for SEED
+ALGO_NAME := SEED_C
+
+# comment out the following line for removement of SEED from the build process
+BLOCK_CIPHERS += $(ALGO_NAME)
+
+$(ALGO_NAME)_OBJ := seed_C.o
+$(ALGO_NAME)_TEST_BIN := main-seed-test.o debug.o uart.o serial-tools.o \
+ nessie_bc_test.o nessie_common.o \
+ cli.o performance_test.o
+$(ALGO_NAME)_NESSIE_TEST := "nessie"
+$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
+
--- /dev/null
+#include "noekeon.h"
+#include "omac_noekeon.h"
+#include "memxor.h"
+#include <string.h>
+#include <stdint.h>
+
+
+void omac_noekeon_init(omac_noekeon_ctx_t* ctx){
+ memset(ctx, 0, 16);
+}
+
+
+void omac_noekeon_tweak(uint8_t t, const void* key, omac_noekeon_ctx_t* ctx){
+ *ctx[15] = t;
+ noekeon_enc(ctx, key);
+}
+
+void omac_noekeon_next(const void* buffer, const void* key, omac_noekeon_ctx_t* ctx){
+ memxor(ctx, buffer, 16);
+ noekeon_enc(ctx, key);
+}
+
+static
+void omac_noekeon_comppad(uint8_t* pad, const void* key, uint8_t length_b){
+ uint8_t c1,c2,r,j;
+ memset(pad, 0, 16);
+ noekeon_enc(pad, key);
+ r=(length_b==128)?1:2;
+ for(;r!=0;--r){
+ c1=0;
+ for(j=0;j<16;++j){
+ c2 = c1;
+ c1 = (pad[15-j])>>7;
+ pad[15-j] = ((pad[15-j])<<1) | c2;
+ }
+ if(c1){
+ pad[15] ^= 0x87;
+ }
+ }
+ if(length_b<128){
+ pad[(length_b)/8] ^= 0x80 >> (length_b%8);
+ }
+}
+
+void omac_noekeon_last(const void* buffer, uint8_t length_b, const void* key, omac_noekeon_ctx_t* ctx){
+ while(length_b>128){
+ omac_noekeon_next(buffer, key, ctx);
+ buffer = (uint8_t*)buffer +16;
+ length_b -= 128;
+ }
+ uint8_t pad[16];
+ omac_noekeon_comppad(pad, key, length_b);
+ memxor(pad, buffer, (length_b+7)/8);
+ omac_noekeon_next(pad, key, ctx);
+}
+
+
+void omac_noekeon(void* dest, const void* msg, uint16_t msglength_b,
+ const void* key, uint8_t t){
+ omac_noekeon_init(dest);
+ if(t!=0xff)
+ omac_noekeon_tweak(t,key,dest);
+ while(msglength_b>128){
+ omac_noekeon_next(msg, key, dest);
+ msg = (uint8_t*)msg +16;
+ msglength_b -= 128;
+ }
+ omac_noekeon_last(msg, msglength_b, key, dest);
+}
+
+
+
+
+
#define SEED_H_
#include <stdint.h>
-
+/** \typedef seed_ctx_t
+ * \brief SEED context
+ *
+ * A variable of this type may hold the key material for the SEED cipher.
+ * This context is regulary generated by the
+ * void seed_init(const void * key, seed_ctx_t * ctx) function.
+ */
typedef struct{
uint32_t k[4];
} seed_ctx_t;
/******************************************************************************/
-void seed_init(uint8_t * key, seed_ctx_t * ctx);
-void seed_enc(void * buffer, seed_ctx_t * ctx);
-void seed_dec(void * buffer, seed_ctx_t * ctx);
+/** \fn void seed_init(void * key, seed_ctx_t * ctx)
+ * \brief initializes context for SEED operation
+ *
+ * This function copys the key material into a context variable.
+ *
+ * \param key pointer to the key material (128 bit = 16 bytes)
+ * \param ctx pointer to the context (seed_ctx_t)
+ */
+void seed_init(const void * key, seed_ctx_t * ctx);
+
+/** \fn void seed_enc(void * buffer, seed_ctx_t * ctx)
+ * \brief encrypt a block with SEED
+ *
+ * This function encrypts a block of 64 bits (8 bytes) with the SEED algorithm.
+ * The round keys are computed on demand, so the context is modifyed while
+ * encrypting but the original stated is restored when the function exits.
+ *
+ * \param buffer pointer to the block (64 bit = 8 byte) which will be encrypted
+ * \param ctx pointer to the key material (seed_ctx_t)
+ */
+void seed_enc(void * buffer, const seed_ctx_t * ctx);
+
+
+/** \fn void seed_dec(void * buffer, seed_ctx_t * ctx)
+ * \brief decrypt a block with SEED
+ *
+ * This function decrypts a block of 64 bits (8 bytes) with the SEED algorithm.
+ * The round keys are computed on demand, so the context is modifyed while
+ * decrypting but the original stated is restored when the function exits.
+ *
+ * \param buffer pointer to the block (64 bit = 8 byte) which will be decrypted
+ * \param ctx pointer to the key material (seed_ctx_t)
+ */
+void seed_dec(void * buffer, const seed_ctx_t * ctx);
+
#endif /*SEED_H_*/
/******************************************************************************/
-void seed_init(uint8_t * key, seed_ctx_t * ctx){
+void seed_init(const void * key, seed_ctx_t * ctx){
memcpy(ctx->k, key, 128/8);
}
#define L (((uint64_t*)buffer)[0])
#define R (((uint64_t*)buffer)[1])
-void seed_enc(void * buffer, seed_ctx_t * ctx){
+void seed_enc(void * buffer, const seed_ctx_t * ctx){
uint8_t r;
keypair_t k;
for(r=0; r<8; ++r){
- k = getnextkeys(ctx->k, 2*r);
+ k = getnextkeys(((seed_ctx_t*)ctx)->k, 2*r);
/*
DEBUG_S("\r\n\tDBG ka,0: "); uart_hexdump(&k.k0, 4);
DEBUG_S("\r\n\tDBG ka,1: "); uart_hexdump(&k.k1, 4);
*/
L ^= f_function(&R,k.k0,k.k1);
- k = getnextkeys(ctx->k, 2*r+1);
+ k = getnextkeys(((seed_ctx_t*)ctx)->k, 2*r+1);
/*
DEBUG_S("\r\n\tDBG kb,0: "); uart_hexdump(&k.k0, 4);
DEBUG_S("\r\n\tDBG kb,1: "); uart_hexdump(&k.k1, 4);
int8_t r;
keypair_t k;
for(r=7; r>=0; --r){
- k = getprevkeys(ctx->k, 2*r+1);
+ k = getprevkeys(((seed_ctx_t*)ctx)->k, 2*r+1);
/*
DEBUG_S("\r\n\tDBG ka,0: "); uart_hexdump(&k.k0, 4);
DEBUG_S("\r\n\tDBG ka,1: "); uart_hexdump(&k.k1, 4);
*/
L ^= f_function(&R,k.k0,k.k1);
- k = getprevkeys(ctx->k, 2*r+0);
+ k = getprevkeys(((seed_ctx_t*)ctx)->k, 2*r+0);
/*
DEBUG_S("\r\n\tDBG kb,0: "); uart_hexdump(&k.k0, 4);
DEBUG_S("\r\n\tDBG kb,1: "); uart_hexdump(&k.k1, 4);