X-Git-Url: https://git.cryptolib.org/?a=blobdiff_plain;f=hfal-basic.c;h=1be95d37baf310735a7ddb067773fb8473a60c7b;hb=d32eba56ce10ea6b9eff123b50d9842673b38f2b;hp=cd6c026115293c8198f45e7efa06a555aa4cb8c5;hpb=e5a49deb52521f019e37779d6e9d81ec4f02aba4;p=avr-crypto-lib.git diff --git a/hfal-basic.c b/hfal-basic.c index cd6c026..1be95d3 100644 --- a/hfal-basic.c +++ b/hfal-basic.c @@ -27,7 +27,7 @@ uint8_t hfal_hash_init(const hfdesc_t* hash_descriptor, hfgen_ctx_t* ctx){ ctx->desc_ptr = (hfdesc_t*)hash_descriptor; if(!(ctx->ctx=malloc(pgm_read_word(&(hash_descriptor->ctxsize_B))))) return 3; - f= (hf_init_fpt)pgm_read_word(hash_descriptor->init); + f= (hf_init_fpt)pgm_read_word(&(hash_descriptor->init)); f(ctx->ctx); return 0; } @@ -39,11 +39,11 @@ void hfal_hash_nextBlock(hfgen_ctx_t* ctx, const void* block){ f(ctx->ctx, block); } -void hfal_hash_lastBlock(hfgen_ctx_t* ctx, const void* block, uint16_t size){ +void hfal_hash_lastBlock(hfgen_ctx_t* ctx, const void* block, uint16_t length_b){ hf_lastBlock_fpt f; hfdesc_t* x=ctx->desc_ptr; f =(hf_lastBlock_fpt)pgm_read_word(&(x->lastBlock)); - f(ctx->ctx, block, size); + f(ctx->ctx, block, length_b); } void hfal_hash_ctx2hash(void* dest, hfgen_ctx_t* ctx){ @@ -64,20 +64,38 @@ void hfal_hash_free(hfgen_ctx_t* ctx){ void hfal_hash_mem(const hfdesc_t* hash_descriptor, void* dest, const void* msg, uint32_t length_b){ void_fpt f; - uint16_t bs,bsb; - uint8_t ctx[pgm_read_word(&(hash_descriptor->ctxsize_B))]; - f=(void_fpt)pgm_read_word(&(hash_descriptor->init)); - ((hf_init_fpt)f)(ctx); - bs=pgm_read_word(&(hash_descriptor->blocksize_b)); - bsb=bs/8; - f=(void_fpt)pgm_read_word(&(hash_descriptor->nextBlock)); - while(length_b>=bs){ - ((hf_nextBlock_fpt)f)(ctx, msg); - length_b -= bs; - msg = (uint8_t*)msg + bsb; + f = (void_fpt)pgm_read_word(&(hash_descriptor->mem)); + if(f){ + ((hf_mem_fpt)f)(dest, msg, length_b); + }else{ + + uint16_t bs,bsb; + uint8_t ctx[pgm_read_word(&(hash_descriptor->ctxsize_B))]; + f=(void_fpt)pgm_read_word(&(hash_descriptor->init)); + ((hf_init_fpt)f)(ctx); + bs=pgm_read_word(&(hash_descriptor->blocksize_b)); + bsb=bs/8; + f=(void_fpt)pgm_read_word(&(hash_descriptor->nextBlock)); + while(length_b>=bs){ + ((hf_nextBlock_fpt)f)(ctx, msg); + length_b -= bs; + msg = (uint8_t*)msg + bsb; + } + f=(void_fpt)pgm_read_word(&(hash_descriptor->lastBlock)); + ((hf_lastBlock_fpt)f)(ctx, msg, length_b); + f=(void_fpt)pgm_read_word(&(hash_descriptor->ctx2hash)); + ((hf_ctx2hash_fpt)f)(dest, ctx); } - f=(void_fpt)pgm_read_word(&(hash_descriptor->lastBlock)); - ((hf_lastBlock_fpt)f)(ctx, msg, length_b); - f=(void_fpt)pgm_read_word(&(hash_descriptor->ctx2hash)); - ((hf_ctx2hash_fpt)f)(dest, ctx); } + +uint16_t hfal_hash_getBlocksize(const hfdesc_t* hash_descriptor){ + uint16_t ret; + ret = pgm_read_word(&(hash_descriptor->blocksize_b)); + return ret; +} + +uint16_t hfal_hash_getHashsize(const hfdesc_t* hash_descriptor){ + uint16_t ret; + ret = pgm_read_word(&(hash_descriptor->hashsize_b)); + return ret; +}