camellia seems broken
This commit is contained in:
parent
f6e331f765
commit
2e7bb1f5e5
|
@ -82,7 +82,7 @@ void camellia128_ctx_dump(camellia128_ctx_t *s){
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
/* extern prog_uint64_t camellia_sigma[6]; */
|
/* extern prog_uint64_t camellia_sigma[6]; */
|
||||||
|
|
||||||
void camellia128_init(camellia128_ctx_t* s, uint8_t* key){
|
void camellia128_init(uint8_t* key, camellia128_ctx_t* s){
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
s->kll = 0; /* ((uint64_t*)key)[0]; */
|
s->kll = 0; /* ((uint64_t*)key)[0]; */
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ void camellia_6rounds(camellia128_ctx_t* s, uint64_t* bl, uint64_t* br, uint8_t
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
void camellia128_enc(camellia128_ctx_t* s, void* block){
|
void camellia128_enc(void* block, camellia128_ctx_t* s){
|
||||||
|
|
||||||
#define BL (((uint64_t*)block)[0])
|
#define BL (((uint64_t*)block)[0])
|
||||||
#define BR (((uint64_t*)block)[1])
|
#define BR (((uint64_t*)block)[1])
|
||||||
|
@ -188,7 +188,7 @@ void camellia128_enc(camellia128_ctx_t* s, void* block){
|
||||||
|
|
||||||
/*****************************************************************************/
|
/*****************************************************************************/
|
||||||
|
|
||||||
void camellia128_dec(camellia128_ctx_t* s, void* block){
|
void camellia128_dec(void* block, camellia128_ctx_t* s){
|
||||||
|
|
||||||
#define BL (((uint64_t*)block)[1])
|
#define BL (((uint64_t*)block)[1])
|
||||||
#define BR (((uint64_t*)block)[0])
|
#define BR (((uint64_t*)block)[0])
|
||||||
|
|
|
@ -29,9 +29,9 @@ typedef struct camellia128_ctx_s{
|
||||||
}camellia128_ctx_t;
|
}camellia128_ctx_t;
|
||||||
|
|
||||||
|
|
||||||
void camellia128_init(camellia128_ctx_t* s, uint8_t* key);
|
void camellia128_init(uint8_t* key, camellia128_ctx_t* s);
|
||||||
void camellia128_enc(camellia128_ctx_t* s, void* block);
|
void camellia128_enc(void* block, camellia128_ctx_t* s);
|
||||||
void camellia128_dec(camellia128_ctx_t* s, void* block);
|
void camellia128_dec(void* block, camellia128_ctx_t* s);
|
||||||
|
|
||||||
|
|
||||||
#endif /*CAMELLIA_H_*/
|
#endif /*CAMELLIA_H_*/
|
||||||
|
|
14
cast5.c
14
cast5.c
|
@ -113,17 +113,17 @@ void cast5_init_rM(uint8_t *klo, uint8_t *khi, uint8_t offset, uint8_t *src, boo
|
||||||
* @param key Pointer to binary key.
|
* @param key Pointer to binary key.
|
||||||
* @param keylength length of keydata in bits.
|
* @param keylength length of keydata in bits.
|
||||||
*/
|
*/
|
||||||
void cast5_init(cast5_ctx_t* s, uint8_t* key, uint8_t keylength){
|
void cast5_init(uint8_t* key, uint8_t keylength_b, cast5_ctx_t* s){
|
||||||
/* we migth return if the key is valid and if setup was sucessfull */
|
/* we migth return if the key is valid and if setup was sucessfull */
|
||||||
uint32_t x[4], z[4];
|
uint32_t x[4], z[4];
|
||||||
#define BPX ((uint8_t*)&(x[0]))
|
#define BPX ((uint8_t*)&(x[0]))
|
||||||
#define BPZ ((uint8_t*)&(z[0]))
|
#define BPZ ((uint8_t*)&(z[0]))
|
||||||
s->shortkey = (keylength<=80);
|
s->shortkey = (keylength_b<=80);
|
||||||
/* littel endian only! */
|
/* littel endian only! */
|
||||||
memset(&(x[0]), 0 ,16); /* set x to zero */
|
memset(&(x[0]), 0 ,16); /* set x to zero */
|
||||||
if(keylength > 128)
|
if(keylength_b > 128)
|
||||||
keylength=128;
|
keylength_b=128;
|
||||||
memcpy(&(x[0]), key, (keylength+7)/8);
|
memcpy(&(x[0]), key, (keylength_b+7)/8);
|
||||||
|
|
||||||
|
|
||||||
/* todo: merge a and b and compress the whole stuff */
|
/* todo: merge a and b and compress the whole stuff */
|
||||||
|
@ -275,7 +275,7 @@ uint32_t cast5_f3(uint32_t d, uint32_t m, uint8_t r){
|
||||||
* @param s Pointer to cast5 roundkeys (context)
|
* @param s Pointer to cast5 roundkeys (context)
|
||||||
* @param block Pointer to datablock
|
* @param block Pointer to datablock
|
||||||
*/
|
*/
|
||||||
void cast5_enc(cast5_ctx_t *s, void* block){
|
void cast5_enc(void* block, cast5_ctx_t *s){
|
||||||
uint32_t l,r, x, y;
|
uint32_t l,r, x, y;
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
cast5_f_t* f[]={cast5_f1,cast5_f2,cast5_f3};
|
cast5_f_t* f[]={cast5_f1,cast5_f2,cast5_f3};
|
||||||
|
@ -304,7 +304,7 @@ void cast5_enc(cast5_ctx_t *s, void* block){
|
||||||
* @param s Pointer to cast5 roundkeys (context)
|
* @param s Pointer to cast5 roundkeys (context)
|
||||||
* @param block Pointer to datablock
|
* @param block Pointer to datablock
|
||||||
*/
|
*/
|
||||||
void cast5_dec(cast5_ctx_t *s, void* block){
|
void cast5_dec(void* block, cast5_ctx_t *s){
|
||||||
uint32_t l,r, x, y;
|
uint32_t l,r, x, y;
|
||||||
int8_t i, rounds;
|
int8_t i, rounds;
|
||||||
cast5_f_t* f[]={cast5_f1,cast5_f2,cast5_f3};
|
cast5_f_t* f[]={cast5_f1,cast5_f2,cast5_f3};
|
||||||
|
|
8
cast5.h
8
cast5.h
|
@ -19,7 +19,7 @@
|
||||||
/*
|
/*
|
||||||
* File: cast5.h
|
* File: cast5.h
|
||||||
* Author: Daniel Otte
|
* Author: Daniel Otte
|
||||||
* Date: 26.07.2006
|
* Date: 2006-07-26
|
||||||
* License: GPL
|
* License: GPL
|
||||||
* Description: Implementation of the CAST5 (aka CAST-128) cipher algorithm as described in RFC 2144
|
* Description: Implementation of the CAST5 (aka CAST-128) cipher algorithm as described in RFC 2144
|
||||||
*
|
*
|
||||||
|
@ -48,9 +48,9 @@ typedef struct cast5_ctx_st{
|
||||||
bool shortkey;
|
bool shortkey;
|
||||||
} cast5_ctx_t;
|
} cast5_ctx_t;
|
||||||
|
|
||||||
void cast5_init(cast5_ctx_t* s, uint8_t* key, uint8_t keylength);
|
void cast5_init(uint8_t* key, uint8_t keylength_b, cast5_ctx_t* s);
|
||||||
void cast5_enc(cast5_ctx_t *s, void* block);
|
void cast5_enc(void* block, cast5_ctx_t *s);
|
||||||
void cast5_dec(cast5_ctx_t *s, void* block);
|
void cast5_dec(void* block, cast5_ctx_t *s);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -27,203 +27,82 @@
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
#include "camellia.h"
|
#include "camellia.h"
|
||||||
|
#include "nessie_bc_test.h"
|
||||||
|
#include "performance_test.h"
|
||||||
|
#include "cli.h"
|
||||||
|
|
||||||
|
char* cipher_name = "Camellia";
|
||||||
|
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <avr/pgmspace.h>
|
#include <avr/pgmspace.h>
|
||||||
|
|
||||||
|
|
||||||
#ifndef BOOL
|
|
||||||
#define BOOL
|
|
||||||
#ifndef __BOOL
|
|
||||||
#define __BOOL
|
|
||||||
#ifndef __BOOL__
|
|
||||||
#define __BOOL__
|
|
||||||
typedef enum{false=0,true=1} bool;
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* additional validation-functions *
|
* additional validation-functions *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
|
void camellia128_init_dummy(void* key, uint16_t keysize_b, void* ctx){
|
||||||
|
camellia128_init(key, ctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
void testrun_nessie_camellia(void){
|
||||||
|
nessie_bc_ctx.blocksize_B = 16;
|
||||||
|
nessie_bc_ctx.keysize_b = 128;
|
||||||
|
nessie_bc_ctx.name = cipher_name;
|
||||||
|
nessie_bc_ctx.ctx_size_B = sizeof(camellia128_ctx_t);
|
||||||
|
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)camellia128_enc;
|
||||||
|
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)camellia128_dec;
|
||||||
|
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)camellia128_init_dummy;
|
||||||
|
|
||||||
|
nessie_bc_run();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void test_performance_cast5(void){
|
||||||
|
uint64_t t;
|
||||||
|
char str[6];
|
||||||
|
uint8_t key[16], data[16];
|
||||||
|
camellia128_ctx_t ctx;
|
||||||
|
|
||||||
|
calibrateTimer();
|
||||||
|
print_overhead();
|
||||||
|
|
||||||
|
memset(key, 0, 16);
|
||||||
|
memset(data, 0, 16);
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
camellia128_init(key, &ctx);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
camellia128_enc(data, &ctx);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
camellia128_dec(data, &ctx);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
uart_putstr_P(PSTR("\r\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* self tests *
|
* self tests *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
void camellia128_ctx_dump(camellia128_ctx_t *s);
|
|
||||||
|
|
||||||
void test_encrypt(uint8_t *block, uint8_t *key, uint16_t keylength, bool print){
|
|
||||||
camellia128_ctx_t s;
|
|
||||||
if (print){
|
|
||||||
uart_putstr("\r\nCamellia (enc):\r\n key:\t\t");
|
|
||||||
uart_hexdump(key, keylength/8);
|
|
||||||
uart_putstr("\r\n plaintext:\t");
|
|
||||||
uart_hexdump(block, 16);
|
|
||||||
}
|
|
||||||
|
|
||||||
camellia128_init(&s, key);;
|
|
||||||
camellia128_enc(&s, block);
|
|
||||||
if (print){
|
|
||||||
uart_putstr("\r\n ciphertext:\t");
|
|
||||||
uart_hexdump(block, 16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_decrypt(uint8_t *block, uint8_t *key, uint16_t keylength, bool print){
|
|
||||||
camellia128_ctx_t s;
|
|
||||||
if (print){
|
|
||||||
uart_putstr("\r\nCamellia (dec):\r\n key:\t\t");
|
|
||||||
uart_hexdump(key, keylength/8);
|
|
||||||
uart_putstr("\r\n ciphertext:\t");
|
|
||||||
uart_hexdump(block, 16);
|
|
||||||
}
|
|
||||||
camellia128_init(&s, key);
|
|
||||||
camellia128_dec(&s, block);
|
|
||||||
if (print){
|
|
||||||
uart_putstr("\r\n plaintext:\t");
|
|
||||||
uart_hexdump(block, 16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void nessie_test_iterate(uint8_t *block, uint8_t *key){
|
|
||||||
uint16_t i;
|
|
||||||
test_encrypt(block, key, 128, true);
|
|
||||||
test_decrypt(block, key, 128, true);
|
|
||||||
uart_putstr("\r\n100 times:");
|
|
||||||
for(i=0; i<99; ++i){
|
|
||||||
test_encrypt(block, key, 128, false);
|
|
||||||
}
|
|
||||||
test_encrypt(block, key, 128, true);
|
|
||||||
uart_putstr("\r\n1000 times:");
|
|
||||||
for(i=0; i<(999-100); ++i){
|
|
||||||
test_encrypt(block, key, 128, false);
|
|
||||||
}
|
|
||||||
test_encrypt(block, key, 128, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void nessie_test_iterate_inv(uint8_t *block, uint8_t *key){
|
|
||||||
uint16_t i;
|
|
||||||
test_decrypt(block, key, 128, true);
|
|
||||||
test_encrypt(block, key, 128, true);
|
|
||||||
uart_putstr("\r\n100 times:");
|
|
||||||
for(i=0; i<99; ++i){
|
|
||||||
test_decrypt(block, key, 128, false);
|
|
||||||
}
|
|
||||||
test_encrypt(block, key, 128, true);
|
|
||||||
uart_putstr("\r\n1000 times:");
|
|
||||||
for(i=0; i<(999-100); ++i){
|
|
||||||
test_decrypt(block, key, 128, false);
|
|
||||||
}
|
|
||||||
test_decrypt(block, key, 128, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
prog_uint8_t ntt_test_values_in[16] = {
|
|
||||||
0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef,
|
|
||||||
0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10
|
|
||||||
};
|
|
||||||
|
|
||||||
prog_uint8_t ntt_test_values_out[16] = {
|
|
||||||
0x67, 0x67, 0x31, 0x38, 0x54, 0x96, 0x69, 0x73,
|
|
||||||
0x08, 0x57, 0x06, 0x56, 0x48, 0xea, 0xbe, 0x43
|
|
||||||
};
|
|
||||||
/* memcmp_P() is now implemented in avr-libc
|
|
||||||
int memcmp_P(const void *s1, PGM_P s2, size_t n){
|
|
||||||
uint8_t b;
|
|
||||||
while(n--){
|
|
||||||
b = pgm_read_byte_near(s2);
|
|
||||||
if( *((uint8_t*)s1) != b)
|
|
||||||
return(*((uint8_t*)s1)-b);
|
|
||||||
++s1; ++s2;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
void testrun_camellia(void){
|
|
||||||
/* we run the NESSIE test for Camellia here see
|
|
||||||
* https://www.cosic.esat.kuleuven.be/nessie/testvectors/bc/camellia/Camellia-128-128.verified.test-vectors
|
|
||||||
* for the vectors
|
|
||||||
*/
|
|
||||||
unsigned j, setn;
|
|
||||||
uint8_t block[16];
|
|
||||||
uint8_t key[16];
|
|
||||||
memcpy_P(block, ntt_test_values_in, 16);
|
|
||||||
memcpy_P(key, ntt_test_values_in, 16);
|
|
||||||
test_encrypt(block, key, 128, true);
|
|
||||||
if(memcmp_P(block, ntt_test_values_out, 16)){
|
|
||||||
uart_putstr("\t[FAILED]\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uart_putstr("\t[OK]");
|
|
||||||
test_decrypt(block, key, 128, true);
|
|
||||||
if(memcmp_P(block, ntt_test_values_in, 16)){
|
|
||||||
uart_putstr("\t[FAILED]\r\n");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
uart_putstr("\t[OK]");
|
|
||||||
|
|
||||||
/* test set #1 & #2 */
|
|
||||||
setn=1;
|
|
||||||
for(setn=1; setn<=2; ++setn){
|
|
||||||
for(j=0; j<128; ++j){
|
|
||||||
uart_putstr("\r\n\r\n### SET: ");
|
|
||||||
uart_hexdump(&setn,1);
|
|
||||||
uart_putstr(" Vector: ");
|
|
||||||
uart_hexdump(&j,1);
|
|
||||||
|
|
||||||
memset(block, 0, 16);
|
|
||||||
memset(key, 0, 16);
|
|
||||||
((setn&0x1)?key:block)[j>>3] = 1<<(((~j)&0x7));
|
|
||||||
nessie_test_iterate(block, key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* test set #3 */
|
|
||||||
for(j=0; j<256; ++j){
|
|
||||||
uart_putstr("\r\n### SET: ");
|
|
||||||
uart_hexdump(&setn,1);
|
|
||||||
uart_putstr(" Vector: ");
|
|
||||||
uart_hexdump(&j,1);
|
|
||||||
|
|
||||||
memset(block, j, 16);
|
|
||||||
memset(key, 0, 16);
|
|
||||||
nessie_test_iterate(block, key);
|
|
||||||
}
|
|
||||||
setn++;
|
|
||||||
/* test set #4 (some strange values*/
|
|
||||||
setn++;
|
|
||||||
/* test ser #5 & #6 (same as 1&2 but enc and dec exchanged)*/
|
|
||||||
for(setn=5; setn<=6; ++setn){
|
|
||||||
for(j=0; j<128; ++j){
|
|
||||||
uart_putstr("\r\n\r\n### SET: ");
|
|
||||||
uart_hexdump(&setn,1);
|
|
||||||
uart_putstr(" Vector: ");
|
|
||||||
uart_hexdump(&j,1);
|
|
||||||
|
|
||||||
memset(block, 0, 16);
|
|
||||||
memset(key, 0, 16);
|
|
||||||
((setn&0x1)?key:block)[j>>3] = 1<<(((~j)&0x7));
|
|
||||||
nessie_test_iterate_inv(block, key);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
/* test set #7 */
|
|
||||||
for(j=0; j<256; ++j){
|
|
||||||
uart_putstr("\r\n### SET: ");
|
|
||||||
uart_hexdump(&setn,1);
|
|
||||||
uart_putstr(" Vector: ");
|
|
||||||
uart_hexdump(&j,1);
|
|
||||||
|
|
||||||
memset(block, j, 16);
|
|
||||||
memset(key, 0, 16);
|
|
||||||
nessie_test_iterate_inv(block, key);
|
|
||||||
}
|
|
||||||
setn++;
|
|
||||||
/* test set #4 (some strange values*/
|
|
||||||
setn++;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* main *
|
* main *
|
||||||
|
@ -236,16 +115,21 @@ int main (void){
|
||||||
DEBUG_INIT();
|
DEBUG_INIT();
|
||||||
uart_putstr("\r\n");
|
uart_putstr("\r\n");
|
||||||
|
|
||||||
uart_putstr("\r\n\r\nCrypto-VS (Camellia)\r\nloaded and running\r\n");
|
uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
|
||||||
restart:
|
uart_putstr(cipher_name);
|
||||||
|
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
||||||
|
|
||||||
|
PGM_P u = PSTR("nessie\0test\0performance\0");
|
||||||
|
void_fpt v[] = {testrun_nessie_camellia, testrun_nessie_camellia, test_performance_cast5};
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
|
if(execcommand_d0_P(str, u, v)<0){
|
||||||
testrun_camellia();
|
uart_putstr_P(PSTR("\r\nunknown command\r\n"));
|
||||||
goto restart;
|
}
|
||||||
continue;
|
continue;
|
||||||
error:
|
error:
|
||||||
uart_putstr("ERROR\r\n");
|
uart_putstr("ERROR\r\n");
|
||||||
} /* while (1) */
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,32 +40,15 @@ char* cipher_name = "cast-128 (cast5)";
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* additional validation-functions *
|
* additional validation-functions *
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
/*
|
|
||||||
void cast5_init(cast5_ctx_t* s, uint8_t* key, uint8_t keylength);
|
|
||||||
void cast5_enc(cast5_ctx_t *s, void* block);
|
|
||||||
void cast5_dec(cast5_ctx_t *s, void* block);
|
|
||||||
*/
|
|
||||||
|
|
||||||
void cast5_init_dummy(uint8_t* key, uint8_t keylength_b, cast5_ctx_t* ctx){
|
void testrun_nessie_cast5(void){
|
||||||
cast5_init(ctx, key, keylength_b);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cast5_enc_dummy(void* buffer, cast5_ctx_t* ctx){
|
|
||||||
cast5_enc(ctx, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void cast5_dec_dummy(void* buffer, cast5_ctx_t* ctx){
|
|
||||||
cast5_dec(ctx, buffer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void test_nessie_cast5(void){
|
|
||||||
nessie_bc_ctx.blocksize_B = 8;
|
nessie_bc_ctx.blocksize_B = 8;
|
||||||
nessie_bc_ctx.keysize_b = 128;
|
nessie_bc_ctx.keysize_b = 128;
|
||||||
nessie_bc_ctx.name = cipher_name;
|
nessie_bc_ctx.name = cipher_name;
|
||||||
nessie_bc_ctx.ctx_size_B = sizeof(cast5_ctx_t);
|
nessie_bc_ctx.ctx_size_B = sizeof(cast5_ctx_t);
|
||||||
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)cast5_enc_dummy;
|
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt)cast5_enc;
|
||||||
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)cast5_dec_dummy;
|
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt)cast5_dec;
|
||||||
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)cast5_init_dummy;
|
nessie_bc_ctx.cipher_genctx = (nessie_bc_gen_fpt)cast5_init;
|
||||||
|
|
||||||
nessie_bc_run();
|
nessie_bc_run();
|
||||||
}
|
}
|
||||||
|
@ -100,9 +83,8 @@ void test_encrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){
|
||||||
uart_putstr("\r\n plaintext:\t");
|
uart_putstr("\r\n plaintext:\t");
|
||||||
uart_hexdump(block, 8);
|
uart_hexdump(block, 8);
|
||||||
}
|
}
|
||||||
cast5_init(&s, key, keylength);
|
cast5_init(key, keylength, &s);
|
||||||
// cast5_ctx_dump(&s);
|
cast5_enc(block, &s);
|
||||||
cast5_enc(&s, block);
|
|
||||||
if (print){
|
if (print){
|
||||||
uart_putstr("\r\n ciphertext:\t");
|
uart_putstr("\r\n ciphertext:\t");
|
||||||
uart_hexdump(block, 8);
|
uart_hexdump(block, 8);
|
||||||
|
@ -117,9 +99,8 @@ void test_decrypt(uint8_t *block, uint8_t *key, uint8_t keylength, bool print){
|
||||||
uart_putstr("\r\n ciphertext:\t");
|
uart_putstr("\r\n ciphertext:\t");
|
||||||
uart_hexdump(block, 8);
|
uart_hexdump(block, 8);
|
||||||
}
|
}
|
||||||
cast5_init(&s, key, keylength);
|
cast5_init(key, keylength, &s);
|
||||||
// cast5_ctx_dump(&s);
|
cast5_dec(block, &s);
|
||||||
cast5_dec(&s, block);
|
|
||||||
if (print){
|
if (print){
|
||||||
uart_putstr("\r\n plaintext:\t");
|
uart_putstr("\r\n plaintext:\t");
|
||||||
uart_hexdump(block, 8);
|
uart_hexdump(block, 8);
|
||||||
|
@ -170,28 +151,20 @@ void testrun_cast5(void){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void test_performance_cast5(void){
|
void testrun_performance_cast5(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[6];
|
char str[6];
|
||||||
uint8_t key[16], data[16];
|
uint8_t key[16], data[16];
|
||||||
cast5_ctx_t ctx;
|
cast5_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 16);
|
memset(key, 0, 16);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
cast5_init(&ctx, key, 128);
|
cast5_init(key, 128, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
@ -199,7 +172,7 @@ void test_performance_cast5(void){
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
cast5_enc(&ctx, data);
|
cast5_enc(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
|
uart_putstr_P(PSTR("\r\n\tencrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
@ -207,7 +180,7 @@ void test_performance_cast5(void){
|
||||||
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
cast5_dec(&ctx, data);
|
cast5_dec(data, &ctx);
|
||||||
t = stopTimer();
|
t = stopTimer();
|
||||||
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
uart_putstr_P(PSTR("\r\n\tdecrypt time: "));
|
||||||
ultoa((unsigned long)t, str, 10);
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
@ -232,7 +205,7 @@ int main (void){
|
||||||
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
||||||
|
|
||||||
PGM_P u = PSTR("nessie\0test\0performance\0");
|
PGM_P u = PSTR("nessie\0test\0performance\0");
|
||||||
void_fpt v[] = {test_nessie_cast5, test_nessie_cast5, test_performance_cast5};
|
void_fpt v[] = {testrun_nessie_cast5, testrun_cast5, testrun_performance_cast5};
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
|
|
|
@ -67,21 +67,13 @@ void testrun_nessie_des(void){
|
||||||
|
|
||||||
|
|
||||||
void testrun_performance_des(void){
|
void testrun_performance_des(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[8], data[8];
|
uint8_t key[8], data[8];
|
||||||
|
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 8);
|
memset(key, 0, 8);
|
||||||
memset(data, 0, 8);
|
memset(data, 0, 8);
|
||||||
|
|
|
@ -62,20 +62,12 @@ void testrun_entropium(void){
|
||||||
|
|
||||||
|
|
||||||
void testrun_performance_entropium(void){
|
void testrun_performance_entropium(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t data[32];
|
uint8_t data[32];
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
startTimer(1);
|
startTimer(1);
|
||||||
entropium_addEntropy(128, data);
|
entropium_addEntropy(128, data);
|
||||||
|
|
|
@ -121,21 +121,13 @@ void testrun_std_grain(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_performance_grain(void){
|
void testrun_performance_grain(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[10], iv[8];
|
uint8_t key[10], iv[8];
|
||||||
grain_ctx_t ctx;
|
grain_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 10);
|
memset(key, 0, 10);
|
||||||
memset(iv, 0, 8);
|
memset(iv, 0, 8);
|
||||||
|
|
|
@ -28,9 +28,11 @@
|
||||||
|
|
||||||
#include "md5.h"
|
#include "md5.h"
|
||||||
#include "nessie_hash_test.h"
|
#include "nessie_hash_test.h"
|
||||||
|
#include "performance_test.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
|
||||||
char* algo_name = "MD5";
|
char* algo_name = "MD5";
|
||||||
|
@ -100,6 +102,43 @@ void testrun_md5(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void testrun_performance_md5(void){
|
||||||
|
uint64_t t;
|
||||||
|
char str[16];
|
||||||
|
uint8_t data[32];
|
||||||
|
md5_ctx_t ctx;
|
||||||
|
|
||||||
|
calibrateTimer();
|
||||||
|
print_overhead();
|
||||||
|
|
||||||
|
memset(data, 0, 32);
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
md5_init(&ctx);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
md5_nextBlock(&ctx, data);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tone-block time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
md5_lastBlock(&ctx, data, 0);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tlast block time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
uart_putstr_P(PSTR("\r\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* main *
|
* main *
|
||||||
|
@ -113,8 +152,8 @@ int main (void){
|
||||||
uart_putstr("\r\n");
|
uart_putstr("\r\n");
|
||||||
|
|
||||||
uart_putstr("\r\n\r\nCrypto-VS (MD5)\r\nloaded and running\r\n");
|
uart_putstr("\r\n\r\nCrypto-VS (MD5)\r\nloaded and running\r\n");
|
||||||
PGM_P u = PSTR("nessie\0test\0");
|
PGM_P u = PSTR("nessie\0test\0performance\0");
|
||||||
void_fpt v[] = {testrun_nessie_md5, testrun_md5};
|
void_fpt v[] = {testrun_nessie_md5, testrun_md5, testrun_performance_md5};
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
|
|
|
@ -167,21 +167,13 @@ void testrun_stdtest_noekeon(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_performance_noekeon(void){
|
void testrun_performance_noekeon(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[16], data[16];
|
uint8_t key[16], data[16];
|
||||||
noekeon_ctx_t ctx;
|
noekeon_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 16);
|
memset(key, 0, 16);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
|
@ -61,21 +61,13 @@ void testrun_nessie_rc5(void){
|
||||||
|
|
||||||
|
|
||||||
void testrun_performance_rc5(void){
|
void testrun_performance_rc5(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[16], data[16];
|
uint8_t key[16], data[16];
|
||||||
rc5_ctx_t ctx;
|
rc5_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 16);
|
memset(key, 0, 16);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
|
@ -68,21 +68,13 @@ void testrun_nessie_rc6(void){
|
||||||
|
|
||||||
|
|
||||||
void testrun_performance_rc6(void){
|
void testrun_performance_rc6(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[16], data[16];
|
uint8_t key[16], data[16];
|
||||||
rc6_ctx_t ctx;
|
rc6_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 16);
|
memset(key, 0, 16);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
|
@ -64,21 +64,13 @@ void testrun_nessie_seed(void){
|
||||||
|
|
||||||
|
|
||||||
void testrun_performance_seed(void){
|
void testrun_performance_seed(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[16], data[16];
|
uint8_t key[16], data[16];
|
||||||
seed_ctx_t ctx;
|
seed_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 16);
|
memset(key, 0, 16);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
|
@ -64,21 +64,13 @@ void testrun_nessie_serpent(void){
|
||||||
|
|
||||||
|
|
||||||
void testrun_performance_serpent(void){
|
void testrun_performance_serpent(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[32], data[16];
|
uint8_t key[32], data[16];
|
||||||
serpent_ctx_t ctx;
|
serpent_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 32);
|
memset(key, 0, 32);
|
||||||
memset(data, 0, 16);
|
memset(data, 0, 16);
|
||||||
|
|
|
@ -28,9 +28,11 @@
|
||||||
|
|
||||||
#include "sha1.h"
|
#include "sha1.h"
|
||||||
#include "nessie_hash_test.h"
|
#include "nessie_hash_test.h"
|
||||||
|
#include "performance_test.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
|
||||||
char* algo_name = "SHA-1";
|
char* algo_name = "SHA-1";
|
||||||
|
@ -102,6 +104,42 @@ void testrun_sha1(void){
|
||||||
uart_putstr("\r\nx");
|
uart_putstr("\r\nx");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testrun_performance_sha1(void){
|
||||||
|
uint64_t t;
|
||||||
|
char str[16];
|
||||||
|
uint8_t data[32];
|
||||||
|
sha1_ctx_t ctx;
|
||||||
|
|
||||||
|
calibrateTimer();
|
||||||
|
print_overhead();
|
||||||
|
|
||||||
|
memset(data, 0, 32);
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
sha1_init(&ctx);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
sha1_nextBlock(&ctx, data);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tone-block time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
sha1_lastBlock(&ctx, data, 0);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tlast block time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
uart_putstr_P(PSTR("\r\n"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
|
@ -116,8 +154,8 @@ int main (void){
|
||||||
|
|
||||||
uart_putstr("\r\n\r\nCrypto-VS (SHA-1)\r\nloaded and running\r\n");
|
uart_putstr("\r\n\r\nCrypto-VS (SHA-1)\r\nloaded and running\r\n");
|
||||||
|
|
||||||
PGM_P u = PSTR("nessie\0test\0");
|
PGM_P u = PSTR("nessie\0test\0performance\0");
|
||||||
void_fpt v[] = {testrun_nessie_sha1, testrun_sha1};
|
void_fpt v[] = {testrun_nessie_sha1, testrun_sha1, testrun_performance_sha1};
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
|
|
|
@ -28,9 +28,11 @@
|
||||||
|
|
||||||
#include "sha256.h"
|
#include "sha256.h"
|
||||||
#include "nessie_hash_test.h"
|
#include "nessie_hash_test.h"
|
||||||
|
#include "performance_test.h"
|
||||||
|
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
|
|
||||||
char* algo_name = "SHA-256";
|
char* algo_name = "SHA-256";
|
||||||
|
@ -59,7 +61,42 @@ void testrun_nessie_sha256(void){
|
||||||
nessie_hash_run();
|
nessie_hash_run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void testrun_performance_sha256(void){
|
||||||
|
uint64_t t;
|
||||||
|
char str[16];
|
||||||
|
uint8_t data[32];
|
||||||
|
sha256_ctx_t ctx;
|
||||||
|
|
||||||
|
calibrateTimer();
|
||||||
|
print_overhead();
|
||||||
|
|
||||||
|
memset(data, 0, 32);
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
sha256_init(&ctx);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tctx-gen time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
sha256_nextBlock(&ctx, data);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tone-block time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
|
||||||
|
startTimer(1);
|
||||||
|
sha256_lastBlock(&ctx, data, 0);
|
||||||
|
t = stopTimer();
|
||||||
|
uart_putstr_P(PSTR("\r\n\tlast block time: "));
|
||||||
|
ultoa((unsigned long)t, str, 10);
|
||||||
|
uart_putstr(str);
|
||||||
|
|
||||||
|
uart_putstr_P(PSTR("\r\n"));
|
||||||
|
}
|
||||||
|
|
||||||
/*****************************************************************************
|
/*****************************************************************************
|
||||||
* main *
|
* main *
|
||||||
|
@ -74,8 +111,8 @@ int main (void){
|
||||||
uart_putstr(algo_name);
|
uart_putstr(algo_name);
|
||||||
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
|
||||||
|
|
||||||
PGM_P u = PSTR("nessie\0test\0");
|
PGM_P u = PSTR("nessie\0test\0performance\0");
|
||||||
void_fpt v[] = {testrun_nessie_sha256, testrun_nessie_sha256};
|
void_fpt v[] = {testrun_nessie_sha256, testrun_nessie_sha256, testrun_performance_sha256};
|
||||||
|
|
||||||
while(1){
|
while(1){
|
||||||
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;}
|
||||||
|
|
|
@ -71,20 +71,12 @@ void testrun_nessie_shabea(void){
|
||||||
|
|
||||||
|
|
||||||
void testrun_performance_shabea(void){
|
void testrun_performance_shabea(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[32], data[32];
|
uint8_t key[32], data[32];
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 32);
|
memset(key, 0, 32);
|
||||||
memset(data, 0, 32);
|
memset(data, 0, 32);
|
||||||
|
|
|
@ -59,20 +59,12 @@ void testrun_nessie_skipjack(void){
|
||||||
|
|
||||||
|
|
||||||
void testrun_performance_skipjack(void){
|
void testrun_performance_skipjack(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[10], data[8];
|
uint8_t key[10], data[8];
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 10);
|
memset(key, 0, 10);
|
||||||
memset(data, 0, 8);
|
memset(data, 0, 8);
|
||||||
|
|
|
@ -67,21 +67,13 @@ void testrun_nessie_tdes(void){
|
||||||
|
|
||||||
|
|
||||||
void testrun_performance_tdes(void){
|
void testrun_performance_tdes(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[8*3], data[8];
|
uint8_t key[8*3], data[8];
|
||||||
|
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 8*3);
|
memset(key, 0, 8*3);
|
||||||
memset(data, 0, 8);
|
memset(data, 0, 8);
|
||||||
|
|
|
@ -67,21 +67,13 @@ void testrun_nessie_trivium(void){
|
||||||
}
|
}
|
||||||
|
|
||||||
void testrun_performance_trivium(void){
|
void testrun_performance_trivium(void){
|
||||||
uint16_t i,c;
|
|
||||||
uint64_t t;
|
uint64_t t;
|
||||||
char str[16];
|
char str[16];
|
||||||
uint8_t key[10], iv[10];
|
uint8_t key[10], iv[10];
|
||||||
trivium_ctx_t ctx;
|
trivium_ctx_t ctx;
|
||||||
|
|
||||||
calibrateTimer();
|
calibrateTimer();
|
||||||
getOverhead(&c, &i);
|
print_overhead();
|
||||||
uart_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
|
|
||||||
utoa(c, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tconst overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
utoa(i, str, 10);
|
|
||||||
uart_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
|
|
||||||
uart_putstr(str);
|
|
||||||
|
|
||||||
memset(key, 0, 10);
|
memset(key, 0, 10);
|
||||||
memset(iv, 0, 10);
|
memset(iv, 0, 10);
|
||||||
|
|
|
@ -7,7 +7,8 @@ BLOCK_CIPHERS += $(ALGO_NAME)
|
||||||
# main-camellia-test.o debug.o uart.o serial-tools.o camellia.o camellia-asm.o
|
# main-camellia-test.o debug.o uart.o serial-tools.o camellia.o camellia-asm.o
|
||||||
$(ALGO_NAME)_OBJ := camellia.o camellia-asm.o
|
$(ALGO_NAME)_OBJ := camellia.o camellia-asm.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-camellia-test.o debug.o uart.o serial-tools.o \
|
$(ALGO_NAME)_TEST_BIN := main-camellia-test.o debug.o uart.o serial-tools.o \
|
||||||
camellia.o camellia-asm.o
|
camellia.o camellia-asm.o nessie_bc_test.o \
|
||||||
|
nessie_common.o cli.o performance_test.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ HASHES += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := md5.o
|
$(ALGO_NAME)_OBJ := md5.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-md5-test.o debug.o uart.o serial-tools.o md5.o \
|
$(ALGO_NAME)_TEST_BIN := main-md5-test.o debug.o uart.o serial-tools.o md5.o \
|
||||||
nessie_hash_test.o nessie_common.o cli.o
|
nessie_hash_test.o nessie_common.o cli.o performance_test.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ HASHES += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := sha1-asm.o
|
$(ALGO_NAME)_OBJ := sha1-asm.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-sha1-test.o debug.o uart.o serial-tools.o \
|
$(ALGO_NAME)_TEST_BIN := main-sha1-test.o debug.o uart.o serial-tools.o \
|
||||||
sha1-asm.o nessie_hash_test.o nessie_common.o cli.o
|
sha1-asm.o nessie_hash_test.o nessie_common.o cli.o \
|
||||||
|
performance_test.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ HASHES += $(ALGO_NAME)
|
||||||
|
|
||||||
$(ALGO_NAME)_OBJ := sha256-asm.o
|
$(ALGO_NAME)_OBJ := sha256-asm.o
|
||||||
$(ALGO_NAME)_TEST_BIN := main-sha256-test.o debug.o uart.o serial-tools.o \
|
$(ALGO_NAME)_TEST_BIN := main-sha256-test.o debug.o uart.o serial-tools.o \
|
||||||
sha256-asm.o nessie_hash_test.o nessie_common.o cli.o
|
sha256-asm.o nessie_hash_test.o nessie_common.o cli.o \
|
||||||
|
performance_test.o
|
||||||
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
$(ALGO_NAME)_NESSIE_TEST := "nessie"
|
||||||
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
$(ALGO_NAME)_PEROFRMANCE_TEST := "performance"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue