]> git.cryptolib.org Git - avr-crypto-lib.git/blob - shabal/shabal384.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / shabal / shabal384.c
1 /* shabal384.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
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    shabal384.c
21  * \author  Daniel Otte
22  * \email   bg@nerilex.org
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 const uint32_t shabal384_iv[] PROGMEM = {
34         /* A */ 
35         0xC8FCA331, 0xE55C504E, 0x003EBF26, 0xBB6B8D83, 
36         0x7B0448C1, 0x41B82789, 0x0A7C9601, 0x8D659CFF,
37         0xB6E2673E, 0xCA54C77B, 0x1460FD7E, 0x3FCB8F2D,
38         /* B */ 
39         0x527291FC, 0x2A16455F, 0x78E627E5, 0x944F169F, 
40         0x1CA6F016, 0xA854EA25, 0x8DB98ABE, 0xF2C62641,
41     0x30117DCB, 0xCF5C4309, 0x93711A25, 0xF9F671B8, 
42         0xB01D2116, 0x333F4B89, 0xB285D165, 0x86829B36,
43         /* C */ 
44         0xF764B11A, 0x76172146, 0xCEF6934D, 0xC6D28399, 
45         0xFE095F61, 0x5E6018B4, 0x5048ECF5, 0x51353261,
46     0x6E6E36DC, 0x63130DAD, 0xA9C69BD6, 0x1E90EA0C, 
47         0x7C35073B, 0x28D95E6D, 0xAA340E0D, 0xCB3DEE70
48 };
49
50 void shabal384_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(&(shabal384_iv[i]));
57         }
58         for(i=0;i<16;++i){
59                 ctx->b[i] = pgm_read_dword(&(shabal384_iv[SHABAL_R+i]));
60         }
61         for(i=0;i<16;++i){
62                 ctx->c[i] = pgm_read_dword(&(shabal384_iv[SHABAL_R+16+i]));
63         }
64 }
65
66 void shabal384_ctx2hash(void *dest, const shabal_ctx_t *ctx){
67         shabal_ctx2hash(dest, ctx, 384);
68 }
69
70 void shabal384(void *dest, void *msg, uint32_t length_b){
71         shabal_ctx_t ctx;
72         shabal384_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         shabal384_ctx2hash(dest, &ctx);
80 }