]> git.cryptolib.org Git - arm-crypto-lib.git/blob - shabal/shabal256.c
a lot of fixing ...
[arm-crypto-lib.git] / shabal / shabal256.c
1 /* shabal256.c */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2006-2010  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    shabal256.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 <string.h>
31
32 const uint32_t shabal256_iv[] = {
33         /* A */ 
34         0x52F84552, 0xE54B7999, 0x2D8EE3EC, 0xB9645191, 
35         0xE0078B86, 0xBB7C44C9, 0xD2B5C1CA, 0xB0D2EB8C,
36         0x14CE5A45, 0x22AF50DC, 0xEFFDBC6B, 0xEB21B74A,
37         /* B */ 
38         0xB555C6EE, 0x3E710596, 0xA72A652F, 0x9301515F, 
39         0xDA28C1FA, 0x696FD868, 0x9CB6BF72, 0x0AFE4002,
40     0xA6E03615, 0x5138C1D4, 0xBE216306, 0xB38B8890, 
41         0x3EA8B96B, 0x3299ACE4, 0x30924DD4, 0x55CB34A5,
42         /* C */ 
43         0xB405F031, 0xC4233EBA, 0xB3733979, 0xC0DD9D55,
44         0xC51C28AE, 0xA327B8E1, 0x56C56167, 0xED614433,
45         0x88B59D60, 0x60E2CEBA, 0x758B4B8B, 0x83E82A7F, 
46         0xBC968828, 0xE6E00BF7, 0xBA839E55, 0x9B491C60
47 };
48
49 void shabal256_init(shabal_ctx_t* ctx){
50         uint8_t i;
51         ctx->b = ctx->b_buffer;
52         ctx->c = ctx->c_buffer;
53         ctx->w.w64 = 1LL;
54         for(i=0;i<SHABAL_R;++i){
55                 ctx->a[i] = shabal256_iv[i];
56         }
57         for(i=0;i<16;++i){
58                 ctx->b[i] = shabal256_iv[SHABAL_R+i];
59         }
60         for(i=0;i<16;++i){
61                 ctx->c[i] = shabal256_iv[SHABAL_R+16+i];
62         }
63 }
64
65 void shabal256_ctx2hash(void* dest, const shabal_ctx_t* ctx){
66         shabal_ctx2hash(dest, ctx, 256);
67 }
68
69 void shabal256(void* dest, void* msg, uint32_t length_b){
70         shabal_ctx_t ctx;
71         shabal256_init(&ctx);
72         while(length_b>=SHABAL_BLOCKSIZE){
73                 shabal_nextBlock(&ctx, msg);
74                 msg = (uint8_t*)msg+SHABAL_BLOCKSIZE_B;
75                 length_b -= SHABAL_BLOCKSIZE;
76         }
77         shabal_lastBlock(&ctx, msg, length_b);
78         shabal256_ctx2hash(dest, &ctx);
79 }