1 /* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2 /* SPDX-License-Identifier: Unlicense */
3 #include "tomcrypt_private.h"
4
5 /**
6 Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
7 */
8
9 #ifdef LTC_XTS_MODE
10
11 /** Start XTS mode
12 @param cipher The index of the cipher to use
13 @param key1 The encrypt key
14 @param key2 The tweak encrypt key
15 @param keylen The length of the keys (each) in octets
16 @param num_rounds The number of rounds for the cipher (0 == default)
17 @param xts [out] XTS structure
18 Returns CRYPT_OK upon success.
19 */
xts_start(int cipher,const unsigned char * key1,const unsigned char * key2,unsigned long keylen,int num_rounds,symmetric_xts * xts)20 int xts_start(int cipher, const unsigned char *key1, const unsigned char *key2, unsigned long keylen, int num_rounds,
21 symmetric_xts *xts)
22 {
23 int err;
24
25 /* check inputs */
26 LTC_ARGCHK(key1 != NULL);
27 LTC_ARGCHK(key2 != NULL);
28 LTC_ARGCHK(xts != NULL);
29
30 /* check if valid */
31 if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
32 return err;
33 }
34
35 if (cipher_descriptor[cipher]->block_length != 16) {
36 return CRYPT_INVALID_ARG;
37 }
38
39 /* schedule the two ciphers */
40 if ((err = cipher_descriptor[cipher]->setup(key1, keylen, num_rounds, &xts->key1)) != CRYPT_OK) {
41 return err;
42 }
43 if ((err = cipher_descriptor[cipher]->setup(key2, keylen, num_rounds, &xts->key2)) != CRYPT_OK) {
44 return err;
45 }
46 xts->cipher = cipher;
47
48 return err;
49 }
50
51 #endif
52