Path: blob/master/libs/tomcrypt/src/modes/xts/xts_init.c
5972 views
/* LibTomCrypt, modular cryptographic library -- Tom St Denis1*2* LibTomCrypt is a library that provides various cryptographic3* algorithms in a highly modular and flexible manner.4*5* The library is free for all purposes without any express6* guarantee it works.7*/8#include "tomcrypt.h"910/**11Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects12*/1314#ifdef LTC_XTS_MODE1516/** Start XTS mode17@param cipher The index of the cipher to use18@param key1 The encrypt key19@param key2 The tweak encrypt key20@param keylen The length of the keys (each) in octets21@param num_rounds The number of rounds for the cipher (0 == default)22@param xts [out] XTS structure23Returns CRYPT_OK upon success.24*/25int xts_start(int cipher, const unsigned char *key1, const unsigned char *key2, unsigned long keylen, int num_rounds,26symmetric_xts *xts)27{28int err;2930/* check inputs */31LTC_ARGCHK(key1 != NULL);32LTC_ARGCHK(key2 != NULL);33LTC_ARGCHK(xts != NULL);3435/* check if valid */36if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {37return err;38}3940if (cipher_descriptor[cipher].block_length != 16) {41return CRYPT_INVALID_ARG;42}4344/* schedule the two ciphers */45if ((err = cipher_descriptor[cipher].setup(key1, keylen, num_rounds, &xts->key1)) != CRYPT_OK) {46return err;47}48if ((err = cipher_descriptor[cipher].setup(key2, keylen, num_rounds, &xts->key2)) != CRYPT_OK) {49return err;50}51xts->cipher = cipher;5253return err;54}5556#endif575859