Add function pointers for accelerated XTS to ltc_cipher_descriptor
Similar to what already exists for other modes. Signed-off-by: Jerome Forissier <jerome.forissier@linaro.org>
This commit is contained in:
		
							parent
							
								
									99214b53f6
								
							
						
					
					
						commit
						5c3f177b34
					
				@ -49,7 +49,7 @@ const struct ltc_cipher_descriptor rijndael_desc =
 | 
				
			|||||||
    6,
 | 
					    6,
 | 
				
			||||||
    16, 32, 16, 10,
 | 
					    16, 32, 16, 10,
 | 
				
			||||||
    SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS,
 | 
					    SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const struct ltc_cipher_descriptor aes_desc =
 | 
					const struct ltc_cipher_descriptor aes_desc =
 | 
				
			||||||
@ -58,7 +58,7 @@ const struct ltc_cipher_descriptor aes_desc =
 | 
				
			|||||||
    6,
 | 
					    6,
 | 
				
			||||||
    16, 32, 16, 10,
 | 
					    16, 32, 16, 10,
 | 
				
			||||||
    SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS,
 | 
					    SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#else
 | 
					#else
 | 
				
			||||||
@ -74,7 +74,7 @@ const struct ltc_cipher_descriptor rijndael_enc_desc =
 | 
				
			|||||||
    6,
 | 
					    6,
 | 
				
			||||||
    16, 32, 16, 10,
 | 
					    16, 32, 16, 10,
 | 
				
			||||||
    SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS,
 | 
					    SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const struct ltc_cipher_descriptor aes_enc_desc =
 | 
					const struct ltc_cipher_descriptor aes_enc_desc =
 | 
				
			||||||
