]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - nessie_bc_test.c
insereated GPLv3 stub
[avr-crypto-lib.git] / nessie_bc_test.c
index b6256d4e31e6e77960f3477d8015bb51285d67a2..f9a91e547a8f82f745e9f9df73201d0da8245e50 100644 (file)
@@ -1,3 +1,21 @@
+/* nessie_bc_test.c */
+/*
+    This file is part of the Crypto-avr-lib/microcrypt-lib.
+    Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
+
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
 /**
  * 
  * author: Daniel Otte
 
 nessie_bc_ctx_t nessie_bc_ctx;
 
+void nessie_bc_init(void){
+       memset(&nessie_bc_ctx, 0, sizeof(nessie_bc_ctx_t));     
+}
+static
+void nessie_bc_free(void* ctx){
+       if(nessie_bc_ctx.cipher_free)
+               nessie_bc_ctx.cipher_free(ctx);
+}
+
 void nessie_bc_enc(uint8_t* key, uint8_t* pt){
        uint8_t ctx[nessie_bc_ctx.ctx_size_B];
        uint8_t buffer[nessie_bc_ctx.blocksize_B];
@@ -23,13 +50,15 @@ void nessie_bc_enc(uint8_t* key, uint8_t* pt){
        /* single test */
        nessie_print_item("key", key, (nessie_bc_ctx.keysize_b+7)/8);
        nessie_bc_ctx.cipher_genctx(key, nessie_bc_ctx.keysize_b, ctx);
+       
        memcpy(buffer, pt, nessie_bc_ctx.blocksize_B);
        nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B);
        nessie_bc_ctx.cipher_enc(buffer, ctx);
        nessie_print_item("cipher", buffer, nessie_bc_ctx.blocksize_B);
-       nessie_bc_ctx.cipher_dec(buffer, ctx);
-       nessie_print_item("decrypted", buffer, nessie_bc_ctx.blocksize_B);
-       
+       if(nessie_bc_ctx.cipher_dec){
+               nessie_bc_ctx.cipher_dec(buffer, ctx);
+               nessie_print_item("decrypted", buffer, nessie_bc_ctx.blocksize_B);
+       }
        /* 100 times test */
        memcpy(buffer, pt, nessie_bc_ctx.blocksize_B);
        for(i=0; i<100; ++i){
@@ -43,6 +72,7 @@ void nessie_bc_enc(uint8_t* key, uint8_t* pt){
        }
        nessie_print_item("Iterated 1000 times", buffer, nessie_bc_ctx.blocksize_B);
 #endif
+       nessie_bc_free(ctx);
 }
 
 void nessie_bc_dec(uint8_t* key, uint8_t* ct){
@@ -58,7 +88,7 @@ void nessie_bc_dec(uint8_t* key, uint8_t* ct){
        nessie_print_item("plain", buffer, nessie_bc_ctx.blocksize_B);
        nessie_bc_ctx.cipher_enc(buffer, ctx);
        nessie_print_item("encrypted", buffer, nessie_bc_ctx.blocksize_B);
-       
+       nessie_bc_free(ctx);
 }
 
 void nessie_bc_run(void){
@@ -126,6 +156,8 @@ void nessie_bc_run(void){
        }
        nessie_bc_enc(key, buffer);
        /* half done ;-) */
+       if(nessie_bc_ctx.cipher_dec==NULL)
+               return;
        /* test set 5 */
        set=5;
        nessie_print_setheader(set);