auto-format xts code
This commit is contained in:
parent
b25d04ed94
commit
181d2f2df7
@ -57,10 +57,8 @@ static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char
|
|||||||
@param tweak [in] The 128--bit encryption tweak (e.g. sector number)
|
@param tweak [in] The 128--bit encryption tweak (e.g. sector number)
|
||||||
@param xts The XTS structure
|
@param xts The XTS structure
|
||||||
Returns CRYPT_OK upon success
|
Returns CRYPT_OK upon success
|
||||||
*/int xts_decrypt(
|
*/
|
||||||
const unsigned char *ct, unsigned long ptlen,
|
int xts_decrypt(const unsigned char *ct, unsigned long ptlen, unsigned char *pt, unsigned char *tweak,
|
||||||
unsigned char *pt,
|
|
||||||
unsigned char *tweak,
|
|
||||||
symmetric_xts *xts)
|
symmetric_xts *xts)
|
||||||
{
|
{
|
||||||
unsigned char PP[16], CC[16], T[16];
|
unsigned char PP[16], CC[16], T[16];
|
||||||
@ -96,8 +94,8 @@ static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char
|
|||||||
if (cipher_descriptor[xts->cipher].accel_xts_decrypt && lim > 0) {
|
if (cipher_descriptor[xts->cipher].accel_xts_decrypt && lim > 0) {
|
||||||
|
|
||||||
/* use accelerated decryption for whole blocks */
|
/* use accelerated decryption for whole blocks */
|
||||||
if ((err = cipher_descriptor[xts->cipher].accel_xts_decrypt(ct, pt,
|
if ((err = cipher_descriptor[xts->cipher].accel_xts_decrypt(ct, pt, lim, tweak, &xts->key1, &xts->key2) !=
|
||||||
lim, tweak, &xts->key1, &xts->key2) != CRYPT_OK)) {
|
CRYPT_OK)) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
ct += lim * 16;
|
ct += lim * 16;
|
||||||
@ -107,8 +105,7 @@ static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char
|
|||||||
XMEMCPY(T, tweak, sizeof(T));
|
XMEMCPY(T, tweak, sizeof(T));
|
||||||
} else {
|
} else {
|
||||||
/* encrypt the tweak */
|
/* encrypt the tweak */
|
||||||
if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T,
|
if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T, &xts->key2)) != CRYPT_OK) {
|
||||||
&xts->key2)) != CRYPT_OK) {
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -145,8 +142,7 @@ 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,
|
if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak, &xts->key2)) != CRYPT_OK) {
|
||||||
&xts->key2)) != CRYPT_OK) {
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,4 +154,3 @@ static int tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char
|
|||||||
/* $Source$ */
|
/* $Source$ */
|
||||||
/* $Revision$ */
|
/* $Revision$ */
|
||||||
/* $Date$ */
|
/* $Date$ */
|
||||||
|
|
||||||
|
@ -31,4 +31,3 @@ void xts_done(symmetric_xts *xts)
|
|||||||
/* $Source$ */
|
/* $Source$ */
|
||||||
/* $Revision$ */
|
/* $Revision$ */
|
||||||
/* $Date$ */
|
/* $Date$ */
|
||||||
|
|
||||||
|
@ -60,10 +60,7 @@ static int tweak_crypt(const unsigned char *P, unsigned char *C, unsigned char *
|
|||||||
@param xts The XTS structure
|
@param xts The XTS structure
|
||||||
Returns CRYPT_OK upon success
|
Returns CRYPT_OK upon success
|
||||||
*/
|
*/
|
||||||
int xts_encrypt(
|
int xts_encrypt(const unsigned char *pt, unsigned long ptlen, unsigned char *ct, unsigned char *tweak,
|
||||||
const unsigned char *pt, unsigned long ptlen,
|
|
||||||
unsigned char *ct,
|
|
||||||
unsigned char *tweak,
|
|
||||||
symmetric_xts *xts)
|
symmetric_xts *xts)
|
||||||
{
|
{
|
||||||
unsigned char PP[16], CC[16], T[16];
|
unsigned char PP[16], CC[16], T[16];
|
||||||
@ -99,8 +96,8 @@ int xts_encrypt(
|
|||||||
if (cipher_descriptor[xts->cipher].accel_xts_encrypt && lim > 0) {
|
if (cipher_descriptor[xts->cipher].accel_xts_encrypt && lim > 0) {
|
||||||
|
|
||||||
/* use accelerated encryption for whole blocks */
|
/* use accelerated encryption for whole blocks */
|
||||||
if ((err = cipher_descriptor[xts->cipher].accel_xts_encrypt(pt, ct, lim,
|
if ((err = cipher_descriptor[xts->cipher].accel_xts_encrypt(pt, ct, lim, tweak, &xts->key1, &xts->key2) !=
|
||||||
tweak, &xts->key1, &xts->key2) != CRYPT_OK)) {
|
CRYPT_OK)) {
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
ct += lim * 16;
|
ct += lim * 16;
|
||||||
@ -111,8 +108,7 @@ int xts_encrypt(
|
|||||||
} else {
|
} else {
|
||||||
|
|
||||||
/* encrypt the tweak */
|
/* encrypt the tweak */
|
||||||
if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T,
|
if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(tweak, T, &xts->key2)) != CRYPT_OK) {
|
||||||
&xts->key2)) != CRYPT_OK) {
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,8 +143,7 @@ int xts_encrypt(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Decrypt the tweak back */
|
/* Decrypt the tweak back */
|
||||||
if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak,
|
if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak, &xts->key2)) != CRYPT_OK) {
|
||||||
&xts->key2)) != CRYPT_OK) {
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -160,4 +155,3 @@ int xts_encrypt(
|
|||||||
/* $Source$ */
|
/* $Source$ */
|
||||||
/* $Revision$ */
|
/* $Revision$ */
|
||||||
/* $Date$ */
|
/* $Date$ */
|
||||||
|
|
||||||
|
@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
#ifdef LTC_XTS_MODE
|
#ifdef LTC_XTS_MODE
|
||||||
|
|
||||||
|
|
||||||
/** Start XTS mode
|
/** Start XTS mode
|
||||||
@param cipher The index of the cipher to use
|
@param cipher The index of the cipher to use
|
||||||
@param key1 The encrypt key
|
@param key1 The encrypt key
|
||||||
@ -26,11 +25,7 @@
|
|||||||
@param xts [out] XTS structure
|
@param xts [out] XTS structure
|
||||||
Returns CRYPT_OK upon success.
|
Returns CRYPT_OK upon success.
|
||||||
*/
|
*/
|
||||||
int xts_start( int cipher,
|
int xts_start(int cipher, const unsigned char *key1, const unsigned char *key2, unsigned long keylen, int num_rounds,
|
||||||
const unsigned char *key1,
|
|
||||||
const unsigned char *key2,
|
|
||||||
unsigned long keylen,
|
|
||||||
int num_rounds,
|
|
||||||
symmetric_xts *xts)
|
symmetric_xts *xts)
|
||||||
{
|
{
|
||||||
int err;
|
int err;
|
||||||
@ -66,4 +61,3 @@ int xts_start( int cipher,
|
|||||||
/* $Source$ */
|
/* $Source$ */
|
||||||
/* $Revision$ */
|
/* $Revision$ */
|
||||||
/* $Date$ */
|
/* $Date$ */
|
||||||
|
|
||||||
|
@ -39,4 +39,3 @@ void xts_mult_x(unsigned char *I)
|
|||||||
/* $Source$ */
|
/* $Source$ */
|
||||||
/* $Revision$ */
|
/* $Revision$ */
|
||||||
/* $Date$ */
|
/* $Date$ */
|
||||||
|
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
|
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
|
||||||
|
|
||||||
Returns CRYPT_OK upon success.
|
Returns CRYPT_OK upon success.
|
||||||
*/
|
*/
|
||||||
int xts_test(void)
|
int xts_test(void)
|
||||||
@ -21,7 +22,8 @@ int xts_test(void)
|
|||||||
#ifdef LTC_NO_TEST
|
#ifdef LTC_NO_TEST
|
||||||
return CRYPT_NOP;
|
return CRYPT_NOP;
|
||||||
#else
|
#else
|
||||||
static const struct {
|
static const struct
|
||||||
|
{
|
||||||
int keylen;
|
int keylen;
|
||||||
unsigned char key1[32];
|
unsigned char key1[32];
|
||||||
unsigned char key2[32];
|
unsigned char key2[32];
|
||||||
@ -154,7 +156,6 @@ int xts_test(void)
|
|||||||
return CRYPT_NOP;
|
return CRYPT_NOP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for (j = 0; j < 2; j++) {
|
for (j = 0; j < 2; j++) {
|
||||||
for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
|
for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
|
||||||
/* skip the cases where
|
/* skip the cases where
|
||||||
@ -182,8 +183,7 @@ int xts_test(void)
|
|||||||
xts_done(&xts);
|
xts_done(&xts);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
err = xts_encrypt(tests[i].PTX, len, OUT, T, &xts);
|
err = xts_encrypt(tests[i].PTX, len, OUT, T, &xts);
|
||||||
if (err != CRYPT_OK) {
|
if (err != CRYPT_OK) {
|
||||||
xts_done(&xts);
|
xts_done(&xts);
|
||||||
@ -198,7 +198,9 @@ int xts_test(void)
|
|||||||
|
|
||||||
if (XMEMCMP(OUT, tests[i].CTX, tests[i].PTLEN)) {
|
if (XMEMCMP(OUT, tests[i].CTX, tests[i].PTLEN)) {
|
||||||
#ifdef LTC_TEST_DBG
|
#ifdef LTC_TEST_DBG
|
||||||
printf("\nTestcase #%d with original length %lu and half of it %lu\n", i, tests[i].PTLEN, len);
|
printf("\nTestcase #%d with original length %lu and half of it "
|
||||||
|
"%lu\n",
|
||||||
|
i, tests[i].PTLEN, len);
|
||||||
printf("\nencrypt\n");
|
printf("\nencrypt\n");
|
||||||
print_hex("should", tests[i].CTX, tests[i].PTLEN);
|
print_hex("should", tests[i].CTX, tests[i].PTLEN);
|
||||||
print_hex("is", OUT, tests[i].PTLEN);
|
print_hex("is", OUT, tests[i].PTLEN);
|
||||||
@ -214,8 +216,7 @@ int xts_test(void)
|
|||||||
xts_done(&xts);
|
xts_done(&xts);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
err = xts_decrypt(tests[i].CTX, len, OUT, T, &xts);
|
err = xts_decrypt(tests[i].CTX, len, OUT, T, &xts);
|
||||||
if (err != CRYPT_OK) {
|
if (err != CRYPT_OK) {
|
||||||
xts_done(&xts);
|
xts_done(&xts);
|
||||||
@ -249,4 +250,3 @@ int xts_test(void)
|
|||||||
/* $Source$ */
|
/* $Source$ */
|
||||||
/* $Revision$ */
|
/* $Revision$ */
|
||||||
/* $Date$ */
|
/* $Date$ */
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user