@ -83,7 +83,7 @@ const struct ltc_cipher_descriptor aes_enc_desc =
 | 
				
			|||||||
    6,
 | 
					    6,
 | 
				
			||||||
    16, 32, 16, 10,
 | 
					    16, 32, 16, 10,
 | 
				
			||||||
    SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS,
 | 
					    SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#endif
 | 
					#endif
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,7 @@ const struct ltc_cipher_descriptor anubis_desc = {
 | 
				
			|||||||
   &anubis_test,
 | 
					   &anubis_test,
 | 
				
			||||||
   &anubis_done,
 | 
					   &anubis_done,
 | 
				
			||||||
   &anubis_keysize,
 | 
					   &anubis_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define MIN_N           4
 | 
					#define MIN_N           4
 | 
				
			||||||
 | 
				
			|||||||
@ -27,7 +27,7 @@ const struct ltc_cipher_descriptor blowfish_desc =
 | 
				
			|||||||
    &blowfish_test,
 | 
					    &blowfish_test,
 | 
				
			||||||
    &blowfish_done,
 | 
					    &blowfish_done,
 | 
				
			||||||
    &blowfish_keysize,
 | 
					    &blowfish_keysize,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const ulong32 ORIG_P[16 + 2] = {
 | 
					static const ulong32 ORIG_P[16 + 2] = {
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ const struct ltc_cipher_descriptor camellia_desc = {
 | 
				
			|||||||
   &camellia_test,
 | 
					   &camellia_test,
 | 
				
			||||||
   &camellia_done,
 | 
					   &camellia_done,
 | 
				
			||||||
   &camellia_keysize,
 | 
					   &camellia_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const ulong32 SP1110[] = {
 | 
					static const ulong32 SP1110[] = {
 | 
				
			||||||
 | 
				
			|||||||
@ -27,7 +27,7 @@ const struct ltc_cipher_descriptor cast5_desc = {
 | 
				
			|||||||
   &cast5_test,
 | 
					   &cast5_test,
 | 
				
			||||||
   &cast5_done,
 | 
					   &cast5_done,
 | 
				
			||||||
   &cast5_keysize,
 | 
					   &cast5_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const ulong32 S1[256] = {
 | 
					static const ulong32 S1[256] = {
 | 
				
			||||||
 | 
				
			|||||||
@ -31,7 +31,7 @@ const struct ltc_cipher_descriptor des_desc =
 | 
				
			|||||||
    &des_test,
 | 
					    &des_test,
 | 
				
			||||||
    &des_done,
 | 
					    &des_done,
 | 
				
			||||||
    &des_keysize,
 | 
					    &des_keysize,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
const struct ltc_cipher_descriptor des3_desc =
 | 
					const struct ltc_cipher_descriptor des3_desc =
 | 
				
			||||||
@ -45,7 +45,7 @@ const struct ltc_cipher_descriptor des3_desc =
 | 
				
			|||||||
    &des3_test,
 | 
					    &des3_test,
 | 
				
			||||||
    &des3_done,
 | 
					    &des3_done,
 | 
				
			||||||
    &des3_keysize,
 | 
					    &des3_keysize,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const ulong32 bytebit[8] =
 | 
					static const ulong32 bytebit[8] =
 | 
				
			||||||
 | 
				
			|||||||
@ -33,7 +33,7 @@ const struct ltc_cipher_descriptor kasumi_desc = {
 | 
				
			|||||||
   &kasumi_test,
 | 
					   &kasumi_test,
 | 
				
			||||||
   &kasumi_done,
 | 
					   &kasumi_done,
 | 
				
			||||||
   &kasumi_keysize,
 | 
					   &kasumi_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static u16 FI( u16 in, u16 subkey )
 | 
					static u16 FI( u16 in, u16 subkey )
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ const struct ltc_cipher_descriptor khazad_desc = {
 | 
				
			|||||||
   &khazad_test,
 | 
					   &khazad_test,
 | 
				
			||||||
   &khazad_done,
 | 
					   &khazad_done,
 | 
				
			||||||
   &khazad_keysize,
 | 
					   &khazad_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#define R      8
 | 
					#define R      8
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,7 @@ const struct ltc_cipher_descriptor kseed_desc = {
 | 
				
			|||||||
   &kseed_test,
 | 
					   &kseed_test,
 | 
				
			||||||
   &kseed_done,
 | 
					   &kseed_done,
 | 
				
			||||||
   &kseed_keysize,
 | 
					   &kseed_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const ulong32 SS0[256] = {
 | 
					static const ulong32 SS0[256] = {
 | 
				
			||||||
 | 
				
			|||||||
@ -116,7 +116,7 @@ const struct ltc_cipher_descriptor multi2_desc = {
 | 
				
			|||||||
   &multi2_test,
 | 
					   &multi2_test,
 | 
				
			||||||
   &multi2_done,
 | 
					   &multi2_done,
 | 
				
			||||||
   &multi2_keysize,
 | 
					   &multi2_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int  multi2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 | 
					int  multi2_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 | 
				
			||||||
 | 
				
			|||||||
@ -27,7 +27,7 @@ const struct ltc_cipher_descriptor noekeon_desc =
 | 
				
			|||||||
    &noekeon_test,
 | 
					    &noekeon_test,
 | 
				
			||||||
    &noekeon_done,
 | 
					    &noekeon_done,
 | 
				
			||||||
    &noekeon_keysize,
 | 
					    &noekeon_keysize,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const ulong32 RC[] = {
 | 
					static const ulong32 RC[] = {
 | 
				
			||||||
 | 
				
			|||||||
@ -36,7 +36,7 @@ const struct ltc_cipher_descriptor rc2_desc = {
 | 
				
			|||||||
   &rc2_test,
 | 
					   &rc2_test,
 | 
				
			||||||
   &rc2_done,
 | 
					   &rc2_done,
 | 
				
			||||||
   &rc2_keysize,
 | 
					   &rc2_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* 256-entry permutation table, probably derived somehow from pi */
 | 
					/* 256-entry permutation table, probably derived somehow from pi */
 | 
				
			||||||
 | 
				
			|||||||
@ -29,7 +29,7 @@ const struct ltc_cipher_descriptor rc5_desc =
 | 
				
			|||||||
    &rc5_test,
 | 
					    &rc5_test,
 | 
				
			||||||
    &rc5_done,
 | 
					    &rc5_done,
 | 
				
			||||||
    &rc5_keysize,
 | 
					    &rc5_keysize,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const ulong32 stab[50] = {
 | 
					static const ulong32 stab[50] = {
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ const struct ltc_cipher_descriptor rc6_desc =
 | 
				
			|||||||
    &rc6_test,
 | 
					    &rc6_test,
 | 
				
			||||||
    &rc6_done,
 | 
					    &rc6_done,
 | 
				
			||||||
    &rc6_keysize,
 | 
					    &rc6_keysize,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const ulong32 stab[44] = {
 | 
					static const ulong32 stab[44] = {
 | 
				
			||||||
 | 
				
			|||||||
@ -45,7 +45,7 @@ const struct ltc_cipher_descriptor
 | 
				
			|||||||
   &safer_k64_test,
 | 
					   &safer_k64_test,
 | 
				
			||||||
   &safer_done,
 | 
					   &safer_done,
 | 
				
			||||||
   &safer_64_keysize,
 | 
					   &safer_64_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
   },
 | 
					   },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   safer_sk64_desc = {
 | 
					   safer_sk64_desc = {
 | 
				
			||||||
@ -57,7 +57,7 @@ const struct ltc_cipher_descriptor
 | 
				
			|||||||
   &safer_sk64_test,
 | 
					   &safer_sk64_test,
 | 
				
			||||||
   &safer_done,
 | 
					   &safer_done,
 | 
				
			||||||
   &safer_64_keysize,
 | 
					   &safer_64_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
   },
 | 
					   },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   safer_k128_desc = {
 | 
					   safer_k128_desc = {
 | 
				
			||||||
@ -69,7 +69,7 @@ const struct ltc_cipher_descriptor
 | 
				
			|||||||
   &safer_sk128_test,
 | 
					   &safer_sk128_test,
 | 
				
			||||||
   &safer_done,
 | 
					   &safer_done,
 | 
				
			||||||
   &safer_128_keysize,
 | 
					   &safer_128_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
   },
 | 
					   },
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   safer_sk128_desc = {
 | 
					   safer_sk128_desc = {
 | 
				
			||||||
@ -81,7 +81,7 @@ const struct ltc_cipher_descriptor
 | 
				
			|||||||
   &safer_sk128_test,
 | 
					   &safer_sk128_test,
 | 
				
			||||||
   &safer_done,
 | 
					   &safer_done,
 | 
				
			||||||
   &safer_128_keysize,
 | 
					   &safer_128_keysize,
 | 
				
			||||||
   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					   NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
   };
 | 
					   };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/******************* Constants ************************************************/
 | 
					/******************* Constants ************************************************/
 | 
				
			||||||
 | 
				
			|||||||
@ -31,7 +31,7 @@ const struct ltc_cipher_descriptor saferp_desc =
 | 
				
			|||||||
    &saferp_test,
 | 
					    &saferp_test,
 | 
				
			||||||
    &saferp_done,
 | 
					    &saferp_done,
 | 
				
			||||||
    &saferp_keysize,
 | 
					    &saferp_keysize,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* ROUND(b,i)
 | 
					/* ROUND(b,i)
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ const struct ltc_cipher_descriptor skipjack_desc =
 | 
				
			|||||||
    &skipjack_test,
 | 
					    &skipjack_test,
 | 
				
			||||||
    &skipjack_done,
 | 
					    &skipjack_done,
 | 
				
			||||||
    &skipjack_keysize,
 | 
					    &skipjack_keysize,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
static const unsigned char sbox[256] = {
 | 
					static const unsigned char sbox[256] = {
 | 
				
			||||||
 | 
				
			|||||||
@ -35,7 +35,7 @@ const struct ltc_cipher_descriptor twofish_desc =
 | 
				
			|||||||
    &twofish_test,
 | 
					    &twofish_test,
 | 
				
			||||||
    &twofish_done,
 | 
					    &twofish_done,
 | 
				
			||||||
    &twofish_keysize,
 | 
					    &twofish_keysize,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/* the two polynomials */
 | 
					/* the two polynomials */
 | 
				
			||||||
 | 
				
			|||||||
@ -28,7 +28,7 @@ const struct ltc_cipher_descriptor xtea_desc =
 | 
				
			|||||||
    &xtea_test,
 | 
					    &xtea_test,
 | 
				
			||||||
    &xtea_done,
 | 
					    &xtea_done,
 | 
				
			||||||
    &xtea_keysize,
 | 
					    &xtea_keysize,
 | 
				
			||||||
    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
					    NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
 | 
				
			||||||
};
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 | 
					int xtea_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey)
 | 
				
			||||||
 | 
				
			|||||||
@ -553,6 +553,36 @@ extern struct ltc_cipher_descriptor {
 | 
				
			|||||||
       const unsigned char *key, unsigned long keylen,
 | 
					       const unsigned char *key, unsigned long keylen,
 | 
				
			||||||
       const unsigned char *in,  unsigned long inlen,
 | 
					       const unsigned char *in,  unsigned long inlen,
 | 
				
			||||||
             unsigned char *out, unsigned long *outlen);
 | 
					             unsigned char *out, unsigned long *outlen);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					   /** Accelerated XTS encryption
 | 
				
			||||||
 | 
					       @param pt      Plaintext
 | 
				
			||||||
 | 
					       @param ct      Ciphertext
 | 
				
			||||||
 | 
					       @param blocks  The number of complete blocks to process
 | 
				
			||||||
 | 
					       @param tweak   The 128-bit encryption tweak (input/output).
 | 
				
			||||||
 | 
					                      The tweak should not be encrypted on input, but
 | 
				
			||||||
 | 
					                      next tweak will be copied encrypted on output.
 | 
				
			||||||
 | 
					       @param skey1   The first scheduled key context
 | 
				
			||||||
 | 
					       @param skey2   The second scheduled key context
 | 
				
			||||||
 | 
					       @return CRYPT_OK if successful
 | 
				
			||||||
 | 
					    */
 | 
				
			||||||
 | 
					    int (*accel_xts_encrypt)(const unsigned char *pt, unsigned char *ct,
 | 
				
			||||||
 | 
					        unsigned long blocks, unsigned char *tweak, symmetric_key *skey1,
 | 
				
			||||||
 | 
					        symmetric_key *skey2);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    /** Accelerated XTS decryption
 | 
				
			||||||
 | 
					        @param ct      Ciphertext
 | 
				
			||||||
 | 
					        @param pt      Plaintext
 | 
				
			||||||
 | 
					        @param blocks  The number of complete blocks to process
 | 
				
			||||||
 | 
					        @param tweak   The 128-bit encryption tweak (input/output).
 | 
				
			||||||
 | 
					                       The tweak should not be encrypted on input, but
 | 
				
			||||||
 | 
					                       next tweak will be copied encrypted on output.
 | 
				
			||||||
 | 
					        @param skey1   The first scheduled key context
 | 
				
			||||||
 | 
					        @param skey2   The second scheduled key context
 | 
				
			||||||
 | 
					        @return CRYPT_OK if successful
 | 
				
			||||||
 | 
					     */
 | 
				
			||||||
 | 
					     int (*accel_xts_decrypt)(const unsigned char *ct, unsigned char *pt,
 | 
				
			||||||
 | 
					         unsigned long blocks, unsigned char *tweak, symmetric_key *skey1,
 | 
				
			||||||
 | 
					         symmetric_key *skey2);
 | 
				
			||||||
} cipher_descriptor[];
 | 
					} cipher_descriptor[];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#ifdef LTC_BLOWFISH
 | 
					#ifdef LTC_BLOWFISH
 | 
				
			||||||
 | 
				
			|||||||
@ -16,7 +16,7 @@
 | 
				
			|||||||
*/
 | 
					*/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
struct ltc_cipher_descriptor cipher_descriptor[TAB_SIZE] = {
 | 
					struct ltc_cipher_descriptor cipher_descriptor[TAB_SIZE] = {
 | 
				
			||||||
{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
 | 
					{ NULL, 0, 0, 0, 0, 0, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }
 | 
				
			||||||
 };
 | 
					 };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
LTC_MUTEX_GLOBAL(ltc_cipher_mutex)
 | 
					LTC_MUTEX_GLOBAL(ltc_cipher_mutex)
 | 
				
			||||||
 | 
				
			|||||||
@ -87,22 +87,36 @@ static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char
 | 
				
			|||||||
      return CRYPT_INVALID_ARG;
 | 
					      return CRYPT_INVALID_ARG;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* encrypt the tweak */
 | 
					 | 
				
			||||||
   if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T, &xts->key2)) != CRYPT_OK) {
 | 
					 | 
				
			||||||
      return err;
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   /* for i = 0 to m-2 do */
 | 
					 | 
				
			||||||
   if (mo == 0) {
 | 
					   if (mo == 0) {
 | 
				
			||||||
      lim = m;
 | 
					      lim = m;
 | 
				
			||||||
   } else {
 | 
					   } else {
 | 
				
			||||||
      lim = m - 1;
 | 
					      lim = m - 1;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   for (i = 0; i < lim; i++) {
 | 
					   if (cipher_descriptor[xts->cipher].accel_xts_encrypt && lim > 0) {
 | 
				
			||||||
      err = tweak_uncrypt(ct, pt, T, xts);
 | 
					
 | 
				
			||||||
      ct += 16;
 | 
						   /* use accelerated decryption for whole blocks */
 | 
				
			||||||
      pt += 16;
 | 
						   if ((err = cipher_descriptor[xts->cipher].accel_xts_decrypt(ct, pt,
 | 
				
			||||||
 | 
								lim, tweak, &xts->key1, &xts->key2) != CRYPT_OK)) {
 | 
				
			||||||
 | 
						      return err;
 | 
				
			||||||
 | 
						   }
 | 
				
			||||||
 | 
						   ct += lim * 16;
 | 
				
			||||||
 | 
						   pt += lim * 16;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						   /* tweak is encrypted on output */
 | 
				
			||||||
 | 
						   XMEMCPY(T, tweak, sizeof(T));
 | 
				
			||||||
 | 
					   } else {
 | 
				
			||||||
 | 
					      /* encrypt the tweak */
 | 
				
			||||||
 | 
					      if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T,
 | 
				
			||||||
 | 
								&xts->key2)) != CRYPT_OK) {
 | 
				
			||||||
 | 
						 return err;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      for (i = 0; i < lim; i++) {
 | 
				
			||||||
 | 
						 err = tweak_uncrypt(ct, pt, T, xts);
 | 
				
			||||||
 | 
						 ct += 16;
 | 
				
			||||||
 | 
						 pt += 16;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
   
 | 
					   
 | 
				
			||||||
   /* if ptlen not divide 16 then */
 | 
					   /* if ptlen not divide 16 then */
 | 
				
			||||||
@ -131,7 +145,8 @@ static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char
 | 
				
			|||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* Decrypt the tweak back */
 | 
					   /* Decrypt the tweak back */
 | 
				
			||||||
   if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak, &xts->key2)) != CRYPT_OK) {
 | 
					   if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak,
 | 
				
			||||||
 | 
								&xts->key2)) != CRYPT_OK) {
 | 
				
			||||||
      return err;
 | 
					      return err;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -85,27 +85,42 @@ int xts_encrypt(
 | 
				
			|||||||
   m  = ptlen >> 4;
 | 
					   m  = ptlen >> 4;
 | 
				
			||||||
   mo = ptlen & 15;
 | 
					   mo = ptlen & 15;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	   /* must have at least one full block */
 | 
					   /* must have at least one full block */
 | 
				
			||||||
   if (m == 0) {
 | 
					   if (m == 0) {
 | 
				
			||||||
      return CRYPT_INVALID_ARG;
 | 
					      return CRYPT_INVALID_ARG;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* encrypt the tweak */
 | 
					 | 
				
			||||||
   if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T, &xts->key2)) != CRYPT_OK) {
 | 
					 | 
				
			||||||
      return err;
 | 
					 | 
				
			||||||
   }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
   /* for i = 0 to m-2 do */
 | 
					 | 
				
			||||||
   if (mo == 0) {
 | 
					   if (mo == 0) {
 | 
				
			||||||
      lim = m;
 | 
					      lim = m;
 | 
				
			||||||
   } else {
 | 
					   } else {
 | 
				
			||||||
      lim = m - 1;
 | 
					      lim = m - 1;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   for (i = 0; i < lim; i++) {
 | 
					   if (cipher_descriptor[xts->cipher].accel_xts_encrypt && lim > 0) {
 | 
				
			||||||
      err = tweak_crypt(pt, ct, T, xts);
 | 
					
 | 
				
			||||||
      ct += 16;
 | 
					      /* use accelerated encryption for whole blocks */
 | 
				
			||||||
      pt += 16;
 | 
					      if ((err = cipher_descriptor[xts->cipher].accel_xts_encrypt(pt, ct, lim,
 | 
				
			||||||
 | 
								tweak, &xts->key1, &xts->key2) != CRYPT_OK)) {
 | 
				
			||||||
 | 
						 return err;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      ct += lim * 16;
 | 
				
			||||||
 | 
					      pt += lim * 16;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      /* tweak is encrypted on output */
 | 
				
			||||||
 | 
					      XMEMCPY(T, tweak, sizeof(T));
 | 
				
			||||||
 | 
					   } else {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      /* encrypt the tweak */
 | 
				
			||||||
 | 
					      if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T,
 | 
				
			||||||
 | 
								&xts->key2)) != CRYPT_OK) {
 | 
				
			||||||
 | 
						 return err;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					      for (i = 0; i < lim; i++) {
 | 
				
			||||||
 | 
						 err = tweak_crypt(pt, ct, T, xts);
 | 
				
			||||||
 | 
						 ct += 16;
 | 
				
			||||||
 | 
						 pt += 16;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
   
 | 
					   
 | 
				
			||||||
   /* if ptlen not divide 16 then */
 | 
					   /* if ptlen not divide 16 then */
 | 
				
			||||||
@ -132,7 +147,8 @@ int xts_encrypt(
 | 
				
			|||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
   /* Decrypt the tweak back */
 | 
					   /* Decrypt the tweak back */
 | 
				
			||||||
   if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak, &xts->key2)) != CRYPT_OK) {
 | 
					   if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak,
 | 
				
			||||||
 | 
							&xts->key2)) != CRYPT_OK) {
 | 
				
			||||||
      return err;
 | 
					      return err;
 | 
				
			||||||
   }
 | 
					   }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user