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
33 void skein256_init(skein256_ctx_t* ctx, uint16_t outsize_b){
35 uint8_t null[UBI256_BLOCKSIZE_B];
36 memset(null, 0, UBI256_BLOCKSIZE_B);
37 memset(&conf, 0, sizeof(skein_config_t));
43 conf.out_length = outsize_b;
44 ctx->outsize_b = outsize_b;
45 ubi256_init(&(ctx->ubictx), null, UBI_TYPE_CFG);
46 ubi256_lastBlock(&(ctx->ubictx), &conf, 256);
47 ubi256_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG);
50 void skein256_nextBlock(skein256_ctx_t* ctx, const void* block){
51 ubi256_nextBlock(&(ctx->ubictx), block);
54 void skein256_lastBlock(skein256_ctx_t* ctx, const void* block, uint16_t length_b){
55 ubi256_lastBlock(&(ctx->ubictx), block, length_b);
58 void skein256_ctx2hash(void* dest, skein256_ctx_t* ctx){
63 uint8_t outbuffer[UBI256_BLOCKSIZE_B];
64 ubi256_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT);
66 outsize_b = ctx->outsize_b;
68 memcpy(&uctx, &(ctx->ubictx), sizeof(ubi256_ctx_t));
69 ubi256_lastBlock(&uctx, &counter, 64);
70 ubi256_ctx2hash(outbuffer, &uctx);
71 if(outsize_b<=UBI256_BLOCKSIZE){
72 memcpy(dest, outbuffer, (outsize_b+7)/8);
75 memcpy(dest, outbuffer, UBI256_BLOCKSIZE_B);
76 dest = (uint8_t*)dest + UBI256_BLOCKSIZE_B;
77 outsize_b -= UBI256_BLOCKSIZE;
83 void skein256(void* dest, uint16_t outlength_b,const void* msg, uint32_t length_b){
85 skein256_init(&ctx, outlength_b);
86 while(length_b>SKEIN256_BLOCKSIZE){
87 skein256_nextBlock(&ctx, msg);
88 msg = (uint8_t*)msg + SKEIN256_BLOCKSIZE_B;
89 length_b -= SKEIN256_BLOCKSIZE;
91 skein256_lastBlock(&ctx, msg, length_b);
92 skein256_ctx2hash(dest, &ctx);