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
26 #include "avr-asm-macros.S"
28 /******************************************************************************/
30 void skein1024_init(skein1024_ctx_t* ctx, uint16_t outsize_b){
32 uint8_t null[UBI1024_BLOCKSIZE_B];
33 memset(null, 0, UBI1024_BLOCKSIZE_B);
34 memset(&conf, 0, sizeof(skein_config_t));
40 conf.out_length = outsize_b;
41 ctx->outsize_b = outsize_b;
42 ubi1024_init(&(ctx->ubictx), null, UBI_TYPE_CFG);
43 ubi1024_lastBlock(&(ctx->ubictx), &conf, 256);
44 ubi1024_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG);
49 * param outsize_b: r22:r23
55 .global skein1024_init
58 stack_alloc_large 32+128-22 ; |<- 22 ->|
59 adiw r30, 1 ; | CONF (32) |
60 movw CONF0, r30 ; | null (128) |
84 /* call ubi1024_init*/
91 /* call ubi1024_lastBlock*/
96 rcall ubi1024_lastBlock
97 /* call ubi1024_init*/
104 stack_free_large2 32+128-22
108 /******************************************************************************/
109 .global skein1024_nextBlock
112 rjmp ubi1024_nextBlock
114 /******************************************************************************/
115 .global skein1024_lastBlock
118 rjmp ubi1024_lastBlock
120 /******************************************************************************/
122 void skein1024_ctx2hash(void* dest, skein1024_ctx_t* ctx){
127 uint8_t outbuffer[UBI1024_BLOCKSIZE_B];
128 ubi1024_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT);
130 outsize_b = ctx->outsize_b;
132 memcpy(&uctx, &(ctx->ubictx), sizeof(ubi1024_ctx_t));
133 ubi1024_lastBlock(&uctx, &counter, 64);
134 ubi1024_ctx2hash(outbuffer, &uctx);
135 if(outsize_b<=UBI1024_BLOCKSIZE){
136 memcpy(dest, outbuffer, (ctx->outsize_b+7)/8);
139 memcpy(dest, outbuffer, UBI1024_BLOCKSIZE_B);
140 dest = (uint8_t*)dest + UBI1024_BLOCKSIZE_B;
141 outsize_b -= UBI1024_BLOCKSIZE;
148 * param dest: r24:r25
159 .global skein1024_ctx2hash
162 /* 144 || 8 || 128 */
163 stack_alloc_large 144+8+128 /* uctx || counter || outbuffer */
182 /* call ubi1024_init */
191 /* copy ubictx in uctx*/
199 /* call ubi1024_lastBlock */
208 rcall ubi1024_lastBlock
209 /* copy uctx->g to outbuffer */
221 /* compare outsize_b with 1024*/
228 5: /* copy outbuffer to dest */
241 /* adjust counter and outsize_b*/
258 3: /* last iteraton */
279 stack_free_large3 144+8+128
283 /******************************************************************************/
285 void skein1024(void* dest, uint16_t outlength_b, const void* msg, uint32_t length_b){
287 skein1024_init(&ctx, outlength_b);
288 while(length_b>SKEIN1024_BLOCKSIZE){
289 skein1024_nextBlock(&ctx, msg);
290 msg = (uint8_t*)msg + SKEIN1024_BLOCKSIZE_B;
291 length_b -= SKEIN1024_BLOCKSIZE;
293 skein1024_lastBlock(&ctx, msg, length_b);
294 skein1024_ctx2hash(dest, &ctx);
298 * param dest: r24:r25
299 * param outlength_b: r22:r23
301 * param length_b: r16:r19
316 stack_alloc_large 146
323 /* call skein1024_init */
330 /* call skein1024_lastBlock */
334 rcall skein1024_lastBlock
335 /* call skein1024_ctx2hash */
338 rcall skein1024_ctx2hash
340 stack_free_large2 146
344 4: /* process preceeding blocks */
347 rcall skein1024_nextBlock