3 This file is part of the Crypto-avr-lib/microcrypt-lib.
4 Copyright (C) 2008 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/>.
23 * \brief SEED parts in C for AVR
29 #include <avr/pgmspace.h>
37 /******************************************************************************/
42 uint64_t seed_f_function(const uint64_t* a, uint32_t k0, uint32_t k1);
43 keypair_t seed_getnextkeys(uint32_t *keystate, uint8_t curround);
44 keypair_t seed_getprevkeys(uint32_t *keystate, uint8_t curround);
46 /******************************************************************************/
48 #define L (((uint64_t*)buffer)[0])
49 #define R (((uint64_t*)buffer)[1])
51 void seed_enc(void * buffer, seed_ctx_t * ctx){
55 k = seed_getnextkeys(ctx->k, 2*r);
57 DEBUG_S("\r\n\tDBG ka,0: "); uart_hexdump(&k.k0, 4);
58 DEBUG_S("\r\n\tDBG ka,1: "); uart_hexdump(&k.k1, 4);
59 DEBUG_S("\r\n\t DBG L: "); uart_hexdump((uint8_t*)buffer+0, 8);
60 DEBUG_S("\r\n\t DBG R: "); uart_hexdump((uint8_t*)buffer+8, 8);
62 L ^= seed_f_function(&R,k.k0,k.k1);
64 k = seed_getnextkeys(ctx->k, 2*r+1);
66 DEBUG_S("\r\n\tDBG kb,0: "); uart_hexdump(&k.k0, 4);
67 DEBUG_S("\r\n\tDBG kb,1: "); uart_hexdump(&k.k1, 4);
68 DEBUG_S("\r\n\t DBG L: "); uart_hexdump((uint8_t*)buffer+8, 8);
69 DEBUG_S("\r\n\t DBG R: "); uart_hexdump((uint8_t*)buffer+0, 8);
71 R ^= seed_f_function(&L,k.k0,k.k1);
73 /* just an exchange without temp. variable */
80 /******************************************************************************/
82 #define L (((uint64_t*)buffer)[0])
83 #define R (((uint64_t*)buffer)[1])
85 void seed_dec(void * buffer, seed_ctx_t * ctx){
89 k = seed_getprevkeys(ctx->k, 2*r+1);
91 DEBUG_S("\r\n\tDBG ka,0: "); uart_hexdump(&k.k0, 4);
92 DEBUG_S("\r\n\tDBG ka,1: "); uart_hexdump(&k.k1, 4);
93 DEBUG_S("\r\n\t DBG L: "); uart_hexdump((uint8_t*)buffer+0, 8);
94 DEBUG_S("\r\n\t DBG R: "); uart_hexdump((uint8_t*)buffer+8, 8);
96 L ^= seed_f_function(&R,k.k0,k.k1);
98 k = seed_getprevkeys(ctx->k, 2*r+0);
100 DEBUG_S("\r\n\tDBG kb,0: "); uart_hexdump(&k.k0, 4);
101 DEBUG_S("\r\n\tDBG kb,1: "); uart_hexdump(&k.k1, 4);
102 DEBUG_S("\r\n\t DBG L: "); uart_hexdump((uint8_t*)buffer+8, 8);
103 DEBUG_S("\r\n\t DBG R: "); uart_hexdump((uint8_t*)buffer+0, 8);
105 R ^= seed_f_function(&L,k.k0,k.k1);
107 /* just an exchange without temp. variable */