fixing some warnings (AES); simplifyning AES headers (now simply include "aes.h"); some renaming in the debug module
This commit is contained in:
parent
ca71e48e8e
commit
aa060d30f8
37
aes/aes.h
37
aes/aes.h
|
@ -19,38 +19,25 @@
|
||||||
/**
|
/**
|
||||||
* \file aes.h
|
* \file aes.h
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-30
|
* \date 2008-12-30
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef AES_H_
|
#ifndef AES_H_
|
||||||
#define AES_H_
|
#define AES_H_
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
typedef struct{
|
#include "aes_types.h"
|
||||||
uint8_t ks[16];
|
#include "aes128_enc.h"
|
||||||
} aes_roundkey_t;
|
#include "aes192_enc.h"
|
||||||
|
#include "aes256_enc.h"
|
||||||
typedef struct{
|
#include "aes128_dec.h"
|
||||||
aes_roundkey_t key[10+1];
|
#include "aes192_dec.h"
|
||||||
} aes128_ctx_t;
|
#include "aes256_dec.h"
|
||||||
|
#include "aes_enc.h"
|
||||||
typedef struct{
|
#include "aes_dec.h"
|
||||||
aes_roundkey_t key[12+1];
|
#include "aes_keyschedule.h"
|
||||||
} aes192_ctx_t;
|
|
||||||
|
|
||||||
typedef struct{
|
|
||||||
aes_roundkey_t key[14+1];
|
|
||||||
} aes256_ctx_t;
|
|
||||||
|
|
||||||
typedef struct{
|
|
||||||
aes_roundkey_t key[1]; /* just to avoid the warning */
|
|
||||||
} aes_genctx_t;
|
|
||||||
|
|
||||||
typedef struct{
|
|
||||||
uint8_t s[16];
|
|
||||||
} aes_cipher_state_t;
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
/**
|
/**
|
||||||
* \file aes128_dec.h
|
* \file aes128_dec.h
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-30
|
* \date 2008-12-30
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
* \ingroup AES
|
* \ingroup AES
|
||||||
|
@ -28,16 +28,16 @@
|
||||||
#ifndef AES128_DEC_H_
|
#ifndef AES128_DEC_H_
|
||||||
#define AES128_DEC_H_
|
#define AES128_DEC_H_
|
||||||
|
|
||||||
#include "aes.h"
|
#include "aes_types.h"
|
||||||
#include "aes_dec.h"
|
#include "aes_dec.h"
|
||||||
|
|
||||||
/** \fn void aes128_dec(void* buffer, aes128_ctx_t* ctx)
|
/**
|
||||||
* \brief decrypt with 128 bit key.
|
* \brief decrypt with 128 bit key.
|
||||||
*
|
*
|
||||||
* This function decrypts one block with the AES algorithm under control of
|
* This function decrypts one block with the AES algorithm under control of
|
||||||
* a keyschedule produced from a 128 bit key.
|
* a keyschedule produced from a 128 bit key.
|
||||||
* \param buffer pointer to the block to decrypt
|
* \param buffer pointer to the block to decrypt
|
||||||
* \param ctx pointer to the key schedule
|
* \param ctx pointer to the key schedule
|
||||||
*/
|
*/
|
||||||
void aes128_dec(void* buffer, aes128_ctx_t* ctx);
|
void aes128_dec(void* buffer, aes128_ctx_t* ctx);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
/**
|
/**
|
||||||
* \file aes128_enc.h
|
* \file aes128_enc.h
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-30
|
* \date 2008-12-30
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
* \ingroup AES
|
* \ingroup AES
|
||||||
|
@ -28,17 +28,17 @@
|
||||||
#ifndef AES128_ENC_H_
|
#ifndef AES128_ENC_H_
|
||||||
#define AES128_ENC_H_
|
#define AES128_ENC_H_
|
||||||
|
|
||||||
#include "aes.h"
|
#include "aes_types.h"
|
||||||
#include "aes_enc.h"
|
#include "aes_enc.h"
|
||||||
|
|
||||||
|
|
||||||
/** \fn void aes128_enc(void* buffer, aes128_ctx_t* ctx)
|
/**
|
||||||
* \brief encrypt with 128 bit key.
|
* \brief encrypt with 128 bit key.
|
||||||
*
|
*
|
||||||
* This function encrypts one block with the AES algorithm under control of
|
* This function encrypts one block with the AES algorithm under control of
|
||||||
* a keyschedule produced from a 128 bit key.
|
* a keyschedule produced from a 128 bit key.
|
||||||
* \param buffer pointer to the block to encrypt
|
* \param buffer pointer to the block to encrypt
|
||||||
* \param ctx pointer to the key schedule
|
* \param ctx pointer to the key schedule
|
||||||
*/
|
*/
|
||||||
void aes128_enc(void* buffer, aes128_ctx_t* ctx);
|
void aes128_enc(void* buffer, aes128_ctx_t* ctx);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
/**
|
/**
|
||||||
* \file aes192_dec.h
|
* \file aes192_dec.h
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-31
|
* \date 2008-12-31
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
* \ingroup AES
|
* \ingroup AES
|
||||||
|
@ -28,16 +28,16 @@
|
||||||
#ifndef AES192_DEC_H_
|
#ifndef AES192_DEC_H_
|
||||||
#define AES192_DEC_H_
|
#define AES192_DEC_H_
|
||||||
|
|
||||||
#include "aes.h"
|
#include "aes_types.h"
|
||||||
#include "aes_dec.h"
|
#include "aes_dec.h"
|
||||||
|
|
||||||
/** \fn void aes192_dec(void* buffer, aes192_ctx_t* ctx)
|
/**
|
||||||
* \brief decrypt with 192 bit key.
|
* \brief decrypt with 192 bit key.
|
||||||
*
|
*
|
||||||
* This function decrypts one block with the AES algorithm under control of
|
* This function decrypts one block with the AES algorithm under control of
|
||||||
* a keyschedule produced from a 192 bit key.
|
* a keyschedule produced from a 192 bit key.
|
||||||
* \param buffer pointer to the block to decrypt
|
* \param buffer pointer to the block to decrypt
|
||||||
* \param ctx pointer to the key schedule
|
* \param ctx pointer to the key schedule
|
||||||
*/
|
*/
|
||||||
void aes192_dec(void* buffer, aes192_ctx_t* ctx);
|
void aes192_dec(void* buffer, aes192_ctx_t* ctx);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
/**
|
/**
|
||||||
* \file aes192_enc.h
|
* \file aes192_enc.h
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-31
|
* \date 2008-12-31
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
* \ingroup AES
|
* \ingroup AES
|
||||||
|
@ -28,17 +28,17 @@
|
||||||
#ifndef AES192_ENC_H_
|
#ifndef AES192_ENC_H_
|
||||||
#define AES192_ENC_H_
|
#define AES192_ENC_H_
|
||||||
|
|
||||||
#include "aes.h"
|
#include "aes_types.h"
|
||||||
#include "aes_enc.h"
|
#include "aes_enc.h"
|
||||||
|
|
||||||
|
|
||||||
/** \fn void aes192_enc(void* buffer, aes192_ctx_t* ctx)
|
/**
|
||||||
* \brief encrypt with 192 bit key.
|
* \brief encrypt with 192 bit key.
|
||||||
*
|
*
|
||||||
* This function encrypts one block with the AES algorithm under control of
|
* This function encrypts one block with the AES algorithm under control of
|
||||||
* a keyschedule produced from a 192 bit key.
|
* a keyschedule produced from a 192 bit key.
|
||||||
* \param buffer pointer to the block to encrypt
|
* \param buffer pointer to the block to encrypt
|
||||||
* \param ctx pointer to the key schedule
|
* \param ctx pointer to the key schedule
|
||||||
*/
|
*/
|
||||||
void aes192_enc(void* buffer, aes192_ctx_t* ctx);
|
void aes192_enc(void* buffer, aes192_ctx_t* ctx);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
/**
|
/**
|
||||||
* \file aes256_dec.h
|
* \file aes256_dec.h
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-31
|
* \date 2008-12-31
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
* \ingroup AES
|
* \ingroup AES
|
||||||
|
@ -28,16 +28,16 @@
|
||||||
#ifndef AES256_DEC_H_
|
#ifndef AES256_DEC_H_
|
||||||
#define AES256_DEC_H_
|
#define AES256_DEC_H_
|
||||||
|
|
||||||
#include "aes.h"
|
#include "aes_types.h"
|
||||||
#include "aes_dec.h"
|
#include "aes_dec.h"
|
||||||
|
|
||||||
/** \fn void aes256_dec(void* buffer, aes256_ctx_t* ctx)
|
/**
|
||||||
* \brief decrypt with 256 bit key.
|
* \brief decrypt with 256 bit key.
|
||||||
*
|
*
|
||||||
* This function decrypts one block with the AES algorithm under control of
|
* This function decrypts one block with the AES algorithm under control of
|
||||||
* a keyschedule produced from a 256 bit key.
|
* a keyschedule produced from a 256 bit key.
|
||||||
* \param buffer pointer to the block to decrypt
|
* \param buffer pointer to the block to decrypt
|
||||||
* \param ctx pointer to the key schedule
|
* \param ctx pointer to the key schedule
|
||||||
*/
|
*/
|
||||||
void aes256_dec(void* buffer, aes256_ctx_t* ctx);
|
void aes256_dec(void* buffer, aes256_ctx_t* ctx);
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
/**
|
/**
|
||||||
* \file aes256_enc.h
|
* \file aes256_enc.h
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-31
|
* \date 2008-12-31
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
* \ingroup AES
|
* \ingroup AES
|
||||||
|
@ -28,17 +28,17 @@
|
||||||
#ifndef AES256_ENC_H_
|
#ifndef AES256_ENC_H_
|
||||||
#define AES256_ENC_H_
|
#define AES256_ENC_H_
|
||||||
|
|
||||||
#include "aes.h"
|
#include "aes_types.h"
|
||||||
#include "aes_enc.h"
|
#include "aes_enc.h"
|
||||||
|
|
||||||
|
|
||||||
/** \fn void aes256_enc(void* buffer, aes256_ctx_t* ctx)
|
/**
|
||||||
* \brief encrypt with 256 bit key.
|
* \brief encrypt with 256 bit key.
|
||||||
*
|
*
|
||||||
* This function encrypts one block with the AES algorithm under control of
|
* This function encrypts one block with the AES algorithm under control of
|
||||||
* a keyschedule produced from a 256 bit key.
|
* a keyschedule produced from a 256 bit key.
|
||||||
* \param buffer pointer to the block to encrypt
|
* \param buffer pointer to the block to encrypt
|
||||||
* \param ctx pointer to the key schedule
|
* \param ctx pointer to the key schedule
|
||||||
*/
|
*/
|
||||||
void aes256_enc(void* buffer, aes256_ctx_t* ctx);
|
void aes256_enc(void* buffer, aes256_ctx_t* ctx);
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
/**
|
/**
|
||||||
* \file aes_dec.h
|
* \file aes_dec.h
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-30
|
* \date 2008-12-30
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef AES_DEC_H_
|
#ifndef AES_DEC_H_
|
||||||
#define AES_DEC_H_
|
#define AES_DEC_H_
|
||||||
#include "aes.h"
|
#include "aes_types.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,14 +19,14 @@
|
||||||
/**
|
/**
|
||||||
* \file aes_enc.h
|
* \file aes_enc.h
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-30
|
* \date 2008-12-30
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#ifndef AES_ENC_H_
|
#ifndef AES_ENC_H_
|
||||||
#define AES_ENC_H_
|
#define AES_ENC_H_
|
||||||
#include "aes.h"
|
#include "aes_types.h"
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -19,10 +19,10 @@
|
||||||
/**
|
/**
|
||||||
* \file aes_keyschedule.c
|
* \file aes_keyschedule.c
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-30
|
* \date 2008-12-30
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -49,32 +49,35 @@ uint8_t rc_tab[] PROGMEM = { 0x01, 0x02, 0x04, 0x08,
|
||||||
void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx){
|
void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx){
|
||||||
uint8_t hi,i,nk, next_nk;
|
uint8_t hi,i,nk, next_nk;
|
||||||
uint8_t rc=0;
|
uint8_t rc=0;
|
||||||
uint8_t tmp[4];
|
union {
|
||||||
|
uint32_t v32;
|
||||||
|
uint8_t v8[4];
|
||||||
|
} tmp;
|
||||||
nk=keysize_b>>5; /* 4, 6, 8 */
|
nk=keysize_b>>5; /* 4, 6, 8 */
|
||||||
hi=4*(nk+6+1);
|
hi=4*(nk+6+1);
|
||||||
memcpy(ctx, key, keysize_b/8);
|
memcpy(ctx, key, keysize_b/8);
|
||||||
next_nk = nk;
|
next_nk = nk;
|
||||||
for(i=nk;i<hi;++i){
|
for(i=nk;i<hi;++i){
|
||||||
*((uint32_t*)tmp) = ((uint32_t*)(ctx->key[0].ks))[i-1];
|
tmp.v32 = ((uint32_t*)(ctx->key[0].ks))[i-1];
|
||||||
if(i!=next_nk){
|
if(i!=next_nk){
|
||||||
if(nk==8 && i%8==4){
|
if(nk==8 && i%8==4){
|
||||||
tmp[0] = pgm_read_byte(aes_sbox+tmp[0]);
|
tmp.v8[0] = pgm_read_byte(aes_sbox+tmp.v8[0]);
|
||||||
tmp[1] = pgm_read_byte(aes_sbox+tmp[1]);
|
tmp.v8[1] = pgm_read_byte(aes_sbox+tmp.v8[1]);
|
||||||
tmp[2] = pgm_read_byte(aes_sbox+tmp[2]);
|
tmp.v8[2] = pgm_read_byte(aes_sbox+tmp.v8[2]);
|
||||||
tmp[3] = pgm_read_byte(aes_sbox+tmp[3]);
|
tmp.v8[3] = pgm_read_byte(aes_sbox+tmp.v8[3]);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
next_nk += nk;
|
next_nk += nk;
|
||||||
aes_rotword(tmp);
|
aes_rotword(&(tmp.v32));
|
||||||
tmp[0] = pgm_read_byte(aes_sbox+tmp[0]);
|
tmp.v8[0] = pgm_read_byte(aes_sbox+tmp.v8[0]);
|
||||||
tmp[1] = pgm_read_byte(aes_sbox+tmp[1]);
|
tmp.v8[1] = pgm_read_byte(aes_sbox+tmp.v8[1]);
|
||||||
tmp[2] = pgm_read_byte(aes_sbox+tmp[2]);
|
tmp.v8[2] = pgm_read_byte(aes_sbox+tmp.v8[2]);
|
||||||
tmp[3] = pgm_read_byte(aes_sbox+tmp[3]);
|
tmp.v8[3] = pgm_read_byte(aes_sbox+tmp.v8[3]);
|
||||||
tmp[0] ^= pgm_read_byte(rc_tab+rc);
|
tmp.v8[0] ^= pgm_read_byte(rc_tab+rc);
|
||||||
rc++;
|
rc++;
|
||||||
}
|
}
|
||||||
((uint32_t*)(ctx->key[0].ks))[i] = ((uint32_t*)(ctx->key[0].ks))[i-nk]
|
((uint32_t*)(ctx->key[0].ks))[i] = ((uint32_t*)(ctx->key[0].ks))[i-nk]
|
||||||
^ *((uint32_t*)tmp);
|
^ tmp.v32;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
/**
|
/**
|
||||||
* \file aes_keyschedule.h
|
* \file aes_keyschedule.h
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \author Daniel Otte
|
* \author Daniel Otte
|
||||||
* \date 2008-12-30
|
* \date 2008-12-30
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
* \ingroup AES
|
* \ingroup AES
|
||||||
|
@ -29,10 +29,10 @@
|
||||||
#ifndef AES_KEYSCHEDULE_H_
|
#ifndef AES_KEYSCHEDULE_H_
|
||||||
#define AES_KEYSCHEDULE_H_
|
#define AES_KEYSCHEDULE_H_
|
||||||
|
|
||||||
#include "aes.h"
|
#include "aes_types.h"
|
||||||
/** \fn void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx)
|
/**
|
||||||
* \brief initialize the keyschedule
|
* \brief initialize the keyschedule
|
||||||
*
|
*
|
||||||
* This function computes the keyschedule from a given key with a given length
|
* This function computes the keyschedule from a given key with a given length
|
||||||
* and stores it in the context variable
|
* and stores it in the context variable
|
||||||
* \param key pointer to the key material
|
* \param key pointer to the key material
|
||||||
|
@ -41,9 +41,9 @@
|
||||||
*/
|
*/
|
||||||
void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx);
|
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
|
* \brief initialize the keyschedule for 128 bit key
|
||||||
*
|
*
|
||||||
* This function computes the keyschedule from a given 128 bit key
|
* This function computes the keyschedule from a given 128 bit key
|
||||||
* and stores it in the context variable
|
* and stores it in the context variable
|
||||||
* \param key pointer to the key material
|
* \param key pointer to the key material
|
||||||
|
@ -51,9 +51,9 @@ void aes_init(const void* key, uint16_t keysize_b, aes_genctx_t* ctx);
|
||||||
*/
|
*/
|
||||||
void aes128_init(const void* key, aes128_ctx_t* ctx);
|
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
|
* \brief initialize the keyschedule for 192 bit key
|
||||||
*
|
*
|
||||||
* This function computes the keyschedule from a given 192 bit key
|
* This function computes the keyschedule from a given 192 bit key
|
||||||
* and stores it in the context variable
|
* and stores it in the context variable
|
||||||
* \param key pointer to the key material
|
* \param key pointer to the key material
|
||||||
|
@ -61,9 +61,9 @@ void aes128_init(const void* key, aes128_ctx_t* ctx);
|
||||||
*/
|
*/
|
||||||
void aes192_init(const void* key, aes192_ctx_t* ctx);
|
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
|
* \brief initialize the keyschedule for 256 bit key
|
||||||
*
|
*
|
||||||
* This function computes the keyschedule from a given 256 bit key
|
* This function computes the keyschedule from a given 256 bit key
|
||||||
* and stores it in the context variable
|
* and stores it in the context variable
|
||||||
* \param key pointer to the key material
|
* \param key pointer to the key material
|
||||||
|
@ -72,4 +72,4 @@ void aes192_init(const void* key, aes192_ctx_t* ctx);
|
||||||
void aes256_init(const void* key, aes256_ctx_t* ctx);
|
void aes256_init(const void* key, aes256_ctx_t* ctx);
|
||||||
|
|
||||||
#endif /* AES_KEYSCHEDULE_H_ */
|
#endif /* AES_KEYSCHEDULE_H_ */
|
||||||
|
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
/* serial-tools.h */
|
/* aes.h */
|
||||||
/*
|
/*
|
||||||
This file is part of the AVR-Crypto-Lib.
|
This file is part of the AVR-Crypto-Lib.
|
||||||
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
|
Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de)
|
||||||
|
@ -16,12 +16,41 @@
|
||||||
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
||||||
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 SERIALTOOLS_H_
|
/**
|
||||||
#define SERIALTOOLS_H_
|
* \file aes_types.h
|
||||||
|
* \email daniel.otte@rub.de
|
||||||
|
* \author Daniel Otte
|
||||||
|
* \date 2008-12-30
|
||||||
|
* \license GPLv3 or later
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
#ifndef AES_TYPES_H_
|
||||||
|
#define AES_TYPES_H_
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
int getnextwordn(char *s, int n); /* words are seperated by spaces */
|
typedef struct{
|
||||||
void readhex2buffer(void* buffer, int n);
|
uint8_t ks[16];
|
||||||
void uart_putptr(void* p);
|
} aes_roundkey_t;
|
||||||
|
|
||||||
#endif /*SERIALTOOLS_H_*/
|
typedef struct{
|
||||||
|
aes_roundkey_t key[10+1];
|
||||||
|
} aes128_ctx_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
aes_roundkey_t key[12+1];
|
||||||
|
} aes192_ctx_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
aes_roundkey_t key[14+1];
|
||||||
|
} aes256_ctx_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
aes_roundkey_t key[1]; /* just to avoid the warning */
|
||||||
|
} aes_genctx_t;
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
uint8_t s[16];
|
||||||
|
} aes_cipher_state_t;
|
||||||
|
|
||||||
|
#endif
|
|
@ -213,24 +213,25 @@ uint32_t k_lut[] PROGMEM = {
|
||||||
static
|
static
|
||||||
uint32_t bmw_small_expand1(uint8_t j, const uint32_t* q, const void* m, const void* h){
|
uint32_t bmw_small_expand1(uint8_t j, const uint32_t* q, const void* m, const void* h){
|
||||||
uint32_t(*s[])(uint32_t) = {bmw_small_s1, bmw_small_s2, bmw_small_s3, bmw_small_s0};
|
uint32_t(*s[])(uint32_t) = {bmw_small_s1, bmw_small_s2, bmw_small_s3, bmw_small_s0};
|
||||||
uint32_t r=0;
|
uint32_t r;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
/* r = 0x05555555*(j+16); */
|
/* r = 0x05555555*(j+16); */
|
||||||
for(i=0; i<16; ++i){
|
|
||||||
r += s[i%4](q[j+i]);
|
|
||||||
}
|
|
||||||
#if TWEAK
|
#if TWEAK
|
||||||
r += ( ROTL32(((uint32_t*)m)[j&0xf], ((j+0)&0xf)+1 )
|
r = ( ROTL32(((uint32_t*)m)[j&0xf], ((j+0)&0xf)+1 )
|
||||||
+ ROTL32(((uint32_t*)m)[(j+3)&0xf], ((j+3)&0xf)+1 )
|
+ ROTL32(((uint32_t*)m)[(j+3)&0xf], ((j+3)&0xf)+1 )
|
||||||
- ROTL32(((uint32_t*)m)[(j+10)&0xf], ((j+10)&0xf)+1 )
|
- ROTL32(((uint32_t*)m)[(j+10)&0xf], ((j+10)&0xf)+1 )
|
||||||
+ pgm_read_dword(k_lut+j)
|
+ pgm_read_dword(k_lut+j)
|
||||||
) ^ ((uint32_t*)h)[(j+7)&0xf];
|
) ^ ((uint32_t*)h)[(j+7)&0xf];
|
||||||
#else
|
#else
|
||||||
r += pgm_read_dword(k_lut+j);
|
r = pgm_read_dword(k_lut+j);
|
||||||
r += ((uint32_t*)m)[j&0xf];
|
r += ((uint32_t*)m)[j&0xf];
|
||||||
r += ((uint32_t*)m)[(j+3)&0xf];
|
r += ((uint32_t*)m)[(j+3)&0xf];
|
||||||
r -= ((uint32_t*)m)[(j+10)&0xf];
|
r -= ((uint32_t*)m)[(j+10)&0xf];
|
||||||
#endif
|
#endif
|
||||||
|
for(i=0; i<16; ++i){
|
||||||
|
r += s[i%4](q[j+i]);
|
||||||
|
}
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
|
||||||
|
|
||||||
q[ 0] = (+ h[ 5] - h[ 7] + h[10] + h[13] + h[14]);
|
q[ 0] = (+ h[ 5] - h[ 7] + h[10] + h[13] + h[14]);
|
||||||
q[ 1] = (+ h[ 6] - h[ 8] + h[11] + h[14] - h[15]);
|
q[ 1] = (+ h[ 6] - h[ 8] + h[11] + h[14] - h[15]);
|
||||||
q[ 2] = (+ h[ 7] + h[ 9] - h[12] + h[15] + h[ 0]);
|
q[ 2] = (+ h[ 7] + h[ 9] - h[12] + h[15] + h[ 0]);
|
||||||
|
|
8
config.h
8
config.h
|
@ -20,16 +20,14 @@
|
||||||
#define __CONFIG_H__
|
#define __CONFIG_H__
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
// #define F_CPU 20000000
|
// #define F_CPU 20000000
|
||||||
#define F_CPU 16000000 /* Oszillator-Frequenz in Hz */
|
// #define F_CPU 16000000 /* oscillator-frequency in Hz */
|
||||||
// #define F_CPU 14745600
|
// #define F_CPU 14745600
|
||||||
|
#define F_CPU 20000000 /* this is out of spec but lets try it */
|
||||||
|
|
||||||
|
#define DEBUG_METHOD uart
|
||||||
|
|
||||||
#include "uart_defs.h"
|
#include "uart_defs.h"
|
||||||
|
|
||||||
#define DEBUG uart
|
|
||||||
|
|
||||||
#undef UART_LEDS
|
|
||||||
|
|
||||||
#define UART0_I 1
|
#define UART0_I 1
|
||||||
#define UART0_BAUD_RATE 38400
|
#define UART0_BAUD_RATE 38400
|
||||||
#define UART0_PARATY UART_PARATY_NONE
|
#define UART0_PARATY UART_PARATY_NONE
|
||||||
|
|
2
debug.h
2
debug.h
|
@ -19,7 +19,7 @@
|
||||||
#ifndef DEBUG_H_
|
#ifndef DEBUG_H_
|
||||||
#define DEBUG_H_
|
#define DEBUG_H_
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG_METHOD
|
||||||
#define DEBUG_INIT() debug_init()
|
#define DEBUG_INIT() debug_init()
|
||||||
#define DEBUG_C(_c) debug_char(_c)
|
#define DEBUG_C(_c) debug_char(_c)
|
||||||
#define DEBUG_S(_s) debug_str(_s)
|
#define DEBUG_S(_s) debug_str(_s)
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \date 2009-05-19
|
* \date 2009-05-19
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "groestl_small.h"
|
#include "groestl_small.h"
|
||||||
|
@ -74,7 +74,7 @@ void groestl_small_rounds(uint8_t *m, uint8_t q){
|
||||||
}else{
|
}else{
|
||||||
m[0] ^= r;
|
m[0] ^= r;
|
||||||
}
|
}
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if(r<2){
|
if(r<2){
|
||||||
cli_putstr_P(PSTR("\r\npost add-const"));
|
cli_putstr_P(PSTR("\r\npost add-const"));
|
||||||
dump_m(m);
|
dump_m(m);
|
||||||
|
@ -90,12 +90,12 @@ void groestl_small_rounds(uint8_t *m, uint8_t q){
|
||||||
m[i+((j-i+8)%8)*8] = tmp[j];
|
m[i+((j-i+8)%8)*8] = tmp[j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
if(r<2){
|
if(r<2){
|
||||||
cli_putstr_P(PSTR("\r\npost shift-bytes"));
|
cli_putstr_P(PSTR("\r\npost shift-bytes"));
|
||||||
dump_m(m);
|
dump_m(m);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
for(i=0; i<8; ++i){
|
for(i=0; i<8; ++i){
|
||||||
memcpy(tmp, m+8*i, 8);
|
memcpy(tmp, m+8*i, 8);
|
||||||
for(j=0; j<8; ++j){
|
for(j=0; j<8; ++j){
|
||||||
|
@ -114,20 +114,20 @@ void groestl_small_rounds(uint8_t *m, uint8_t q){
|
||||||
cli_putstr_P(PSTR("\r\npost mix-bytes"));
|
cli_putstr_P(PSTR("\r\npost mix-bytes"));
|
||||||
dump_m(m);
|
dump_m(m);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void groestl224_init(groestl224_ctx_t* ctx){
|
void groestl224_init(groestl224_ctx_t* ctx){
|
||||||
memset(ctx->h, 0, 8*8);
|
memset(ctx->h, 0, 8*8);
|
||||||
ctx->h[8*8-1] = 224;
|
ctx->h[8*8-1] = 224;
|
||||||
ctx->counter = 0;
|
ctx->counter = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void groestl256_init(groestl256_ctx_t* ctx){
|
void groestl256_init(groestl256_ctx_t* ctx){
|
||||||
memset(ctx->h, 0, 8*8);
|
memset(ctx->h, 0, 8*8);
|
||||||
ctx->h[8*8-2] = 1;
|
ctx->h[8*8-2] = 1;
|
||||||
ctx->counter = 0;
|
ctx->counter = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void groestl_small_nextBlock(groestl_small_ctx_t* ctx, const void* block){
|
void groestl_small_nextBlock(groestl_small_ctx_t* ctx, const void* block){
|
||||||
|
@ -137,7 +137,7 @@ void groestl_small_nextBlock(groestl_small_ctx_t* ctx, const void* block){
|
||||||
tmp1[j*8+i] = ((uint8_t*)block)[i*8+j];
|
tmp1[j*8+i] = ((uint8_t*)block)[i*8+j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
memcpy(tmp1, block, 64);
|
memcpy(tmp1, block, 64);
|
||||||
memcpy(tmp2, tmp1, 64);
|
memcpy(tmp2, tmp1, 64);
|
||||||
memxor(tmp1, ctx->h, 64);
|
memxor(tmp1, ctx->h, 64);
|
||||||
|
@ -157,12 +157,12 @@ void groestl_small_lastBlock(groestl_small_ctx_t* ctx, const void* block, uint16
|
||||||
}
|
}
|
||||||
memset(buffer, 0, 64);
|
memset(buffer, 0, 64);
|
||||||
memcpy(buffer, block, (length_b+7)/8);
|
memcpy(buffer, block, (length_b+7)/8);
|
||||||
buffer[length_b/8] |= 0x80>>(length_b%8);
|
buffer[length_b/8] |= 0x80>>(length_b&0x7);
|
||||||
if(length_b>512-65){
|
if(length_b>512-65){
|
||||||
groestl_small_nextBlock(ctx, buffer);
|
groestl_small_nextBlock(ctx, buffer);
|
||||||
memset(buffer, 0, 64-4);
|
memset(buffer, 0, 64-4);
|
||||||
}
|
}
|
||||||
ctx->counter++;
|
// ctx->counter++;
|
||||||
buffer[64-1] = (uint8_t)(ctx->counter);
|
buffer[64-1] = (uint8_t)(ctx->counter);
|
||||||
buffer[64-2] = (uint8_t)((ctx->counter)>>8);
|
buffer[64-2] = (uint8_t)((ctx->counter)>>8);
|
||||||
buffer[64-3] = (uint8_t)((ctx->counter)>>16);
|
buffer[64-3] = (uint8_t)((ctx->counter)>>16);
|
||||||
|
@ -178,7 +178,7 @@ void groestl_small_ctx2hash(void* dest, const groestl_small_ctx_t* ctx, uint16_t
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
cli_putstr_P(PSTR("\r\npost finalisation"));
|
cli_putstr_P(PSTR("\r\npost finalisation"));
|
||||||
dump_m(tmp);
|
dump_m(tmp);
|
||||||
#endif
|
#endif
|
||||||
memcpy(dest, tmp+64-outlength_b/8, outlength_b/8);
|
memcpy(dest, tmp+64-outlength_b/8, outlength_b/8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
* \email daniel.otte@rub.de
|
* \email daniel.otte@rub.de
|
||||||
* \date 2009-05-10
|
* \date 2009-05-10
|
||||||
* \license GPLv3 or later
|
* \license GPLv3 or later
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "hfal-performance.h"
|
#include "hfal-performance.h"
|
||||||
|
@ -53,23 +53,24 @@ void hfal_performance(const hfdesc_t* hd){
|
||||||
uint8_t data[(hf.blocksize_b+7)/8];
|
uint8_t data[(hf.blocksize_b+7)/8];
|
||||||
uint8_t digest[(hf.hashsize_b+7)/8];
|
uint8_t digest[(hf.hashsize_b+7)/8];
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
|
|
||||||
if(hf.type!=HFDESC_TYPE_HASHFUNCTION)
|
if(hf.type!=HFDESC_TYPE_HASHFUNCTION)
|
||||||
return;
|
return;
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
|
print_overhead();
|
||||||
cli_putstr_P(PSTR("\r\n\r\n === "));
|
cli_putstr_P(PSTR("\r\n\r\n === "));
|
||||||
cli_putstr_P(hf.name);
|
cli_putstr_P(hf.name);
|
||||||
cli_putstr_P(PSTR(" performance === "
|
cli_putstr_P(PSTR(" performance === "
|
||||||
"\r\n type: hashfunction"
|
"\r\n type: hashfunction"
|
||||||
"\r\n hashsize (bits): "));
|
"\r\n hashsize (bits): "));
|
||||||
printvalue(hf.hashsize_b);
|
printvalue(hf.hashsize_b);
|
||||||
|
|
||||||
cli_putstr_P(PSTR("\r\n ctxsize (bytes): "));
|
cli_putstr_P(PSTR("\r\n ctxsize (bytes): "));
|
||||||
printvalue(hf.ctxsize_B);
|
printvalue(hf.ctxsize_B);
|
||||||
|
|
||||||
cli_putstr_P(PSTR("\r\n blocksize (bits): "));
|
cli_putstr_P(PSTR("\r\n blocksize (bits): "));
|
||||||
printvalue(hf.blocksize_b);
|
printvalue(hf.blocksize_b);
|
||||||
|
|
||||||
startTimer(0);
|
startTimer(0);
|
||||||
START_TIMER;
|
START_TIMER;
|
||||||
hf.init(&ctx);
|
hf.init(&ctx);
|
||||||
|
@ -77,7 +78,7 @@ void hfal_performance(const hfdesc_t* hd){
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n init (cycles): "));
|
cli_putstr_P(PSTR("\r\n init (cycles): "));
|
||||||
printvalue(t);
|
printvalue(t);
|
||||||
|
|
||||||
startTimer(0);
|
startTimer(0);
|
||||||
START_TIMER;
|
START_TIMER;
|
||||||
hf.nextBlock(&ctx, data);
|
hf.nextBlock(&ctx, data);
|
||||||
|
@ -85,7 +86,7 @@ void hfal_performance(const hfdesc_t* hd){
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n nextBlock (cycles): "));
|
cli_putstr_P(PSTR("\r\n nextBlock (cycles): "));
|
||||||
printvalue(t);
|
printvalue(t);
|
||||||
|
|
||||||
startTimer(0);
|
startTimer(0);
|
||||||
START_TIMER;
|
START_TIMER;
|
||||||
hf.lastBlock(&ctx, data, 0);
|
hf.lastBlock(&ctx, data, 0);
|
||||||
|
@ -93,7 +94,7 @@ void hfal_performance(const hfdesc_t* hd){
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n lastBlock (cycles): "));
|
cli_putstr_P(PSTR("\r\n lastBlock (cycles): "));
|
||||||
printvalue(t);
|
printvalue(t);
|
||||||
|
|
||||||
startTimer(0);
|
startTimer(0);
|
||||||
START_TIMER;
|
START_TIMER;
|
||||||
hf.ctx2hash(digest, &ctx);
|
hf.ctx2hash(digest, &ctx);
|
||||||
|
|
|
@ -25,8 +25,12 @@ require 'serialport'
|
||||||
require 'getopt/std'
|
require 'getopt/std'
|
||||||
|
|
||||||
$buffer_size = 0
|
$buffer_size = 0
|
||||||
|
$conffile_check = Hash.new
|
||||||
|
$conffile_check.default = 0
|
||||||
|
|
||||||
def readconfigfile(fname, conf)
|
def readconfigfile(fname, conf)
|
||||||
|
return conf if $conffile_check[fname]==1
|
||||||
|
$conffile_check[fname]=1
|
||||||
section = "default"
|
section = "default"
|
||||||
if not File.exists?(fname)
|
if not File.exists?(fname)
|
||||||
return conf
|
return conf
|
||||||
|
@ -42,7 +46,11 @@ def readconfigfile(fname, conf)
|
||||||
end
|
end
|
||||||
next if not /=/.match(line)
|
next if not /=/.match(line)
|
||||||
m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line)
|
m=/[\s]*([^\s]*)[\s]*=[\s]*([^\s]*)/.match(line)
|
||||||
conf[section][m[1]] = m[2]
|
if m[1]=="include"
|
||||||
|
Dir.glob(m[2]){ |fn| conf = readconfigfile(fn, conf) }
|
||||||
|
else
|
||||||
|
conf[section][m[1]] = m[2]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
file.close()
|
file.close()
|
||||||
return conf
|
return conf
|
||||||
|
@ -96,6 +104,7 @@ def send_md(md_string)
|
||||||
for i in 0..md_string.length-1
|
for i in 0..md_string.length-1
|
||||||
$sp.print(md_string[i].chr)
|
$sp.print(md_string[i].chr)
|
||||||
# print("DBG s: "+ md_string[i].chr) if $debug
|
# print("DBG s: "+ md_string[i].chr) if $debug
|
||||||
|
sleep(0.01)
|
||||||
if((i%($buffer_size*2)==0)&&(i!=0))
|
if((i%($buffer_size*2)==0)&&(i!=0))
|
||||||
begin
|
begin
|
||||||
line=$sp.gets()
|
line=$sp.gets()
|
||||||
|
@ -148,7 +157,8 @@ def run_test(filename, skip=0)
|
||||||
putc('*')
|
putc('*')
|
||||||
else
|
else
|
||||||
putc('!')
|
putc('!')
|
||||||
printf("<%d>",len)
|
# printf("<%d>",len)
|
||||||
|
printf("\nError @%05d: %s \n != %s - ",len, a, b)
|
||||||
nerrors += 1
|
nerrors += 1
|
||||||
end
|
end
|
||||||
pos += 1
|
pos += 1
|
||||||
|
@ -156,10 +166,14 @@ def run_test(filename, skip=0)
|
||||||
return nerrors.to_i
|
return nerrors.to_i
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts = Getopt::Std.getopts("s:f:i:hdca")
|
||||||
|
|
||||||
conf = Hash.new
|
conf = Hash.new
|
||||||
conf = readconfigfile("/etc/testport.conf", conf)
|
conf = readconfigfile("/etc/testport.conf", conf)
|
||||||
conf = readconfigfile("~/.testport.conf", conf)
|
conf = readconfigfile("~/.testport.conf", conf)
|
||||||
conf = readconfigfile("testport.conf", conf)
|
conf = readconfigfile("testport.conf", conf)
|
||||||
|
conf = readconfigfile(opts["f"], conf) if opts["f"]
|
||||||
|
|
||||||
#puts conf.inspect
|
#puts conf.inspect
|
||||||
|
|
||||||
puts("serial port interface version: " + SerialPort::VERSION);
|
puts("serial port interface version: " + SerialPort::VERSION);
|
||||||
|
@ -190,7 +204,19 @@ reset_system()
|
||||||
algos=scan_system()
|
algos=scan_system()
|
||||||
#puts algos.inspect
|
#puts algos.inspect
|
||||||
|
|
||||||
algos.sort.each do |algoa|
|
if opts["s"]
|
||||||
|
algos_rev = algos.invert
|
||||||
|
algo_tasks = Array.new
|
||||||
|
opts["s"].each_byte{ |x|
|
||||||
|
if algos_rev[x.chr]
|
||||||
|
algo_tasks << [algos_rev[x.chr],x.chr]
|
||||||
|
end
|
||||||
|
}
|
||||||
|
else
|
||||||
|
algo_tasks=algos.sort
|
||||||
|
end
|
||||||
|
|
||||||
|
algo_tasks.each do |algoa|
|
||||||
algo = algoa[0]
|
algo = algoa[0]
|
||||||
if conf[algo]==nil
|
if conf[algo]==nil
|
||||||
puts("No test-set defined for #{algo} \r\n")
|
puts("No test-set defined for #{algo} \r\n")
|
||||||
|
@ -202,7 +228,9 @@ algos.sort.each do |algoa|
|
||||||
puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}")
|
puts("Testing #{algo} with #{conf[algo]["file_#{i}"]}")
|
||||||
reset_system()
|
reset_system()
|
||||||
init_system(algoa[1])
|
init_system(algoa[1])
|
||||||
nerrors=run_test(conf[algo]["file_#{i}"], 0)
|
skip=0
|
||||||
|
skip=opts["i"].to_i if opts["i"]
|
||||||
|
nerrors=run_test(conf[algo]["file_#{i}"], skip)
|
||||||
if nerrors == 0
|
if nerrors == 0
|
||||||
puts("\n[ok]")
|
puts("\n[ok]")
|
||||||
logfile.puts("[ok] "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")
|
logfile.puts("[ok] "+conf[algo]["file_#{i}"]+ " ("+Time.now.to_s()+")")
|
||||||
|
|
|
@ -20,16 +20,14 @@
|
||||||
#define __CONFIG_H__
|
#define __CONFIG_H__
|
||||||
#include <avr/io.h>
|
#include <avr/io.h>
|
||||||
// #define F_CPU 20000000
|
// #define F_CPU 20000000
|
||||||
#define F_CPU 16000000 /* Oszillator-Frequenz in Hz */
|
// #define F_CPU 16000000 /* oscillator-frequency in Hz */
|
||||||
// #define F_CPU 14745600
|
// #define F_CPU 14745600
|
||||||
|
#define F_CPU 20000000 /* this is out of spec but lets try it */
|
||||||
|
|
||||||
|
#define DEBUG_METHOD uart
|
||||||
|
|
||||||
#include "uart_defs.h"
|
#include "uart_defs.h"
|
||||||
|
|
||||||
#define DEBUG uart
|
|
||||||
|
|
||||||
#undef UART_LEDS
|
|
||||||
|
|
||||||
#define UART0_I 1
|
#define UART0_I 1
|
||||||
#define UART0_BAUD_RATE 38400
|
#define UART0_BAUD_RATE 38400
|
||||||
#define UART0_PARATY UART_PARATY_NONE
|
#define UART0_PARATY UART_PARATY_NONE
|
||||||
|
|
|
@ -23,35 +23,35 @@
|
||||||
****************************/
|
****************************/
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
#if DEBUG == uart
|
#if DEBUG_METHOD == uart
|
||||||
#include "uart_i.h"
|
#include "uart_i.h"
|
||||||
#else
|
#else
|
||||||
#error "Your DEBUG methode is not suported!"
|
#error "Your DEBUG methode is not suported!"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG_METHOD
|
||||||
void debug_init(void){
|
void debug_init(void){
|
||||||
#if DBUG==uart
|
#if DEBUG_METHOD==uart
|
||||||
uart0_init();
|
uart0_init();
|
||||||
#else
|
#else
|
||||||
#error "Your DEBUG methode is not suported!"
|
#error "Your DEBUG methode is not suported!"
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_char(char c){
|
void debug_char(char c){
|
||||||
static char initialised = 0;
|
static char initialised = 0;
|
||||||
if (!initialised){
|
if (!initialised){
|
||||||
uart0_init();
|
uart0_init();
|
||||||
initialised=1;
|
initialised=1;
|
||||||
}
|
}
|
||||||
uart0_putc(c);
|
uart0_putc(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
void debug_str(char* s){
|
void debug_str(char* s){
|
||||||
while (*s)
|
while (*s)
|
||||||
debug_char(*s++);
|
debug_char(*s++);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void debug_byte(char b){
|
void debug_byte(char b){
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* AES test-suit
|
* AES test-suit
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -27,13 +27,6 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "aes/aes.h"
|
#include "aes/aes.h"
|
||||||
#include "aes/aes128_enc.h"
|
|
||||||
#include "aes/aes128_dec.h"
|
|
||||||
#include "aes/aes192_enc.h"
|
|
||||||
#include "aes/aes192_dec.h"
|
|
||||||
#include "aes/aes256_enc.h"
|
|
||||||
#include "aes/aes256_dec.h"
|
|
||||||
#include "aes/aes_keyschedule.h"
|
|
||||||
|
|
||||||
#include "nessie_bc_test.h"
|
#include "nessie_bc_test.h"
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
@ -59,28 +52,28 @@ void testrun_nessie_aes(void){
|
||||||
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)aes128_dec;
|
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)aes128_dec;
|
||||||
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)aes_init;
|
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)aes_init;
|
||||||
nessie_bc_run();
|
nessie_bc_run();
|
||||||
|
|
||||||
nessie_bc_ctx.keysize_b = 192;
|
nessie_bc_ctx.keysize_b = 192;
|
||||||
nessie_bc_ctx.ctx_size_B = sizeof(aes192_ctx_t);
|
nessie_bc_ctx.ctx_size_B = sizeof(aes192_ctx_t);
|
||||||
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)aes192_enc;
|
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)aes192_enc;
|
||||||
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)aes192_dec;
|
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)aes192_dec;
|
||||||
nessie_bc_run();
|
nessie_bc_run();
|
||||||
|
|
||||||
nessie_bc_ctx.keysize_b = 256;
|
nessie_bc_ctx.keysize_b = 256;
|
||||||
nessie_bc_ctx.ctx_size_B = sizeof(aes256_ctx_t);
|
nessie_bc_ctx.ctx_size_B = sizeof(aes256_ctx_t);
|
||||||
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)aes256_enc;
|
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)aes256_enc;
|
||||||
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)aes256_dec;
|
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)aes256_dec;
|
||||||
nessie_bc_run();
|
nessie_bc_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_test_aes(void){
|
void testrun_test_aes(void){
|
||||||
uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
|
uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
|
||||||
0x28, 0xae, 0xd2, 0xa6,
|
0x28, 0xae, 0xd2, 0xa6,
|
||||||
0xab, 0xf7, 0x15, 0x88,
|
0xab, 0xf7, 0x15, 0x88,
|
||||||
0x09, 0xcf, 0x4f, 0x3c };
|
0x09, 0xcf, 0x4f, 0x3c };
|
||||||
uint8_t data[16] = { 0x32, 0x43, 0xf6, 0xa8,
|
uint8_t data[16] = { 0x32, 0x43, 0xf6, 0xa8,
|
||||||
0x88, 0x5a, 0x30, 0x8d,
|
0x88, 0x5a, 0x30, 0x8d,
|
||||||
0x31, 0x31, 0x98, 0xa2,
|
0x31, 0x31, 0x98, 0xa2,
|
||||||
0xe0, 0x37, 0x07, 0x34 };
|
0xe0, 0x37, 0x07, 0x34 };
|
||||||
aes128_ctx_t ctx;
|
aes128_ctx_t ctx;
|
||||||
aes128_init(key, &ctx);
|
aes128_init(key, &ctx);
|
||||||
|
@ -94,12 +87,12 @@ void testrun_test_aes(void){
|
||||||
aes128_dec(data, &ctx);
|
aes128_dec(data, &ctx);
|
||||||
cli_putstr_P(PSTR("\r\n plaintext: "));
|
cli_putstr_P(PSTR("\r\n plaintext: "));
|
||||||
cli_hexdump(data, 16);
|
cli_hexdump(data, 16);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_testkey_aes128(void){
|
void testrun_testkey_aes128(void){
|
||||||
uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
|
uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
|
||||||
0x28, 0xae, 0xd2, 0xa6,
|
0x28, 0xae, 0xd2, 0xa6,
|
||||||
0xab, 0xf7, 0x15, 0x88,
|
0xab, 0xf7, 0x15, 0x88,
|
||||||
0x09, 0xcf, 0x4f, 0x3c};
|
0x09, 0xcf, 0x4f, 0x3c};
|
||||||
|
@ -118,11 +111,11 @@ void testrun_testkey_aes128(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_testkey_aes192(void){
|
void testrun_testkey_aes192(void){
|
||||||
uint8_t key[24] = { 0x8e, 0x73, 0xb0, 0xf7,
|
uint8_t key[24] = { 0x8e, 0x73, 0xb0, 0xf7,
|
||||||
0xda, 0x0e, 0x64, 0x52,
|
0xda, 0x0e, 0x64, 0x52,
|
||||||
0xc8, 0x10, 0xf3, 0x2b,
|
0xc8, 0x10, 0xf3, 0x2b,
|
||||||
0x80, 0x90, 0x79, 0xe5,
|
0x80, 0x90, 0x79, 0xe5,
|
||||||
0x62, 0xf8, 0xea, 0xd2,
|
0x62, 0xf8, 0xea, 0xd2,
|
||||||
0x52, 0x2c, 0x6b, 0x7b};
|
0x52, 0x2c, 0x6b, 0x7b};
|
||||||
aes192_ctx_t ctx;
|
aes192_ctx_t ctx;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
@ -141,13 +134,13 @@ void testrun_testkey_aes192(void){
|
||||||
|
|
||||||
|
|
||||||
void testrun_testkey_aes256(void){
|
void testrun_testkey_aes256(void){
|
||||||
uint8_t key[32] = { 0x60, 0x3d, 0xeb, 0x10,
|
uint8_t key[32] = { 0x60, 0x3d, 0xeb, 0x10,
|
||||||
0x15, 0xca, 0x71, 0xbe,
|
0x15, 0xca, 0x71, 0xbe,
|
||||||
0x2b, 0x73, 0xae, 0xf0,
|
0x2b, 0x73, 0xae, 0xf0,
|
||||||
0x85, 0x7d, 0x77, 0x81,
|
0x85, 0x7d, 0x77, 0x81,
|
||||||
0x1f, 0x35, 0x2c, 0x07,
|
0x1f, 0x35, 0x2c, 0x07,
|
||||||
0x3b, 0x61, 0x08, 0xd7,
|
0x3b, 0x61, 0x08, 0xd7,
|
||||||
0x2d, 0x98, 0x10, 0xa3,
|
0x2d, 0x98, 0x10, 0xa3,
|
||||||
0x09, 0x14, 0xdf, 0xf4};
|
0x09, 0x14, 0xdf, 0xf4};
|
||||||
aes256_ctx_t ctx;
|
aes256_ctx_t ctx;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
@ -176,36 +169,36 @@ void testrun_performance_aes128(void){
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[32], data[16];
|
uint8_t key[32], data[16];
|
||||||
aes128_ctx_t ctx;
|
aes128_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
print_overhead();
|
print_overhead();
|
||||||
|
|
||||||
memset(key, 0, 32);
|
memset(key, 0, 32);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes128_init(key, &ctx);
|
aes128_init(key, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes128_enc(data, &ctx);
|
aes128_enc(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes128_dec(data, &ctx);
|
aes128_dec(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
cli_putstr_P(PSTR("\r\n"));
|
cli_putstr_P(PSTR("\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -215,36 +208,36 @@ void testrun_performance_aes192(void){
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[32], data[16];
|
uint8_t key[32], data[16];
|
||||||
aes192_ctx_t ctx;
|
aes192_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
print_overhead();
|
print_overhead();
|
||||||
|
|
||||||
memset(key, 0, 32);
|
memset(key, 0, 32);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes192_init(key, &ctx);
|
aes192_init(key, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes192_enc(data, &ctx);
|
aes192_enc(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes192_dec(data, &ctx);
|
aes192_dec(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
cli_putstr_P(PSTR("\r\n"));
|
cli_putstr_P(PSTR("\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -254,36 +247,36 @@ void testrun_performance_aes256(void){
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[32], data[16];
|
uint8_t key[32], data[16];
|
||||||
aes256_ctx_t ctx;
|
aes256_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
print_overhead();
|
print_overhead();
|
||||||
|
|
||||||
memset(key, 0, 32);
|
memset(key, 0, 32);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes256_init(key, &ctx);
|
aes256_init(key, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes256_enc(data, &ctx);
|
aes256_enc(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes256_dec(data, &ctx);
|
aes256_dec(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
cli_putstr_P(PSTR("\r\n"));
|
cli_putstr_P(PSTR("\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -314,13 +307,13 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
|
||||||
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
|
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
|
||||||
{ NULL, NULL, NULL}
|
{ NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
int main (void){
|
int main (void){
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
|
|
||||||
cli_rx = (cli_rx_fpt)uart0_getc;
|
cli_rx = (cli_rx_fpt)uart0_getc;
|
||||||
cli_tx = (cli_tx_fpt)uart0_putc;
|
cli_tx = (cli_tx_fpt)uart0_putc;
|
||||||
for(;;){
|
for(;;){
|
||||||
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
||||||
cli_putstr(algo_name);
|
cli_putstr(algo_name);
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* AES-128 test-suit
|
* AES-128 test-suit
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -27,10 +27,6 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "aes/aes.h"
|
#include "aes/aes.h"
|
||||||
#include "aes/aes128_enc.h"
|
|
||||||
#include "aes/aes128_dec.h"
|
|
||||||
#include "aes/aes_keyschedule.h"
|
|
||||||
|
|
||||||
#include "nessie_bc_test.h"
|
#include "nessie_bc_test.h"
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
#include "performance_test.h"
|
#include "performance_test.h"
|
||||||
|
@ -57,13 +53,13 @@ void testrun_nessie_aes(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_test_aes(void){
|
void testrun_test_aes(void){
|
||||||
uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
|
uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
|
||||||
0x28, 0xae, 0xd2, 0xa6,
|
0x28, 0xae, 0xd2, 0xa6,
|
||||||
0xab, 0xf7, 0x15, 0x88,
|
0xab, 0xf7, 0x15, 0x88,
|
||||||
0x09, 0xcf, 0x4f, 0x3c };
|
0x09, 0xcf, 0x4f, 0x3c };
|
||||||
uint8_t data[16] = { 0x32, 0x43, 0xf6, 0xa8,
|
uint8_t data[16] = { 0x32, 0x43, 0xf6, 0xa8,
|
||||||
0x88, 0x5a, 0x30, 0x8d,
|
0x88, 0x5a, 0x30, 0x8d,
|
||||||
0x31, 0x31, 0x98, 0xa2,
|
0x31, 0x31, 0x98, 0xa2,
|
||||||
0xe0, 0x37, 0x07, 0x34 };
|
0xe0, 0x37, 0x07, 0x34 };
|
||||||
aes128_ctx_t ctx;
|
aes128_ctx_t ctx;
|
||||||
aes128_init(key, &ctx);
|
aes128_init(key, &ctx);
|
||||||
|
@ -77,12 +73,12 @@ void testrun_test_aes(void){
|
||||||
aes128_dec(data, &ctx);
|
aes128_dec(data, &ctx);
|
||||||
cli_putstr_P(PSTR("\r\n plaintext: "));
|
cli_putstr_P(PSTR("\r\n plaintext: "));
|
||||||
cli_hexdump(data, 16);
|
cli_hexdump(data, 16);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_testkey_aes128(void){
|
void testrun_testkey_aes128(void){
|
||||||
uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
|
uint8_t key[16] = { 0x2b, 0x7e, 0x15, 0x16,
|
||||||
0x28, 0xae, 0xd2, 0xa6,
|
0x28, 0xae, 0xd2, 0xa6,
|
||||||
0xab, 0xf7, 0x15, 0x88,
|
0xab, 0xf7, 0x15, 0x88,
|
||||||
0x09, 0xcf, 0x4f, 0x3c};
|
0x09, 0xcf, 0x4f, 0x3c};
|
||||||
|
@ -110,36 +106,36 @@ void testrun_performance_aes128(void){
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[32], data[16];
|
uint8_t key[32], data[16];
|
||||||
aes128_ctx_t ctx;
|
aes128_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
print_overhead();
|
print_overhead();
|
||||||
|
|
||||||
memset(key, 0, 32);
|
memset(key, 0, 32);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes128_init(key, &ctx);
|
aes128_init(key, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes128_enc(data, &ctx);
|
aes128_enc(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes128_dec(data, &ctx);
|
aes128_dec(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
cli_putstr_P(PSTR("\r\n"));
|
cli_putstr_P(PSTR("\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -166,12 +162,12 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
|
||||||
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
|
{ echo_str, (void*)1, (void_fpt)echo_ctrl},
|
||||||
{ NULL, NULL, NULL}
|
{ NULL, NULL, NULL}
|
||||||
};
|
};
|
||||||
|
|
||||||
int main (void){
|
int main (void){
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
|
|
||||||
cli_rx = (cli_rx_fpt)uart0_getc;
|
cli_rx = (cli_rx_fpt)uart0_getc;
|
||||||
cli_tx = (cli_tx_fpt)uart0_putc;
|
cli_tx = (cli_tx_fpt)uart0_putc;
|
||||||
for(;;){
|
for(;;){
|
||||||
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
||||||
cli_putstr(algo_name);
|
cli_putstr(algo_name);
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* AES-192 test-suit
|
* AES-192 test-suit
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -27,9 +27,6 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "aes/aes.h"
|
#include "aes/aes.h"
|
||||||
#include "aes/aes192_enc.h"
|
|
||||||
#include "aes/aes192_dec.h"
|
|
||||||
#include "aes/aes_keyschedule.h"
|
|
||||||
|
|
||||||
#include "nessie_bc_test.h"
|
#include "nessie_bc_test.h"
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
@ -57,11 +54,11 @@ void testrun_nessie_aes(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_testkey_aes192(void){
|
void testrun_testkey_aes192(void){
|
||||||
uint8_t key[24] = { 0x8e, 0x73, 0xb0, 0xf7,
|
uint8_t key[24] = { 0x8e, 0x73, 0xb0, 0xf7,
|
||||||
0xda, 0x0e, 0x64, 0x52,
|
0xda, 0x0e, 0x64, 0x52,
|
||||||
0xc8, 0x10, 0xf3, 0x2b,
|
0xc8, 0x10, 0xf3, 0x2b,
|
||||||
0x80, 0x90, 0x79, 0xe5,
|
0x80, 0x90, 0x79, 0xe5,
|
||||||
0x62, 0xf8, 0xea, 0xd2,
|
0x62, 0xf8, 0xea, 0xd2,
|
||||||
0x52, 0x2c, 0x6b, 0x7b};
|
0x52, 0x2c, 0x6b, 0x7b};
|
||||||
aes192_ctx_t ctx;
|
aes192_ctx_t ctx;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
@ -88,36 +85,36 @@ void testrun_performance_aes192(void){
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[32], data[16];
|
uint8_t key[32], data[16];
|
||||||
aes192_ctx_t ctx;
|
aes192_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
print_overhead();
|
print_overhead();
|
||||||
|
|
||||||
memset(key, 0, 32);
|
memset(key, 0, 32);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes192_init(key, &ctx);
|
aes192_init(key, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes192_enc(data, &ctx);
|
aes192_enc(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes192_dec(data, &ctx);
|
aes192_dec(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
cli_putstr_P(PSTR("\r\n"));
|
cli_putstr_P(PSTR("\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -148,9 +145,9 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
|
||||||
|
|
||||||
int main (void){
|
int main (void){
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
|
|
||||||
cli_rx = (cli_rx_fpt)uart0_getc;
|
cli_rx = (cli_rx_fpt)uart0_getc;
|
||||||
cli_tx = (cli_tx_fpt)uart0_putc;
|
cli_tx = (cli_tx_fpt)uart0_putc;
|
||||||
for(;;){
|
for(;;){
|
||||||
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
||||||
cli_putstr(algo_name);
|
cli_putstr(algo_name);
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* AES-256 test-suit
|
* AES-256 test-suit
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -27,9 +27,6 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "aes/aes.h"
|
#include "aes/aes.h"
|
||||||
#include "aes/aes256_enc.h"
|
|
||||||
#include "aes/aes256_dec.h"
|
|
||||||
#include "aes/aes_keyschedule.h"
|
|
||||||
|
|
||||||
#include "nessie_bc_test.h"
|
#include "nessie_bc_test.h"
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
@ -57,13 +54,13 @@ void testrun_nessie_aes(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_testkey_aes256(void){
|
void testrun_testkey_aes256(void){
|
||||||
uint8_t key[32] = { 0x60, 0x3d, 0xeb, 0x10,
|
uint8_t key[32] = { 0x60, 0x3d, 0xeb, 0x10,
|
||||||
0x15, 0xca, 0x71, 0xbe,
|
0x15, 0xca, 0x71, 0xbe,
|
||||||
0x2b, 0x73, 0xae, 0xf0,
|
0x2b, 0x73, 0xae, 0xf0,
|
||||||
0x85, 0x7d, 0x77, 0x81,
|
0x85, 0x7d, 0x77, 0x81,
|
||||||
0x1f, 0x35, 0x2c, 0x07,
|
0x1f, 0x35, 0x2c, 0x07,
|
||||||
0x3b, 0x61, 0x08, 0xd7,
|
0x3b, 0x61, 0x08, 0xd7,
|
||||||
0x2d, 0x98, 0x10, 0xa3,
|
0x2d, 0x98, 0x10, 0xa3,
|
||||||
0x09, 0x14, 0xdf, 0xf4};
|
0x09, 0x14, 0xdf, 0xf4};
|
||||||
aes256_ctx_t ctx;
|
aes256_ctx_t ctx;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
|
@ -90,36 +87,36 @@ void testrun_performance_aes256(void){
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[32], data[16];
|
uint8_t key[32], data[16];
|
||||||
aes256_ctx_t ctx;
|
aes256_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
print_overhead();
|
print_overhead();
|
||||||
|
|
||||||
memset(key, 0, 32);
|
memset(key, 0, 32);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes256_init(key, &ctx);
|
aes256_init(key, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes256_enc(data, &ctx);
|
aes256_enc(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
aes256_dec(data, &ctx);
|
aes256_dec(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
cli_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
cli_putstr(str);
|
cli_putstr(str);
|
||||||
|
|
||||||
cli_putstr_P(PSTR("\r\n"));
|
cli_putstr_P(PSTR("\r\n"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -150,9 +147,9 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
|
||||||
|
|
||||||
int main (void){
|
int main (void){
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
|
|
||||||
cli_rx = (cli_rx_fpt)uart0_getc;
|
cli_rx = (cli_rx_fpt)uart0_getc;
|
||||||
cli_tx = (cli_tx_fpt)uart0_putc;
|
cli_tx = (cli_tx_fpt)uart0_putc;
|
||||||
for(;;){
|
for(;;){
|
||||||
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
||||||
cli_putstr(algo_name);
|
cli_putstr(algo_name);
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
*/
|
*/
|
||||||
/*
|
/*
|
||||||
* groestl test-suit
|
* groestl test-suit
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
@ -78,7 +78,7 @@ void groestl512_test(void* msg, uint32_t length_b){
|
||||||
|
|
||||||
|
|
||||||
void testrun_stdtest_groestl(void){
|
void testrun_stdtest_groestl(void){
|
||||||
uint8_t msg1[144];
|
uint8_t msg1[144];
|
||||||
memset(msg1, 0, 144);
|
memset(msg1, 0, 144);
|
||||||
groestl224_test("", 8);
|
groestl224_test("", 8);
|
||||||
groestl224_test(msg1, 576);
|
groestl224_test(msg1, 576);
|
||||||
|
@ -98,6 +98,19 @@ void testlshort(void){
|
||||||
groestl512_test("abc", 24);
|
groestl512_test("abc", 24);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void test505(void){
|
||||||
|
uint8_t data[] = {
|
||||||
|
0x84, 0x73, 0xDC, 0x53, 0x82, 0xDE, 0x32, 0x95,
|
||||||
|
0x7E, 0x3A, 0x15, 0xCA, 0x3D, 0x79, 0x1C, 0x67,
|
||||||
|
0xD2, 0x0C, 0xF9, 0xEF, 0xBE, 0x3E, 0x46, 0x40,
|
||||||
|
0x7D, 0xCA, 0x5D, 0x02, 0x63, 0x5A, 0xC8, 0x6D,
|
||||||
|
0x2E, 0x0B, 0x22, 0xC7, 0x6D, 0x7D, 0x08, 0x0D,
|
||||||
|
0x36, 0x2E, 0x82, 0x75, 0x89, 0x14, 0xCC, 0x0A,
|
||||||
|
0xE2, 0xB8, 0x9B, 0xD3, 0x5F, 0x71, 0xD8, 0x44,
|
||||||
|
0x92, 0xD9, 0x43, 0x07, 0x42, 0x78, 0x9C, 0x80 };
|
||||||
|
groestl224_test(data, 505);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void performance_groestl(void){
|
void performance_groestl(void){
|
||||||
hfal_performance_multiple(algolist);
|
hfal_performance_multiple(algolist);
|
||||||
|
@ -112,6 +125,7 @@ const char nessie_str[] PROGMEM = "nessie";
|
||||||
const char test_str[] PROGMEM = "test";
|
const char test_str[] PROGMEM = "test";
|
||||||
const char testshort_str[] PROGMEM = "short";
|
const char testshort_str[] PROGMEM = "short";
|
||||||
const char testlshort_str[] PROGMEM = "lshort";
|
const char testlshort_str[] PROGMEM = "lshort";
|
||||||
|
const char test505_str[] PROGMEM = "test505";
|
||||||
const char performance_str[] PROGMEM = "performance";
|
const char performance_str[] PROGMEM = "performance";
|
||||||
const char echo_str[] PROGMEM = "echo";
|
const char echo_str[] PROGMEM = "echo";
|
||||||
const char shavs_list_str[] PROGMEM = "shavs_list";
|
const char shavs_list_str[] PROGMEM = "shavs_list";
|
||||||
|
@ -123,6 +137,7 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
|
||||||
{ test_str, NULL, testrun_stdtest_groestl},
|
{ test_str, NULL, testrun_stdtest_groestl},
|
||||||
{ testshort_str, NULL, testshort},
|
{ testshort_str, NULL, testshort},
|
||||||
{ testlshort_str, NULL, testlshort},
|
{ testlshort_str, NULL, testlshort},
|
||||||
|
{ test505_str, NULL, test505},
|
||||||
{ performance_str, NULL, performance_groestl},
|
{ performance_str, NULL, performance_groestl},
|
||||||
{ shavs_list_str, NULL, shavs_listalgos},
|
{ shavs_list_str, NULL, shavs_listalgos},
|
||||||
{ shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
|
{ shavs_set_str, (void*)1, (void_fpt)shavs_setalgo},
|
||||||
|
@ -133,9 +148,9 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
|
||||||
|
|
||||||
int main (void){
|
int main (void){
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
|
|
||||||
cli_rx = (cli_rx_fpt)uart0_getc;
|
cli_rx = (cli_rx_fpt)uart0_getc;
|
||||||
cli_tx = (cli_tx_fpt)uart0_putc;
|
cli_tx = (cli_tx_fpt)uart0_putc;
|
||||||
shavs_algolist=(hfdesc_t**)algolist;
|
shavs_algolist=(hfdesc_t**)algolist;
|
||||||
shavs_algo=(hfdesc_t*)&groestl256_desc;
|
shavs_algo=(hfdesc_t*)&groestl256_desc;
|
||||||
for(;;){
|
for(;;){
|
||||||
|
@ -146,7 +161,7 @@ int main (void){
|
||||||
cli_putstr_P(PSTR(" "));
|
cli_putstr_P(PSTR(" "));
|
||||||
cli_putstr(__TIME__);
|
cli_putstr(__TIME__);
|
||||||
cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
||||||
|
|
||||||
cmd_interface(cmdlist);
|
cmd_interface(cmdlist);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,7 @@ ISR(TIMER1_OVF_vect){
|
||||||
}
|
}
|
||||||
|
|
||||||
void calibrateTimer(void){
|
void calibrateTimer(void){
|
||||||
volatile uint8_t i;
|
volatile uint8_t i=0;
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
stopTimer();
|
stopTimer();
|
||||||
const_overhead = TCNT1;
|
const_overhead = TCNT1;
|
||||||
|
|
|
@ -6,60 +6,9 @@ baud = 38400
|
||||||
databits = 8
|
databits = 8
|
||||||
stopbits = 1
|
stopbits = 1
|
||||||
paraty = none
|
paraty = none
|
||||||
testlogbase = testlog_
|
testlogbase = testlog/testlog_
|
||||||
|
|
||||||
###############################################################################
|
include=testconf/*.conf
|
||||||
|
|
||||||
[BlueMidnightWish-224]
|
|
||||||
algo=a
|
|
||||||
file_0=testvectors/shavs/BlueMidnightWish/ShortMsgKAT_224.txt
|
|
||||||
file_1=testvectors/shavs/BlueMidnightWish/LongMsgKAT_224.txt
|
|
||||||
|
|
||||||
[BlueMidnightWish-256]
|
|
||||||
algo=b
|
|
||||||
file_0=testvectors/shavs/BlueMidnightWish/ShortMsgKAT_256.txt
|
|
||||||
file_1=testvectors/shavs/BlueMidnightWish/LongMsgKAT_256.txt
|
|
||||||
|
|
||||||
[BlueMidnightWish-384]
|
|
||||||
algo=c
|
|
||||||
file_0=testvectors/shavs/BlueMidnightWish/ShortMsgKAT_384.txt
|
|
||||||
file_1=testvectors/shavs/BlueMidnightWish/LongMsgKAT_384.txt
|
|
||||||
|
|
||||||
[BlueMidnightWish-512]
|
|
||||||
algo=d
|
|
||||||
file_0=testvectors/shavs/BlueMidnightWish/ShortMsgKAT_512.txt
|
|
||||||
file_1=testvectors/shavs/BlueMidnightWish/LongMsgKAT_512.txt
|
|
||||||
|
|
||||||
[BlueMidnightWish]
|
|
||||||
meta=1
|
|
||||||
test_0=BlueMidnightWish-256
|
|
||||||
test_1=BlueMidnightWish-512
|
|
||||||
test_2=BlueMidnightWish-224
|
|
||||||
test_3=BlueMidnightWish-384
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
[Blake-28]
|
|
||||||
algo=a
|
|
||||||
file_0=testvectors/shavs/Blake/ShortMsgKAT_224.txt
|
|
||||||
file_1=testvectors/shavs/Blake/LongMsgKAT_224.txt
|
|
||||||
|
|
||||||
[Blake-32]
|
|
||||||
algo=b
|
|
||||||
file_0=testvectors/shavs/Blake/ShortMsgKAT_256.txt
|
|
||||||
file_1=testvectors/shavs/Blake/LongMsgKAT_256.txt
|
|
||||||
|
|
||||||
[Blake-48]
|
|
||||||
algo=c
|
|
||||||
file_0=testvectors/shavs/Blake/ShortMsgKAT_384.txt
|
|
||||||
file_1=testvectors/shavs/Blake/LongMsgKAT_384.txt
|
|
||||||
|
|
||||||
[Blake-64]
|
|
||||||
algo=d
|
|
||||||
file_0=testvectors/shavs/Blake/ShortMsgKAT_512.txt
|
|
||||||
file_1=testvectors/shavs/Blake/LongMsgKAT_512.txt
|
|
||||||
|
|
||||||
###############################################################################
|
|
||||||
|
|
||||||
|
|
||||||
# END OF CONFIGFILE
|
# END OF CONFIGFILE
|
||||||
|
|
Loading…
Reference in New Issue