3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
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 bg@nerilex.org
23 * \license GPLv3 or later
33 void skein1024_init(skein1024_ctx_t *ctx, uint16_t outsize_b){
35 uint8_t null[UBI1024_BLOCKSIZE_B];
36 memset(null, 0, UBI1024_BLOCKSIZE_B);
37 memset(&conf, 0, sizeof(skein_config_t));
43 conf.out_length = outsize_b;
44 ctx->outsize_b = outsize_b;
45 ubi1024_init(&(ctx->ubictx), null, UBI_TYPE_CFG);
46 ubi1024_lastBlock(&(ctx->ubictx), &conf, 256);
47 ubi1024_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG);
50 void skein1024_nextBlock(skein1024_ctx_t *ctx, const void *block){
51 ubi1024_nextBlock(&(ctx->ubictx), block);
54 void skein1024_lastBlock(skein1024_ctx_t *ctx, const void *block, uint16_t length_b){
55 ubi1024_lastBlock(&(ctx->ubictx), block, length_b);
58 void skein1024_ctx2hash(void *dest, skein1024_ctx_t *ctx){
63 uint8_t outbuffer[UBI1024_BLOCKSIZE_B];
64 ubi1024_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT);
66 outsize_b = ctx->outsize_b;
68 memcpy(&uctx, &(ctx->ubictx), sizeof(ubi1024_ctx_t));
69 ubi1024_lastBlock(&uctx, &counter, 64);
70 ubi1024_ctx2hash(outbuffer, &uctx);
71 if(outsize_b<=UBI1024_BLOCKSIZE){
72 memcpy(dest, outbuffer, (ctx->outsize_b+7)/8);
75 memcpy(dest, outbuffer, UBI1024_BLOCKSIZE_B);
76 dest = (uint8_t*)dest + UBI1024_BLOCKSIZE_B;
77 outsize_b -= UBI1024_BLOCKSIZE;
83 void skein1024(void *dest, uint16_t outlength_b, const void *msg, uint32_t length_b){
85 skein1024_init(&ctx, outlength_b);
86 while(length_b>SKEIN1024_BLOCKSIZE){
87 skein1024_nextBlock(&ctx, msg);
88 msg = (uint8_t*)msg + SKEIN1024_BLOCKSIZE_B;
89 length_b -= SKEIN1024_BLOCKSIZE;
91 skein1024_lastBlock(&ctx, msg, length_b);
92 skein1024_ctx2hash(dest, &ctx);