]> git.cryptolib.org Git - avr-crypto-lib.git/blob - shabal/shabal224.c
updated Grøstl for round 3
[avr-crypto-lib.git] / shabal / shabal224.c
1 /* shabal224.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2009  Daniel Otte (daniel.otte@rub.de)
5
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.
10
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.
15
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/>.
18 */
19 /*
20  * \file    shabal224.c
21  * \author  Daniel Otte
22  * \email   daniel.otte@rub.de
23  * \date    2009-04-27
24  * \license GPLv3 or later
25  * 
26  */
27
28 #include <stdint.h>
29 #include "shabal.h"
30 #include <avr/pgmspace.h>
31 #include <string.h>
32
33 uint32_t shabal224_iv[] PROGMEM = {
34         /* A */
35         0xA5201467, 0xA9B8D94A, 0xD4CED997, 0x68379D7B, 
36         0xA7FC73BA, 0xF1A2546B, 0x606782BF, 0xE0BCFD0F,
37         0x2F25374E, 0x069A149F, 0x5E2DFF25, 0xFAECF061,
38         /* B */ 
39         0xEC9905D8, 0xF21850CF, 0xC0A746C8, 0x21DAD498,
40         0x35156EEB, 0x088C97F2, 0x26303E40, 0x8A2D4FB5,
41     0xFEEE44B6, 0x8A1E9573, 0x7B81111A, 0xCBC139F0, 
42         0xA3513861, 0x1D2C362E, 0x918C580E, 0xB58E1B9C,
43         /* C */
44         0xE4B573A1, 0x4C1A0880, 0x1E907C51, 0x04807EFD, 
45         0x3AD8CDE5, 0x16B21302, 0x02512C53, 0x2204CB18,
46     0x99405F2D, 0xE5B648A1, 0x70AB1D43, 0xA10C25C2, 
47         0x16F1AC05, 0x38BBEB56, 0x9B01DC60, 0xB1096D83
48 };
49
50 void shabal224_init(shabal_ctx_t* ctx){
51         uint8_t i;
52         ctx->b = ctx->b_buffer;
53         ctx->c = ctx->c_buffer;
54         ctx->w.w64 = 1LL;
55         for(i=0;i<SHABAL_R;++i){
56                 ctx->a[i] = pgm_read_dword(&(shabal224_iv[i]));
57         }
58         for(i=0;i<16;++i){
59                 ctx->b[i] = pgm_read_dword(&(shabal224_iv[SHABAL_R+i]));
60         }
61         for(i=0;i<16;++i){
62                 ctx->c[i] = pgm_read_dword(&(shabal224_iv[SHABAL_R+16+i]));
63         }
64 }
65
66 void shabal224_ctx2hash(void* dest, const shabal_ctx_t* ctx){
67         shabal_ctx2hash(dest, ctx, 224);
68 }
69
70 void shabal224(void* dest, void* msg, uint32_t length_b){
71         shabal_ctx_t ctx;
72         shabal224_init(&ctx);
73         while(length_b>=SHABAL_BLOCKSIZE){
74                 shabal_nextBlock(&ctx, msg);
75                 msg = (uint8_t*)msg+SHABAL_BLOCKSIZE_B;
76                 length_b -= SHABAL_BLOCKSIZE;
77         }
78         shabal_lastBlock(&ctx, msg, length_b);
79         shabal224_ctx2hash(dest, &ctx);
80 }