1 /* jh_simple_speed.c */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2006-2010 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/>.
21 #include <avr/pgmspace.h>
25 #include "jh_simple.h"
34 void jh_init(uint16_t hashlen_b, jh_ctx_t* ctx){
35 memset(ctx->a, 0, 128);
36 ctx->a[0] = hashlen_b>>8;
37 ctx->a[1] = hashlen_b&0xff;
42 void jh_nextBlock(jh_ctx_t* ctx, void* block){
43 memxor(ctx->a, block, 64);
45 memxor(ctx->a+64, block, 64);
49 void jh_lastBlock(jh_ctx_t* ctx, void* block, uint16_t length_b){
50 while(length_b>=64*8){
51 jh_nextBlock(ctx, block);
52 block = (uint8_t*)block + 64;
56 uint64_t total_length;
57 memset(buffer, 0, 64);
58 memcpy(buffer, block, (length_b+7)/8);
59 buffer[length_b/8] |= 0x80>>(length_b%8);
60 total_length=ctx->block_hashed*512+length_b;
64 jh_nextBlock(ctx, buffer);
67 memset(buffer+1, 0, 64-8-1);
68 buffer[63] = total_length&0xff;
69 buffer[62] = (total_length>> 8)&0xff;
70 buffer[61] = (total_length>>16)&0xff;
71 buffer[60] = (total_length>>24)&0xff;
72 buffer[59] = (total_length>>32)&0xff;
73 buffer[58] = (total_length>>40)&0xff;
74 buffer[57] = (total_length>>48)&0xff;
75 buffer[56] = (total_length>>56)&0xff;
76 jh_nextBlock(ctx, buffer);
79 void jh_ctx2hash(void* dest, uint16_t length_b, jh_ctx_t* ctx){
80 memcpy(dest, ctx->a+128-(length_b+7)/8, (length_b+7)/8);
84 void jh224_init(jh_ctx_t* ctx){
88 void jh224_ctx2hash(void* dest, jh_ctx_t* ctx){
89 jh_ctx2hash(dest, 224, ctx);
92 void jh256_init(jh_ctx_t* ctx){
96 void jh256_ctx2hash(void* dest, jh_ctx_t* ctx){
97 jh_ctx2hash(dest, 256, ctx);
100 void jh384_init(jh_ctx_t* ctx){
104 void jh384_ctx2hash(void* dest, jh_ctx_t* ctx){
105 jh_ctx2hash(dest, 384, ctx);
108 void jh512_init(jh_ctx_t* ctx){
112 void jh512_ctx2hash(void* dest, jh_ctx_t* ctx){
113 jh_ctx2hash(dest, 512, ctx);