1 /* cscipher_tiny_asm.S */
3 This file is part of the AVR-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/>.
20 #include "avr-asm-macros.S"
24 a ^= pgm_read_byte(fg_table+(a&0xf))&0xf0;
25 a ^= pgm_read_byte(fg_table+(a>>4)) &0x0f;
26 a ^= pgm_read_byte(fg_table+(a&0xf))&0xf0;
32 .byte 0xfa, 0xd6, 0xb0, 0xb2, 0x7b, 0x5e, 0x71, 0x78
33 .byte 0xed, 0xd4, 0xa5, 0xb3, 0xef, 0xdc, 0xe7, 0xf9
37 ldi r30, lo8(fg_table)
38 ldi r31, hi8(fg_table)
70 .byte 0x29,0x0d,0x61,0x40,0x9c,0xeb,0x9e,0x8f
71 .byte 0x1f,0x85,0x5f,0x58,0x5b,0x01,0x39,0x86
72 .byte 0x97,0x2e,0xd7,0xd6,0x35,0xae,0x17,0x16
73 .byte 0x21,0xb6,0x69,0x4e,0xa5,0x72,0x87,0x08
74 .byte 0x3c,0x18,0xe6,0xe7,0xfa,0xad,0xb8,0x89
75 .byte 0xb7,0x00,0xf7,0x6f,0x73,0x84,0x11,0x63
76 .byte 0x3f,0x96,0x7f,0x6e,0xbf,0x14,0x9d,0xac
77 .byte 0xa4,0x0e,0x7e,0xf6,0x20,0x4a,0x62,0x30
78 .byte 0x03,0xc5,0x4b,0x5a,0x46,0xa3,0x44,0x65
87 stack_alloc 24, 28, 29
91 /* copy key to local tmp_key */
101 /* copy part of tmp_key to tmp */
110 adiw r28, 8 /* Y points at tmp */
111 /* xor ks constant into tmp */
113 ldi r22, lo8(ks_const)
114 ldi r23, hi8(ks_const)
123 /* do P transformation */
130 sbiw r28, 8 /* Y points at tmp */
135 /* do T transformation */
145 sbiw r28, 8 /* Y points at tmp */
152 sbiw r28, 16 /* Y points at tmp_key (again) */
163 .byte 0xb7, 0xe1, 0x51, 0x62, 0x8a, 0xed, 0x2a, 0x6a
164 .byte 0xbf, 0x71, 0x58, 0x80, 0x9c, 0xf4, 0xf3, 0xc7
167 void cscipher_enc(void* buffer, const cscipher_ctx_t* ctx){
173 memxor(buffer, ctx->keys[i], 8);
175 memxor_P(buffer, round_const+((j==1)?0:8), 8);
178 ((uint16_t*)tmp)[k] = m(((uint16_t*)buffer)[k]);
181 ((uint8_t*)buffer)[k] = tmp[2*k];
182 ((uint8_t*)buffer)[k+4] = tmp[2*k+1];
186 memxor(buffer, ctx->keys[8], 8);
219 ldi r30, lo8(round_const)
220 ldi r31, hi8(round_const)
227 /* xor and m transformation */
291 void cscipher_dec(void* buffer, const cscipher_ctx_t* ctx){
294 memxor(buffer, ctx->keys[8], 8);
298 tmp[2*k] = ((uint8_t*)buffer)[k];
299 tmp[2*k+1] = ((uint8_t*)buffer)[4+k];
302 ((uint16_t*)buffer)[k] = m_inv(((uint16_t*)tmp)[k]);
305 memxor(buffer, ctx->keys[i], 8);
307 memxor_P(buffer, round_const+((j==1)?0:8), 8);
339 /* m_inv transformation */
384 ldi r26, lo8(round_const)
385 ldi r27, hi8(round_const)