Mercurial > dropbear
comparison libtomcrypt/src/headers/tomcrypt_cipher.h @ 1471:6dba84798cd5
Update to libtomcrypt 1.18.1, merged with Dropbear changes
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Fri, 09 Feb 2018 21:44:05 +0800 |
parents | f849a5ca2efc |
children |
comparison
equal
deleted
inserted
replaced
1470:8bba51a55704 | 1471:6dba84798cd5 |
---|---|
1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis | |
2 * | |
3 * LibTomCrypt is a library that provides various cryptographic | |
4 * algorithms in a highly modular and flexible manner. | |
5 * | |
6 * The library is free for all purposes without any express | |
7 * guarantee it works. | |
8 */ | |
9 | |
1 /* ---- SYMMETRIC KEY STUFF ----- | 10 /* ---- SYMMETRIC KEY STUFF ----- |
2 * | 11 * |
3 * We put each of the ciphers scheduled keys in their own structs then we put all of | 12 * We put each of the ciphers scheduled keys in their own structs then we put all of |
4 * the key formats in one union. This makes the function prototypes easier to use. | 13 * the key formats in one union. This makes the function prototypes easier to use. |
5 */ | 14 */ |
6 #ifdef LTC_BLOWFISH | 15 #ifdef LTC_BLOWFISH |
7 struct blowfish_key { | 16 struct blowfish_key { |
8 ulong32 S[4][256]; | 17 ulong32 S[4][256]; |
107 struct noekeon_key { | 116 struct noekeon_key { |
108 ulong32 K[4], dK[4]; | 117 ulong32 K[4], dK[4]; |
109 }; | 118 }; |
110 #endif | 119 #endif |
111 | 120 |
112 #ifdef LTC_SKIPJACK | 121 #ifdef LTC_SKIPJACK |
113 struct skipjack_key { | 122 struct skipjack_key { |
114 unsigned char key[10]; | 123 unsigned char key[10]; |
115 }; | 124 }; |
116 #endif | 125 #endif |
117 | 126 |
118 #ifdef LTC_KHAZAD | 127 #ifdef LTC_KHAZAD |
119 struct khazad_key { | 128 struct khazad_key { |
120 ulong64 roundKeyEnc[8 + 1]; | 129 ulong64 roundKeyEnc[8 + 1]; |
121 ulong64 roundKeyDec[8 + 1]; | 130 ulong64 roundKeyDec[8 + 1]; |
122 }; | 131 }; |
123 #endif | 132 #endif |
124 | 133 |
125 #ifdef LTC_ANUBIS | 134 #ifdef LTC_ANUBIS |
126 struct anubis_key { | 135 struct anubis_key { |
127 int keyBits; | 136 int keyBits; |
128 int R; | 137 int R; |
129 ulong32 roundKeyEnc[18 + 1][4]; | 138 ulong32 roundKeyEnc[18 + 1][4]; |
130 ulong32 roundKeyDec[18 + 1][4]; | 139 ulong32 roundKeyDec[18 + 1][4]; |
131 }; | 140 }; |
132 #endif | 141 #endif |
133 | 142 |
134 #ifdef LTC_MULTI2 | 143 #ifdef LTC_MULTI2 |
135 struct multi2_key { | 144 struct multi2_key { |
136 int N; | 145 int N; |
137 ulong32 uk[8]; | 146 ulong32 uk[8]; |
138 }; | 147 }; |
139 #endif | 148 #endif |
140 | 149 |
150 #ifdef LTC_CAMELLIA | |
151 struct camellia_key { | |
152 int R; | |
153 ulong64 kw[4], k[24], kl[6]; | |
154 }; | |
155 #endif | |
156 | |
141 typedef union Symmetric_key { | 157 typedef union Symmetric_key { |
142 #ifdef LTC_DES | 158 #ifdef LTC_DES |
143 struct des_key des; | 159 struct des_key des; |
144 struct des3_key des3; | 160 struct des3_key des3; |
145 #endif | 161 #endif |
173 #ifdef LTC_CAST5 | 189 #ifdef LTC_CAST5 |
174 struct cast5_key cast5; | 190 struct cast5_key cast5; |
175 #endif | 191 #endif |
176 #ifdef LTC_NOEKEON | 192 #ifdef LTC_NOEKEON |
177 struct noekeon_key noekeon; | 193 struct noekeon_key noekeon; |
178 #endif | 194 #endif |
179 #ifdef LTC_SKIPJACK | 195 #ifdef LTC_SKIPJACK |
180 struct skipjack_key skipjack; | 196 struct skipjack_key skipjack; |
181 #endif | 197 #endif |
182 #ifdef LTC_KHAZAD | 198 #ifdef LTC_KHAZAD |
183 struct khazad_key khazad; | 199 struct khazad_key khazad; |
188 #ifdef LTC_KSEED | 204 #ifdef LTC_KSEED |
189 struct kseed_key kseed; | 205 struct kseed_key kseed; |
190 #endif | 206 #endif |
191 #ifdef LTC_KASUMI | 207 #ifdef LTC_KASUMI |
192 struct kasumi_key kasumi; | 208 struct kasumi_key kasumi; |
193 #endif | 209 #endif |
194 #ifdef LTC_MULTI2 | 210 #ifdef LTC_MULTI2 |
195 struct multi2_key multi2; | 211 struct multi2_key multi2; |
212 #endif | |
213 #ifdef LTC_CAMELLIA | |
214 struct camellia_key camellia; | |
196 #endif | 215 #endif |
197 void *data; | 216 void *data; |
198 } symmetric_key; | 217 } symmetric_key; |
199 | 218 |
200 #ifdef LTC_ECB_MODE | 219 #ifdef LTC_ECB_MODE |
201 /** A block cipher ECB structure */ | 220 /** A block cipher ECB structure */ |
202 typedef struct { | 221 typedef struct { |
203 /** The index of the cipher chosen */ | 222 /** The index of the cipher chosen */ |
204 int cipher, | 223 int cipher, |
205 /** The block size of the given cipher */ | 224 /** The block size of the given cipher */ |
206 blocklen; | 225 blocklen; |
207 /** The scheduled key */ | 226 /** The scheduled key */ |
208 symmetric_key key; | 227 symmetric_key key; |
209 } symmetric_ECB; | 228 } symmetric_ECB; |
210 #endif | 229 #endif |
211 | 230 |
212 #ifdef LTC_CFB_MODE | 231 #ifdef LTC_CFB_MODE |
213 /** A block cipher CFB structure */ | 232 /** A block cipher CFB structure */ |
214 typedef struct { | 233 typedef struct { |
215 /** The index of the cipher chosen */ | 234 /** The index of the cipher chosen */ |
216 int cipher, | 235 int cipher, |
217 /** The block size of the given cipher */ | 236 /** The block size of the given cipher */ |
218 blocklen, | 237 blocklen, |
219 /** The padding offset */ | 238 /** The padding offset */ |
220 padlen; | 239 padlen; |
221 /** The current IV */ | 240 /** The current IV */ |
222 unsigned char IV[MAXBLOCKSIZE], | 241 unsigned char IV[MAXBLOCKSIZE], |
223 /** The pad used to encrypt/decrypt */ | 242 /** The pad used to encrypt/decrypt */ |
224 pad[MAXBLOCKSIZE]; | 243 pad[MAXBLOCKSIZE]; |
225 /** The scheduled key */ | 244 /** The scheduled key */ |
226 symmetric_key key; | 245 symmetric_key key; |
227 } symmetric_CFB; | 246 } symmetric_CFB; |
228 #endif | 247 #endif |
229 | 248 |
230 #ifdef LTC_OFB_MODE | 249 #ifdef LTC_OFB_MODE |
231 /** A block cipher OFB structure */ | 250 /** A block cipher OFB structure */ |
232 typedef struct { | 251 typedef struct { |
233 /** The index of the cipher chosen */ | 252 /** The index of the cipher chosen */ |
234 int cipher, | 253 int cipher, |
235 /** The block size of the given cipher */ | 254 /** The block size of the given cipher */ |
236 blocklen, | 255 blocklen, |
237 /** The padding offset */ | 256 /** The padding offset */ |
238 padlen; | 257 padlen; |
239 /** The current IV */ | 258 /** The current IV */ |
240 unsigned char IV[MAXBLOCKSIZE]; | 259 unsigned char IV[MAXBLOCKSIZE]; |
241 /** The scheduled key */ | 260 /** The scheduled key */ |
245 | 264 |
246 #ifdef LTC_CBC_MODE | 265 #ifdef LTC_CBC_MODE |
247 /** A block cipher CBC structure */ | 266 /** A block cipher CBC structure */ |
248 typedef struct { | 267 typedef struct { |
249 /** The index of the cipher chosen */ | 268 /** The index of the cipher chosen */ |
250 int cipher, | 269 int cipher, |
251 /** The block size of the given cipher */ | 270 /** The block size of the given cipher */ |
252 blocklen; | 271 blocklen; |
253 /** The current IV */ | 272 /** The current IV */ |
254 unsigned char IV[MAXBLOCKSIZE]; | 273 unsigned char IV[MAXBLOCKSIZE]; |
255 /** The scheduled key */ | 274 /** The scheduled key */ |
256 symmetric_key key; | 275 symmetric_key key; |
261 #ifdef LTC_CTR_MODE | 280 #ifdef LTC_CTR_MODE |
262 /** A block cipher CTR structure */ | 281 /** A block cipher CTR structure */ |
263 typedef struct { | 282 typedef struct { |
264 /** The index of the cipher chosen */ | 283 /** The index of the cipher chosen */ |
265 int cipher, | 284 int cipher, |
266 /** The block size of the given cipher */ | 285 /** The block size of the given cipher */ |
267 blocklen, | 286 blocklen, |
268 /** The padding offset */ | 287 /** The padding offset */ |
269 padlen, | 288 padlen, |
270 /** The mode (endianess) of the CTR, 0==little, 1==big */ | 289 /** The mode (endianess) of the CTR, 0==little, 1==big */ |
271 mode, | 290 mode, |
272 /** counter width */ | 291 /** counter width */ |
273 ctrlen; | 292 ctrlen; |
274 | 293 |
275 /** The counter */ | 294 /** The counter */ |
276 unsigned char ctr[MAXBLOCKSIZE], | 295 unsigned char ctr[MAXBLOCKSIZE], |
277 /** The pad used to encrypt/decrypt */ | 296 /** The pad used to encrypt/decrypt */ |
278 pad[MAXBLOCKSIZE]; | 297 pad[MAXBLOCKSIZE]; |
279 /** The scheduled key */ | 298 /** The scheduled key */ |
280 symmetric_key key; | 299 symmetric_key key; |
281 } symmetric_CTR; | 300 } symmetric_CTR; |
282 #endif | 301 #endif |
288 /** The index of the cipher chosen (must be a 128-bit block cipher) */ | 307 /** The index of the cipher chosen (must be a 128-bit block cipher) */ |
289 int cipher; | 308 int cipher; |
290 | 309 |
291 /** The current IV */ | 310 /** The current IV */ |
292 unsigned char IV[16], | 311 unsigned char IV[16], |
293 | 312 |
294 /** the tweak key */ | 313 /** the tweak key */ |
295 tweak[16], | 314 tweak[16], |
296 | 315 |
297 /** The current pad, it's the product of the first 15 bytes against the tweak key */ | 316 /** The current pad, it's the product of the first 15 bytes against the tweak key */ |
298 pad[16]; | 317 pad[16]; |
299 | 318 |
300 /** The scheduled symmetric key */ | 319 /** The scheduled symmetric key */ |
301 symmetric_key key; | 320 symmetric_key key; |
302 | 321 |
303 #ifdef LRW_TABLES | 322 #ifdef LTC_LRW_TABLES |
304 /** The pre-computed multiplication table */ | 323 /** The pre-computed multiplication table */ |
305 unsigned char PC[16][256][16]; | 324 unsigned char PC[16][256][16]; |
306 #endif | 325 #endif |
307 } symmetric_LRW; | 326 } symmetric_LRW; |
308 #endif | 327 #endif |
309 | 328 |
310 #ifdef LTC_F8_MODE | 329 #ifdef LTC_F8_MODE |
311 /** A block cipher F8 structure */ | 330 /** A block cipher F8 structure */ |
312 typedef struct { | 331 typedef struct { |
313 /** The index of the cipher chosen */ | 332 /** The index of the cipher chosen */ |
314 int cipher, | 333 int cipher, |
315 /** The block size of the given cipher */ | 334 /** The block size of the given cipher */ |
316 blocklen, | 335 blocklen, |
317 /** The padding offset */ | 336 /** The padding offset */ |
318 padlen; | 337 padlen; |
319 /** The current IV */ | 338 /** The current IV */ |
320 unsigned char IV[MAXBLOCKSIZE], | 339 unsigned char IV[MAXBLOCKSIZE], |
321 MIV[MAXBLOCKSIZE]; | 340 MIV[MAXBLOCKSIZE]; |
328 | 347 |
329 | 348 |
330 /** cipher descriptor table, last entry has "name == NULL" to mark the end of table */ | 349 /** cipher descriptor table, last entry has "name == NULL" to mark the end of table */ |
331 extern struct ltc_cipher_descriptor { | 350 extern struct ltc_cipher_descriptor { |
332 /** name of cipher */ | 351 /** name of cipher */ |
333 char *name; | 352 const char *name; |
334 /** internal ID */ | 353 /** internal ID */ |
335 unsigned char ID; | 354 unsigned char ID; |
336 /** min keysize (octets) */ | 355 /** min keysize (octets) */ |
337 int min_key_length, | 356 int min_key_length, |
338 /** max keysize (octets) */ | 357 /** max keysize (octets) */ |
339 max_key_length, | 358 max_key_length, |
340 /** block size (octets) */ | 359 /** block size (octets) */ |
341 block_length, | 360 block_length, |
342 /** default number of rounds */ | 361 /** default number of rounds */ |
343 default_rounds; | 362 default_rounds; |
344 /** Setup the cipher | 363 /** Setup the cipher |
345 @param key The input symmetric key | 364 @param key The input symmetric key |
346 @param keylen The length of the input key (octets) | 365 @param keylen The length of the input key (octets) |
347 @param num_rounds The requested number of rounds (0==default) | 366 @param num_rounds The requested number of rounds (0==default) |
348 @param skey [out] The destination of the scheduled key | 367 @param skey [out] The destination of the scheduled key |
349 @return CRYPT_OK if successful | 368 @return CRYPT_OK if successful |
366 /** Test the block cipher | 385 /** Test the block cipher |
367 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled | 386 @return CRYPT_OK if successful, CRYPT_NOP if self-testing has been disabled |
368 */ | 387 */ |
369 int (*test)(void); | 388 int (*test)(void); |
370 | 389 |
371 /** Terminate the context | 390 /** Terminate the context |
372 @param skey The scheduled key | 391 @param skey The scheduled key |
373 */ | 392 */ |
374 void (*done)(symmetric_key *skey); | 393 void (*done)(symmetric_key *skey); |
375 | 394 |
376 /** Determine a key size | 395 /** Determine a key size |
377 @param keysize [in/out] The size of the key desired and the suggested size | 396 @param keysize [in/out] The size of the key desired and the suggested size |
378 @return CRYPT_OK if successful | 397 @return CRYPT_OK if successful |
379 */ | 398 */ |
380 int (*keysize)(int *keysize); | 399 int (*keysize)(int *keysize); |
381 | 400 |
382 /** Accelerators **/ | 401 /** Accelerators **/ |
383 /** Accelerated ECB encryption | 402 /** Accelerated ECB encryption |
384 @param pt Plaintext | 403 @param pt Plaintext |
385 @param ct Ciphertext | 404 @param ct Ciphertext |
386 @param blocks The number of complete blocks to process | 405 @param blocks The number of complete blocks to process |
387 @param skey The scheduled key context | 406 @param skey The scheduled key context |
388 @return CRYPT_OK if successful | 407 @return CRYPT_OK if successful |
389 */ | 408 */ |
390 int (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey); | 409 int (*accel_ecb_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, symmetric_key *skey); |
391 | 410 |
392 /** Accelerated ECB decryption | 411 /** Accelerated ECB decryption |
393 @param pt Plaintext | 412 @param pt Plaintext |
394 @param ct Ciphertext | 413 @param ct Ciphertext |
395 @param blocks The number of complete blocks to process | 414 @param blocks The number of complete blocks to process |
396 @param skey The scheduled key context | 415 @param skey The scheduled key context |
397 @return CRYPT_OK if successful | 416 @return CRYPT_OK if successful |
398 */ | 417 */ |
399 int (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey); | 418 int (*accel_ecb_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, symmetric_key *skey); |
400 | 419 |
401 /** Accelerated CBC encryption | 420 /** Accelerated CBC encryption |
402 @param pt Plaintext | 421 @param pt Plaintext |
403 @param ct Ciphertext | 422 @param ct Ciphertext |
404 @param blocks The number of complete blocks to process | 423 @param blocks The number of complete blocks to process |
405 @param IV The initial value (input/output) | 424 @param IV The initial value (input/output) |
406 @param skey The scheduled key context | 425 @param skey The scheduled key context |
407 @return CRYPT_OK if successful | 426 @return CRYPT_OK if successful |
408 */ | 427 */ |
409 int (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey); | 428 int (*accel_cbc_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, symmetric_key *skey); |
410 | 429 |
411 /** Accelerated CBC decryption | 430 /** Accelerated CBC decryption |
412 @param pt Plaintext | 431 @param pt Plaintext |
413 @param ct Ciphertext | 432 @param ct Ciphertext |
414 @param blocks The number of complete blocks to process | 433 @param blocks The number of complete blocks to process |
415 @param IV The initial value (input/output) | 434 @param IV The initial value (input/output) |
416 @param skey The scheduled key context | 435 @param skey The scheduled key context |
417 @return CRYPT_OK if successful | 436 @return CRYPT_OK if successful |
418 */ | 437 */ |
419 int (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey); | 438 int (*accel_cbc_decrypt)(const unsigned char *ct, unsigned char *pt, unsigned long blocks, unsigned char *IV, symmetric_key *skey); |
420 | 439 |
421 /** Accelerated CTR encryption | 440 /** Accelerated CTR encryption |
422 @param pt Plaintext | 441 @param pt Plaintext |
423 @param ct Ciphertext | 442 @param ct Ciphertext |
424 @param blocks The number of complete blocks to process | 443 @param blocks The number of complete blocks to process |
425 @param IV The initial value (input/output) | 444 @param IV The initial value (input/output) |
426 @param mode little or big endian counter (mode=0 or mode=1) | 445 @param mode little or big endian counter (mode=0 or mode=1) |
427 @param skey The scheduled key context | 446 @param skey The scheduled key context |
428 @return CRYPT_OK if successful | 447 @return CRYPT_OK if successful |
429 */ | 448 */ |
430 int (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey); | 449 int (*accel_ctr_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, int mode, symmetric_key *skey); |
431 | 450 |
432 /** Accelerated LRW | 451 /** Accelerated LRW |
433 @param pt Plaintext | 452 @param pt Plaintext |
434 @param ct Ciphertext | 453 @param ct Ciphertext |
435 @param blocks The number of complete blocks to process | 454 @param blocks The number of complete blocks to process |
436 @param IV The initial value (input/output) | 455 @param IV The initial value (input/output) |
437 @param tweak The LRW tweak | 456 @param tweak The LRW tweak |
438 @param skey The scheduled key context | 457 @param skey The scheduled key context |
439 @return CRYPT_OK if successful | 458 @return CRYPT_OK if successful |
440 */ | 459 */ |
441 int (*accel_lrw_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey); | 460 int (*accel_lrw_encrypt)(const unsigned char *pt, unsigned char *ct, unsigned long blocks, unsigned char *IV, const unsigned char *tweak, symmetric_key *skey); |
442 | 461 |
443 /** Accelerated LRW | 462 /** Accelerated LRW |
444 @param ct Ciphertext | 463 @param ct Ciphertext |
445 @param pt Plaintext | 464 @param pt Plaintext |
446 @param blocks The number of complete blocks to process | 465 @param blocks The number of complete blocks to process |
447 @param IV The initial value (input/output) | 466 @param IV The initial value (input/output) |
448 @param tweak The LRW tweak | 467 @param tweak The LRW tweak |
478 int direction); | 497 int direction); |
479 | 498 |
480 /** Accelerated GCM packet (one shot) | 499 /** Accelerated GCM packet (one shot) |
481 @param key The secret key | 500 @param key The secret key |
482 @param keylen The length of the secret key | 501 @param keylen The length of the secret key |
483 @param IV The initial vector | 502 @param IV The initialization vector |
484 @param IVlen The length of the initial vector | 503 @param IVlen The length of the initialization vector |
485 @param adata The additional authentication data (header) | 504 @param adata The additional authentication data (header) |
486 @param adatalen The length of the adata | 505 @param adatalen The length of the adata |
487 @param pt The plaintext | 506 @param pt The plaintext |
488 @param ptlen The length of the plaintext (ciphertext length is the same) | 507 @param ptlen The length of the plaintext (ciphertext length is the same) |
489 @param ct The ciphertext | 508 @param ct The ciphertext |
495 int (*accel_gcm_memory)( | 514 int (*accel_gcm_memory)( |
496 const unsigned char *key, unsigned long keylen, | 515 const unsigned char *key, unsigned long keylen, |
497 const unsigned char *IV, unsigned long IVlen, | 516 const unsigned char *IV, unsigned long IVlen, |
498 const unsigned char *adata, unsigned long adatalen, | 517 const unsigned char *adata, unsigned long adatalen, |
499 unsigned char *pt, unsigned long ptlen, | 518 unsigned char *pt, unsigned long ptlen, |
500 unsigned char *ct, | 519 unsigned char *ct, |
501 unsigned char *tag, unsigned long *taglen, | 520 unsigned char *tag, unsigned long *taglen, |
502 int direction); | 521 int direction); |
503 | 522 |
504 /** Accelerated one shot LTC_OMAC | 523 /** Accelerated one shot LTC_OMAC |
505 @param key The secret key | 524 @param key The secret key |
506 @param keylen The key length (octets) | 525 @param keylen The key length (octets) |
507 @param in The message | 526 @param in The message |
508 @param inlen Length of message (octets) | 527 @param inlen Length of message (octets) |
509 @param out [out] Destination for tag | 528 @param out [out] Destination for tag |
510 @param outlen [in/out] Initial and final size of out | 529 @param outlen [in/out] Initial and final size of out |
511 @return CRYPT_OK on success | 530 @return CRYPT_OK on success |
512 */ | 531 */ |
513 int (*omac_memory)( | 532 int (*omac_memory)( |
514 const unsigned char *key, unsigned long keylen, | 533 const unsigned char *key, unsigned long keylen, |
515 const unsigned char *in, unsigned long inlen, | 534 const unsigned char *in, unsigned long inlen, |
516 unsigned char *out, unsigned long *outlen); | 535 unsigned char *out, unsigned long *outlen); |
517 | 536 |
518 /** Accelerated one shot XCBC | 537 /** Accelerated one shot XCBC |
519 @param key The secret key | 538 @param key The secret key |
520 @param keylen The key length (octets) | 539 @param keylen The key length (octets) |
521 @param in The message | 540 @param in The message |
522 @param inlen Length of message (octets) | 541 @param inlen Length of message (octets) |
523 @param out [out] Destination for tag | 542 @param out [out] Destination for tag |
524 @param outlen [in/out] Initial and final size of out | 543 @param outlen [in/out] Initial and final size of out |
525 @return CRYPT_OK on success | 544 @return CRYPT_OK on success |
526 */ | 545 */ |
527 int (*xcbc_memory)( | 546 int (*xcbc_memory)( |
528 const unsigned char *key, unsigned long keylen, | 547 const unsigned char *key, unsigned long keylen, |
529 const unsigned char *in, unsigned long inlen, | 548 const unsigned char *in, unsigned long inlen, |
530 unsigned char *out, unsigned long *outlen); | 549 unsigned char *out, unsigned long *outlen); |
531 | 550 |
532 /** Accelerated one shot F9 | 551 /** Accelerated one shot F9 |
533 @param key The secret key | 552 @param key The secret key |
534 @param keylen The key length (octets) | 553 @param keylen The key length (octets) |
535 @param in The message | 554 @param in The message |
536 @param inlen Length of message (octets) | 555 @param inlen Length of message (octets) |
537 @param out [out] Destination for tag | 556 @param out [out] Destination for tag |
538 @param outlen [in/out] Initial and final size of out | 557 @param outlen [in/out] Initial and final size of out |
539 @return CRYPT_OK on success | 558 @return CRYPT_OK on success |
540 @remark Requires manual padding | 559 @remark Requires manual padding |
541 */ | 560 */ |
542 int (*f9_memory)( | 561 int (*f9_memory)( |
543 const unsigned char *key, unsigned long keylen, | 562 const unsigned char *key, unsigned long keylen, |
544 const unsigned char *in, unsigned long inlen, | 563 const unsigned char *in, unsigned long inlen, |
545 unsigned char *out, unsigned long *outlen); | 564 unsigned char *out, unsigned long *outlen); |
565 | |
566 /** Accelerated XTS encryption | |
567 @param pt Plaintext | |
568 @param ct Ciphertext | |
569 @param blocks The number of complete blocks to process | |
570 @param tweak The 128-bit encryption tweak (input/output). | |
571 The tweak should not be encrypted on input, but | |
572 next tweak will be copied encrypted on output. | |
573 @param skey1 The first scheduled key context | |
574 @param skey2 The second scheduled key context | |
575 @return CRYPT_OK if successful | |
576 */ | |
577 int (*accel_xts_encrypt)(const unsigned char *pt, unsigned char *ct, | |
578 unsigned long blocks, unsigned char *tweak, symmetric_key *skey1, | |
579 symmetric_key *skey2); | |
580 | |
581 /** Accelerated XTS decryption | |
582 @param ct Ciphertext | |
583 @param pt Plaintext | |
584 @param blocks The number of complete blocks to process | |
585 @param tweak The 128-bit encryption tweak (input/output). | |
586 The tweak should not be encrypted on input, but | |
587 next tweak will be copied encrypted on output. | |
588 @param skey1 The first scheduled key context | |
589 @param skey2 The second scheduled key context | |
590 @return CRYPT_OK if successful | |
591 */ | |
592 int (*accel_xts_decrypt)(const unsigned char *ct, unsigned char *pt, | |
593 unsigned long blocks, unsigned char *tweak, symmetric_key *skey1, | |
594 symmetric_key *skey2); | |
546 } cipher_descriptor[]; | 595 } cipher_descriptor[]; |
547 | 596 |
548 #ifdef LTC_BLOWFISH | 597 #ifdef LTC_BLOWFISH |
549 int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | 598 int blowfish_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); |
550 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); | 599 int blowfish_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); |
575 extern const struct ltc_cipher_descriptor rc6_desc; | 624 extern const struct ltc_cipher_descriptor rc6_desc; |
576 #endif | 625 #endif |
577 | 626 |
578 #ifdef LTC_RC2 | 627 #ifdef LTC_RC2 |
579 int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | 628 int rc2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); |
629 int rc2_setup_ex(const unsigned char *key, int keylen, int bits, int num_rounds, symmetric_key *skey); | |
580 int rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); | 630 int rc2_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); |
581 int rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); | 631 int rc2_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); |
582 int rc2_test(void); | 632 int rc2_test(void); |
583 void rc2_done(symmetric_key *skey); | 633 void rc2_done(symmetric_key *skey); |
584 int rc2_keysize(int *keysize); | 634 int rc2_keysize(int *keysize); |
754 void multi2_done(symmetric_key *skey); | 804 void multi2_done(symmetric_key *skey); |
755 int multi2_keysize(int *keysize); | 805 int multi2_keysize(int *keysize); |
756 extern const struct ltc_cipher_descriptor multi2_desc; | 806 extern const struct ltc_cipher_descriptor multi2_desc; |
757 #endif | 807 #endif |
758 | 808 |
809 #ifdef LTC_CAMELLIA | |
810 int camellia_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey); | |
811 int camellia_ecb_encrypt(const unsigned char *pt, unsigned char *ct, symmetric_key *skey); | |
812 int camellia_ecb_decrypt(const unsigned char *ct, unsigned char *pt, symmetric_key *skey); | |
813 int camellia_test(void); | |
814 void camellia_done(symmetric_key *skey); | |
815 int camellia_keysize(int *keysize); | |
816 extern const struct ltc_cipher_descriptor camellia_desc; | |
817 #endif | |
818 | |
759 #ifdef LTC_ECB_MODE | 819 #ifdef LTC_ECB_MODE |
760 int ecb_start(int cipher, const unsigned char *key, | 820 int ecb_start(int cipher, const unsigned char *key, |
761 int keylen, int num_rounds, symmetric_ECB *ecb); | 821 int keylen, int num_rounds, symmetric_ECB *ecb); |
762 int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb); | 822 int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb); |
763 int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb); | 823 int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb); |
764 int ecb_done(symmetric_ECB *ecb); | 824 int ecb_done(symmetric_ECB *ecb); |
765 #endif | 825 #endif |
766 | 826 |
767 #ifdef LTC_CFB_MODE | 827 #ifdef LTC_CFB_MODE |
768 int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key, | 828 int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key, |
769 int keylen, int num_rounds, symmetric_CFB *cfb); | 829 int keylen, int num_rounds, symmetric_CFB *cfb); |
770 int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb); | 830 int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb); |
771 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb); | 831 int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb); |
772 int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb); | 832 int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb); |
773 int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb); | 833 int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb); |
774 int cfb_done(symmetric_CFB *cfb); | 834 int cfb_done(symmetric_CFB *cfb); |
775 #endif | 835 #endif |
776 | 836 |
777 #ifdef LTC_OFB_MODE | 837 #ifdef LTC_OFB_MODE |
778 int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key, | 838 int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key, |
779 int keylen, int num_rounds, symmetric_OFB *ofb); | 839 int keylen, int num_rounds, symmetric_OFB *ofb); |
780 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb); | 840 int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb); |
781 int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb); | 841 int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb); |
782 int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb); | 842 int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb); |
783 int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb); | 843 int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb); |
813 int ctr_test(void); | 873 int ctr_test(void); |
814 #endif | 874 #endif |
815 | 875 |
816 #ifdef LTC_LRW_MODE | 876 #ifdef LTC_LRW_MODE |
817 | 877 |
818 #define LRW_ENCRYPT 0 | 878 #define LRW_ENCRYPT LTC_ENCRYPT |
819 #define LRW_DECRYPT 1 | 879 #define LRW_DECRYPT LTC_DECRYPT |
820 | 880 |
821 int lrw_start( int cipher, | 881 int lrw_start( int cipher, |
822 const unsigned char *IV, | 882 const unsigned char *IV, |
823 const unsigned char *key, int keylen, | 883 const unsigned char *key, int keylen, |
824 const unsigned char *tweak, | 884 const unsigned char *tweak, |
825 int num_rounds, | 885 int num_rounds, |
826 symmetric_LRW *lrw); | 886 symmetric_LRW *lrw); |
827 int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw); | 887 int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw); |
828 int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw); | 888 int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw); |
829 int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw); | 889 int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw); |
830 int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw); | 890 int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw); |
831 int lrw_done(symmetric_LRW *lrw); | 891 int lrw_done(symmetric_LRW *lrw); |
832 int lrw_test(void); | 892 int lrw_test(void); |
833 | 893 |
834 /* don't call */ | 894 /* don't call */ |
835 int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw); | 895 int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw); |
836 #endif | 896 #endif |
837 | 897 |
838 #ifdef LTC_F8_MODE | 898 #ifdef LTC_F8_MODE |
839 int f8_start( int cipher, const unsigned char *IV, | 899 int f8_start( int cipher, const unsigned char *IV, |
840 const unsigned char *key, int keylen, | 900 const unsigned char *key, int keylen, |
841 const unsigned char *salt_key, int skeylen, | 901 const unsigned char *salt_key, int skeylen, |
842 int num_rounds, symmetric_F8 *f8); | 902 int num_rounds, symmetric_F8 *f8); |
843 int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8); | 903 int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8); |
844 int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8); | 904 int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8); |
845 int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8); | 905 int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8); |
853 symmetric_key key1, key2; | 913 symmetric_key key1, key2; |
854 int cipher; | 914 int cipher; |
855 } symmetric_xts; | 915 } symmetric_xts; |
856 | 916 |
857 int xts_start( int cipher, | 917 int xts_start( int cipher, |
858 const unsigned char *key1, | 918 const unsigned char *key1, |
859 const unsigned char *key2, | 919 const unsigned char *key2, |
860 unsigned long keylen, | 920 unsigned long keylen, |
861 int num_rounds, | 921 int num_rounds, |
862 symmetric_xts *xts); | 922 symmetric_xts *xts); |
863 | 923 |
864 int xts_encrypt( | 924 int xts_encrypt( |
865 const unsigned char *pt, unsigned long ptlen, | 925 const unsigned char *pt, unsigned long ptlen, |
866 unsigned char *ct, | 926 unsigned char *ct, |
867 const unsigned char *tweak, | 927 unsigned char *tweak, |
868 symmetric_xts *xts); | 928 symmetric_xts *xts); |
869 int xts_decrypt( | 929 int xts_decrypt( |
870 const unsigned char *ct, unsigned long ptlen, | 930 const unsigned char *ct, unsigned long ptlen, |
871 unsigned char *pt, | 931 unsigned char *pt, |
872 const unsigned char *tweak, | 932 unsigned char *tweak, |
873 symmetric_xts *xts); | 933 symmetric_xts *xts); |
874 | 934 |
875 void xts_done(symmetric_xts *xts); | 935 void xts_done(symmetric_xts *xts); |
876 int xts_test(void); | 936 int xts_test(void); |
877 void xts_mult_x(unsigned char *I); | 937 void xts_mult_x(unsigned char *I); |
880 int find_cipher(const char *name); | 940 int find_cipher(const char *name); |
881 int find_cipher_any(const char *name, int blocklen, int keylen); | 941 int find_cipher_any(const char *name, int blocklen, int keylen); |
882 int find_cipher_id(unsigned char ID); | 942 int find_cipher_id(unsigned char ID); |
883 int register_cipher(const struct ltc_cipher_descriptor *cipher); | 943 int register_cipher(const struct ltc_cipher_descriptor *cipher); |
884 int unregister_cipher(const struct ltc_cipher_descriptor *cipher); | 944 int unregister_cipher(const struct ltc_cipher_descriptor *cipher); |
945 int register_all_ciphers(void); | |
885 int cipher_is_valid(int idx); | 946 int cipher_is_valid(int idx); |
886 | 947 |
887 LTC_MUTEX_PROTO(ltc_cipher_mutex) | 948 LTC_MUTEX_PROTO(ltc_cipher_mutex) |
888 | 949 |
889 /* $Source$ */ | 950 /* ---- stream ciphers ---- */ |
890 /* $Revision$ */ | 951 |
891 /* $Date$ */ | 952 #ifdef LTC_CHACHA |
953 | |
954 typedef struct { | |
955 ulong32 input[16]; | |
956 unsigned char kstream[64]; | |
957 unsigned long ksleft; | |
958 unsigned long ivlen; | |
959 int rounds; | |
960 } chacha_state; | |
961 | |
962 int chacha_setup(chacha_state *st, const unsigned char *key, unsigned long keylen, int rounds); | |
963 int chacha_ivctr32(chacha_state *st, const unsigned char *iv, unsigned long ivlen, ulong32 counter); | |
964 int chacha_ivctr64(chacha_state *st, const unsigned char *iv, unsigned long ivlen, ulong64 counter); | |
965 int chacha_crypt(chacha_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out); | |
966 int chacha_keystream(chacha_state *st, unsigned char *out, unsigned long outlen); | |
967 int chacha_done(chacha_state *st); | |
968 int chacha_test(void); | |
969 | |
970 #endif /* LTC_CHACHA */ | |
971 | |
972 #ifdef LTC_RC4_STREAM | |
973 | |
974 typedef struct { | |
975 unsigned int x, y; | |
976 unsigned char buf[256]; | |
977 } rc4_state; | |
978 | |
979 int rc4_stream_setup(rc4_state *st, const unsigned char *key, unsigned long keylen); | |
980 int rc4_stream_crypt(rc4_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out); | |
981 int rc4_stream_keystream(rc4_state *st, unsigned char *out, unsigned long outlen); | |
982 int rc4_stream_done(rc4_state *st); | |
983 int rc4_stream_test(void); | |
984 | |
985 #endif /* LTC_RC4_STREAM */ | |
986 | |
987 #ifdef LTC_SOBER128_STREAM | |
988 | |
989 typedef struct { | |
990 ulong32 R[17], /* Working storage for the shift register */ | |
991 initR[17], /* saved register contents */ | |
992 konst, /* key dependent constant */ | |
993 sbuf; /* partial word encryption buffer */ | |
994 int nbuf; /* number of part-word stream bits buffered */ | |
995 } sober128_state; | |
996 | |
997 int sober128_stream_setup(sober128_state *st, const unsigned char *key, unsigned long keylen); | |
998 int sober128_stream_setiv(sober128_state *st, const unsigned char *iv, unsigned long ivlen); | |
999 int sober128_stream_crypt(sober128_state *st, const unsigned char *in, unsigned long inlen, unsigned char *out); | |
1000 int sober128_stream_keystream(sober128_state *st, unsigned char *out, unsigned long outlen); | |
1001 int sober128_stream_done(sober128_state *st); | |
1002 int sober128_stream_test(void); | |
1003 | |
1004 #endif /* LTC_SOBER128_STREAM */ | |
1005 | |
1006 /* ref: $Format:%D$ */ | |
1007 /* git commit: $Format:%H$ */ | |
1008 /* commit time: $Format:%ai$ */ |