]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
"new cbc-mode for bcal; docu comming soon
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Sat, 30 Jan 2010 00:49:31 +0000 (00:49 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Sat, 30 Jan 2010 00:49:31 +0000 (00:49 +0000)
28 files changed:
bcal-basic.c
bcal-basic.h
bcal-cbc.c [new file with mode: 0644]
bcal-cbc.h [new file with mode: 0644]
bcal_aes128.c
bcal_aes128.h
bcal_aes192.h
bcal_aes256.h
bcal_camellia128.h
bcal_cast5.h
bcal_cast6.h
bcal_des.h
bcal_noekeon.h
bcal_present.h
bcal_rc5.h
bcal_rc6.h
bcal_seed.h
bcal_serpent.h
bcal_skipjack.h
bcal_tdes.h
bcal_xtea.h
keysize_descriptor.c
mkfiles/aes.mk
mkfiles/aes_c.mk
test_src/main-aes-test.c
test_src/main-aes128-test.c
test_src/main-sha256-test.c
test_src/main-shabal-test.c

index d37f40ab41dc7d3dbea05c3c98f5876886795dfc..07ec2da5ea331c02380e758fb58d8f1187054446 100644 (file)
 #include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
+#include <avr/pgmspace.h>
 #include "blockcipher_descriptor.h"
 #include "keysize_descriptor.h"
 
-
 uint8_t bcal_cipher_init(const bcdesc_t* cipher_descriptor,
                          const void* key, uint16_t keysize, bcgen_ctx_t* ctx){
-       if(!is_valid_keysize_P((PGM_VOID_P)(pgm_read_word(cipher_descriptor->valid_keysize_desc)),
-                              keysize))
+       if(!is_valid_keysize_P((PGM_VOID_P)pgm_read_word(&(cipher_descriptor->valid_keysize_desc)),
+                              keysize)){
                return 1;
-               
+       }
        uint8_t flags;
        bc_init_fpt init_fpt;
        ctx->desc_ptr = (bcdesc_t*)cipher_descriptor;
        ctx->keysize  = keysize;
        flags = pgm_read_byte(cipher_descriptor->flags);
-       init_fpt.initvoid = (void_fpt)(pgm_read_word(cipher_descriptor->init.initvoid));
+       init_fpt.initvoid = (void_fpt)(pgm_read_word(&(cipher_descriptor->init.initvoid)));
        if(init_fpt.initvoid == NULL){
-               if(!(ctx->ctx = malloc(keysize/8)))
+               if(!(ctx->ctx = malloc((keysize+7)/8)))
                        return 2;
-               memcpy(ctx->ctx, key, keysize/8);
+               memcpy(ctx->ctx, key, (keysize+7)/8);
                return 0;
        }
-       if(!(ctx->ctx = malloc(pgm_read_word(cipher_descriptor->ctxsize_B))))
+       if(!(ctx->ctx = malloc(pgm_read_word(&(cipher_descriptor->ctxsize_B)))))
                return 3;
        if((flags&BC_INIT_TYPE)==BC_INIT_TYPE_1){
-               init_fpt.init1((void*)key, ctx->ctx);
+               init_fpt.init1((void*)key, (ctx->ctx));
        }else{
-               init_fpt.init2((void*)key, keysize, ctx->ctx);
+               init_fpt.init2((void*)key, keysize, (ctx->ctx));
        }
        return 0;
 }
@@ -56,32 +56,39 @@ void bcal_cipher_free(bcgen_ctx_t* ctx){
        if(!ctx)
                return;
        bc_free_fpt free_fpt;
-       free_fpt = (bc_free_fpt)(pgm_read_word(ctx->desc_ptr->free));
+       free_fpt = (bc_free_fpt)(pgm_read_word(&(ctx->desc_ptr->free)));
        if(free_fpt)
-               free_fpt(ctx->ctx);
+               free_fpt((ctx->ctx));
        free(ctx->ctx);
 }
 
 void bcal_cipher_enc(void* block, const bcgen_ctx_t* ctx){
        bc_enc_fpt enc_fpt;
-       enc_fpt.encvoid = (void_fpt)pgm_read_word(ctx->desc_ptr->enc.encvoid);
+       enc_fpt.encvoid = (void_fpt)pgm_read_word(&(ctx->desc_ptr->enc.encvoid));
        if(!enc_fpt.encvoid){
                /* very bad error, no enciphering function specified */
                return;
        }
-       enc_fpt.enc1(block, ctx->ctx);
+       enc_fpt.enc1(block, (ctx->ctx));
        
 }
 
 void bcal_cipher_dec(void* block, const bcgen_ctx_t* ctx){
        bc_dec_fpt dec_fpt;
-       dec_fpt.decvoid = (void_fpt)pgm_read_word(ctx->desc_ptr->dec.decvoid);
+       dec_fpt.decvoid = (void_fpt)pgm_read_word(&(ctx->desc_ptr->dec.decvoid));
        if(!dec_fpt.decvoid){
                /* very bad error, no deciphering function specified */
                return;
        }
-       dec_fpt.dec1(block, ctx->ctx);
+       dec_fpt.dec1(block, (ctx->ctx));
 }
 
+uint16_t bcal_cipher_getBlocksize_b(const bcdesc_t* desc){
+       return pgm_read_word(&(desc->blocksize_b));
+}
+
+PGM_VOID_P bcal_cipher_getKeysizeDesc(const bcdesc_t* desc){
+       return (PGM_VOID_P)pgm_read_word(&(desc->valid_keysize_desc));
+}
 
 
index 4d79ef885ce2d5d3d633aa9085d91b148c7a61e2..e9c8331e5602f0b1e0709ecb7e5c9bd55e8d0143 100644 (file)
 
 #include <stdlib.h>
 #include <stdint.h>
-#include "blockciper_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "keysize_descriptor.h"
-
+#include <avr/pgmspace.h>
 
 uint8_t bcal_cipher_init(const bcdesc_t* cipher_descriptor,
                          const void* key, uint16_t keysize, bcgen_ctx_t* ctx);
 void bcal_cipher_free(bcgen_ctx_t* ctx);
 void bcal_cipher_enc(void* block, const bcgen_ctx_t* ctx);
 void bcal_cipher_dec(void* block, const bcgen_ctx_t* ctx);
-
+uint16_t bcal_cipher_getBlocksize_b(const bcdesc_t* desc);
+PGM_VOID_P bcal_cipher_getKeysizeDesc(const bcdesc_t* desc);
 #endif /* BCAL_BASIC_H_ */
diff --git a/bcal-cbc.c b/bcal-cbc.c
new file mode 100644 (file)
index 0000000..7ae892e
--- /dev/null
@@ -0,0 +1,83 @@
+/* bcal-cbc.c */
+/*
+    This file is part of the AVR-Crypto-Lib.
+    Copyright (C) 2010  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 "bcal-cbc.h"
+#include "bcal-basic.h"
+#include "memxor.h"
+
+uint8_t bcal_cbc_init(const bcdesc_t* desc, const void* key, uint16_t keysize, bcal_cbc_ctx_t* ctx){
+       ctx->desc = (bcdesc_t*)desc;
+       ctx->blocksize_B = (bcal_cipher_getBlocksize_b(desc)+7)/8;
+       ctx->prev_block = malloc(ctx->blocksize_B);
+
+       if(!(ctx->prev_block)){
+               return 0x11;
+       }
+       return bcal_cipher_init(desc, key, keysize, &(ctx->cctx));
+}
+
+void bcal_cbc_free(bcal_cbc_ctx_t* ctx){
+       bcal_cipher_free(&(ctx->cctx));
+       free(ctx->prev_block);
+}
+
+
+void bcal_cbc_loadIV(const void* iv, bcal_cbc_ctx_t* ctx){
+       memcpy(ctx->prev_block, iv, ctx->blocksize_B);
+}
+
+void bcal_cbc_encNext(void* block, bcal_cbc_ctx_t* ctx){
+       memxor(block, ctx->prev_block, ctx->blocksize_B);
+       bcal_cipher_enc(block, &(ctx->cctx));
+       memcpy(ctx->prev_block, block, ctx->blocksize_B);
+}
+
+void bcal_cbc_decNext(void* block, bcal_cbc_ctx_t* ctx){
+       uint8_t tmp[ctx->blocksize_B];
+       memcpy(tmp, block, ctx->blocksize_B);
+       bcal_cipher_dec(block, &(ctx->cctx));
+       memxor(block, ctx->prev_block, ctx->blocksize_B);
+       memcpy(ctx->prev_block, tmp, ctx->blocksize_B);
+}
+void bcal_cbc_decRand(void* block, const void* prev_block, bcal_cbc_ctx_t* ctx){
+       bcal_cipher_dec(block, &(ctx->cctx));
+       memxor(block, prev_block, ctx->blocksize_B);
+}
+
+void bcal_cbc_encMsg(const void* iv, void* msg, uint16_t msg_blocks, bcal_cbc_ctx_t* ctx){
+       bcal_cbc_loadIV(iv, ctx);
+       while(msg_blocks){
+               bcal_cbc_encNext(msg, ctx);
+               msg_blocks -= 1;
+               msg = (uint8_t*)msg + ctx->blocksize_B;
+       }
+}
+
+void bcal_cbc_decMsg(const void* iv, void* msg, uint16_t msg_blocks, bcal_cbc_ctx_t* ctx){
+       msg=(uint8_t*)msg + (msg_blocks-1)*ctx->blocksize_B;
+       while(msg_blocks>1){
+               bcal_cbc_decRand(msg, (uint8_t*)msg-ctx->blocksize_B, ctx);
+               msg_blocks -= 1;
+               msg=(uint8_t*)msg-ctx->blocksize_B;
+       }
+       bcal_cbc_decRand(msg, iv, ctx);
+}
+
diff --git a/bcal-cbc.h b/bcal-cbc.h
new file mode 100644 (file)
index 0000000..fc1ffa1
--- /dev/null
@@ -0,0 +1,44 @@
+/* bcal-cbc.h */
+/*
+    This file is part of the AVR-Crypto-Lib.
+    Copyright (C) 2010 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 BCALCBC_H_
+#define BCALCBC_H_
+
+#include <stdint.h>
+#include "blockcipher_descriptor.h"
+#include "bcal-basic.h"
+
+typedef struct{
+       bcdesc_t*    desc;
+       bcgen_ctx_t  cctx;
+       uint8_t*     prev_block;
+       uint8_t      blocksize_B;
+} bcal_cbc_ctx_t;
+
+uint8_t bcal_cbc_init(const bcdesc_t* desc, const void* key, uint16_t keysize, bcal_cbc_ctx_t* ctx);
+void bcal_cbc_free(bcal_cbc_ctx_t* ctx);
+void bcal_cbc_loadIV(const void* iv, bcal_cbc_ctx_t* ctx);
+void bcal_cbc_encNext(void* block, bcal_cbc_ctx_t* ctx);
+void bcal_cbc_decNext(void* block, bcal_cbc_ctx_t* ctx);
+void bcal_cbc_decRand(void* block, const void* prev_block, bcal_cbc_ctx_t* ctx);
+void bcal_cbc_encMsg(const void* iv, void* msg, uint16_t msg_blocks, bcal_cbc_ctx_t* ctx);
+void bcal_cbc_decMsg(const void* iv, void* msg, uint16_t msg_blocks, bcal_cbc_ctx_t* ctx);
+
+
+#endif /* BCALCBC_H_ */
index 8bdde252b616e4209a250c7ff1e95651a4409667..946d7a978ab9c73e601a11c2342d8fe2169fdcbd 100644 (file)
@@ -41,11 +41,11 @@ const uint8_t aes128_keysize_desc[] PROGMEM = { KS_TYPE_LIST, 1, KS_INT(128),
 
 const bcdesc_t aes128_desc PROGMEM = {
        BCDESC_TYPE_BLOCKCIPHER,
-       BC_INIT_TYPE_2,
+       BC_INIT_TYPE_1,
        aes128_str,
        sizeof(aes128_ctx_t),
        128,
-       {(void_fpt)aes_init},
+       {(void_fpt)aes128_init},
        {(void_fpt)aes128_enc},
        {(void_fpt)aes128_dec},
        (bc_free_fpt)NULL,
index ff6568942f5eafa43eeef6d7417a6fb4da466e5b..72574258a6ec52824bd2715e3b9f8eec239a44cd 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "aes.h"
 #include "aes128_enc.h"
 #include "aes128_dec.h"
index 7abc44e8a9a33a8826ccbce74e392a77da3ea5a7..cff8371e4658554fd4ee4b488949830b23730771 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "aes.h"
 #include "aes192_enc.h"
 #include "aes192_dec.h"
index 216342b9db5f5abee61190a107ea4b3594080861..19dbb501322535ec8f4b1fce958303fb950e0b27 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "aes.h"
 #include "aes256_enc.h"
 #include "aes256_dec.h"
index fcd69703b7e11fa8e08de44eb32e3136de6a0b7b..bbe01992b841a29ae14c661193281e2f4f3c90c1 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "camellia.h"
 #include "keysize_descriptor.h"
 
index b5ade13dd5393923861cc894742449daafe9314f..2b620eacd09eb3b3d14df8af77c26de2a6d97523 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "cast5.h"
 #include "keysize_descriptor.h"
 
index eb527cda4f75008512d364daad229e03a483fc98..c327cf6ff68b2e3ed74ff5e7d5626da7e5ec4ad6 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "cast6.h"
 #include "keysize_descriptor.h"
 
index 571c6c6655a89695dc03b77adc6a878bec3c394f..84f76d2da11449e51be10816743d40c0f553a142 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "des.h"
 #include "keysize_descriptor.h"
 
index c74b1afbba6654dbbdd9d5730dce723c711eefe6..e8ea544735fa76de4c27df4543ecafe50eaf87c9 100644 (file)
@@ -1,7 +1,7 @@
 /* bcal_noekeon.h */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "noekeon.h"
 #include "keysize_descriptor.h"
 
index 52cabe7b0942105db8eedad89ba1e43e8127e8b8..1de83657e21bf363458403b2f3e4ca10a4be55b8 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "present.h"
 #include "keysize_descriptor.h"
 
index 6c33993808d1cc0c35e1e6afe8b560ecd0ef8662..30d2100ac3dd1a4a169ae30a6678bb3dbe3e557a 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "rc5.h"
 #include "keysize_descriptor.h"
 
index 9c5745cb6961cb10b8770e52c0376268e5d329ea..f6d0d1bb70b5bfb86c3e9e6d0e06f596f168ad4a 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "rc6.h"
 #include "keysize_descriptor.h"
 
index 9bd1f1899c91ea97f3b445907d9ea276c1519b5a..a8bdf2c8fe894916a4405391b32e9d384c8d30cd 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "seed.h"
 #include "keysize_descriptor.h"
 
index dc3674a16cc32550df85fd091d35f587fda81d2f..60fc8cc105389776c78986d10b875c81b71ad47f 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "serpent.h"
 #include "keysize_descriptor.h"
 
index ba154243baae5c1428cbd788356432fc5afde82c..e238141355df808fe1f503661e9b7551fa79adaf 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "skipjack.h"
 #include "keysize_descriptor.h"
 
index 43ee27f5796b12a7229d24759aa936f69612294b..e2f2b31d758f370402e04df3c7a6f69e2a498aa2 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "des.h"
 #include "keysize_descriptor.h"
 
index 41423861999e07613e67f8e1b96d3aa149137d1b..66e6d266b302295b07772478dfbecf7f74a99cbb 100644 (file)
@@ -26,7 +26,7 @@
  */
 
 #include <avr/pgmspace.h>
-#include "blopckcipher_descriptor.h"
+#include "blockcipher_descriptor.h"
 #include "xtea.h"
 #include "keysize_descriptor.h"
 
index 193c07ae217b0f860a9518b1ca8f4be226609362..5dcdcc05008088c0c109debd5a6d806e1348eba3 100644 (file)
@@ -39,16 +39,16 @@ uint8_t is_valid_keysize_P(PGM_VOID_P ks_desc, uint16_t keysize){
                items = pgm_read_byte(ks_desc++);
                while(items--){
                        item = pgm_read_word(ks_desc);
-                       ks_desc+=2;
+                       ks_desc = (uint8_t*)ks_desc + 2;
                        if(item==keysize)
                                return 1;
                }
-               ks_desc -= 2;
+               ks_desc = (uint8_t*)ks_desc - 2;
        }
        if(type==KS_TYPE_RANGE){
                uint16_t max, min;
                min = pgm_read_word(ks_desc);
-               ks_desc+=2;
+               ks_desc = (uint8_t*)ks_desc + 2;
                max = pgm_read_word(ks_desc);
                if(min<=keysize && keysize<=max)
                        return 1;
@@ -56,11 +56,11 @@ uint8_t is_valid_keysize_P(PGM_VOID_P ks_desc, uint16_t keysize){
        if(type==KS_TYPE_ARG_RANGE){
                uint16_t max, min, dist, offset;
                min = pgm_read_word(ks_desc);
-               ks_desc+=2;
+               ks_desc = (uint8_t*)ks_desc + 2;
                max = pgm_read_word(ks_desc);
-               ks_desc+=2;
+               ks_desc = (uint8_t*)ks_desc + 2;
                dist = pgm_read_word(ks_desc);
-               ks_desc+=2;
+               ks_desc = (uint8_t*)ks_desc + 2;
                offset = pgm_read_word(ks_desc);
                if(min<=keysize && keysize<=max && (keysize%dist==offset))
                        return 1;
@@ -69,7 +69,7 @@ uint8_t is_valid_keysize_P(PGM_VOID_P ks_desc, uint16_t keysize){
                /* bad error, you may insert a big warning message here */
                return 0;
        }
-       return is_valid_keysize(ks_desc+1, keysize) /* search the next record */
+       return is_valid_keysize_P((uint8_t*)ks_desc+1, keysize); /* search the next record */
 }
 
 
index d687c74386f09397c877efca6643ee643050c1ed..bc52d94a5baced3c894e0275a7f162b2fa62e97d 100644 (file)
@@ -6,9 +6,11 @@ BLOCK_CIPHERS += $(ALGO_NAME)
 
 $(ALGO_NAME)_DIR      := aes/
 $(ALGO_NAME)_OBJ      := aes_enc-asm.o aes_dec-asm.o aes_sbox-asm.o aes_invsbox-asm.o  \
-                         aes_keyschedule-asm.o
+                         aes_keyschedule-asm.o 
 $(ALGO_NAME)_TEST_BIN := main-aes-test.o $(CLI_STD)  \
-                         nessie_bc_test.o nessie_common.o performance_test.o
+                         nessie_bc_test.o nessie_common.o performance_test.o memxor.o \
+                         bcal_aes128.o bcal_aes192.o bcal_aes256.o bcal-basic.o bcal-cbc.o \
+                         keysize_descriptor.o dump-asm.o dump-decl.o
 $(ALGO_NAME)_NESSIE_TEST      := test nessie
 $(ALGO_NAME)_PERFORMANCE_TEST := performance
 
index f0301369971fd7a2311ea47c6603af0b2d5524a9..69ddd5af28c1a65d0d11f70b30d0ea5cddbcb4b5 100644 (file)
@@ -11,7 +11,9 @@ $(ALGO_NAME)_OBJ      := aes_enc.o aes_dec.o aes_sbox.o aes_invsbox.o \
                          aes128_enc.o aes128_dec.o aes192_enc.o aes192_dec.o \
                          aes256_enc.o aes256_dec.o
 $(ALGO_NAME)_TEST_BIN := main-aes-test.o $(CLI_STD)  \
-                         nessie_bc_test.o nessie_common.o performance_test.o
+                         nessie_bc_test.o nessie_common.o performance_test.o memxor.o \
+                         bcal_aes128.o bcal_aes192.o bcal_aes256.o bcal-basic.o bcal-cbc.o \
+                         keysize_descriptor.o dump-asm.o dump-decl.o
 $(ALGO_NAME)_NESSIE_TEST      := test nessie
 $(ALGO_NAME)_PERFORMANCE_TEST := performance
 
index 71b6600a6dcee9f607c84d6649bd58df7f675226..ac80d80f036499d466fee129f8a9e3b4c523e26d 100644 (file)
 #include "nessie_bc_test.h"
 #include "cli.h"
 #include "performance_test.h"
+#include "dump.h"
+
+#include "bcal_aes128.h"
+#include "bcal_aes192.h"
+#include "bcal_aes256.h"
+#include "bcal-cbc.h"
 
 #include <stdint.h>
 #include <string.h>
@@ -87,8 +93,19 @@ void testrun_test_aes(void){
        aes128_dec(data, &ctx);
        cli_putstr_P(PSTR("\r\n plaintext:  "));
        cli_hexdump(data, 16);
-
-
+       cli_putstr(PSTR("\r\n testing bcal:"));
+       bcgen_ctx_t bcal_ctx;
+       uint8_t r;
+       r = bcal_cipher_init(&aes128_desc, key, 128, &bcal_ctx);
+       cli_putstr_P(PSTR("\r\n init = 0x"));
+       cli_hexdump(&r, 1);
+
+       bcal_cipher_enc(data, &bcal_ctx);
+       cli_putstr_P(PSTR("\r\n ciphertext: "));
+       cli_hexdump(data, 16);
+       bcal_cipher_dec(data, &bcal_ctx);
+       cli_putstr_P(PSTR("\r\n plaintext:  "));
+       cli_hexdump(data, 16);
 }
 
 void testrun_testkey_aes128(void){
@@ -162,6 +179,48 @@ void testrun_testkey_aes(void){
        testrun_testkey_aes192();
        testrun_testkey_aes256();
 }
+
+
+void testrun_aes128_cbc(void){
+       uint8_t key[]     = { 0x2b, 0x7e, 0x15, 0x16, 0x28, 0xae, 0xd2, 0xa6,
+                                     0xab, 0xf7, 0x15, 0x88, 0x09, 0xcf, 0x4f, 0x3c };
+       uint8_t iv[]      = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+                                     0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
+       uint8_t plain[]   = { 0x6b, 0xc1, 0xbe, 0xe2, 0x2e, 0x40, 0x9f, 0x96,
+                                     0xe9, 0x3d, 0x7e, 0x11, 0x73, 0x93, 0x17, 0x2a,
+                                     /* --- */
+                                     0xae, 0x2d, 0x8a, 0x57, 0x1e, 0x03, 0xac, 0x9c,
+                                     0x9e, 0xb7, 0x6f, 0xac, 0x45, 0xaf, 0x8e, 0x51,
+                                     /* --- */
+                                     0x30, 0xc8, 0x1c, 0x46, 0xa3, 0x5c, 0xe4, 0x11,
+                                     0xe5, 0xfb, 0xc1, 0x19, 0x1a, 0x0a, 0x52, 0xef,
+                                     /* --- */
+                                     0xf6, 0x9f, 0x24, 0x45, 0xdf, 0x4f, 0x9b, 0x17,
+                                     0xad, 0x2b, 0x41, 0x7b, 0xe6, 0x6c, 0x37, 0x10 };
+       bcal_cbc_ctx_t ctx;
+       uint8_t r;
+       cli_putstr_P(PSTR("\r\n** AES128-CBC-TEST **"));
+       r = bcal_cbc_init(&aes128_desc, key, 128, &ctx);
+       cli_putstr_P(PSTR("\r\n  init = 0x"));
+       cli_hexdump(&r, 1);
+       cli_putstr_P(PSTR("\r\n  key:   "));
+       cli_hexdump(key, 128/8);
+       cli_putstr_P(PSTR("\r\n  IV:    "));
+       cli_hexdump(iv, 128/8);
+       cli_putstr_P(PSTR("\r\n  plaintext:"));
+       cli_hexdump_block(plain, 4*128/8, 4, 8);
+       if(r)
+               return;
+       bcal_cbc_encMsg(iv, plain, 4, &ctx);
+       cli_putstr_P(PSTR("\r\n  ciphertext:  "));
+       cli_hexdump_block(plain, 4*128/8, 4, 8);
+       bcal_cbc_decMsg(iv, plain, 4, &ctx);
+       cli_putstr_P(PSTR("\r\n  plaintext:   "));
+       cli_hexdump_block(plain, 4*128/8, 4, 8);
+       bcal_cbc_free(&ctx);
+}
+
+
 /*****************************************************************************/
 
 void testrun_performance_aes128(void){
@@ -296,14 +355,18 @@ void testrun_performance_aes(void){
 const char nessie_str[]      PROGMEM = "nessie";
 const char test_str[]        PROGMEM = "test";
 const char testkey_str[]     PROGMEM = "testkey";
+const char testcbc128_str[]  PROGMEM = "testcbc128";
 const char performance_str[] PROGMEM = "performance";
+const char dump_str[]        PROGMEM = "dump";
 const char echo_str[]        PROGMEM = "echo";
 
 cmdlist_entry_t cmdlist[] PROGMEM = {
        { nessie_str,      NULL, testrun_nessie_aes },
        { test_str,        NULL, testrun_test_aes},
        { testkey_str,     NULL, testrun_testkey_aes},
+       { testcbc128_str,  NULL, testrun_aes128_cbc},
        { performance_str, NULL, testrun_performance_aes},
+       { dump_str,    (void*)1, (void_fpt)dump},
        { echo_str,    (void*)1, (void_fpt)echo_ctrl},
        { NULL,            NULL, NULL}
 };
index 01cf583557440443c00e1716b5d782d7e0edc01f..72e06f6198bbcd0819395eb3ddbdbe79b810b255 100644 (file)
 #include "nessie_bc_test.h"
 #include "cli.h"
 #include "performance_test.h"
-
 #include <stdint.h>
 #include <string.h>
 #include <stdlib.h>
+#include <avr/pgmspace.h>
 
 char* algo_name = "AES-128";
 
@@ -99,6 +99,7 @@ void testrun_testkey_aes128(void){
 void testrun_testkey_aes(void){
        testrun_testkey_aes128();
 }
+
 /*****************************************************************************/
 
 void testrun_performance_aes128(void){
index f31656785cb5f6b620d874183283df4299bd08ea..1907390b21adffa7c96fe6fe71740701f1ba939d 100644 (file)
@@ -88,10 +88,10 @@ void test_monte(void){
      0x38, 0xF0, 0xDF, 0x70, 0x1D, 0xA9, 0x3C, 0x3B,
      0xF2, 0xC9, 0xC8, 0x68, 0x96, 0xE7, 0xE6, 0xC7 };
    uint8_t hash[SHA256_HASH_BYTES];
-   sha256(hash, data1, 3*32*8);
+   sha256((sha256_hash_t*)hash, data1, 3*32*8);
    cli_putstr_P(PSTR("\r\n hash(data1) = "));
    cli_hexdump(hash, 32);
-   sha256(hash, data2, 3*32*8);
+   sha256((sha256_hash_t*)hash, data2, 3*32*8);
    cli_putstr_P(PSTR("\r\n hash(data2) = "));
    cli_hexdump(hash, 32);
 }
@@ -116,7 +116,7 @@ void test_monte2(void){
        0x39, 0xd8, 0x35, 0xa7, 0x24, 0xe2, 0xfa, 0xe7 };
 
    uint8_t hash[SHA256_HASH_BYTES];
-   sha256(hash, data, 1024);
+   sha256((sha256_hash_t*)hash, data, 1024);
    cli_putstr_P(PSTR("\r\n hash(data) = "));
    cli_hexdump(hash, 32);
 }
@@ -139,19 +139,19 @@ const char shavs_test3_str[] PROGMEM = "shavs_test3";
 const char dump_str[]        PROGMEM = "dump";
 
 cmdlist_entry_t cmdlist[] PROGMEM = {
-       { nessie_str,          NULL, testrun_nessie_sha256},
-       { test_str,            NULL, testrun_nessie_sha256},
-       { monte_str,           NULL, test_monte},
-       { monte2_str,          NULL, test_monte2},
-       { performance_str,     NULL, testrun_performance_sha256},
-       { echo_str,        (void*)1, (void_fpt)echo_ctrl},
-       { shavs_list_str,      NULL, shavs_listalgos},
-       { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
-       { shavs_test1_str,     NULL, shavs_test1},
-       { shavs_test2_str,     NULL, shavs_test2},
-       { shavs_test3_str,     NULL, shavs_test3},
-       { dump_str,        (void*)1, (void_fpt)dump},
-       { NULL,                NULL, NULL}
+       { nessie_str,          NULL, testrun_nessie_sha256          },
+       { test_str,            NULL, testrun_nessie_sha256          },
+       { monte_str,           NULL, test_monte                     },
+       { monte2_str,          NULL, test_monte2                    },
+       { performance_str,     NULL, testrun_performance_sha256     },
+       { echo_str,        (void*)1, (void_fpt)echo_ctrl            },
+       { shavs_list_str,      NULL, shavs_listalgos                },
+       { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo        },
+       { shavs_test1_str,     NULL, shavs_test1                    },
+       { shavs_test2_str,     NULL, shavs_test2                    },
+       { shavs_test3_str,     NULL, shavs_test3                    },
+       { dump_str,        (void*)1, (void_fpt)dump                 },
+       { NULL,                NULL, NULL                           }
 };
 
 int main (void){
index 17f303f636c4cae39322a72e2f2ba3490cc649d0..bcdc57aeef20e90b94527ff138a191221ce71868 100644 (file)
@@ -18,7 +18,7 @@
 */
 /*
  * shabal test-suit
- * 
+ *
 */
 
 #include "config.h"
@@ -48,7 +48,7 @@ const hfdesc_t* algolist[] PROGMEM = {
        (hfdesc_t*)&shabal224_desc,
        (hfdesc_t*)&shabal256_desc,
        (hfdesc_t*)&shabal384_desc,
-       (hfdesc_t*)&shabal512_desc,     
+       (hfdesc_t*)&shabal512_desc,
        NULL
 };
 
@@ -111,7 +111,7 @@ void shabal_ctx_dump(shabal_ctx_t* ctx){
                cli_putc('0'+i/100);
        if(i>=10)
                cli_putc('0'+(i/10)%10);
-       cli_putc('0'+i%10);     
+       cli_putc('0'+i%10);
        cli_putstr_P(PSTR("\r\n  a = "));
        cli_hexdump_block(ctx->a, 12*4, 5, 4*8);
        cli_putstr_P(PSTR("\r\n  b_buffer = "));
@@ -121,7 +121,7 @@ void shabal_ctx_dump(shabal_ctx_t* ctx){
        if(ctx->b == &(ctx->b_buffer[0]))
                cli_putstr_P(PSTR("\r\nb --> b_buffer"));
        if(ctx->b == &(ctx->c_buffer[0]))
-               cli_putstr_P(PSTR("\r\nb --> c_buffer"));       
+               cli_putstr_P(PSTR("\r\nb --> c_buffer"));
        if(ctx->c == &(ctx->b_buffer[0]))
                cli_putstr_P(PSTR("\r\nc --> b_buffer"));
        if(ctx->c == &(ctx->c_buffer[0]))
@@ -132,7 +132,7 @@ void shabal_ctx_dump(shabal_ctx_t* ctx){
        cli_putstr_P(PSTR("\r\n b (should) = "));
        cli_hexdump(&p, 2);
        cli_putstr_P(PSTR("\r\n c = "));
-       cli_hexdump(&(ctx->c), 2);      
+       cli_hexdump(&(ctx->c), 2);
        p = ctx->c_buffer;
        cli_putstr_P(PSTR("\r\n c (should) = "));
        cli_hexdump(&p, 2);
@@ -200,26 +200,30 @@ const char echo_str[]        PROGMEM = "echo";
 const char shavs_list_str[]  PROGMEM = "shavs_list";
 const char shavs_set_str[]   PROGMEM = "shavs_set";
 const char shavs_test1_str[] PROGMEM = "shavs_test1";
+const char shavs_test2_str[] PROGMEM = "shavs_test2";
+const char shavs_test3_str[] PROGMEM = "shavs_test3";
 
 cmdlist_entry_t cmdlist[] PROGMEM = {
-       { nessie_str,          NULL, testrun_nessie_shabal},
-       { test_str,            NULL, testrun_stdtest_shabal},
-       { testinit192_str,     NULL, testinit_192},
-       { testinit_str,        NULL, testinit},
-       { testshort_str,       NULL, testshort},
-       { performance_str,     NULL, performance_shabal},
-       { shavs_list_str,      NULL, shavs_listalgos},
-       { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
-       { shavs_test1_str,     NULL, shavs_test1},
-       { echo_str,        (void*)1, (void_fpt)echo_ctrl},
-       { NULL,                NULL, NULL}
+       { nessie_str,          NULL, testrun_nessie_shabal          },
+       { test_str,            NULL, testrun_stdtest_shabal         },
+       { testinit192_str,     NULL, testinit_192                   },
+       { testinit_str,        NULL, testinit                       },
+       { testshort_str,       NULL, testshort                      },
+       { performance_str,     NULL, performance_shabal             },
+       { shavs_list_str,      NULL, shavs_listalgos                },
+       { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo        },
+       { shavs_test1_str,     NULL, shavs_test1                    },
+       { shavs_test2_str,     NULL, shavs_test2                    },
+       { shavs_test3_str,     NULL, shavs_test3                    },
+       { echo_str,        (void*)1, (void_fpt)echo_ctrl            },
+       { NULL,                NULL, NULL                           }
 };
 
 int main (void){
        DEBUG_INIT();
-       
+
        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_algo=(hfdesc_t*)&shabal256_desc;
        for(;;){
@@ -230,7 +234,7 @@ int main (void){
                cli_putstr_P(PSTR(" "));
                cli_putstr(__TIME__);
                cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
-               
+
                cmd_interface(cmdlist);
        }
-}      
+}