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"
33 void jh_encrypt(uint8_t *a);
35 void jh_init(uint16_t hashlen_b, jh_ctx_t *ctx){
36 memset(ctx->a, 0, 128);
37 ctx->a[0] = hashlen_b>>8;
38 ctx->a[1] = hashlen_b&0xff;
43 void jh_nextBlock(jh_ctx_t *ctx, void *block){
44 memxor(ctx->a, block, 64);
46 memxor(ctx->a+64, block, 64);
50 void jh_lastBlock(jh_ctx_t *ctx, void *block, uint16_t length_b){
51 while(length_b>=64*8){
52 jh_nextBlock(ctx, block);
53 block = (uint8_t*)block + 64;
57 uint64_t total_length;
58 memset(buffer, 0, 64);
59 memcpy(buffer, block, (length_b+7)/8);
60 buffer[length_b/8] |= 0x80>>(length_b%8);
61 total_length=ctx->block_hashed*512+length_b;
65 jh_nextBlock(ctx, buffer);
68 memset(buffer+1, 0, 64-8-1);
69 buffer[63] = total_length&0xff;
70 buffer[62] = (total_length>> 8)&0xff;
71 buffer[61] = (total_length>>16)&0xff;
72 buffer[60] = (total_length>>24)&0xff;
73 buffer[59] = (total_length>>32)&0xff;
74 buffer[58] = (total_length>>40)&0xff;
75 buffer[57] = (total_length>>48)&0xff;
76 buffer[56] = (total_length>>56)&0xff;
77 jh_nextBlock(ctx, buffer);
80 void jh_ctx2hash(void *dest, uint16_t length_b, jh_ctx_t *ctx){
81 memcpy(dest, ctx->a+128-(length_b+7)/8, (length_b+7)/8);
85 void jh224_init(jh_ctx_t *ctx){
89 void jh224_ctx2hash(void *dest, jh_ctx_t *ctx){
90 jh_ctx2hash(dest, 224, ctx);
93 void jh256_init(jh_ctx_t *ctx){
97 void jh256_ctx2hash(void *dest, jh_ctx_t *ctx){
98 jh_ctx2hash(dest, 256, ctx);
101 void jh384_init(jh_ctx_t *ctx){
105 void jh384_ctx2hash(void *dest, jh_ctx_t *ctx){
106 jh_ctx2hash(dest, 384, ctx);
109 void jh512_init(jh_ctx_t *ctx){
113 void jh512_ctx2hash(void *dest, jh_ctx_t *ctx){
114 jh_ctx2hash(dest, 512, ctx);