3 This file is part of the ARM-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/>.
22 * \email daniel.otte@rub.de
24 * \license GPLv3 or later
38 uint32_t shabal_u(uint32_t a){
39 return (a<<1)+a; /* a*3 */
43 uint32_t shabal_v(uint32_t a){
44 return (a<<2)+a; /* a*5 */
47 #define ROTL32(a,n) (((a)<<(n))|((a)>>(32-(n))))
50 void shabal_p(shabal_ctx_t* ctx, const void* m){
53 ctx->b[i] = ROTL32(ctx->b[i],17);
55 for(j=0;j<SHABAL_P;j++){
57 ctx->a[(i+j*16)%SHABAL_R] =
58 shabal_u(ctx->a[(i+j*16)%SHABAL_R]
59 ^ shabal_v(ROTL32(ctx->a[(i+j*16+SHABAL_R-1)%SHABAL_R],15))
60 ^ ctx->c[(8-i+16)%16])
61 ^ ctx->b[(i+SHABAL_O1)%16]
62 ^ ((ctx->b[(i+SHABAL_O2)%16]) & ~(ctx->b[(i+SHABAL_O3)%16]))
64 ctx->b[i] = ROTL32(ctx->b[i], 1) ^ ~(ctx->a[(i+j*16)%SHABAL_R]);
69 ctx->a[j%SHABAL_R] += ctx->c[(j+3)%16];
73 void shabal_nextBlock(shabal_ctx_t* ctx, const void* block){
77 ctx->b[i] += ((uint32_t*)block)[i];
79 ctx->a[0] ^= ctx->w.w32[0];
80 ctx->a[1] ^= ctx->w.w32[1];
83 ctx->c[i] -= ((uint32_t*)block)[i];
91 void shabal_lastBlock(shabal_ctx_t* ctx, const void* block, uint16_t length_b){
95 while(length_b>=SHABAL_BLOCKSIZE){
96 shabal_nextBlock(ctx, block);
97 block = (uint8_t*)block + SHABAL_BLOCKSIZE_B;
98 length_b -= SHABAL_BLOCKSIZE;
100 memset(buffer, 0, 64);
101 memcpy(buffer, block, (length_b+7)/8);
102 buffer[length_b/8] |= 0x80>>(length_b%8);
105 ctx->b[i] += ((uint32_t*)buffer)[i];
109 ctx->a[0] ^= ctx->w.w32[0];
110 ctx->a[1] ^= ctx->w.w32[1];
111 shabal_p(ctx, buffer);
119 void shabal_ctx2hash(void* dest, const shabal_ctx_t* ctx, uint16_t outlength_b){
120 memcpy(dest, &(ctx->c[16-outlength_b/32]), outlength_b/8);