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/>.
21 * \email daniel.otte@rub.de
23 * \license GPLv3 or later
29 #include "threefish.h"
33 void ubi1024_init(ubi1024_ctx_t *ctx, const void *g, uint8_t type){
34 memset(ctx->tweak.v8, 0, 15);
35 ctx->tweak.v8[15] = 0x40+type;
36 memcpy(ctx->g, g, UBI1024_BLOCKSIZE_B);
39 void ubi1024_nextBlock(ubi1024_ctx_t *ctx, const void *block){
40 threefish1024_ctx_t tfctx;
41 ctx->tweak.v64[0] += UBI1024_BLOCKSIZE_B;
42 threefish1024_init(ctx->g, ctx->tweak.v8, &tfctx);
43 memcpy(ctx->g, block, UBI1024_BLOCKSIZE_B);
44 threefish1024_enc(ctx->g, &tfctx);
45 memxor(ctx->g, block, UBI1024_BLOCKSIZE_B);
46 ctx->tweak.v8[15] &= (uint8_t)~0x40;
50 void ubi1024_lastBlock(ubi1024_ctx_t *ctx, const void *block, uint16_t length_b){
51 threefish1024_ctx_t tfctx;
52 while(length_b>UBI1024_BLOCKSIZE){
53 ubi1024_nextBlock(ctx, block);
54 block = (uint8_t*)block + UBI1024_BLOCKSIZE_B;
55 length_b -= UBI1024_BLOCKSIZE;
57 ctx->tweak.v8[15] |= 0x80;
58 ctx->tweak.v64[0] += (length_b+7)/8;
60 ctx->tweak.v8[14] |= 0x80;
61 threefish1024_init(ctx->g, ctx->tweak.v8, &tfctx);
62 memset(ctx->g, 0, UBI1024_BLOCKSIZE_B);
63 memcpy(ctx->g, block, (length_b+7)/8);
65 ctx->g[(length_b+7)/8-1] |= 0x80>>(length_b&7);
66 threefish1024_enc(ctx->g, &tfctx);
67 memxor(ctx->g, block, (length_b+7)/8);
69 ctx->g[((length_b+7)/8)-1] ^= 0x80>>(length_b&7);
73 void ubi1024_ctx2hash(void *dest, const ubi1024_ctx_t *ctx){
74 memcpy(dest, ctx->g, UBI1024_BLOCKSIZE_B);