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 skein256_init(skein256_ctx_t* ctx, uint16_t outsize_b){
32 uint8_t null[UBI256_BLOCKSIZE_B];
33 memset(null, 0, UBI256_BLOCKSIZE_B);
34 memset(&conf, 0, sizeof(skein_config_t));
40 conf.out_length = outsize_b;
41 ctx->outsize_b = outsize_b;
42 ubi256_init(&(ctx->ubictx), null, UBI_TYPE_CFG);
43 ubi256_lastBlock(&(ctx->ubictx), &conf, 256);
44 ubi256_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_MSG);
49 * param outsize_b: r22:r23
90 /* call ubi256_lastBlock*/
95 rcall ubi256_lastBlock
107 /******************************************************************************/
108 .global skein256_nextBlock
111 rjmp ubi256_nextBlock
113 /******************************************************************************/
114 .global skein256_lastBlock
117 rjmp ubi256_lastBlock
119 /******************************************************************************/
121 void skein256_ctx2hash(void* dest, skein256_ctx_t* ctx){
126 uint8_t outbuffer[UBI256_BLOCKSIZE_B];
127 ubi256_init(&(ctx->ubictx), ctx->ubictx.g, UBI_TYPE_OUT);
129 outsize_b = ctx->outsize_b;
131 memcpy(&uctx, &(ctx->ubictx), sizeof(ubi256_ctx_t));
132 ubi256_lastBlock(&uctx, &counter, 64);
133 ubi256_ctx2hash(outbuffer, &uctx);
134 if(outsize_b<=UBI256_BLOCKSIZE){
135 memcpy(dest, outbuffer, (outsize_b+7)/8);
138 memcpy(dest, outbuffer, UBI256_BLOCKSIZE_B);
139 dest = (uint8_t*)dest + UBI256_BLOCKSIZE_B;
140 outsize_b -= UBI256_BLOCKSIZE;
147 * param dest: r24:r25
158 .global skein256_ctx2hash
162 stack_alloc_large 88 /* uctx || counter || outbuffer */
179 /* call ubi256_init */
188 /* copy ubictx in uctx*/
196 /* call ubi256_lastBlock */
203 rcall ubi256_lastBlock
204 /* copy uctx->g to outbuffer */
214 /* compare outsize_b with 256*/
221 5: /* copy outbuffer to dest */
231 movw DEST0, r30 ;XXX r26
232 /* adjust counter and outsize_b*/
247 3: /* last iteraton */
268 /******************************************************************************/
270 void skein256(void* dest, uint16_t outlength_b, const void* msg, uint32_t length_b){
272 skein256_init(&ctx, outlength_b);
273 while(length_b>SKEIN256_BLOCKSIZE){
274 skein256_nextBlock(&ctx, msg);
275 msg = (uint8_t*)msg + SKEIN256_BLOCKSIZE_B;
276 length_b -= SKEIN256_BLOCKSIZE;
278 skein256_lastBlock(&ctx, msg, length_b);
279 skein256_ctx2hash(dest, &ctx);
283 * param dest: r24:r25
284 * param outlength_b: r22:r23
286 * param length_b: r16:r19
308 /* call skein256_init */
315 /* call skein256_lastBlock */
319 rcall skein256_lastBlock
320 /* call skein256_ctx2hash */
323 rcall skein256_ctx2hash
329 4: /* process preceeding blocks */
332 rcall skein256_nextBlock