fixed small bug in MD5

This commit is contained in:
bg 2008-08-19 12:18:25 +00:00
parent 36101d05fd
commit 6bd58d7909
20 changed files with 25832 additions and 386 deletions

103
Makefile
View File

@ -73,10 +73,12 @@ info:
@echo " $(MACS)"
@echo " PRNG functions:"
@echo " $(PRNGS)"
@echo " ALGORITHMS_TEST_BIN"
@echo " $(ALGORITHMS_TEST_BIN)"
@echo " ALGORITHMS_TEST_TARGET_ELF:"
@echo " $(ALGORITHMS_TEST_TARGET_ELF)"
# @echo " ALGORITHMS_TEST_BIN"
# @echo " $(ALGORITHMS_TEST_BIN)"
# @echo " ALGORITHMS_TEST_TARGET_ELF:"
# @echo " $(ALGORITHMS_TEST_TARGET_ELF)"
#-------------------------------------------------------------------------------
$(BIN_DIR)%.o: %.c
@ -104,37 +106,7 @@ $(TESTBIN_DIR)%.o: $(TESTSRC_DIR)%.S
@echo "[as] : $@"
@$(CC) $(ASFLAGS) -c -o $@ $<
.PHONY: cores
cores: $(ALGORITHMS_OBJ)
.PHONY: blockciphers
blockciphers: $(patsubst %, %_OBJ, $(BLOCK_CIPHERS))
.PHONY: streamciphers
streamciphers: $(patsubst %, %_OBJ, $(STREAM_CIPHERS))
.PHONY: hashes
hashes: $(patsubst %, %_OBJ, $(HASHES))
.PHONY: macs
macs: $(patsubst %, %_OBJ, $(MACS))
.PHONY: prngs
prngs: $(patsubst %, %_OBJ, $(PRNGS))
tests: $(ALGORITHMS_TEST_BIN) \
$(ALGORITHMS_TEST_TARGET_ELF) \
$(ALGORITHMS_TEST_TARGET_HEX)
.PHONY: stats
stats: $(SIZESTAT_FILE)
$(SIZESTAT_FILE): $(patsubst %, %_size.txt, $(ALGORITHMS_LC))
$(RUBY) sumsize.rb $^ > $(SIZESTAT_FILE)
@cat $(SIZESTAT_FILE)
#-------------------------------------------------------------------------------
#-------------------------------------------------------------------------------
define OBJ_TEMPLATE
$(1)_OBJ: $(2)
@ -162,7 +134,7 @@ $(1)_size.txt: $(2)
@$(SIZE) $(2) > $(1)_size.txt
endef
$(foreach algo, $(ALGORITHMS), $(eval $(call SIZE_TEMPLATE, $(call lc,$(algo)), $($(algo)_OBJ))))
$(foreach algo, $(ALGORITHMS), $(eval $(call SIZE_TEMPLATE, $(STAT_DIR)$(call lc,$(algo)), $($(algo)_OBJ))))
#-------------------------------------------------------------------------------
@ -188,12 +160,62 @@ ALL_TESTRUN: $(foreach algo, $(ALGORITHMS), $(algo)_TESTRUN)
#-------------------------------------------------------------------------------
define LISTING_TEMPLATE
$(1)_LIST: $(2)
endef
$(foreach algo, $(ALGORITHMS),$(eval $(call LISTING_TEMPLATE,$(call uc, $(algo)), $(patsubst %.o,%.lst,$(algo)_OBJ) )))
listings: $(patsubst %,%_LIST,$(ALGORITHMS))
$(LIST_DIR)%.lst: $(TESTBIN_DIR)%.elf
$(OBJDUMP) -h -S $< > $@
$(LIST_DIR)%.lst: $(BIN_DIR)%.o
$(OBJDUMP) -h -S $< > $@
$(LIST_DIR)%.lst: $(TESTBIN_DIR)%.o
$(OBJDUMP) -h -S $< > $@
#-------------------------------------------------------------------------------
.PHONY: cores
cores: $(ALGORITHMS_OBJ)
.PHONY: blockciphers
blockciphers: $(patsubst %, %_OBJ, $(BLOCK_CIPHERS))
.PHONY: streamciphers
streamciphers: $(patsubst %, %_OBJ, $(STREAM_CIPHERS))
.PHONY: hashes
hashes: $(patsubst %, %_OBJ, $(HASHES))
.PHONY: macs
macs: $(patsubst %, %_OBJ, $(MACS))
.PHONY: prngs
prngs: $(patsubst %, %_OBJ, $(PRNGS))
tests: $(ALGORITHMS_TEST_BIN) \
$(ALGORITHMS_TEST_TARGET_ELF) \
$(ALGORITHMS_TEST_TARGET_HEX)
.PHONY: stats
stats: $(SIZESTAT_FILE)
@cat $(STAT_DIR)$(SIZESTAT_FILE)
$(SIZESTAT_FILE): $(patsubst %, $(STAT_DIR)%_size.txt, $(ALGORITHMS_LC))
$(RUBY) sumsize.rb $^ > $(STAT_DIR)$(SIZESTAT_FILE)
#-------------------------------------------------------------------------------
.PHONY: clean
clean:
rm -rf $(BIN_DIR)*.o *.o $(TESTBIN_DIR)*.elf $(TESTBIN_DIR)* *.elf *.eps *.png *.pdf *.bak *_size.txt
rm -rf *.lst *.map $(EXTRA_CLEAN_FILES) $(SIZESTAT_FILE)
rm -rf $(BIN_DIR)*.o *.o $(TESTBIN_DIR)*.elf $(TESTBIN_DIR)* *.elf *.eps *.png *.pdf *.bak
rm -rf *.lst *.map $(EXTRA_CLEAN_FILES) $(STAT_DIR)$(SIZESTAT_FILE) $(STAT_DIR)*_size.txt
xclean: clean
rm -rf $(DEP_DIR)*.d
@ -201,11 +223,6 @@ docu:
doxygen
%.lst: %.elf
$(OBJDUMP) -h -S $< > $@
%.lst: %.o
$(OBJDUMP) -h -S $< > $@
# Rules for building the .text rom images

