comparison libtomcrypt/src/ciphers/noekeon.c @ 435:337c45621e81

merge of 'a9b0496634cdd25647b65e585cc3240f3fa699ee' and 'c22be8b8f570b48e9662dac32c7b3e7148a42206'
author Matt Johnston <matt@ucc.asn.au>
date Thu, 22 Feb 2007 14:53:49 +0000
parents 0cbe8f6dbf9e
children f849a5ca2efc
comparison
equal deleted inserted replaced
434:0aaaf68e97dc 435:337c45621e81
4 * algorithms in a highly modular and flexible manner. 4 * algorithms in a highly modular and flexible manner.
5 * 5 *
6 * The library is free for all purposes without any express 6 * The library is free for all purposes without any express
7 * guarantee it works. 7 * guarantee it works.
8 * 8 *
9 * Tom St Denis, [email protected], http://libtomcrypt.org 9 * Tom St Denis, [email protected], http://libtomcrypt.com
10 */ 10 */
11 /** 11 /**
12 @file noekeon.c 12 @file noekeon.c
13 Implementation of the Noekeon block cipher by Tom St Denis 13 Implementation of the Noekeon block cipher by Tom St Denis
14 */ 14 */
25 &noekeon_ecb_encrypt, 25 &noekeon_ecb_encrypt,
26 &noekeon_ecb_decrypt, 26 &noekeon_ecb_decrypt,
27 &noekeon_test, 27 &noekeon_test,
28 &noekeon_done, 28 &noekeon_done,
29 &noekeon_keysize, 29 &noekeon_keysize,
30 NULL, NULL, NULL, NULL, NULL, NULL, NULL 30 NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
31 }; 31 };
32 32
33 static const ulong32 RC[] = { 33 static const ulong32 RC[] = {
34 0x00000080UL, 0x0000001bUL, 0x00000036UL, 0x0000006cUL, 34 0x00000080UL, 0x0000001bUL, 0x00000036UL, 0x0000006cUL,
35 0x000000d8UL, 0x000000abUL, 0x0000004dUL, 0x0000009aUL, 35 0x000000d8UL, 0x000000abUL, 0x0000004dUL, 0x0000009aUL,
105 /** 105 /**
106 Encrypts a block of text with Noekeon 106 Encrypts a block of text with Noekeon
107 @param pt The input plaintext (16 bytes) 107 @param pt The input plaintext (16 bytes)
108 @param ct The output ciphertext (16 bytes) 108 @param ct The output ciphertext (16 bytes)
109 @param skey The key as scheduled 109 @param skey The key as scheduled
110 @return CRYPT_OK if successful
110 */ 111 */
111 #ifdef LTC_CLEAN_STACK 112 #ifdef LTC_CLEAN_STACK
112 static void _noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) 113 static int _noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
113 #else 114 #else
114 void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) 115 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
115 #endif 116 #endif
116 { 117 {
117 ulong32 a,b,c,d,temp; 118 ulong32 a,b,c,d,temp;
118 int r; 119 int r;
119 120
140 a ^= RC[16]; 141 a ^= RC[16];
141 THETA(skey->noekeon.K, a, b, c, d); 142 THETA(skey->noekeon.K, a, b, c, d);
142 143
143 STORE32H(a,&ct[0]); STORE32H(b,&ct[4]); 144 STORE32H(a,&ct[0]); STORE32H(b,&ct[4]);
144 STORE32H(c,&ct[8]); STORE32H(d,&ct[12]); 145 STORE32H(c,&ct[8]); STORE32H(d,&ct[12]);
146
147 return CRYPT_OK;
145 } 148 }
146 149
147 #ifdef LTC_CLEAN_STACK 150 #ifdef LTC_CLEAN_STACK
148 void noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey) 151 int noekeon_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey)
149 { 152 {
150 _noekeon_ecb_encrypt(pt, ct, skey); 153 int err = _noekeon_ecb_encrypt(pt, ct, skey);
151 burn_stack(sizeof(ulong32) * 5 + sizeof(int)); 154 burn_stack(sizeof(ulong32) * 5 + sizeof(int));
155 return CRYPT_OK;
152 } 156 }
153 #endif 157 #endif
154 158
155 /** 159 /**
156 Decrypts a block of text with Noekeon 160 Decrypts a block of text with Noekeon
157 @param ct The input ciphertext (16 bytes) 161 @param ct The input ciphertext (16 bytes)
158 @param pt The output plaintext (16 bytes) 162 @param pt The output plaintext (16 bytes)
159 @param skey The key as scheduled 163 @param skey The key as scheduled
164 @return CRYPT_OK if successful
160 */ 165 */
161 #ifdef LTC_CLEAN_STACK 166 #ifdef LTC_CLEAN_STACK
162 static void _noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) 167 static int _noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
163 #else 168 #else
164 void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) 169 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
165 #endif 170 #endif
166 { 171 {
167 ulong32 a,b,c,d, temp; 172 ulong32 a,b,c,d, temp;
168 int r; 173 int r;
169 174
190 195
191 THETA(skey->noekeon.dK, a,b,c,d); 196 THETA(skey->noekeon.dK, a,b,c,d);
192 a ^= RC[0]; 197 a ^= RC[0];
193 STORE32H(a,&pt[0]); STORE32H(b, &pt[4]); 198 STORE32H(a,&pt[0]); STORE32H(b, &pt[4]);
194 STORE32H(c,&pt[8]); STORE32H(d, &pt[12]); 199 STORE32H(c,&pt[8]); STORE32H(d, &pt[12]);
200 return CRYPT_OK;
195 } 201 }
196 202
197 #ifdef LTC_CLEAN_STACK 203 #ifdef LTC_CLEAN_STACK
198 void noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey) 204 int noekeon_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey)
199 { 205 {
200 _noekeon_ecb_decrypt(ct, pt, skey); 206 int err = _noekeon_ecb_decrypt(ct, pt, skey);
201 burn_stack(sizeof(ulong32) * 5 + sizeof(int)); 207 burn_stack(sizeof(ulong32) * 5 + sizeof(int));
208 return err;
202 } 209 }
203 #endif 210 #endif
204 211
205 /** 212 /**
206 Performs a self-test of the Noekeon block cipher 213 Performs a self-test of the Noekeon block cipher
233 return err; 240 return err;
234 } 241 }
235 242
236 noekeon_ecb_encrypt(tests[i].pt, tmp[0], &key); 243 noekeon_ecb_encrypt(tests[i].pt, tmp[0], &key);
237 noekeon_ecb_decrypt(tmp[0], tmp[1], &key); 244 noekeon_ecb_decrypt(tmp[0], tmp[1], &key);
238 if (memcmp(tmp[0], tests[i].ct, 16) || memcmp(tmp[1], tests[i].pt, 16)) { 245 if (XMEMCMP(tmp[0], tests[i].ct, 16) || XMEMCMP(tmp[1], tests[i].pt, 16)) {
239 #if 0 246 #if 0
240 printf("\n\nTest %d failed\n", i); 247 printf("\n\nTest %d failed\n", i);
241 if (memcmp(tmp[0], tests[i].ct, 16)) { 248 if (XMEMCMP(tmp[0], tests[i].ct, 16)) {
242 printf("CT: "); 249 printf("CT: ");
243 for (i = 0; i < 16; i++) { 250 for (i = 0; i < 16; i++) {
244 printf("%02x ", tmp[0][i]); 251 printf("%02x ", tmp[0][i]);
245 } 252 }
246 printf("\n"); 253 printf("\n");
290 297
291 #endif 298 #endif
292 299
293 300
294 /* $Source: /cvs/libtom/libtomcrypt/src/ciphers/noekeon.c,v $ */ 301 /* $Source: /cvs/libtom/libtomcrypt/src/ciphers/noekeon.c,v $ */
295 /* $Revision: 1.7 $ */ 302 /* $Revision: 1.12 $ */
296 /* $Date: 2005/05/05 14:35:58 $ */ 303 /* $Date: 2006/11/08 23:01:06 $ */