3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2009 Daniel Otte (daniel.otte@rub.de)
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.
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.
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/>.
20 #include <avr/pgmspace.h>
21 #include "hashfunction_descriptor.h"
22 #include "hfal-basic.h"
25 uint8_t hfal_hash_init(const hfdesc_t* hash_descriptor, hfgen_ctx_t* ctx){
28 ctx->desc_ptr = (hfdesc_t*)hash_descriptor;
29 tmp = pgm_read_word(&(hash_descriptor->ctxsize_B));
30 if(!(ctx->ctx=malloc(tmp)))
32 f= (hf_init_fpt)pgm_read_word(&(hash_descriptor->init));
37 void hfal_hash_nextBlock(hfgen_ctx_t* ctx, const void* block){
39 hfdesc_t* x=(ctx->desc_ptr);
40 f =(hf_nextBlock_fpt)pgm_read_word(&(x->nextBlock));
44 void hfal_hash_lastBlock(hfgen_ctx_t* ctx, const void* block, uint16_t length_b){
46 hfdesc_t* x=ctx->desc_ptr;
47 f =(hf_lastBlock_fpt)pgm_read_word(&(x->lastBlock));
48 f(ctx->ctx, block, length_b);
51 void hfal_hash_ctx2hash(void* dest, hfgen_ctx_t* ctx){
53 hfdesc_t* x=ctx->desc_ptr;
54 f =(hf_ctx2hash_fpt)pgm_read_word(&(x->ctx2hash));
58 void hfal_hash_free(hfgen_ctx_t* ctx){
60 hfdesc_t* x=ctx->desc_ptr;
61 f =(hf_free_fpt)pgm_read_word(&(x->free));
67 void hfal_hash_mem(const hfdesc_t* hash_descriptor, void* dest, const void* msg, uint32_t length_b){
69 f = (void_fpt)pgm_read_word(&(hash_descriptor->mem));
71 ((hf_mem_fpt)f)(dest, msg, length_b);
74 uint8_t ctx[pgm_read_word(&(hash_descriptor->ctxsize_B))];
75 f=(void_fpt)(pgm_read_word(&(hash_descriptor->init)));
76 ((hf_init_fpt)f)(ctx);
77 bs=pgm_read_word(&(hash_descriptor->blocksize_b));
79 f=(void_fpt)(pgm_read_word(&(hash_descriptor->nextBlock)));
81 ((hf_nextBlock_fpt)f)(ctx, msg);
83 msg = (uint8_t*)msg + bsb;
85 f=(void_fpt)(pgm_read_word(&(hash_descriptor->lastBlock)));
86 ((hf_lastBlock_fpt)f)(ctx, msg, length_b);
87 f=(void_fpt)(pgm_read_word(&(hash_descriptor->ctx2hash)));
88 ((hf_ctx2hash_fpt)f)(dest, ctx);
92 uint16_t hfal_hash_getBlocksize(const hfdesc_t* hash_descriptor){
94 ret = pgm_read_word(&(hash_descriptor->blocksize_b));
98 uint16_t hfal_hash_getHashsize(const hfdesc_t* hash_descriptor){
100 ret = pgm_read_word(&(hash_descriptor->hashsize_b));
104 uint16_t hfal_hash_getCtxsize_B(const hfdesc_t* hash_descriptor){
106 ret = pgm_read_word(&(hash_descriptor->ctxsize_B));