View File

@ -27,51 +27,7 @@
*/
#include <avr/io.h>
.macro push_ p1:req, p2:vararg
push \p1
.ifnb \p2
push_ \p2
.endif
.endm
.macro pop_ p1:req, p2:vararg
pop \p1
.ifnb \p2
pop_ \p2
.endif
.endm
.macro push_range from:req, to:req
push \from
.if \to-\from
push_range "(\from+1)",\to
.endif
.endm
.macro pop_range from:req, to:req
pop \to
.if \to-\from
pop_range \from,"(\to-1)"
.endif
.endm
.macro stack_alloc size:req, reg1=r30, reg2=r31
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
sbiw r30, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
.endm
.macro stack_free size:req, reg1=r30, reg2=r31
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
adiw r30, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
.endm
#include "avr-asm-macros.S"
/* +---+---+---------------------+
* | i | j | ......<256>........ |

View File

@ -14,7 +14,9 @@ TESTPORT = /dev/ttyUSB1
TESTPORTBAUDR = 9600
TESTLOG_DIR = testlog/
TESTPREFIX = nessie-
CC = avr-gcc
LIST_DIR = listings/
STAT_DIR = stats/
CC = avr-gcc
override CFLAGS = -MMD -MF$(DEP_DIR)$(patsubst %.c,%.d,$(patsubst $(TESTSRC_DIR)%,%,$<)) -I. -gdwarf-2 -pedantic -std=c99 -Wall -Wstrict-prototypes $(OPTIMIZE) -mmcu=$(MCU_TARGET) $(DEFS)

18
md5.c
View File

@ -132,32 +132,32 @@ void md5_nextBlock(md5_ctx_t *state, void* block){
state->counter++;
}
void md5_lastBlock(md5_ctx_t *state, void* block, uint16_t length){
void md5_lastBlock(md5_ctx_t *state, void* block, uint16_t length_b){
uint16_t l;
uint8_t b[64];
while (length >= 512){
while (length_b >= 512){
md5_nextBlock(state, block);
length -= 512;
length_b -= 512;
block = ((uint8_t*)block) + 512/8;
}
memset(b, 0, 64);
memcpy(b, block, length/8);
memcpy(b, block, length_b/8);
/* insert padding one */
l=length/8;
if(length%8){
l=length_b/8;
if(length_b%8){
uint8_t t;
t = ((uint8_t*)block)[l];
t |= (0x80>>(length%8));
t |= (0x80>>(length_b%8));
b[l]=t;
}else{
b[l]=0x80;
}
/* insert length value */
if(l+sizeof(uint64_t) > 512/8){
if(l+sizeof(uint64_t) >= 512/8){
md5_nextBlock(state, b);
state->counter--;
memset(b, 0, 64);
}
*((uint64_t*)&b[64-sizeof(uint64_t)]) = (state->counter * 512) + length;
*((uint64_t*)&b[64-sizeof(uint64_t)]) = (state->counter * 512) + length_b;
md5_nextBlock(state, b);
}

View File

@ -27,51 +27,7 @@
*/
#include <avr/io.h>
.macro push_ p1:req, p2:vararg
push \p1
.ifnb \p2
push_ \p2
.endif
.endm
.macro pop_ p1:req, p2:vararg
pop \p1
.ifnb \p2
pop_ \p2
.endif
.endm
.macro push_range from:req, to:req
push \from
.if \to-\from
push_range "(\from+1)",\to
.endif
.endm
.macro pop_range from:req, to:req
pop \to
.if \to-\from
pop_range \from,"(\to-1)"
.endif
.endm
.macro stack_alloc size:req, reg1=r30, reg2=r31
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
sbiw r30, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
.endm
.macro stack_free size:req, reg1=r30, reg2=r31
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
adiw r30, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
.endm
#include "avr-asm-macros.S"
/*
* void memxor(void* dest, const void* src, uint16_t n);

View File

@ -19,11 +19,12 @@
#ifndef NOEKEON_H_
#define NOEKEON_H_
/*
* author: Daniel Otte
* email: daniel.otte@rub.de
* license: GPLv3
*
/**
* \author Daniel Otte
* \email daniel.otte@rub.de
* \date 2008-04-11
* \license GPLv3
* \brief
*
*
*/
@ -32,8 +33,44 @@
typedef uint8_t noekeon_ctx_t[16];
/** \fn void noekeon_enc(void* buffer, void* key)
* \brief noekeon encrytion funtion
*
* This function encrypts a block (64 bit = 8 byte) with the noekeon encrytion
* algorithm. Due to the two modes of noekeon (direct mode and indirect mode)
* the second parameter either points directly to the key (direct mode) or to a
* context generated by the noekeon_init() function (indirect mode)
* \param buffer pointer to the 64 bit (8 byte) block to encrypt
* \param key pointer to either the key (128 bit = 16 byte; direct mode) or
* to the context (indirect mode)
*/
void noekeon_enc(void* buffer, void* key);
/** \fn void noekeon_enc(void* buffer, void* key)
* \brief noekeon encrytion funtion
*
* This function decrypts a block (64 bit = 8 byte) encrypted with the noekeon
* encrytion algorithm. Due to the two modes of noekeon (direct mode and
* indirect mode) the second parameter either points directly to the key
* (direct mode) or to a context generated by the noekeon_init() function
* (indirect mode)
* \param buffer pointer to the 64 bit (8 byte) block to decrypt
* \param key pointer to either the key (128 bit = 16 byte; direct mode) or
* to the context (indirect mode)
*/
void noekeon_dec(void* buffer, void* key);
/** \fn void noekeon_init(void* key, noekeon_ctx_t* ctx)
* \brief noekeon context generation function for indirect mode
*
* This function generates a context from the supplied key for using
* noekeon in indirect mode. For using noekeon in direct mode supply the key
* direct to the noekeon_enc() and noekeon_dec() functions
* \param key pointer to the key (128 bit = 16 byte)
* \param ctx pointer to the context to fill with key material
* to the context (indirect mode)
*/
void noekeon_init(void* key, noekeon_ctx_t* ctx);
#endif /*NOEKEON_H_*/

View File

@ -27,52 +27,9 @@
*/
#include <avr/io.h>
#include "avr-asm-macros.S"
.macro push_ p1:req, p2:vararg
push \p1
.ifnb \p2
push_ \p2
.endif
.endm
.macro pop_ p1:req, p2:vararg
pop \p1
.ifnb \p2
pop_ \p2
.endif
.endm
.macro push_range from:req, to:req
push \from
.if \to-\from
push_range "(\from+1)",\to
.endif
.endm
.macro pop_range from:req, to:req
pop \to
.if \to-\from
pop_range \from,"(\to-1)"
.endif
.endm
.macro stack_alloc size:req, reg1=r30, reg2=r31
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
sbiw r30, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
.endm
.macro stack_free size:req, reg1=r30, reg2=r31
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
adiw r30, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
.endm
push_r18_r27_func:
pop r31
pop r30
@ -108,10 +65,10 @@ noekeon_omac:
dec r17
brne 1b
sbiw r30, 48
mov r26, r22
mov r22, r18
mov r18, r24
mov r24, r30
movw r26, r22
movw r22, r18
movw r18, r24
movw r24, r30
cpi r16, 0xff
breq 2f
st Z, r16

View File

@ -27,64 +27,7 @@
*/
#include <avr/io.h>
/*******************************************************************************
* MACRO SECTION *
*******************************************************************************/
.macro push_ p1:req, p2:vararg
push \p1
.ifnb \p2
push_ \p2
.endif
.endm
.macro pop_ p1:req, p2:vararg
pop \p1
.ifnb \p2
pop_ \p2
.endif
.endm
.macro push_range from:req, to:req
push \from
.if \to-\from
push_range "(\from+1)",\to
.endif
.endm
.macro pop_range from:req, to:req
pop \to
.if \to-\from
pop_range \from,"(\to-1)"
.endif
.endm
.macro stack_alloc size:req, reg1=r30, reg2=r31
in r0, _SFR_IO_ADDR(SREG)
cli
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
sbiw \reg1, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
out _SFR_IO_ADDR(SREG), r0
.endm
.macro stack_free size:req, reg1=r30, reg2=r31
in r0, _SFR_IO_ADDR(SREG)
cli
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
adiw \reg1, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
out _SFR_IO_ADDR(SREG), r0
.endm
/*******************************************************************************
* END of MACRO SECTION *
*******************************************************************************/
#include "avr-asm-macros.S"
/*
static void serpent_lt(uint8_t *b){

View File

@ -17,7 +17,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* serpent-sboxes.c
* a non-bitsliced implementation of the serpent sboxes
* a bitsliced implementation of the serpent sboxes
* author: Daniel Otte
* email: daniel.otte@rub.de
* license: GPLv3

View File

@ -27,64 +27,8 @@
*/
#include <avr/io.h>
#include "avr-asm-macros.S"
/*******************************************************************************
* MACRO SECTION *
*******************************************************************************/
.macro push_ p1:req, p2:vararg
push \p1
.ifnb \p2
push_ \p2
.endif
.endm
.macro pop_ p1:req, p2:vararg
pop \p1
.ifnb \p2
pop_ \p2
.endif
.endm
.macro push_range from:req, to:req
push \from
.if \to-\from
push_range "(\from+1)",\to
.endif
.endm
.macro pop_range from:req, to:req
pop \to
.if \to-\from
pop_range \from,"(\to-1)"
.endif
.endm
.macro stack_alloc size:req, reg1=r30, reg2=r31
in r0, _SFR_IO_ADDR(SREG)
cli
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
sbiw \reg1, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
out _SFR_IO_ADDR(SREG), r0
.endm
.macro stack_free size:req, reg1=r30, reg2=r31
in r0, _SFR_IO_ADDR(SREG)
cli
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
adiw \reg1, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
out _SFR_IO_ADDR(SREG), r0
.endm
/*******************************************************************************
* END of MACRO SECTION *
*******************************************************************************/
serpent_sbox_fast:
.byte 0x33, 0x88, 0xFF, 0x11, 0xAA, 0x66, 0x55, 0xBB

View File

@ -27,64 +27,9 @@
*/
#include <avr/io.h>
#include "avr-asm-macros.S"
/*******************************************************************************
* MACRO SECTION *
*******************************************************************************/
.macro push_ p1:req, p2:vararg
push \p1
.ifnb \p2
push_ \p2
.endif
.endm
.macro pop_ p1:req, p2:vararg
pop \p1
.ifnb \p2
pop_ \p2
.endif
.endm
.macro push_range from:req, to:req
push \from
.if \to-\from
push_range "(\from+1)",\to
.endif
.endm
.macro pop_range from:req, to:req
pop \to
.if \to-\from
pop_range \from,"(\to-1)"
.endif
.endm
.macro stack_alloc size:req, reg1=r30, reg2=r31
in r0, _SFR_IO_ADDR(SREG)
cli
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
sbiw \reg1, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
out _SFR_IO_ADDR(SREG), r0
.endm
.macro stack_free size:req, reg1=r30, reg2=r31
in r0, _SFR_IO_ADDR(SREG)
cli
in \reg1, _SFR_IO_ADDR(SPL)
in \reg2, _SFR_IO_ADDR(SPH)
adiw \reg1, \size
out _SFR_IO_ADDR(SPH), \reg2
out _SFR_IO_ADDR(SPL), \reg1
out _SFR_IO_ADDR(SREG), r0
.endm
/*******************************************************************************
* END of MACRO SECTION *
*******************************************************************************/
serpent_sbox:
.byte 0x83, 0x1F, 0x6A, 0xB5, 0xDE, 0x24, 0x07, 0xC9
.byte 0xCF, 0x72, 0x09, 0xA5, 0xB1, 0x8E, 0xD6, 0x43

View File

@ -19,18 +19,37 @@
#ifndef SKIPJACK_H_
#define SKIPJACK_H_
#include <stdint.h>
/*****************************************************************************/
/**
* block is 64 bits (=8 bytes) in size, key is 80 bits (=10 bytes) in size.
/**
* \file skipjack.h
* \author Daniel Otte
* \date 2006-11-01
* \license GPLv3 or later
* \brief Implementation of the serpent sbox function.
*
*/
void skipjack_enc(void* block, void* key);
/*****************************************************************************/
/**
* block is 64 bits (=8 bytes) in size, key is 80 bits (=10 bytes) in size.
#include <stdint.h>
/** \fn void skipjack_enc(void* block, void* key)
* \brief skipjack encryption function
*
* This function encrypts a block of plaintext with the Skipjac encryption
* algorithm. The block is 64 bit (8 byte) long, the key is 80 bit (10 byte)
* long.
* \param block pointer to the 64 bit (8 byte) block to encrypt
* \param key pointer to the 80 bit (10 byte) key
*/
void skipjack_enc(void* block, void* key);
/** \fn void skipjack_dec(void* block, void* key)
* \brief skipjack decryption function
*
* This function decrypts a block of ciphertext encrypted with the Skipjac
* encryption algorithm.
* The block is 64 bit (8 byte) long, the key is 80 bit (10 byte) long.
* \param block pointer to the 64 bit (8 byte) block to decrypt
* \param key pointer to the 80 bit (10 byte) key
*/
void skipjack_dec(void* block, void* key);

View File

@ -26,7 +26,7 @@
#include "uart.h"
#include "debug.h"
#include "arcfour.h"
#include <arcfour.h>
#include "nessie_stream_test.h"
#include "cli.h"
#include "performance_test.h"

View File

@ -26,7 +26,7 @@
#include "uart.h"
#include "debug.h"
#include "cast5.h"
#include <cast5.h>
#include "nessie_bc_test.h"
#include "performance_test.h"
#include "cli.h"

View File

@ -26,7 +26,7 @@
#include "uart.h"
#include "debug.h"
#include "noekeon.h"
#include <noekeon.h>
#include "nessie_bc_test.h"
#include "cli.h"
#include "performance_test.h"

View File

@ -26,7 +26,7 @@
#include "uart.h"
#include "debug.h"
#include "present.h"
#include <present.h>
#include "nessie_bc_test.h"
#include "cli.h"
#include "performance_test.h"

View File

@ -30,13 +30,15 @@
#include <string.h>
#include <stdint.h>
int getnextwordn(char *s, int n){ /* words are seperated by spaces */
int getnextwordn(char *s, int n){ /* words are seperated by spaces, lf or cr */
char c = ' ';
while ((c=uart_getc()) == ' ')
;
do{
c=uart_getc();
}while(c==' ' || c=='\r' || c=='\n');
*s++ = c;
while (n && (*s++=uart_getc())!=' ')
;
do{
*s++ = c = uart_getc();
}while(c!=' ' && c!='\r' && c!='\n' && --n);
*(s-1) = '\0';
return n;
}

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