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){
27 ctx->desc_ptr = (hfdesc_t*)hash_descriptor;
28 if(!(ctx->ctx=malloc(pgm_read_word(&(hash_descriptor->ctxsize_B)))))
30 f= (hf_init_fpt)pgm_read_word(&(hash_descriptor->init));
35 void hfal_hash_nextBlock(hfgen_ctx_t* ctx, const void* block){
37 hfdesc_t* x=(ctx->desc_ptr);
38 f =(hf_nextBlock_fpt)pgm_read_word(&(x->nextBlock));
42 void hfal_hash_lastBlock(hfgen_ctx_t* ctx, const void* block, uint16_t length_b){
44 hfdesc_t* x=ctx->desc_ptr;
45 f =(hf_lastBlock_fpt)pgm_read_word(&(x->lastBlock));
46 f(ctx->ctx, block, length_b);
49 void hfal_hash_ctx2hash(void* dest, hfgen_ctx_t* ctx){
51 hfdesc_t* x=ctx->desc_ptr;
52 f =(hf_ctx2hash_fpt)pgm_read_word(&(x->ctx2hash));
56 void hfal_hash_free(hfgen_ctx_t* ctx){
58 hfdesc_t* x=ctx->desc_ptr;
59 f =(hf_free_fpt)pgm_read_word(&(x->free));
65 void hfal_hash_mem(const hfdesc_t* hash_descriptor, void* dest, const void* msg, uint32_t length_b){
67 f = (void_fpt)pgm_read_word(&(hash_descriptor->mem));
69 ((hf_mem_fpt)f)(dest, msg, length_b);
73 uint8_t ctx[pgm_read_word(&(hash_descriptor->ctxsize_B))];
74 f=(void_fpt)pgm_read_word(&(hash_descriptor->init));
75 ((hf_init_fpt)f)(ctx);
76 bs=pgm_read_word(&(hash_descriptor->blocksize_b));
78 f=(void_fpt)pgm_read_word(&(hash_descriptor->nextBlock));
80 ((hf_nextBlock_fpt)f)(ctx, msg);
82 msg = (uint8_t*)msg + bsb;
84 f=(void_fpt)pgm_read_word(&(hash_descriptor->lastBlock));
85 ((hf_lastBlock_fpt)f)(ctx, msg, length_b);
86 f=(void_fpt)pgm_read_word(&(hash_descriptor->ctx2hash));
87 ((hf_ctx2hash_fpt)f)(dest, ctx);
91 uint16_t hfal_hash_getBlocksize(const hfdesc_t* hash_descriptor){
93 ret = pgm_read_word(&(hash_descriptor->blocksize_b));
97 uint16_t hfal_hash_getHashsize(const hfdesc_t* hash_descriptor){
99 ret = pgm_read_word(&(hash_descriptor->hashsize_b));