* this function initialises the context
* param1: 16-bit pointer to the key
* given in r24:r25
- * param2: 8-bit integer indicating keylength in byte
- * given in r22
+ * param2: 8-bit integer indicating keylength in bits
+ * given in r22:r23
* param3: 16-bit pointer to a ctx struct
* given in r20:r21
*/
st X+, r1
st X+, r1 /* X points to S */
movw r20, r26 /* store pointer to S in r21:r20 */
-
+ lsr r23
+ ror r22
+ lsr r23
+ ror r22
+ lsr r23
+ ror r22
1:
st X+, r1
inc r1
* length is length of key in bytes!
*/
-void arcfour_init(const void *key, uint8_t length_B, arcfour_ctx_t *ctx){
+void arcfour_init(const void *key, uint16_t length_b, arcfour_ctx_t *ctx){
uint8_t t;
+ uint8_t length_B = length_b/8;
uint16_t x,y=0;
for(x=0; x<= 255; ++x)
ctx->s[x]=x;
* the supplied key of the given length.
* \param ctx pointer to the context
* \param key pointer to the key
- * \param length_B length of the key in bytes (between 1 and 255)
+ * \param length_b length of the key in bits (between 8 and 2048)
*/
-void arcfour_init(const void *key, uint8_t length_B, arcfour_ctx_t *ctx);
+void arcfour_init(const void *key, uint16_t length_b, arcfour_ctx_t *ctx);
/** \fn uint8_t arcfour_gen(arcfour_ctx_t *ctx)
* \brief generates a byte of keystream
*/
#include <stdint.h>
+#include <stdlib.h>
#include <avr/pgmspace.h>
#include "keysize_descriptor.h"
uint8_t type;
uint16_t keysize;
type = pgm_read_byte(ks_desc);
- if(type==KS_TYPE_LIST)
+ if(type==KS_TYPE_LIST){
ks_desc = (uint8_t*)ks_desc + 1;
+ }
ks_desc = (uint8_t*)ks_desc + 1;
keysize = pgm_read_word(ks_desc);
return keysize;
}
-
+uint16_t get_keysizes(PGM_VOID_P ks_desc, uint16_t** list){
+ uint8_t type;
+ uint16_t items;
+ uint8_t i;
+ type = pgm_read_byte(ks_desc);
+ ks_desc = (uint8_t*)ks_desc + 1;
+ if(type==KS_TYPE_LIST){
+ items = pgm_read_byte(ks_desc);
+ ks_desc = (uint8_t*)ks_desc + 1;
+ if(!*list){
+ *list = malloc(items*2);
+ if(!*list){
+ return 0;
+ }
+ }
+ for(i=0; i<items; ++i){
+ ((uint16_t*)(*list))[i] = pgm_read_word(ks_desc);
+ ks_desc = (uint8_t*)ks_desc + 2;
+ }
+ return items;
+ }
+ if(type==KS_TYPE_ARG_RANGE){
+ uint16_t min, max, distance, offset;
+ min = pgm_read_word(ks_desc);
+ ks_desc = (uint8_t*)ks_desc + 2;
+ max = pgm_read_word(ks_desc);
+ ks_desc = (uint8_t*)ks_desc + 2;
+ distance = pgm_read_word(ks_desc);
+ ks_desc = (uint8_t*)ks_desc + 2;
+ offset = pgm_read_word(ks_desc);
+ ks_desc = (uint8_t*)ks_desc + 2;
+ items = (max-min)/distance+1;
+ if(min%distance!=offset){
+ --items;
+ min += (distance-(min%distance-offset))%distance;
+ }
+ if(!*list){
+ *list = malloc(items*2);
+ if(!*list){
+ return 0;
+ }
+ }
+ i=0;
+ while(min<max){
+ ((uint16_t*)*list)[i++] = min;
+ min += distance;
+ }
+ return i;
+ }
+ if(type==KS_TYPE_RANGE){
+ uint16_t min, max, distance=8, offset=0;
+ min = pgm_read_word(ks_desc);
+ ks_desc = (uint8_t*)ks_desc + 2;
+ max = pgm_read_word(ks_desc);
+ items = (max-min)/distance+1;
+ if(min%distance!=offset){
+ --items;
+ min += (distance-(min%distance-offset))%distance;
+ }
+ if(!*list){
+ *list = malloc(items*2);
+ if(!*list){
+ return 0;
+ }
+ }
+ i=0;
+ while(min<max){
+ ((uint16_t*)*list)[i++] = min;
+ min += distance;
+ }
+ return i;
+ }
+ return 0;
+}
uint8_t is_valid_keysize_P(PGM_VOID_P ks_desc, uint16_t keysize);
uint16_t get_keysize(PGM_VOID_P ks_desc);
+uint16_t get_keysizes(PGM_VOID_P ks_desc, uint16_t** list);
+
+
#endif /* KEYSIZE_DESCRIPTOR_H_ */
$(ALGO_NAME)_DIR := arcfour/
$(ALGO_NAME)_OBJ := arcfour-asm.o
-$(ALGO_NAME)_TEST_BIN := main-arcfour-test.o $(CLI_STD) \
- nessie_stream_test.o nessie_common.o performance_test.o
+$(ALGO_NAME)_INCDIR := memxor/ scal/
+$(ALGO_NAME)_TEST_BIN := main-arcfour-test.o $(CLI_STD) $(SCAL_STD) scal_arcfour.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
STREAM_CIPHERS += $(ALGO_NAME)
$(ALGO_NAME)_DIR := arcfour/
+$(ALGO_NAME)_INCDIR := memxor/ scal/
$(ALGO_NAME)_OBJ := arcfour.o
-$(ALGO_NAME)_TEST_BIN := main-arcfour-test.o $(CLI_STD) nessie_stream_test.o nessie_common.o performance_test.o
+$(ALGO_NAME)_TEST_BIN := main-arcfour-test.o $(CLI_STD) $(SCAL_STD) scal_arcfour.o
$(ALGO_NAME)_NESSIE_TEST := "nessie"
$(ALGO_NAME)_PERFORMANCE_TEST := "performance"
--- /dev/null
+/* scal-basic.c */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <avr/pgmspace.h>
+#include "streamcipher_descriptor.h"
+#include "keysize_descriptor.h"
+
+uint8_t scal_cipher_init(const scdesc_t* cipher_descriptor,
+ const void* key, uint16_t keysize_b,
+ const void* iv, uint16_t ivsize_b, scgen_ctx_t* ctx){
+ ctx->buffer = NULL;
+ ctx->ctx = NULL;
+
+ if(!is_valid_keysize_P((PGM_VOID_P)pgm_read_word(&(cipher_descriptor->valid_keysize_desc)), keysize_b)){
+ return 1;
+ }
+ if(!is_valid_keysize_P((PGM_VOID_P)pgm_read_word(&(cipher_descriptor->valid_ivsize_desc)), ivsize_b)){
+ return 2;
+ }
+ uint8_t flags;
+ void_fpt init_fpt;
+ flags = pgm_read_byte(&(cipher_descriptor->flags));
+ ctx->desc_ptr = cipher_descriptor;
+ ctx->keysize = keysize_b;
+ ctx->ivsize = ivsize_b;
+ ctx->ctx = malloc(pgm_read_word(&(cipher_descriptor->ctxsize_B)));
+ if(ctx->ctx==NULL){
+ return 3;
+ }
+ init_fpt = (void_fpt)pgm_read_word(&(cipher_descriptor->init));
+ switch(flags&SC_INIT_TYPE){
+ case SC_INIT_TYPE_1:
+ ((sc_init1_fpt)init_fpt)(key, ctx->ctx);
+ break;
+ case SC_INIT_TYPE_2:
+ ((sc_init2_fpt)init_fpt)(key, iv, ctx->ctx);
+ break;
+ case SC_INIT_TYPE_3:
+ ((sc_init3_fpt)init_fpt)(key, keysize_b, ctx->ctx);
+ break;
+ case SC_INIT_TYPE_4:
+ ((sc_init4_fpt)init_fpt)(key, keysize_b, iv, ctx->ctx);
+ break;
+ case SC_INIT_TYPE_5:
+ ((sc_init5_fpt)init_fpt)(key, keysize_b, iv, ivsize_b, ctx->ctx);
+ break;
+ default:
+ return 4;
+ }
+ uint16_t blocksize_b;
+ blocksize_b = pgm_read_word(&(cipher_descriptor->gensize_b));
+ if(blocksize_b>8){
+ ctx->buffer=malloc((blocksize_b+7)/8);
+ if(ctx->buffer==NULL){
+ return 5;
+ }
+ ctx->index=0;
+ }
+ return 0;
+}
+
+
+void scal_cipher_free(scgen_ctx_t* ctx){
+ if(ctx->buffer){
+ free(ctx->buffer);
+ }
+ if(ctx->ctx){
+ free(ctx->ctx);
+ }
+}
+
+uint8_t scal_cipher_gen_byte(scgen_ctx_t* ctx){
+ uint8_t flags;
+ uint16_t blocksize_b;
+ void_fpt gen_fpt;
+ flags = pgm_read_byte(&(ctx->desc_ptr->flags));
+ blocksize_b = pgm_read_word(&(ctx->desc_ptr->gensize_b));
+ gen_fpt = (void_fpt)(pgm_read_word(&(ctx->desc_ptr->gen.genvoid)));
+
+ if(blocksize_b==8){
+ if((flags&SC_GEN_TYPE)==SC_GEN_TYPE_1){
+ return ((sc_gen1_fpt)gen_fpt)(ctx->ctx);
+ }else{
+ uint8_t r;
+ ((sc_gen2_fpt)gen_fpt)(&r, ctx->ctx);
+ return r;
+ }
+ }
+ if(blocksize_b<8){
+ uint8_t r=0;
+ uint8_t fill=0;
+ do{
+ r |= ((((sc_gen1_fpt)gen_fpt)(ctx->ctx))&(0xff<<(8-blocksize_b)))>>fill;
+ fill += blocksize_b;
+ }while(fill<8);
+ return r;
+ }else{
+ uint8_t r;
+ if(ctx->index==0){
+ ((sc_gen2_fpt)gen_fpt)(ctx->buffer, ctx->ctx);
+ ctx->index = blocksize_b;
+ }
+ r=ctx->buffer[(blocksize_b-ctx->index)/8];
+ ctx->index -= 8;
+ return r;
+ }
+}
+
+void scal_cipher_gen_block(void* block, scgen_ctx_t* ctx){
+ uint8_t flags;
+ uint16_t blocksize_b;
+ void_fpt gen_fpt;
+ flags = pgm_read_byte(&(ctx->desc_ptr->flags));
+ blocksize_b = pgm_read_word(&(ctx->desc_ptr->gensize_b));
+ gen_fpt = (void_fpt)pgm_read_word(&(ctx->desc_ptr->gen));
+ if((flags&SC_GEN_TYPE)==SC_GEN_TYPE_1){
+ *((uint8_t*)block) = ((sc_gen1_fpt)gen_fpt)(ctx->ctx);
+ }else{
+ ((sc_gen2_fpt)gen_fpt)(block, ctx->ctx);
+ }
+}
+
+void scal_cipher_gen_fillblock(void* block, uint16_t blocksize_B, scgen_ctx_t* ctx){
+ while(blocksize_B){
+ *((uint8_t*)block) = scal_cipher_gen_byte(ctx);
+ block = (uint8_t*)block + 1;
+ blocksize_B -= 1;
+ }
+}
+
+uint16_t scal_cipher_getBlocksize_b(const scdesc_t* desc){
+ uint16_t blocksize_b;
+ blocksize_b = pgm_read_word(&(desc->gensize_b));
+ return blocksize_b;
+}
+
+PGM_VOID_P scal_cipher_getKeysizeDesc(const scdesc_t* desc){
+ return (PGM_VOID_P)pgm_read_word(&(desc->valid_keysize_desc));
+}
+
+PGM_VOID_P scal_cipher_getIVsizeDesc(const scdesc_t* desc){
+ return (PGM_VOID_P)pgm_read_word(&(desc->valid_ivsize_desc));
+}
+
+
--- /dev/null
+/* scal-basic.h */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef SCAL_BASIC_H_
+#define SCAL_BASIC_H_
+
+#include <stdlib.h>
+#include <stdint.h>
+#include "streamcipher_descriptor.h"
+#include "keysize_descriptor.h"
+#include <avr/pgmspace.h>
+
+uint8_t scal_cipher_init(const scdesc_t* cipher_descriptor,
+ const void* key, uint16_t keysize_b,
+ const void* iv, uint16_t ivsize_b, scgen_ctx_t* ctx);
+void scal_cipher_free(scgen_ctx_t* ctx);
+uint8_t scal_cipher_gen_byte(scgen_ctx_t* ctx);
+void scal_cipher_gen_block(void* block, scgen_ctx_t* ctx);
+void scal_cipher_gen_fillblock(void* block, uint16_t blocksize_B, scgen_ctx_t* ctx);
+uint16_t scal_cipher_getBlocksize_b(const scdesc_t* desc);
+PGM_VOID_P scal_cipher_getKeysizeDesc(const scdesc_t* desc);
+PGM_VOID_P scal_cipher_getIVsizeDesc(const scdesc_t* desc);
+
+
+#endif /* SCAL_BASIC_H_ */
--- /dev/null
+/* scal-nessie.c */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2006-2011 Daniel Otte (daniel.otte@rub.de)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdint.h>
+#include <string.h>
+#include "streamcipher_descriptor.h"
+#include "scal-basic.h"
+#include "nessie_common.h"
+#include "memxor.h"
+#include <avr/pgmspace.h>
+
+static const uint8_t normal_hooks[] PROGMEM = {
+ 0, 192/64, 256/64, 448/64
+};
+
+static const uint16_t long_hooks[] PROGMEM = {
+ 0, 65472/64, 65536/64, 131008/64
+};
+
+static const char stream0_n[] PROGMEM = "stream[0..63]";
+static const char stream1_n[] PROGMEM = "stream[192..255]";
+static const char stream2_n[] PROGMEM = "stream[256..319]";
+static const char stream3_n[] PROGMEM = "stream[448..511]";
+static const char streamX_n[] PROGMEM = "stream[0..511]xored";
+
+static const char* stream_n_str[] PROGMEM = {
+ stream0_n,
+ stream1_n,
+ stream2_n,
+ stream3_n,
+ streamX_n
+};
+
+static const char stream1_l[] PROGMEM = "stream[65472..65535]";
+static const char stream2_l[] PROGMEM = "stream[65536..65599]";
+static const char stream3_l[] PROGMEM = "stream[131008..131071]";
+static const char streamX_l[] PROGMEM = "stream[0..131071]xored";
+
+static const char* stream_l_str[] PROGMEM = {
+ stream0_n,
+ stream1_l,
+ stream2_l,
+ stream3_l,
+ streamX_l
+};
+
+static const uint8_t list_of_keys[][20] PROGMEM = {
+ { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
+ { 0x01, 0x23, 0x45, 0x67, 0x89, 0xab, 0xcd, 0xef, 0xfe, 0xdc,
+ 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, 0x00, 0x00, 0x00, 0x00 },
+ { 0x67, 0x45, 0x23, 0x01, 0xef, 0xcd, 0xab, 0x89, 0x98, 0xba,
+ 0xdc, 0xfe, 0x10, 0x32, 0x54, 0x76, 0xc3, 0xd2, 0xe1, 0xf0 }
+};
+
+static const uint8_t list_of_ivs[][4] PROGMEM = {
+ { 0x00, 0x00, 0x00, 0x00 },
+ { 0x01, 0x01, 0x01, 0x01 },
+ { 0x01, 0x35, 0x77, 0xaf }
+};
+
+static
+void normal_block(scgen_ctx_t *ctx){
+ uint8_t xor_block[64];
+ uint8_t block[64];
+ PGM_VOID_P hook_ptr = normal_hooks;
+ PGM_VOID_P hook_str_ptr = stream_n_str;
+ char str[21];
+ uint8_t i;
+
+ memset(xor_block, 0, 64);
+ for(i=0; i<=448/64; ++i){
+ scal_cipher_gen_fillblock(block, 64, ctx);
+ memxor(xor_block, block, 64);
+ if(i==pgm_read_byte(hook_ptr)){
+ hook_ptr = (uint8_t*)hook_ptr + 1;
+ strcpy_P(str, (PGM_VOID_P)pgm_read_word(hook_str_ptr));
+ hook_str_ptr = (uint8_t*)hook_str_ptr + 2;
+ nessie_print_item(str, block, 64);
+ }
+ }
+ strcpy_P(str, (PGM_VOID_P)pgm_read_word(hook_str_ptr));
+ nessie_print_item(str, xor_block, 64);
+}
+
+static
+void long_block(scgen_ctx_t *ctx){
+ uint8_t xor_block[64];
+ uint8_t block[64];
+ PGM_VOID_P hook_ptr = long_hooks;
+ PGM_VOID_P hook_str_ptr = stream_l_str;
+ char str[24];
+ uint16_t i;
+
+ memset(xor_block, 0, 64);
+ for(i=0; i<=131008/64; ++i){
+ scal_cipher_gen_fillblock(block, 64, ctx);
+ memxor(xor_block, block, 64);
+ if(i==pgm_read_word(hook_ptr)){
+ hook_ptr = (uint8_t*)hook_ptr + 2;
+ strcpy_P(str, (PGM_VOID_P)pgm_read_word(hook_str_ptr));
+ hook_str_ptr = (uint8_t*)hook_str_ptr + 2;
+ nessie_print_item(str, block, 64);
+ }
+ }
+ strcpy_P(str, (PGM_VOID_P)pgm_read_word(hook_str_ptr));
+ nessie_print_item(str, xor_block, 64);
+}
+
+void scal_nessie_stream_run(const scdesc_t *desc, uint16_t keysize_b, uint16_t ivsize_b){
+ uint8_t name_length = strlen_P((PGM_VOID_P)pgm_read_word(&(desc->name)));
+ char name[name_length+1];
+ memcpy_P(name, (PGM_VOID_P)pgm_read_word(&(desc->name)), name_length+1);
+
+ uint8_t key[(keysize_b+7)/8];
+ uint8_t iv[(ivsize_b+7)/8];
+ uint16_t v;
+ scgen_ctx_t ctx;
+ nessie_print_header(name, keysize_b, 0, 0, 0, ivsize_b?ivsize_b:((uint16_t)-1));
+
+ memset(iv, 0, (ivsize_b+7)/8);
+ memset(key, 0, (keysize_b+7)/8);
+ /*** Test SET 1 ***/
+ nessie_print_setheader(1);
+ for(v=0;v<keysize_b; ++v){
+ nessie_print_set_vector(1,v);
+ key[v/8] |= 0x80>>(v&7);
+ nessie_print_item("key", key, (keysize_b+7)/8);
+ if(ivsize_b){
+ nessie_print_item("IV", iv, (ivsize_b+7)/8);
+ }
+ scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
+ normal_block(&ctx);
+ key[v/8] = 0;
+ scal_cipher_free(&ctx);
+ }
+ /*** Test SET 2 ***/
+ nessie_print_setheader(2);
+ for(v=0;v<256; ++v){
+ nessie_print_set_vector(2,v);
+ memset(key, v&0xff, (keysize_b+7)/8);
+ nessie_print_item("key", key, (keysize_b+7)/8);
+ if(ivsize_b){
+ nessie_print_item("IV", iv, (ivsize_b+7)/8);
+ }
+ scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
+ normal_block(&ctx);
+ scal_cipher_free(&ctx);
+ }
+ /*** Test SET 3 ***/
+ nessie_print_setheader(3);
+ for(v=0;v<256; ++v){
+ uint8_t i;
+ nessie_print_set_vector(3,v);
+ for(i=0; i<((keysize_b+7)/8); ++i){
+ key[i]=(i+v)&0xff;
+ }
+ nessie_print_item("key", key, (keysize_b+7)/8);
+ if(ivsize_b){
+ nessie_print_item("IV", iv, (ivsize_b+7)/8);
+ }
+ scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
+ normal_block(&ctx);
+ scal_cipher_free(&ctx);
+ }
+ /*** Test SET 4 ***/
+ nessie_print_setheader(4);
+ for(v=0;v<4; ++v){
+ uint8_t i;
+ nessie_print_set_vector(4,v);
+ for(i=0; i<((keysize_b+7)/8); ++i){
+ key[i]=(i*0x53+v*5)&0xff;
+ }
+ nessie_print_item("key", key, (keysize_b+7)/8);
+ if(ivsize_b){
+ nessie_print_item("IV", iv, (ivsize_b+7)/8);
+ }
+ scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
+ long_block(&ctx);
+ scal_cipher_free(&ctx);
+ }
+ if(ivsize_b==0){ /* exit if there is no IV */
+ nessie_print_footer();
+ return;
+ }
+ /*** Test SET 5 ***/
+ nessie_print_setheader(5);
+ memset(key, 0, (keysize_b+7)/8);
+ for(v=0;v<ivsize_b; ++v){
+ nessie_print_set_vector(5,v);
+ iv[v/8] |= 0x80>>(v&7);
+ nessie_print_item("key", key, (keysize_b+7)/8);
+ nessie_print_item("IV", iv, (ivsize_b+7)/8);
+ scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
+ normal_block(&ctx);
+ scal_cipher_free(&ctx);
+ iv[v/8] = 0;
+ }
+ /*** Test SET 6 ***/
+ nessie_print_setheader(6);
+ for(v=0;v<4; ++v){
+ uint8_t i;
+ nessie_print_set_vector(6,v);
+ for(i=0; i<((keysize_b+7)/8); ++i){
+ key[i]=(i*0x53+v*5)&0xff;
+ }
+ for(i=0; i<((ivsize_b+7)/8); ++i){
+ iv[i]=(i*0x67+v*9+13)&0xff;
+ }
+ nessie_print_item("key", key, (keysize_b+7)/8);
+ nessie_print_item("IV", iv, (ivsize_b+7)/8);
+ scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
+ long_block(&ctx);
+ scal_cipher_free(&ctx);
+ }
+ /*** Test SET 7 ***/
+ nessie_print_setheader(7);
+ uint8_t u;
+ for(v=0;v<3; ++v){
+ for(u=0; u<3; ++u){
+ uint8_t i;
+ nessie_print_set_vector(7,v*3+u);
+ for(i=0; i<((keysize_b+7)/8); ++i){
+ key[i]=pgm_read_byte(list_of_keys+20*v+(i%20));
+ }
+ for(i=0; i<((ivsize_b+7)/8); ++i){
+ key[i]=pgm_read_byte(list_of_keys+4*u+(i%4));
+ }
+ }
+ nessie_print_item("key", key, (keysize_b+7)/8);
+ nessie_print_item("IV", iv, (ivsize_b+7)/8);
+ scal_cipher_init(desc, key, keysize_b, iv, ivsize_b, &ctx);
+ long_block(&ctx);
+ scal_cipher_free(&ctx);
+ }
+ nessie_print_footer();
+}
+
+void scal_nessie_run(const scdesc_t* desc){
+ uint16_t keysizes_count, ivsizes_count,i,j;
+ uint16_t *keysizes=NULL, *ivsizes=NULL;
+ keysizes_count = get_keysizes((PGM_VOID_P)pgm_read_word(&(desc->valid_keysize_desc)), &keysizes);
+ ivsizes_count = get_keysizes((PGM_VOID_P)pgm_read_word(&(desc->valid_ivsize_desc)), &ivsizes);
+ for(i=0; i<keysizes_count; ++i){
+ for(j=0; j<ivsizes_count; ++j){
+ scal_nessie_stream_run(desc, keysizes[i], ivsizes[j]);
+ }
+ }
+}
--- /dev/null
+/* scal-nessie.h */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef SCALNESSIE_H_
+#define SCALNESSIE_H_
+
+#include <stdint.h>
+#include <streamcipher_descriptor.h>
+
+void scal_nessie_stream_run(const scdesc_t *desc, uint16_t keysize_b, uint16_t ivsize_b);
+void scal_nessie_run(const scdesc_t* desc);
+
+#endif /* SCALNESSIE_H_ */
--- /dev/null
+/* scal_arcfour.c */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdlib.h>
+#include <avr/pgmspace.h>
+#include <stdint.h>
+#include "streamcipher_descriptor.h"
+#include "keysize_descriptor.h"
+
+#include "arcfour.h"
+
+const char arcfour_str[] PROGMEM = "ARCFOUR";
+
+const uint8_t arcfour_keysize_desc[] PROGMEM = {
+ KS_TYPE_ARG_RANGE, KS_INT(8), KS_INT(2040), KS_INT(8), KS_INT(0),
+ KS_TYPE_TERMINATOR };
+
+const uint8_t arcfour_ivsize_desc[] PROGMEM = {
+ KS_TYPE_LIST, 1, KS_INT(0),
+ KS_TYPE_TERMINATOR };
+
+const scdesc_t arcfour_desc PROGMEM = {
+ SCDESC_TYPE_BLOCKCIPHER, /* abstraction layer type designator */
+ SC_INIT_TYPE_3|SC_GEN_TYPE_1, /* flags*/
+ arcfour_str, /* name string pointer */
+ sizeof(arcfour_ctx_t), /* size of context */
+ 8, /* blocksize */
+ {(void_fpt)arcfour_init}, /* init function pointer */
+ {(void_fpt)arcfour_gen}, /* key stream generator function pointer */
+ {(void_fpt)NULL}, /* key stream generator for random access function pointer */
+ (sc_free_fpt)NULL, /* free function pointer */
+ arcfour_keysize_desc, /* key size descriptor pointer */
+ arcfour_ivsize_desc /* iv size descriptor pointer */
+};
+
+
+
+
+
+
--- /dev/null
+/* scal_arcfour.h */
+/*
+ This file is part of the AVR-Crypto-Lib.
+ Copyright (C) 2011 Daniel Otte (daniel.otte@rub.de)
+
+ This program is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef SCAL_ARCFOUR_H_
+#define SCAL_ARCFOUR_H_
+
+#include "streamcipher_descriptor.h"
+
+extern const scdesc_t arcfour_desc;
+
+#endif /* SCAL_ARCFOUR_H_ */
#include "debug.h"
#include <arcfour.h>
-#include "nessie_stream_test.h"
#include "cli.h"
#include "performance_test.h"
+#include "scal_arcfour.h"
+#include "scal-basic.h"
+#include "scal-nessie.h"
+
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
arcfour_init(key, (uint8_t)((keysize+7)/8), ctx);
}
-
-
void testrun_nessie_arcfour(void){
- nessie_stream_ctx.outsize_b = 8; /* actually unused */
- nessie_stream_ctx.keysize_b = 128; /* this is theone we have refrence vectors for */
- nessie_stream_ctx.ivsize_b = (uint16_t)-1;
- nessie_stream_ctx.name = algo_name;
- nessie_stream_ctx.ctx_size_B = sizeof(arcfour_ctx_t);
- nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)arcfour_genctx_dummy;
- nessie_stream_ctx.cipher_enc = (nessie_stream_genenc_fpt)arcfour_gen;
-
- nessie_stream_run();
+ scal_nessie_run(&arcfour_desc);
}
void testrun_performance_arcfour(void){
if(ivsize_b){
if(ivsize_b==(uint16_t)-1){
NESSIE_PUTSTR_P(PSTR("\r\nNo initial value (IV) mode"));
- }
- {
+ }else{
NESSIE_PUTSTR_P(PSTR("\r\nIV size: "));
utoa(ivsize_b, str, 10);
NESSIE_PUTSTR(str);
#include <string.h>
#include "nessie_stream_test.h"
#include "nessie_common.h"
+#include "memxor.h"
nessie_stream_ctx_t nessie_stream_ctx;
#define BLOCKSIZE_B 64
-static
-void memxor(void* dest, void* src, uint8_t length){
- while(length--){
- *((uint8_t*)dest) ^= *((uint8_t*)src);
- dest = (uint8_t*)dest +1;
- src = (uint8_t*)src +1;
- }
-}
-
static
void nessie_gen_block(void* ctx, uint8_t* block){