* \author Daniel Otte
* \date 2008-12-30
* \license GPLv3 or later
- *
+ * \ingroup AES
*/
#ifndef AES128_DEC_H_
#include "aes.h"
#include "aes_dec.h"
+/** \fn void aes128_dec(void* buffer, aes128_ctx_t* ctx)
+ * \brief decrypt with 128 bit key.
+ *
+ * This function decrypts one block with the AES algorithm under control of
+ * a keyschedule produced from a 128 bit key.
+ * \param buffer pointer to the block to decrypt
+ * \param ctx pointer to the key schedule
+ */
void aes128_dec(void* buffer, aes128_ctx_t* ctx);
* \author Daniel Otte
* \date 2008-12-30
* \license GPLv3 or later
- *
+ * \ingroup AES
*/
#ifndef AES128_ENC_H_
#include "aes.h"
#include "aes_enc.h"
+
+/** \fn void aes128_enc(void* buffer, aes128_ctx_t* ctx)
+ * \brief encrypt with 128 bit key.
+ *
+ * This function encrypts one block with the AES algorithm under control of
+ * a keyschedule produced from a 128 bit key.
+ * \param buffer pointer to the block to encrypt
+ * \param ctx pointer to the key schedule
+ */
void aes128_enc(void* buffer, aes128_ctx_t* ctx);
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
- * \file aes128_dec.h
+ * \file aes192_dec.h
* \email daniel.otte@rub.de
* \author Daniel Otte
* \date 2008-12-31
* \license GPLv3 or later
- *
+ * \ingroup AES
*/
#ifndef AES192_DEC_H_
#include "aes.h"
#include "aes_dec.h"
+/** \fn void aes192_dec(void* buffer, aes192_ctx_t* ctx)
+ * \brief decrypt with 192 bit key.
+ *
+ * This function decrypts one block with the AES algorithm under control of
+ * a keyschedule produced from a 192 bit key.
+ * \param buffer pointer to the block to decrypt
+ * \param ctx pointer to the key schedule
+ */
void aes192_dec(void* buffer, aes192_ctx_t* ctx);
* \author Daniel Otte
* \date 2008-12-31
* \license GPLv3 or later
- *
+ * \ingroup AES
*/
#ifndef AES192_ENC_H_
#include "aes.h"
#include "aes_enc.h"
+
+/** \fn void aes192_enc(void* buffer, aes192_ctx_t* ctx)
+ * \brief encrypt with 192 bit key.
+ *
+ * This function encrypts one block with the AES algorithm under control of
+ * a keyschedule produced from a 192 bit key.
+ * \param buffer pointer to the block to encrypt
+ * \param ctx pointer to the key schedule
+ */
void aes192_enc(void* buffer, aes192_ctx_t* ctx);
* \author Daniel Otte
* \date 2008-12-31
* \license GPLv3 or later
- *
+ * \ingroup AES
*/
#ifndef AES256_DEC_H_
#include "aes.h"
#include "aes_dec.h"
+/** \fn void aes256_dec(void* buffer, aes256_ctx_t* ctx)
+ * \brief decrypt with 256 bit key.
+ *
+ * This function decrypts one block with the AES algorithm under control of
+ * a keyschedule produced from a 256 bit key.
+ * \param buffer pointer to the block to decrypt
+ * \param ctx pointer to the key schedule
+ */
void aes256_dec(void* buffer, aes256_ctx_t* ctx);
* \author Daniel Otte
* \date 2008-12-31
* \license GPLv3 or later
- *
+ * \ingroup AES
*/
#ifndef AES256_ENC_H_
#include "aes.h"
#include "aes_enc.h"
+
+/** \fn void aes256_enc(void* buffer, aes256_ctx_t* ctx)
+ * \brief encrypt with 256 bit key.
+ *
+ * This function encrypts one block with the AES algorithm under control of
+ * a keyschedule produced from a 256 bit key.
+ * \param buffer pointer to the block to encrypt
+ * \param ctx pointer to the key schedule
+ */
void aes256_enc(void* buffer, aes256_ctx_t* ctx);
* \author Daniel Otte
* \date 2008-12-30
* \license GPLv3 or later
- *
+ * \ingroup AES
*/
#define AES_KEYSCHEDULE_H_
#include "aes.h"
-
+/** \fn void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx)
+ * \brief initialize the keyschedule
+ *
+ * This function computes the keyschedule from a given key with a given length
+ * and stores it in the context variable
+ * \param key pointer to the key material
+ * \param keysize_b length of the key in bits (valid are 128, 192 and 256)
+ * \param ctx pointer to the context where the keyschedule should be stored
+ */
void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx);
+/** \fn void aes128_init(const void* key, aes128_ctx_t* ctx)
+ * \brief initialize the keyschedule for 128 bit key
+ *
+ * This function computes the keyschedule from a given 128 bit key
+ * and stores it in the context variable
+ * \param key pointer to the key material
+ * \param ctx pointer to the context where the keyschedule should be stored
+ */
void aes128_init(const void* key, aes128_ctx_t* ctx);
+
+/** \fn void aes192_init(const void* key, aes192_ctx_t* ctx)
+ * \brief initialize the keyschedule for 192 bit key
+ *
+ * This function computes the keyschedule from a given 192 bit key
+ * and stores it in the context variable
+ * \param key pointer to the key material
+ * \param ctx pointer to the context where the keyschedule should be stored
+ */
void aes192_init(const void* key, aes192_ctx_t* ctx);
+
+/** \fn void aes256_init(const void* key, aes256_ctx_t* ctx)
+ * \brief initialize the keyschedule for 256 bit key
+ *
+ * This function computes the keyschedule from a given 256 bit key
+ * and stores it in the context variable
+ * \param key pointer to the key material
+ * \param ctx pointer to the context where the keyschedule should be stored
+ */
void aes256_init(const void* key, aes256_ctx_t* ctx);
#endif /* AES_KEYSCHEDULE_H_ */
+
} arcfour_ctx_t;
-/** \fn void arcfour_init(arcfour_ctx_t *ctx, void *key, uint8_t length_B)
+/** \fn void arcfour_init(const void *key, uint8_t length_B, arcfour_ctx_t *ctx)
* \brief setup a context with a key
*
* This function sets up a ::arcfour_ctx_t context using
} cast5_ctx_t;
-/** \fn void cast5_init(void* key, uint8_t keylength_b, cast5_ctx_t* s);
+/** \fn void cast5_init(const void* key, uint16_t keylength_b, cast5_ctx_t* s);
* \brief generate keyschedule/contex for CAST-5
*
* This function generates the keyschedule from the supplied key for the
*/
void cast5_init(const void* key, uint16_t keylength_b, cast5_ctx_t* s);
-/** \fn void cast5_enc(void* block, const cast5_ctx_t *s);
+/** \fn void cast5_enc(void* block, const cast5_ctx_t* s);
* \brief encrypt a block with the CAST-5 algorithm
*
* This function encrypts a block of 64 bits (8 bytes) with the CAST-5 algorithm.
* \param block pointer to the block which gets encrypted
* \param s pointer to the keyschedule/context
*/
-void cast5_enc(void* block, const cast5_ctx_t *s);
+void cast5_enc(void* block, const cast5_ctx_t* s);
-/** \fn void cast5_dec(void* block, const cast5_ctx_t *s);
+/** \fn void cast5_dec(void* block, const cast5_ctx_t* s);
* \brief decrypt a block with the CAST-5 algorithm
*
* This function decrypts a block of 64 bits (8 bytes) with the CAST-5 algorithm.
* \param block pointer to the block which gets decrypted
* \param s pointer to the keyschedule/context
*/
-void cast5_dec(void* block, const cast5_ctx_t *s);
+void cast5_dec(void* block, const cast5_ctx_t* s);
#define HFDESC_TYPE_HASHFUNCTION 0x02
typedef struct {
+ /** typefield, always 2 for hash functions */
uint8_t type; /* 2 == hashfunction */
+ /** flags, currently unused should be set to zero */
uint8_t flags;
+ /** name, flash pointer to the name string */
PGM_P name;
+ /** ctxsize_B, size of the hash context in bytes */
uint16_t ctxsize_B;
+ /** blocksize_b, size of an input block in bits */
uint16_t blocksize_b;
+ /** hashsize_b, size of the output hash value in bits */
uint16_t hashsize_b;
-
+ /** init, function pointer to the algorithms init function */
hf_init_fpt init;
+ /** nextBlock, function pointer to the algorithms nextBlock function */
hf_nextBlock_fpt nextBlock;
+ /** lastBlock, function pointer to the algorithms lastBlock function */
hf_lastBlock_fpt lastBlock;
+ /** ctx2hash, function pointer to the algorithms ctx2hash function */
hf_ctx2hash_fpt ctx2hash;
+ /** free, function pointer to the algorithms free function or NULL if
+ * there is no such function */
hf_free_fpt free;
+ /** mem, function pointer to a function which hashes a message in RAM
+ * completely or NULL if there is no such function */
hf_mem_fpt mem;
} hfdesc_t; /* blockcipher descriptor type */
puts("\nPort: "+ARGV[0]+ "@"+ARGV[1]+" "+ARGV[2]+"N"+ARGV[3]+"\n");
$linewidth = 16
$sp = SerialPort.new(ARGV[0], ARGV[1].to_i, ARGV[2].to_i, ARGV[3].to_i, SerialPort::NONE);
-$sp.read_timeout=1*60*1000; # 5 minutes
+$sp.read_timeout=1000; # 1 secound
$extended_wait=100;
$sp.write(command);
begin
l = file.gets().strip
end until /[*]{10,}.*/.match(l)
- puts("DBG 0.0: "+l)
begin
l = file.gets().strip
end until /[*]{10,}.*/.match(l)
- puts("DBG 0.1: "+l)
begin
l = file.gets().strip
end until /[=]{5,}.*/.match(l)
- puts("DBG 0.2: "+l)
begin
l = file.gets().strip
end until /[=]{5,}.*/.match(l)
- puts("DBG 0.3: "+l)
end
def get_next_assign(file, i)
a = get_next_assign(file1, 0)
b = get_next_assign(file2, 1)
return if(a==nil or b==nil)
- puts("") if pos%$linewidth==0 and pos!=0
- putc((a==b)?'*':'!')
-# puts("a == nil") if a==nil
-# puts("b == nil") if b==nil
-
+ if not $quiet
+ puts("") if pos%$linewidth==0 and pos!=0
+ putc((a==b)?'*':'!')
+ pos +=1
+ end
if(a!=b and a!=nil and b!=nil)
$error = 1
puts("a key: "+a[0]+" value: "+a[1])
puts("b key: "+b[0]+" value: "+b[1])
end
- pos +=1
end until a==nil or b==nil
end
$linewidth=64
$last_assign=[nil, nil]
-if ARGV.size!=2
+if ARGV.size<2 or ARGV.size>3
STDERR.print <<EOF
- Usage: ruby #{$0} file1 file2
+ Usage: ruby #{$0} [-q|-v] file1 file2
EOF
exit(1)
end
-puts("compare("+ARGV[1]+", "+ARGV[0]+")")
-compare(ARGV[1], ARGV[0])
+$quiet = false
+if ARGV.size==3
+ f1 = ARGV[1]
+ f2 = ARGV[2]
+ if ARGV[0]=="-q"
+ $quiet=true
+ end
+else
+ f1 = ARGV[1]
+ f2 = ARGV[2]
+end
+
+puts("compare("+f1+", "+f2+")")
+compare(f1, f2)
puts($error==0?"[ok]":"[failed]")
exit($error)
--- /dev/null
+# Makefile for MUGI
+ALGO_NAME := MUGI_C
+
+# comment out the following line for removement of MUGI_C from the build process
+STREAM_CIPHERS += $(ALGO_NAME)
+
+$(ALGO_NAME)_OBJ := mugi.o gf256mul.o aes_sbox.o
+$(ALGO_NAME)_TEST_BIN := main-mugi-test.o debug.o uart.o hexdigit_tab.o serial-tools.o \
+ nessie_stream_test.o nessie_common.o cli.o string-extras.o \
+ performance_test.o
+$(ALGO_NAME)_NESSIE_TEST := "nessie"
+$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
+
--- /dev/null
+/* mugi.c */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2008 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/>.
+*/
+/**
+ * \file mugi.c
+ * \author Daniel Otte
+ * \email daniel.otte@rub.de
+ * \date 2009-02-15
+ * \brief implementation of the MUGI key stream generator
+ * \license GPLv3 or later
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <avr/pgmspace.h>
+#include "aes_sbox.h"
+#include "mugi.h"
+#include "gf256mul.h"
+
+/*
+#include "test_src/cli.h" / * only for debugging * /
+
+void dump_mugi_ctx(mugi_ctx_t* ctx){
+ uint8_t i;
+ cli_putstr_P(PSTR("\r\n== MUGI CTX DUMP==\r\n a:"));
+ cli_hexdump(&(ctx->a[0]), 8);
+ cli_putc(' ');
+ cli_hexdump(&(ctx->a[1]), 8);
+ cli_putc(' ');
+ cli_hexdump(&(ctx->a[2]), 8);
+ cli_putstr_P(PSTR("\r\n b: "));
+ for(i=0; i<4; ++i){
+ cli_putstr_P(PSTR("\r\n "));
+ cli_hexdump(&(ctx->b[i*4+0]), 8);
+ cli_putc(' ');
+ cli_hexdump(&(ctx->b[i*4+1]), 8);
+ cli_putc(' ');
+ cli_hexdump(&(ctx->b[i*4+2]), 8);
+ cli_putc(' ');
+ cli_hexdump(&(ctx->b[i*4+3]), 8);
+ }
+}
+*/
+
+#define C0 0x08c9bcf367e6096all
+#define C1 0x3ba7ca8485ae67bbll
+#define C2 0x2bf894fe72f36e3cll
+
+#define GF256MUL_2(a) (gf256mul(2, (a), 0x1b))
+
+uint64_t changeendian64(uint64_t a){
+ uint8_t r[8];
+ r[0] = ((uint8_t*)&a)[7];
+ r[1] = ((uint8_t*)&a)[6];
+ r[2] = ((uint8_t*)&a)[5];
+ r[3] = ((uint8_t*)&a)[4];
+ r[4] = ((uint8_t*)&a)[3];
+ r[5] = ((uint8_t*)&a)[2];
+ r[6] = ((uint8_t*)&a)[1];
+ r[7] = ((uint8_t*)&a)[0];
+ return *((uint64_t*)r);
+}
+
+static
+uint64_t rotl64(uint64_t a, uint8_t i){
+ uint64_t r;
+ r=changeendian64(a);
+ r=(r<<i | r>>(64-i));
+ r=changeendian64(r);
+ return r;
+}
+
+static
+uint64_t rotr64(uint64_t a, uint8_t i){
+ uint64_t r;
+ r=changeendian64(a);
+ r=(r>>i | r<<(64-i));
+ r=changeendian64(r);
+ return r;
+}
+
+
+#define T(x) (((uint8_t*)&t)[(x)])
+#define D(y) (((uint8_t*)dest)[(y)])
+static void mugi_f(uint64_t* dest, uint64_t* a, uint64_t* b){
+ uint64_t t;
+ uint8_t i,x;
+ t = (*a);
+ if(b)
+ t ^= (*b);
+ for(i=0; i<8; ++i)
+ T(i) = pgm_read_byte(aes_sbox+T(i));
+
+ x = T(0) ^ T(1) ^ T(2) ^ T(3);
+ D(4) =
+ GF256MUL_2(T(0)^T(1))
+ ^ T(0)
+ ^ x;
+ D(5) =
+ GF256MUL_2(T(1)^T(2))
+ ^ T(1)
+ ^ x;
+ D(2) =
+ GF256MUL_2(T(2)^T(3))
+ ^ T(2)
+ ^ x;
+ D(3) =
+ GF256MUL_2(T(3)^T(0))
+ ^ T(3)
+ ^ x;
+ x = T(4) ^ T(5) ^ T(6) ^ T(7);
+ D(0) =
+ GF256MUL_2(T(4)^T(5))
+ ^ T(4)
+ ^ x;
+ D(1) =
+ GF256MUL_2(T(5)^T(6))
+ ^ T(5)
+ ^ x;
+ D(6) =
+ GF256MUL_2(T(6)^T(7))
+ ^ T(6)
+ ^ x;
+ D(7) =
+ GF256MUL_2(T(7)^T(4))
+ ^ T(7)
+ ^ x;
+}
+
+static
+void mugi_rho(mugi_ctx_t* ctx){
+ uint64_t t,bx;
+ t = ctx->a[1];
+ ctx->a[1] = ctx->a[2];
+ ctx->a[2] = ctx->a[0];
+ ctx->a[0] = t;
+ mugi_f(&t, &(ctx->a[0]), &(ctx->b[4]));
+ ctx->a[1] ^= t ^ C1;
+ bx = rotl64(ctx->b[10], 17);
+ mugi_f(&t, &(ctx->a[0]), &bx);
+ ctx->a[2] ^= t ^ C2;
+}
+
+static
+void mugi_rho_init(uint64_t* a){
+ uint64_t t;
+ t = a[1];
+ a[1] = a[2];
+ a[2] = a[0];
+ a[0] = t;
+ mugi_f(&t, &(a[0]), NULL);
+ a[1] ^= t ^ C1;
+ mugi_f(&t, &(a[0]), NULL);
+ a[2] ^= t ^ C2;
+}
+
+static
+void mugi_lambda(uint64_t* b, uint64_t *a){
+ uint8_t i;
+ uint64_t t;
+ t=b[15];
+ for(i=15; i!=0; --i){
+ b[i]=b[i-1];
+ }
+ b[0] = t ^ *a;
+ b[4] ^= b[8];
+ b[10] ^= rotl64(b[14], 32);
+}
+
+void mugi_init(const void* key, const void* iv, mugi_ctx_t* ctx){
+ uint8_t i;
+ uint64_t a0;
+ memcpy(ctx->a, key, 128/8);
+ ctx->a[2] = rotl64(ctx->a[0], 7) ^ rotr64(ctx->a[1], 7) ^ C0;
+ for(i=0; i<16;i++){
+ mugi_rho_init(ctx->a);
+ ctx->b[15-i] = ctx->a[0];
+ }
+ ctx->a[0] ^= ((uint64_t*)iv)[0];
+ ctx->a[1] ^= ((uint64_t*)iv)[1];
+ ctx->a[2] ^= rotl64(((uint64_t*)iv)[0], 7) ^ rotr64(((uint64_t*)iv)[1], 7) ^ C0;
+ for(i=0; i<16;i++){
+ mugi_rho_init(ctx->a);
+ }
+ for(i=0; i<15;i++){
+ a0 = ctx->a[0];
+ mugi_rho(ctx);
+ mugi_lambda(ctx->b, &a0);
+ }
+ a0=0x00;
+}
+
+uint64_t mugi_gen(mugi_ctx_t* ctx){
+ uint64_t r;
+ r=ctx->a[0];
+ mugi_rho(ctx);
+ mugi_lambda(ctx->b, &r);
+ r=ctx->a[2];
+ return r;
+}
--- /dev/null
+/* mugi.h */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2008 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/>.
+*/
+/**
+ * \file mugi.h
+ * \author Daniel Otte
+ * \date 2009-02-15
+ * \brief implementation of the MUGI key stream generator
+ * \license GPLv3 or later
+ */
+
+#ifndef MUGI_H_
+#define MUGI_H_
+
+#include <stdint.h>
+
+typedef struct{
+ uint64_t a[3];
+ uint64_t b[16];
+}mugi_ctx_t; /* 152 bytes in total */
+
+void mugi_init(const void* key, const void* iv, mugi_ctx_t* ctx);
+uint64_t mugi_gen(mugi_ctx_t* ctx);
+
+
+#endif /* MUGI_H_ */
#define NOEKEON_H_
/**
+ * \file noekeon.h
* \author Daniel Otte
* \email daniel.otte@rub.de
* \date 2008-04-11
- * \license GPLv3
- * \brief
- *
- *
+ * \license GPLv3 or later
+ * \brief Implementation of the Noekeon block cipher
+ * \ingroup Noekeon
+ * This is an implementation of the Noekeon block cipher.
+ * For more details on Noekeon see http://gro.noekeon.org/
*/
#include <stdint.h>
+/** \typedef noekeon_ctx_t
+ * \brief holds key data for indirect mode
+ *
+ * A variable of this type may hold the key data for the indirect mode.
+ * For direct mode simply pass the key directly to the encryption or
+ * decryption function.
+ */
typedef uint8_t noekeon_ctx_t[16];
-/** \fn void noekeon_enc(void* buffer, void* key)
+/** \fn void noekeon_enc(void* buffer, const 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)
+ * 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, const void* key);
-/** \fn void noekeon_enc(void* buffer, void* key)
+/** \fn void noekeon_dec(void* buffer, const 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)
+ * (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, const void* key);
-/** \fn void noekeon_init(void* key, noekeon_ctx_t* ctx)
+/** \fn void noekeon_init(const 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
+ * 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)
/******************************************************************************/
-/** \fn void seed_init(void * key, seed_ctx_t * ctx)
+/** \fn void seed_init(const void * key, seed_ctx_t * ctx)
* \brief initializes context for SEED operation
*
* This function copys the key material into a context variable.
*/
void seed_init(const void * key, seed_ctx_t * ctx);
-/** \fn void seed_enc(void * buffer, seed_ctx_t * ctx)
+/** \fn void seed_enc(void * buffer,const seed_ctx_t * ctx)
* \brief encrypt a block with SEED
*
* This function encrypts a block of 64 bits (8 bytes) with the SEED algorithm.
void seed_enc(void * buffer, const seed_ctx_t * ctx);
-/** \fn void seed_dec(void * buffer, seed_ctx_t * ctx)
+/** \fn void seed_dec(void * buffer, const seed_ctx_t * ctx)
* \brief decrypt a block with SEED
*
* This function decrypts a block of 64 bits (8 bytes) with the SEED algorithm.
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
- * \file sha1.c
+ * \file sha1.h
* \author Daniel Otte
+ * \email daniel.otte@rub.de
* \date 2006-10-08
- * \par License:
- * GPL
- * \brief SHA-1 declaration.
+ * \license GPLv3 or later
+ * \brief SHA-1 declaration.
+ * \ingroup SHA-1
*
*/
#define SHA1_H_
#include <stdint.h>
+/** \def SHA1_HASH_BITS
+ * definees the size of a SHA-1 hash in bits
+ */
+
+/** \def SHA1_HASH_BYTES
+ * definees the size of a SHA-1 hash in bytes
+ */
+/** \def SHA1_BLOCK_BITS
+ * definees the size of a SHA-1 input block in bits
+ */
+/** \def SHA1_BLOCK_BYTES
+ * definees the size of a SHA-1 input block in bytes
+ */
#define SHA1_HASH_BITS 160
#define SHA1_HASH_BYTES (SHA1_HASH_BITS/8)
#define SHA1_BLOCK_BITS 512
#define SHA1_BLOCK_BYTES (SHA1_BLOCK_BITS/8)
-/**
+/** \typedef sha1_ctx_t
* \brief SHA-1 context type
*
+ * A vatiable of this type may hold the state of a SHA-1 hashing process
*/
typedef struct {
uint32_t h[5];
uint64_t length;
} sha1_ctx_t;
+/** \typedef sha1_hash_t
+ * \brief hash value type
+ * A variable of this type may hold a SHA-1 hash value
+ */
typedef uint8_t sha1_hash_t[SHA1_HASH_BITS/8];
+/** \fn sha1_init(sha1_ctx_t *state)
+ * \brief initializes a SHA-1 context
+ * This function sets a ::sha1_ctx_t variable to the initialization vector
+ * for SHA-1 hashing.
+ * \param state pointer to the SHA-1 context variable
+ */
void sha1_init(sha1_ctx_t *state);
+/** \fn sha1_nextBlock(sha1_ctx_t *state, void* block)
+ * \brief process one input block
+ * This function processes one input block and updates the hash context
+ * accordingly
+ * \param state pointer to the state variable to update
+ * \param block pointer to the message block to process
+ */
void sha1_nextBlock (sha1_ctx_t *state, void* block);
+
+/** \fn sha1_lastBlock(sha1_ctx_t *state, void* block, uint16_t length_b)
+ * \brief processes the given block and finalizes the context
+ * This function processes the last block in a SHA-1 hashing process.
+ * The block should have a maximum length of a single input block.
+ * \param state pointer to the state variable to update and finalize
+ * \param block pointer to themessage block to process
+ * \param length_b length of the message block in bits
+ */
void sha1_lastBlock (sha1_ctx_t *state, void* block, uint16_t length_b);
+/** \fn sha1_ctx2hash(sha1_hash_t *dest, sha1_ctx_t *state)
+ * \brief convert a state variable into an actual hash value
+ * Writes the hash value corresponding to the state to the memory pointed by dest.
+ * \param dest pointer to the hash value destination
+ * \param state pointer to the hash context
+ */
void sha1_ctx2hash (sha1_hash_t *dest, sha1_ctx_t *state);
-void sha1 (sha1_hash_t *dest, void* msg, uint32_t length_b);
+
+/** \fn sha1(sha1_hash_t *dest, void* msg, uint32_t length_b)
+ * \brief hashing a message which in located entirely in RAM
+ * This function automatically hashes a message which is entirely in RAM with
+ * the SHA-1 hashing algorithm.
+ * \param dest pointer to the hash value destination
+ * \param msg pointer to the message which should be hashed
+ * \param length_b length of the message in bits
+ */
+void sha1(sha1_hash_t *dest, void* msg, uint32_t length_b);
-/* string_extras.h */
+/* string-extras.h */
/*
This file is part of the AVR-Crypto-Lib.
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/**
- * \file string_extras.h
+ * \file string-extras.h
* \author Daniel Otte
* \date 2006-05-16
* \license GPLv3 or later
*
*/
+/** \fn stridentcnt_P(char* a, PGM_P b)
+ * \brief counts the number of identic chars
+ *
+ * This function compares the supplyed strings and returns the index of the
+ * first char where the strings differ.
+ * \param a pointer to string in RAM
+ * \param b pointer to string in Flash
+ * \return index of the first char where \c a and \c b differ
+ */
uint16_t stridentcnt_P(char* a, PGM_P b);
+
+/** \fn firstword_length(char* s)
+ * \brief compute the length of the first word in supllyed string
+ *
+ * This function searches for the first whitespace in the string and returns the
+ * number of chars before the first whitespace.
+ * \param s string
+ * \return number of chars in first word
+ */
uint16_t firstword_length(char* s);
-char* strstrip(char*);
+
+/** \fn strstrip(char* str)
+ * \brief removes whitespace at the beginning and the end of a string
+ *
+ * This function removes whitespaces at the end of a string.
+ * \param str sting
+ * \return pointer to the first non-whitespace char in string
+ */
+char* strstrip(char* str);
--- /dev/null
+/* main-mugi-test.c */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2008 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/>.
+*/
+/*
+ * MUGI test-suit
+ *
+*/
+
+#include "config.h"
+#include "serial-tools.h"
+#include "uart.h"
+#include "debug.h"
+
+#include "mugi.h"
+#include "nessie_stream_test.h"
+#include "cli.h"
+#include "performance_test.h"
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+char* algo_name = "MUGI";
+
+/*****************************************************************************
+ * additional validation-functions *
+ *****************************************************************************/
+
+void testrun_performance_mugi(void){
+ uint64_t t;
+ char str[16];
+ uint8_t key[16];
+ uint8_t iv[16];
+ mugi_ctx_t ctx;
+
+ calibrateTimer();
+ print_overhead();
+
+ memset(key, 0, 16);
+ memset(iv, 0, 16);
+
+ startTimer(1);
+ mugi_init(key, iv, &ctx);
+ t = stopTimer();
+ cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
+ ultoa((unsigned long)t, str, 10);
+ cli_putstr(str);
+
+ startTimer(1);
+ mugi_gen(&ctx);
+ t = stopTimer();
+ cli_putstr_P(PSTR("\r\n\tencrypt time: "));
+ ultoa((unsigned long)t, str, 10);
+ cli_putstr(str);
+
+ cli_putstr_P(PSTR("\r\n"));
+}
+
+
+void testrun_mugi(void){
+ uint8_t key[]={ 0x00, 0x01, 0x02, 0x03,
+ 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0a, 0x0b,
+ 0x0c, 0x0d, 0x0e, 0x0f };
+ uint8_t iv[]= { 0xf0, 0xe0, 0xd0, 0xc0,
+ 0xb0, 0xa0, 0x90, 0x80,
+ 0x70, 0x60, 0x50, 0x40,
+ 0x30, 0x20, 0x10, 0x00 };
+ mugi_ctx_t ctx;
+ uint64_t output;
+ uint8_t i;
+ mugi_init(key, iv, &ctx);
+ cli_putstr_P(PSTR("\r\nkey = "));
+ cli_hexdump2(key, 16);
+ cli_putstr_P(PSTR("\r\niv = "));
+ cli_hexdump2(iv, 16);
+ for(i=0; i<8; ++i){
+ output = mugi_gen(&ctx);
+ cli_putstr_P(PSTR("\r\nMUGI output: "));
+ cli_hexdump(&output, 8);
+ }
+
+ memset(key, 0, 16);
+ memset(iv, 0, 16);
+ mugi_init(key, iv, &ctx);
+ cli_putstr_P(PSTR("\r\nkey = "));
+ cli_hexdump2(key, 16);
+ cli_putstr_P(PSTR("\r\niv = "));
+ cli_hexdump2(iv, 16);
+ for(i=0; i<8; ++i){
+ output = mugi_gen(&ctx);
+ cli_putstr_P(PSTR("\r\nMUGI output: "));
+ cli_hexdump(&output, 8);
+ }
+}
+
+/*****************************************************************************
+ * main *
+ *****************************************************************************/
+
+const char nessie_str[] PROGMEM = "nessie";
+const char test_str[] PROGMEM = "test";
+const char performance_str[] PROGMEM = "performance";
+const char echo_str[] PROGMEM = "echo";
+
+cmdlist_entry_t cmdlist[] PROGMEM = {
+// { nessie_str, NULL, testrun_nessie_arcfour },
+ { test_str, NULL, testrun_mugi},
+ { performance_str, NULL, testrun_performance_mugi},
+ { echo_str, (void*)1, (void_fpt)echo_ctrl},
+ { NULL, NULL, NULL}
+};
+
+int main (void){
+ DEBUG_INIT();
+ uart_putstr("\r\n");
+ cli_rx = uart_getc;
+ cli_tx = uart_putc;
+ for(;;){
+ uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
+ uart_putstr(algo_name);
+ uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
+ cmd_interface(cmdlist);
+ }
+}
+