@@ -274,18 +274,14 @@ typedef struct {
274274#ifdef LTC_CFB_MODE
275275/** A block cipher CFB structure */
276276typedef struct {
277+ /** The ECB context of the cipher */
278+ symmetric_ECB ecb ;
277279 /** The current IV */
278280 unsigned char IV [MAXBLOCKSIZE ],
279281 /** The pad used to encrypt/decrypt */
280282 pad [MAXBLOCKSIZE ];
281- /** The scheduled key */
282- symmetric_key key ;
283- /** The index of the cipher chosen */
284- int cipher ,
285- /** The block size of the given cipher */
286- blocklen ,
287283 /** The width of the mode: 1, 8, 64, or 128 */
288- width ,
284+ int width ,
289285 /** The padding offset */
290286 padlen ;
291287} symmetric_CFB ;
@@ -294,50 +290,39 @@ typedef struct {
294290#ifdef LTC_OFB_MODE
295291/** A block cipher OFB structure */
296292typedef struct {
293+ /** The ECB context of the cipher */
294+ symmetric_ECB ecb ;
297295 /** The current IV */
298296 unsigned char IV [MAXBLOCKSIZE ];
299- /** The scheduled key */
300- symmetric_key key ;
301- /** The index of the cipher chosen */
302- int cipher ,
303- /** The block size of the given cipher */
304- blocklen ,
305297 /** The padding offset */
306- padlen ;
298+ int padlen ;
299+
307300} symmetric_OFB ;
308301#endif
309302
310303#ifdef LTC_CBC_MODE
311304/** A block cipher CBC structure */
312305typedef struct {
306+ /** The ECB context of the cipher */
307+ symmetric_ECB ecb ;
313308 /** The current IV */
314309 unsigned char IV [MAXBLOCKSIZE ];
315- /** The scheduled key */
316- symmetric_key key ;
317- /** The index of the cipher chosen */
318- int cipher ,
319- /** The block size of the given cipher */
320- blocklen ;
321310} symmetric_CBC ;
322311#endif
323312
324313
325314#ifdef LTC_CTR_MODE
326315/** A block cipher CTR structure */
327316typedef struct {
317+ /** The ECB context of the cipher */
318+ symmetric_ECB ecb ;
328319 /** The counter */
329320 unsigned char ctr [MAXBLOCKSIZE ];
330321 /** The pad used to encrypt/decrypt */
331322 unsigned char pad [MAXBLOCKSIZE ];
332- /** The scheduled key */
333- symmetric_key key ;
334323
335- /** The index of the cipher chosen */
336- int cipher ,
337- /** The block size of the given cipher */
338- blocklen ,
339324 /** The padding offset */
340- padlen ,
325+ int padlen ,
341326 /** The mode (endianess) of the CTR, 0==little, 1==big */
342327 mode ,
343328 /** counter width */
@@ -349,18 +334,14 @@ typedef struct {
349334#ifdef LTC_LRW_MODE
350335/** A LRW structure */
351336typedef struct {
337+ /** The ECB context of the cipher */
338+ symmetric_ECB ecb ;
352339 /** The current IV */
353340 unsigned char IV [16 ],
354-
355341 /** the tweak key */
356342 tweak [16 ],
357-
358343 /** The current pad, it's the product of the first 15 bytes against the tweak key */
359344 pad [16 ];
360-
361- /** The scheduled symmetric key */
362- symmetric_key key ;
363-
364345#ifdef LTC_LRW_TABLES
365346 /** The pre-computed multiplication table */
366347 unsigned char PC [16 ][256 ][16 ];
@@ -374,17 +355,13 @@ typedef struct {
374355#ifdef LTC_F8_MODE
375356/** A block cipher F8 structure */
376357typedef struct {
358+ /** The ECB context of the cipher */
359+ symmetric_ECB ecb ;
377360 /** The current IV */
378361 unsigned char IV [MAXBLOCKSIZE ],
379362 MIV [MAXBLOCKSIZE ];
380- /** The scheduled key */
381- symmetric_key key ;
382- /** The index of the cipher chosen */
383- int cipher ,
384- /** The block size of the given cipher */
385- blocklen ,
386363 /** The padding offset */
387- padlen ;
364+ int padlen ;
388365 /** Current block count */
389366 ulong32 blockcnt ;
390367} symmetric_F8 ;
@@ -451,7 +428,7 @@ extern struct ltc_cipher_descriptor {
451428 @param skey The scheduled key context
452429 @return CRYPT_OK if successful
453430 */
454- int (* accel_ecb_encrypt )(const unsigned char * pt , unsigned char * ct , unsigned long blocks , symmetric_key * skey );
431+ int (* accel_ecb_encrypt )(const unsigned char * pt , unsigned char * ct , unsigned long blocks , const symmetric_key * skey );
455432
456433 /** Accelerated ECB decryption
457434 @param pt Plaintext
@@ -460,7 +437,7 @@ extern struct ltc_cipher_descriptor {
460437 @param skey The scheduled key context
461438 @return CRYPT_OK if successful
462439 */
463- int (* accel_ecb_decrypt )(const unsigned char * ct , unsigned char * pt , unsigned long blocks , symmetric_key * skey );
440+ int (* accel_ecb_decrypt )(const unsigned char * ct , unsigned char * pt , unsigned long blocks , const symmetric_key * skey );
464441
465442 /** Accelerated CBC encryption
466443 @param pt Plaintext
@@ -470,7 +447,7 @@ extern struct ltc_cipher_descriptor {
470447 @param skey The scheduled key context
471448 @return CRYPT_OK if successful
472449 */
473- int (* accel_cbc_encrypt )(const unsigned char * pt , unsigned char * ct , unsigned long blocks , unsigned char * IV , symmetric_key * skey );
450+ int (* accel_cbc_encrypt )(const unsigned char * pt , unsigned char * ct , unsigned long blocks , unsigned char * IV , const symmetric_key * skey );
474451
475452 /** Accelerated CBC decryption
476453 @param pt Plaintext
@@ -480,7 +457,7 @@ extern struct ltc_cipher_descriptor {
480457 @param skey The scheduled key context
481458 @return CRYPT_OK if successful
482459 */
483- int (* accel_cbc_decrypt )(const unsigned char * ct , unsigned char * pt , unsigned long blocks , unsigned char * IV , symmetric_key * skey );
460+ int (* accel_cbc_decrypt )(const unsigned char * ct , unsigned char * pt , unsigned long blocks , unsigned char * IV , const symmetric_key * skey );
484461
485462 /** Accelerated CTR encryption
486463 @param pt Plaintext
@@ -491,7 +468,7 @@ extern struct ltc_cipher_descriptor {
491468 @param skey The scheduled key context
492469 @return CRYPT_OK if successful
493470 */
494- int (* accel_ctr_encrypt )(const unsigned char * pt , unsigned char * ct , unsigned long blocks , unsigned char * IV , int mode , symmetric_key * skey );
471+ int (* accel_ctr_encrypt )(const unsigned char * pt , unsigned char * ct , unsigned long blocks , unsigned char * IV , int mode , const symmetric_key * skey );
495472
496473 /** Accelerated LRW
497474 @param pt Plaintext
@@ -502,7 +479,7 @@ extern struct ltc_cipher_descriptor {
502479 @param skey The scheduled key context
503480 @return CRYPT_OK if successful
504481 */
505- int (* accel_lrw_encrypt )(const unsigned char * pt , unsigned char * ct , unsigned long blocks , unsigned char * IV , const unsigned char * tweak , symmetric_key * skey );
482+ int (* accel_lrw_encrypt )(const unsigned char * pt , unsigned char * ct , unsigned long blocks , unsigned char * IV , const unsigned char * tweak , const symmetric_key * skey );
506483
507484 /** Accelerated LRW
508485 @param ct Ciphertext
@@ -513,7 +490,7 @@ extern struct ltc_cipher_descriptor {
513490 @param skey The scheduled key context
514491 @return CRYPT_OK if successful
515492 */
516- int (* accel_lrw_decrypt )(const unsigned char * ct , unsigned char * pt , unsigned long blocks , unsigned char * IV , const unsigned char * tweak , symmetric_key * skey );
493+ int (* accel_lrw_decrypt )(const unsigned char * ct , unsigned char * pt , unsigned long blocks , unsigned char * IV , const unsigned char * tweak , const symmetric_key * skey );
517494
518495 /** Accelerated CCM packet (one-shot)
519496 @param key The secret key to use
@@ -533,7 +510,7 @@ extern struct ltc_cipher_descriptor {
533510 */
534511 int (* accel_ccm_memory )(
535512 const unsigned char * key , unsigned long keylen ,
536- symmetric_key * uskey ,
513+ const symmetric_key * uskey ,
537514 const unsigned char * nonce , unsigned long noncelen ,
538515 const unsigned char * header , unsigned long headerlen ,
539516 unsigned char * pt , unsigned long ptlen ,
@@ -923,8 +900,8 @@ extern const struct ltc_cipher_descriptor tea_desc;
923900#ifdef LTC_ECB_MODE
924901int ecb_start (int cipher , const unsigned char * key ,
925902 int keylen , int num_rounds , symmetric_ECB * ecb );
926- int ecb_encrypt (const unsigned char * pt , unsigned char * ct , unsigned long len , symmetric_ECB * ecb );
927- int ecb_decrypt (const unsigned char * ct , unsigned char * pt , unsigned long len , symmetric_ECB * ecb );
903+ int ecb_encrypt (const unsigned char * pt , unsigned char * ct , unsigned long len , const symmetric_ECB * ecb );
904+ int ecb_decrypt (const unsigned char * ct , unsigned char * pt , unsigned long len , const symmetric_ECB * ecb );
928905int ecb_done (symmetric_ECB * ecb );
929906#endif
930907
@@ -1016,7 +993,7 @@ int f8_test_mode(void);
1016993
1017994#ifdef LTC_XTS_MODE
1018995typedef struct {
1019- symmetric_key key1 , key2 ;
996+ symmetric_ECB key1 , key2 ;
1020997 int cipher ;
1021998} symmetric_xts ;
1022999
0 commit comments