3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2009 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
34 void skein256_init(skein256_ctx_t *ctx, uint16_t outsize_b){
36 uint8_t null[UBI256_BLOCKSIZE_B];
37 memset(null, 0, UBI256_BLOCKSIZE_B);
38 memset(&conf, 0, sizeof(skein_config_t));
44 conf.out_length = outsize_b;
45 ctx->outsize_b = outsize_b;
46 ubi256_init(&(ctx->ubictx), null, UBI_TYPE_CFG);
47 ubi256_lastBlock(&(ctx->ubictx), &conf, 256);
48 ubi256_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG);
51 void skein256_nextBlock(skein256_ctx_t *ctx, const void *block){
52 ubi256_nextBlock(&(ctx->ubictx), block);
55 void skein256_lastBlock(skein256_ctx_t *ctx, const void *block, uint16_t length_b){
56 ubi256_lastBlock(&(ctx->ubictx), block, length_b);
59 void skein256_ctx2hash(void *dest, skein256_ctx_t *ctx){
64 uint8_t outbuffer[UBI256_BLOCKSIZE_B];
65 ubi256_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT);
67 outsize_b = ctx->outsize_b;
69 memcpy(&uctx, &(ctx->ubictx), sizeof(ubi256_ctx_t));
70 ubi256_lastBlock(&uctx, &counter, 64);
71 ubi256_ctx2hash(outbuffer, &uctx);
72 if(outsize_b<=UBI256_BLOCKSIZE){
73 memcpy(dest, outbuffer, (outsize_b+7)/8);
76 memcpy(dest, outbuffer, UBI256_BLOCKSIZE_B);
77 dest = (uint8_t*)dest + UBI256_BLOCKSIZE_B;
78 outsize_b -= UBI256_BLOCKSIZE;
84 void skein256(void *dest, uint16_t outlength_b,const void *msg, uint32_t length_b){
86 skein256_init(&ctx, outlength_b);
87 while(length_b>SKEIN256_BLOCKSIZE){
88 skein256_nextBlock(&ctx, msg);
89 msg = (uint8_t*)msg + SKEIN256_BLOCKSIZE_B;
90 length_b -= SKEIN256_BLOCKSIZE;
92 skein256_lastBlock(&ctx, msg, length_b);
93 skein256_ctx2hash(dest, &ctx);