Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/tomcrypt/src/modes/xts/xts_init.c
5972 views
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
#include "tomcrypt.h"
10
11
/**
12
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
13
*/
14
15
#ifdef LTC_XTS_MODE
16
17
/** Start XTS mode
18
@param cipher The index of the cipher to use
19
@param key1 The encrypt key
20
@param key2 The tweak encrypt key
21
@param keylen The length of the keys (each) in octets
22
@param num_rounds The number of rounds for the cipher (0 == default)
23
@param xts [out] XTS structure
24
Returns CRYPT_OK upon success.
25
*/
26
int xts_start(int cipher, const unsigned char *key1, const unsigned char *key2, unsigned long keylen, int num_rounds,
27
symmetric_xts *xts)
28
{
29
int err;
30
31
/* check inputs */
32
LTC_ARGCHK(key1 != NULL);
33
LTC_ARGCHK(key2 != NULL);
34
LTC_ARGCHK(xts != NULL);
35
36
/* check if valid */
37
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
38
return err;
39
}
40
41
if (cipher_descriptor[cipher].block_length != 16) {
42
return CRYPT_INVALID_ARG;
43
}
44
45
/* schedule the two ciphers */
46
if ((err = cipher_descriptor[cipher].setup(key1, keylen, num_rounds, &xts->key1)) != CRYPT_OK) {
47
return err;
48
}
49
if ((err = cipher_descriptor[cipher].setup(key2, keylen, num_rounds, &xts->key2)) != CRYPT_OK) {
50
return err;
51
}
52
xts->cipher = cipher;
53
54
return err;
55
}
56
57
#endif
58
59