]> git.cryptolib.org Git - arm-crypto-lib.git/blob - bcal/bcal-nessie.c
more precise type for arguments of bcal_nessie_multiple()
[arm-crypto-lib.git] / bcal / bcal-nessie.c
1 /* bcal-nessie.c */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2010 Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 #include "nessie_bc_test.h"
21 #include "blockcipher_descriptor.h"
22 #include "keysize_descriptor.h"
23 #include <stdint.h>
24 #include <stdlib.h>
25 #include <string.h>
26
27
28 void(*bcal_nessie_dummy_init_fpt)(const void* key, void* ctx)=NULL;
29
30 void bcal_nessie_dummy_init(const void* key, uint16_t keysize, void* ctx){
31         if(bcal_nessie_dummy_init_fpt){
32                 bcal_nessie_dummy_init_fpt(key, ctx);
33         }else{
34                 memcpy(ctx, key, (keysize+7)/8);
35         }
36 }
37
38 void bcal_nessie(const bcdesc_t* bcd){
39         if(bcd->type!=BCDESC_TYPE_BLOCKCIPHER)
40                 return;
41         nessie_bc_init();
42
43         nessie_bc_ctx.blocksize_B = (bcd->blocksize_b+7)/8;
44         nessie_bc_ctx.name        = bcd->name;
45         nessie_bc_ctx.ctx_size_B  = bcd->ctxsize_B;
46         nessie_bc_ctx.cipher_enc  = (nessie_bc_enc_fpt)(bcd->enc.encvoid);
47         nessie_bc_ctx.cipher_dec  = (nessie_bc_dec_fpt)(bcd->dec.decvoid);
48         nessie_bc_ctx.cipher_free = (nessie_bc_free_fpt)(bcd->free);
49         if(((bcd->flags)&BC_INIT_TYPE)==BC_INIT_TYPE_2){
50                 nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)(bcd->init.initvoid);
51         }else{
52                 bcal_nessie_dummy_init_fpt = (void(*)(const void*,void*))(bcd->init.initvoid);
53                 nessie_bc_ctx.cipher_genctx  = (nessie_bc_gen_fpt)bcal_nessie_dummy_init;
54         }
55
56         uint16_t *keysize_list=NULL;
57         uint16_t items,i;
58         items = get_keysizes(bcd->valid_keysize_desc, &keysize_list);
59         if(items){
60                 for(i=0; i<items; ++i){
61                         nessie_bc_ctx.keysize_b   = keysize_list[i];
62                         nessie_bc_run();
63                 }
64                 free(keysize_list);
65         }
66
67 }
68
69 void bcal_nessie_multiple(const bcdesc_t* const * bcd_list){
70         const bcdesc_t* bcd;
71         for(;;){
72                 bcd = *bcd_list++;
73                 if(!bcd)
74                         return;
75                 bcal_nessie(bcd);
76         }
77 }
78