2010-12-21 01:31:02 +00:00
|
|
|
/* bcal-nessie.c */
|
|
|
|
/*
|
2014-02-22 17:00:36 +00:00
|
|
|
This file is part of the AVR-Crypto-Lib.
|
2015-02-06 02:43:31 +00:00
|
|
|
Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
|
2010-12-21 01:31:02 +00:00
|
|
|
|
2014-02-22 17:00:36 +00:00
|
|
|
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.
|
2010-12-21 01:31:02 +00:00
|
|
|
|
2014-02-22 17:00:36 +00:00
|
|
|
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.
|
2010-12-21 01:31:02 +00:00
|
|
|
|
2014-02-22 17:00:36 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2010-12-21 01:31:02 +00:00
|
|
|
|
|
|
|
#include "nessie_bc_test.h"
|
|
|
|
#include "blockcipher_descriptor.h"
|
|
|
|
#include "keysize_descriptor.h"
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <avr/pgmspace.h>
|
|
|
|
|
2014-02-22 17:00:36 +00:00
|
|
|
void (*bcal_nessie_dummy_init_fpt)(const void *key, void *ctx) = NULL;
|
2010-12-21 01:31:02 +00:00
|
|
|
|
2014-02-22 17:00:36 +00:00
|
|
|
void bcal_nessie_dummy_init(const void *key, uint16_t keysize, void *ctx)
|
|
|
|
{
|
|
|
|
if (bcal_nessie_dummy_init_fpt) {
|
|
|
|
bcal_nessie_dummy_init_fpt(key, ctx);
|
|
|
|
} else {
|
|
|
|
memcpy(ctx, key, (keysize + 7) / 8);
|
|
|
|
}
|
2010-12-21 01:31:02 +00:00
|
|
|
}
|
|
|
|
|
2014-02-22 17:00:36 +00:00
|
|
|
void bcal_nessie(const bcdesc_t *bcd)
|
|
|
|
{
|
|
|
|
if (pgm_read_byte(&(bcd->type)) != BCDESC_TYPE_BLOCKCIPHER)
|
|
|
|
return;
|
|
|
|
char name[1 + strlen_P((void*) pgm_read_word(&(bcd->name)))];
|
|
|
|
strcpy_P(name, (void*) pgm_read_word(&(bcd->name)));
|
|
|
|
nessie_bc_init();
|
2010-12-21 01:31:02 +00:00
|
|
|
|
2014-02-22 17:00:36 +00:00
|
|
|
nessie_bc_ctx.blocksize_B = (pgm_read_word(&(bcd->blocksize_b)) + 7) / 8;
|
|
|
|
nessie_bc_ctx.name = name;
|
|
|
|
nessie_bc_ctx.ctx_size_B = pgm_read_word(&(bcd->ctxsize_B));
|
|
|
|
nessie_bc_ctx.cipher_enc = (nessie_bc_enc_fpt) pgm_read_word(&(bcd->enc));
|
|
|
|
nessie_bc_ctx.cipher_dec = (nessie_bc_dec_fpt) pgm_read_word(&(bcd->dec));
|
|
|
|
nessie_bc_ctx.cipher_free =
|
|
|
|
(nessie_bc_free_fpt) pgm_read_word(&(bcd->free));
|
|
|
|
if ((pgm_read_byte(&(bcd->flags)) & BC_INIT_TYPE) == BC_INIT_TYPE_2) {
|
|
|
|
nessie_bc_ctx.cipher_genctx =
|
|
|
|
(nessie_bc_gen_fpt) pgm_read_word(&(bcd->init));
|
|
|
|
} else {
|
|
|
|
bcal_nessie_dummy_init_fpt =
|
|
|
|
(void (*)(const void*, void*)) pgm_read_word(&(bcd->init));
|
|
|
|
nessie_bc_ctx.cipher_genctx =
|
|
|
|
(nessie_bc_gen_fpt) bcal_nessie_dummy_init;
|
|
|
|
}
|
2010-12-21 01:31:02 +00:00
|
|
|
|
2014-02-22 17:00:36 +00:00
|
|
|
uint16_t *keysize_list = NULL;
|
|
|
|
uint16_t items, i;
|
|
|
|
items =
|
|
|
|
get_keysizes((PGM_VOID_P) pgm_read_word(&(bcd->valid_keysize_desc)), &keysize_list);
|
|
|
|
if (items) {
|
|
|
|
for (i = 0; i < items; ++i) {
|
|
|
|
nessie_bc_ctx.keysize_b = keysize_list[i];
|
|
|
|
nessie_bc_run();
|
|
|
|
}
|
|
|
|
free(keysize_list);
|
|
|
|
}
|
2010-12-21 01:31:02 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2014-02-22 17:00:36 +00:00
|
|
|
void bcal_nessie_multiple(const bcdesc_t * const *bcd_list)
|
|
|
|
{
|
|
|
|
const bcdesc_t *bcd;
|
|
|
|
for (;;) {
|
|
|
|
bcd = (void*) pgm_read_word(bcd_list);
|
|
|
|
if (!bcd)
|
|
|
|
return;
|
|
|
|
bcal_nessie(bcd);
|
|
|
|
bcd_list = (void*) ((uint8_t*) bcd_list + 2);
|
|
|
|
}
|
2010-12-21 01:31:02 +00:00
|
|
|
}
|
|
|
|
|