mirror of
https://github.com/Laupetin/OpenAssetTools.git
synced 2025-06-10 14:58:10 -05:00
Import code from previous AssetBuilder version
This commit is contained in:
95
thirdparty/libtomcrypt/modes/cbc/cbc_decrypt.c
vendored
Normal file
95
thirdparty/libtomcrypt/modes/cbc/cbc_decrypt.c
vendored
Normal file
@ -0,0 +1,95 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cbc_decrypt.c
|
||||
CBC implementation, encrypt block, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_CBC_MODE
|
||||
|
||||
/**
|
||||
CBC decrypt
|
||||
@param ct Ciphertext
|
||||
@param pt [out] Plaintext
|
||||
@param len The number of bytes to process (must be multiple of block length)
|
||||
@param cbc CBC state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int cbc_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CBC *cbc)
|
||||
{
|
||||
int x, err;
|
||||
unsigned char tmp[16];
|
||||
#ifdef LTC_FAST
|
||||
LTC_FAST_TYPE tmpy;
|
||||
#else
|
||||
unsigned char tmpy;
|
||||
#endif
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen valid? */
|
||||
if (cbc->blocklen < 1 || cbc->blocklen > (int)sizeof(cbc->IV) || cbc->blocklen > (int)sizeof(tmp)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (len % cbc->blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#ifdef LTC_FAST
|
||||
if (cbc->blocklen % sizeof(LTC_FAST_TYPE)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cipher_descriptor[cbc->cipher].accel_cbc_decrypt != NULL) {
|
||||
return cipher_descriptor[cbc->cipher].accel_cbc_decrypt(ct, pt, len / cbc->blocklen, cbc->IV, &cbc->key);
|
||||
} else {
|
||||
while (len) {
|
||||
/* decrypt */
|
||||
if ((err = cipher_descriptor[cbc->cipher].ecb_decrypt(ct, tmp, &cbc->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* xor IV against plaintext */
|
||||
#if defined(LTC_FAST)
|
||||
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
tmpy = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) ^ *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)tmp + x));
|
||||
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x));
|
||||
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) = tmpy;
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < cbc->blocklen; x++) {
|
||||
tmpy = tmp[x] ^ cbc->IV[x];
|
||||
cbc->IV[x] = ct[x];
|
||||
pt[x] = tmpy;
|
||||
}
|
||||
#endif
|
||||
|
||||
ct += cbc->blocklen;
|
||||
pt += cbc->blocklen;
|
||||
len -= cbc->blocklen;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
40
thirdparty/libtomcrypt/modes/cbc/cbc_done.c
vendored
Normal file
40
thirdparty/libtomcrypt/modes/cbc/cbc_done.c
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cbc_done.c
|
||||
CBC implementation, finish chain, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CBC_MODE
|
||||
|
||||
/** Terminate the chain
|
||||
@param cbc The CBC chain to terminate
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int cbc_done(symmetric_CBC *cbc)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[cbc->cipher].done(&cbc->key);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
96
thirdparty/libtomcrypt/modes/cbc/cbc_encrypt.c
vendored
Normal file
96
thirdparty/libtomcrypt/modes/cbc/cbc_encrypt.c
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cbc_encrypt.c
|
||||
CBC implementation, encrypt block, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_CBC_MODE
|
||||
|
||||
/**
|
||||
CBC encrypt
|
||||
@param pt Plaintext
|
||||
@param ct [out] Ciphertext
|
||||
@param len The number of bytes to process (must be multiple of block length)
|
||||
@param cbc CBC state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int cbc_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CBC *cbc)
|
||||
{
|
||||
int x, err;
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cbc->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen valid? */
|
||||
if (cbc->blocklen < 1 || cbc->blocklen > (int)sizeof(cbc->IV)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (len % cbc->blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#ifdef LTC_FAST
|
||||
if (cbc->blocklen % sizeof(LTC_FAST_TYPE)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (cipher_descriptor[cbc->cipher].accel_cbc_encrypt != NULL) {
|
||||
return cipher_descriptor[cbc->cipher].accel_cbc_encrypt(pt, ct, len / cbc->blocklen, cbc->IV, &cbc->key);
|
||||
} else {
|
||||
while (len) {
|
||||
/* xor IV against plaintext */
|
||||
#if defined(LTC_FAST)
|
||||
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) ^= *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x));
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < cbc->blocklen; x++) {
|
||||
cbc->IV[x] ^= pt[x];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* encrypt */
|
||||
if ((err = cipher_descriptor[cbc->cipher].ecb_encrypt(cbc->IV, ct, &cbc->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* store IV [ciphertext] for a future block */
|
||||
#if defined(LTC_FAST)
|
||||
for (x = 0; x < cbc->blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)cbc->IV + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x));
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < cbc->blocklen; x++) {
|
||||
cbc->IV[x] = ct[x];
|
||||
}
|
||||
#endif
|
||||
|
||||
ct += cbc->blocklen;
|
||||
pt += cbc->blocklen;
|
||||
len -= cbc->blocklen;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
44
thirdparty/libtomcrypt/modes/cbc/cbc_getiv.c
vendored
Normal file
44
thirdparty/libtomcrypt/modes/cbc/cbc_getiv.c
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cbc_getiv.c
|
||||
CBC implementation, get IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CBC_MODE
|
||||
|
||||
/**
|
||||
Get the current initialization vector
|
||||
@param IV [out] The destination of the initialization vector
|
||||
@param len [in/out] The max size and resulting size of the initialization vector
|
||||
@param cbc The CBC state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int cbc_getiv(unsigned char *IV, unsigned long *len, symmetric_CBC *cbc)
|
||||
{
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
if ((unsigned long)cbc->blocklen > *len) {
|
||||
*len = cbc->blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, cbc->IV, cbc->blocklen);
|
||||
*len = cbc->blocklen;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
42
thirdparty/libtomcrypt/modes/cbc/cbc_setiv.c
vendored
Normal file
42
thirdparty/libtomcrypt/modes/cbc/cbc_setiv.c
vendored
Normal file
@ -0,0 +1,42 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cbc_setiv.c
|
||||
CBC implementation, set IV, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_CBC_MODE
|
||||
|
||||
/**
|
||||
Set an initialization vector
|
||||
@param IV The initialization vector
|
||||
@param len The length of the vector (in octets)
|
||||
@param cbc The CBC state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int cbc_setiv(const unsigned char *IV, unsigned long len, symmetric_CBC *cbc)
|
||||
{
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
if (len != (unsigned long)cbc->blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
XMEMCPY(cbc->IV, IV, len);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
60
thirdparty/libtomcrypt/modes/cbc/cbc_start.c
vendored
Normal file
60
thirdparty/libtomcrypt/modes/cbc/cbc_start.c
vendored
Normal file
@ -0,0 +1,60 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cbc_start.c
|
||||
CBC implementation, start chain, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CBC_MODE
|
||||
|
||||
/**
|
||||
Initialize a CBC context
|
||||
@param cipher The index of the cipher desired
|
||||
@param IV The initialization vector
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
||||
@param cbc The CBC state to initialize
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int cbc_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
||||
int keylen, int num_rounds, symmetric_CBC *cbc)
|
||||
{
|
||||
int x, err;
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(cbc != NULL);
|
||||
|
||||
/* bad param? */
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* setup cipher */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cbc->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* copy IV */
|
||||
cbc->blocklen = cipher_descriptor[cipher].block_length;
|
||||
cbc->cipher = cipher;
|
||||
for (x = 0; x < cbc->blocklen; x++) {
|
||||
cbc->IV[x] = IV[x];
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
65
thirdparty/libtomcrypt/modes/cfb/cfb_decrypt.c
vendored
Normal file
65
thirdparty/libtomcrypt/modes/cfb/cfb_decrypt.c
vendored
Normal file
@ -0,0 +1,65 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cfb_decrypt.c
|
||||
CFB implementation, decrypt data, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CFB_MODE
|
||||
|
||||
/**
|
||||
CFB decrypt
|
||||
@param ct Ciphertext
|
||||
@param pt [out] Plaintext
|
||||
@param len Length of ciphertext (octets)
|
||||
@param cfb CFB state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int cfb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CFB *cfb)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(cfb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen/padlen valid? */
|
||||
if (cfb->blocklen < 0 || cfb->blocklen > (int)sizeof(cfb->IV) ||
|
||||
cfb->padlen < 0 || cfb->padlen > (int)sizeof(cfb->pad)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
while (len-- > 0) {
|
||||
if (cfb->padlen == cfb->blocklen) {
|
||||
if ((err = cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->pad, cfb->IV, &cfb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cfb->padlen = 0;
|
||||
}
|
||||
cfb->pad[cfb->padlen] = *ct;
|
||||
*pt = *ct ^ cfb->IV[cfb->padlen];
|
||||
++pt;
|
||||
++ct;
|
||||
++(cfb->padlen);
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
40
thirdparty/libtomcrypt/modes/cfb/cfb_done.c
vendored
Normal file
40
thirdparty/libtomcrypt/modes/cfb/cfb_done.c
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cfb_done.c
|
||||
CFB implementation, finish chain, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CFB_MODE
|
||||
|
||||
/** Terminate the chain
|
||||
@param cfb The CFB chain to terminate
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int cfb_done(symmetric_CFB *cfb)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(cfb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[cfb->cipher].done(&cfb->key);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
63
thirdparty/libtomcrypt/modes/cfb/cfb_encrypt.c
vendored
Normal file
63
thirdparty/libtomcrypt/modes/cfb/cfb_encrypt.c
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cfb_encrypt.c
|
||||
CFB implementation, encrypt data, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CFB_MODE
|
||||
|
||||
/**
|
||||
CFB encrypt
|
||||
@param pt Plaintext
|
||||
@param ct [out] Ciphertext
|
||||
@param len Length of plaintext (octets)
|
||||
@param cfb CFB state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int cfb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CFB *cfb)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(cfb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen/padlen valid? */
|
||||
if (cfb->blocklen < 0 || cfb->blocklen > (int)sizeof(cfb->IV) ||
|
||||
cfb->padlen < 0 || cfb->padlen > (int)sizeof(cfb->pad)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
while (len-- > 0) {
|
||||
if (cfb->padlen == cfb->blocklen) {
|
||||
if ((err = cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->pad, cfb->IV, &cfb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cfb->padlen = 0;
|
||||
}
|
||||
cfb->pad[cfb->padlen] = (*ct = *pt ^ cfb->IV[cfb->padlen]);
|
||||
++pt;
|
||||
++ct;
|
||||
++(cfb->padlen);
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
44
thirdparty/libtomcrypt/modes/cfb/cfb_getiv.c
vendored
Normal file
44
thirdparty/libtomcrypt/modes/cfb/cfb_getiv.c
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cfb_getiv.c
|
||||
CFB implementation, get IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CFB_MODE
|
||||
|
||||
/**
|
||||
Get the current initialization vector
|
||||
@param IV [out] The destination of the initialization vector
|
||||
@param len [in/out] The max size and resulting size of the initialization vector
|
||||
@param cfb The CFB state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int cfb_getiv(unsigned char *IV, unsigned long *len, symmetric_CFB *cfb)
|
||||
{
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(cfb != NULL);
|
||||
if ((unsigned long)cfb->blocklen > *len) {
|
||||
*len = cfb->blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, cfb->IV, cfb->blocklen);
|
||||
*len = cfb->blocklen;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
50
thirdparty/libtomcrypt/modes/cfb/cfb_setiv.c
vendored
Normal file
50
thirdparty/libtomcrypt/modes/cfb/cfb_setiv.c
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cfb_setiv.c
|
||||
CFB implementation, set IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CFB_MODE
|
||||
|
||||
/**
|
||||
Set an initialization vector
|
||||
@param IV The initialization vector
|
||||
@param len The length of the vector (in octets)
|
||||
@param cfb The CFB state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int cfb_setiv(const unsigned char *IV, unsigned long len, symmetric_CFB *cfb)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(cfb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cfb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (len != (unsigned long)cfb->blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* force next block */
|
||||
cfb->padlen = 0;
|
||||
return cipher_descriptor[cfb->cipher].ecb_encrypt(IV, cfb->IV, &cfb->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
63
thirdparty/libtomcrypt/modes/cfb/cfb_start.c
vendored
Normal file
63
thirdparty/libtomcrypt/modes/cfb/cfb_start.c
vendored
Normal file
@ -0,0 +1,63 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file cfb_start.c
|
||||
CFB implementation, start chain, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_CFB_MODE
|
||||
|
||||
/**
|
||||
Initialize a CFB context
|
||||
@param cipher The index of the cipher desired
|
||||
@param IV The initialization vector
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
||||
@param cfb The CFB state to initialize
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int cfb_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
||||
int keylen, int num_rounds, symmetric_CFB *cfb)
|
||||
{
|
||||
int x, err;
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(cfb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
/* copy data */
|
||||
cfb->cipher = cipher;
|
||||
cfb->blocklen = cipher_descriptor[cipher].block_length;
|
||||
for (x = 0; x < cfb->blocklen; x++)
|
||||
cfb->IV[x] = IV[x];
|
||||
|
||||
/* init the cipher */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &cfb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* encrypt the IV */
|
||||
cfb->padlen = 0;
|
||||
return cipher_descriptor[cfb->cipher].ecb_encrypt(cfb->IV, cfb->IV, &cfb->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
40
thirdparty/libtomcrypt/modes/ctr/ctr_decrypt.c
vendored
Normal file
40
thirdparty/libtomcrypt/modes/ctr/ctr_decrypt.c
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ctr_decrypt.c
|
||||
CTR implementation, decrypt data, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
|
||||
/**
|
||||
CTR decrypt
|
||||
@param ct Ciphertext
|
||||
@param pt [out] Plaintext
|
||||
@param len Length of ciphertext (octets)
|
||||
@param ctr CTR state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ctr_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_CTR *ctr)
|
||||
{
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
|
||||
return ctr_encrypt(ct, pt, len, ctr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
40
thirdparty/libtomcrypt/modes/ctr/ctr_done.c
vendored
Normal file
40
thirdparty/libtomcrypt/modes/ctr/ctr_done.c
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ctr_done.c
|
||||
CTR implementation, finish chain, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
|
||||
/** Terminate the chain
|
||||
@param ctr The CTR chain to terminate
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int ctr_done(symmetric_CTR *ctr)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[ctr->cipher].done(&ctr->key);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
139
thirdparty/libtomcrypt/modes/ctr/ctr_encrypt.c
vendored
Normal file
139
thirdparty/libtomcrypt/modes/ctr/ctr_encrypt.c
vendored
Normal file
@ -0,0 +1,139 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ctr_encrypt.c
|
||||
CTR implementation, encrypt data, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
|
||||
/**
|
||||
CTR encrypt software implementation
|
||||
@param pt Plaintext
|
||||
@param ct [out] Ciphertext
|
||||
@param len Length of plaintext (octets)
|
||||
@param ctr CTR state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
static int _ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr)
|
||||
{
|
||||
int x, err;
|
||||
|
||||
while (len) {
|
||||
/* is the pad empty? */
|
||||
if (ctr->padlen == ctr->blocklen) {
|
||||
/* increment counter */
|
||||
if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
|
||||
/* little-endian */
|
||||
for (x = 0; x < ctr->ctrlen; x++) {
|
||||
ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
|
||||
if (ctr->ctr[x] != (unsigned char)0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* big-endian */
|
||||
for (x = ctr->blocklen-1; x >= ctr->ctrlen; x--) {
|
||||
ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
|
||||
if (ctr->ctr[x] != (unsigned char)0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* encrypt it */
|
||||
if ((err = cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
ctr->padlen = 0;
|
||||
}
|
||||
#ifdef LTC_FAST
|
||||
if ((ctr->padlen == 0) && (len >= (unsigned long)ctr->blocklen)) {
|
||||
for (x = 0; x < ctr->blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ct + x)) = *(LTC_FAST_TYPE_PTR_CAST((unsigned char *)pt + x)) ^
|
||||
*(LTC_FAST_TYPE_PTR_CAST((unsigned char *)ctr->pad + x));
|
||||
}
|
||||
pt += ctr->blocklen;
|
||||
ct += ctr->blocklen;
|
||||
len -= ctr->blocklen;
|
||||
ctr->padlen = ctr->blocklen;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
*ct++ = *pt++ ^ ctr->pad[ctr->padlen++];
|
||||
--len;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/**
|
||||
CTR encrypt
|
||||
@param pt Plaintext
|
||||
@param ct [out] Ciphertext
|
||||
@param len Length of plaintext (octets)
|
||||
@param ctr CTR state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ctr_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_CTR *ctr)
|
||||
{
|
||||
int err, fr;
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen/padlen valid? */
|
||||
if ((ctr->blocklen < 1) || (ctr->blocklen > (int)sizeof(ctr->ctr)) ||
|
||||
(ctr->padlen < 0) || (ctr->padlen > (int)sizeof(ctr->pad))) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
#ifdef LTC_FAST
|
||||
if (ctr->blocklen % sizeof(LTC_FAST_TYPE)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* handle acceleration only if pad is empty, accelerator is present and length is >= a block size */
|
||||
if ((cipher_descriptor[ctr->cipher].accel_ctr_encrypt != NULL) && (len >= (unsigned long)ctr->blocklen)) {
|
||||
if (ctr->padlen < ctr->blocklen) {
|
||||
fr = ctr->blocklen - ctr->padlen;
|
||||
if ((err = _ctr_encrypt(pt, ct, fr, ctr)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
pt += fr;
|
||||
ct += fr;
|
||||
len -= fr;
|
||||
}
|
||||
|
||||
if (len >= (unsigned long)ctr->blocklen) {
|
||||
if ((err = cipher_descriptor[ctr->cipher].accel_ctr_encrypt(pt, ct, len/ctr->blocklen, ctr->ctr, ctr->mode, &ctr->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
pt += (len / ctr->blocklen) * ctr->blocklen;
|
||||
ct += (len / ctr->blocklen) * ctr->blocklen;
|
||||
len %= ctr->blocklen;
|
||||
}
|
||||
}
|
||||
|
||||
return _ctr_encrypt(pt, ct, len, ctr);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
44
thirdparty/libtomcrypt/modes/ctr/ctr_getiv.c
vendored
Normal file
44
thirdparty/libtomcrypt/modes/ctr/ctr_getiv.c
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ctr_getiv.c
|
||||
CTR implementation, get IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
|
||||
/**
|
||||
Get the current initialization vector
|
||||
@param IV [out] The destination of the initialization vector
|
||||
@param len [in/out] The max size and resulting size of the initialization vector
|
||||
@param ctr The CTR state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ctr_getiv(unsigned char *IV, unsigned long *len, symmetric_CTR *ctr)
|
||||
{
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
if ((unsigned long)ctr->blocklen > *len) {
|
||||
*len = ctr->blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, ctr->ctr, ctr->blocklen);
|
||||
*len = ctr->blocklen;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
54
thirdparty/libtomcrypt/modes/ctr/ctr_setiv.c
vendored
Normal file
54
thirdparty/libtomcrypt/modes/ctr/ctr_setiv.c
vendored
Normal file
@ -0,0 +1,54 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ctr_setiv.c
|
||||
CTR implementation, set IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
|
||||
/**
|
||||
Set an initialization vector
|
||||
@param IV The initialization vector
|
||||
@param len The length of the vector (in octets)
|
||||
@param ctr The CTR state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ctr_setiv(const unsigned char *IV, unsigned long len, symmetric_CTR *ctr)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
|
||||
/* bad param? */
|
||||
if ((err = cipher_is_valid(ctr->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (len != (unsigned long)ctr->blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* set IV */
|
||||
XMEMCPY(ctr->ctr, IV, len);
|
||||
|
||||
/* force next block */
|
||||
ctr->padlen = 0;
|
||||
return cipher_descriptor[ctr->cipher].ecb_encrypt(IV, ctr->pad, &ctr->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
99
thirdparty/libtomcrypt/modes/ctr/ctr_start.c
vendored
Normal file
99
thirdparty/libtomcrypt/modes/ctr/ctr_start.c
vendored
Normal file
@ -0,0 +1,99 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ctr_start.c
|
||||
CTR implementation, start chain, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
|
||||
/**
|
||||
Initialize a CTR context
|
||||
@param cipher The index of the cipher desired
|
||||
@param IV The initialization vector
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
||||
@param ctr_mode The counter mode (CTR_COUNTER_LITTLE_ENDIAN or CTR_COUNTER_BIG_ENDIAN)
|
||||
@param ctr The CTR state to initialize
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ctr_start( int cipher,
|
||||
const unsigned char *IV,
|
||||
const unsigned char *key, int keylen,
|
||||
int num_rounds, int ctr_mode,
|
||||
symmetric_CTR *ctr)
|
||||
{
|
||||
int x, err;
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(ctr != NULL);
|
||||
|
||||
/* bad param? */
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ctrlen == counter width */
|
||||
ctr->ctrlen = (ctr_mode & 255) ? (ctr_mode & 255) : cipher_descriptor[cipher].block_length;
|
||||
if (ctr->ctrlen > cipher_descriptor[cipher].block_length) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if ((ctr_mode & 0x1000) == CTR_COUNTER_BIG_ENDIAN) {
|
||||
ctr->ctrlen = cipher_descriptor[cipher].block_length - ctr->ctrlen;
|
||||
}
|
||||
|
||||
/* setup cipher */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ctr->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* copy ctr */
|
||||
ctr->blocklen = cipher_descriptor[cipher].block_length;
|
||||
ctr->cipher = cipher;
|
||||
ctr->padlen = 0;
|
||||
ctr->mode = ctr_mode & 0x1000;
|
||||
for (x = 0; x < ctr->blocklen; x++) {
|
||||
ctr->ctr[x] = IV[x];
|
||||
}
|
||||
|
||||
if (ctr_mode & LTC_CTR_RFC3686) {
|
||||
/* increment the IV as per RFC 3686 */
|
||||
if (ctr->mode == CTR_COUNTER_LITTLE_ENDIAN) {
|
||||
/* little-endian */
|
||||
for (x = 0; x < ctr->ctrlen; x++) {
|
||||
ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
|
||||
if (ctr->ctr[x] != (unsigned char)0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
/* big-endian */
|
||||
for (x = ctr->blocklen-1; x >= ctr->ctrlen; x--) {
|
||||
ctr->ctr[x] = (ctr->ctr[x] + (unsigned char)1) & (unsigned char)255;
|
||||
if (ctr->ctr[x] != (unsigned char)0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return cipher_descriptor[ctr->cipher].ecb_encrypt(ctr->ctr, ctr->pad, &ctr->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
83
thirdparty/libtomcrypt/modes/ctr/ctr_test.c
vendored
Normal file
83
thirdparty/libtomcrypt/modes/ctr/ctr_test.c
vendored
Normal file
@ -0,0 +1,83 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ctr_test.c
|
||||
CTR implementation, Tests again RFC 3686, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_CTR_MODE
|
||||
|
||||
int ctr_test(void)
|
||||
{
|
||||
#ifdef LTC_NO_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
static const struct {
|
||||
int keylen, msglen;
|
||||
unsigned char key[32], IV[16], pt[64], ct[64];
|
||||
} tests[] = {
|
||||
/* 128-bit key, 16-byte pt */
|
||||
{
|
||||
16, 16,
|
||||
{0xAE,0x68,0x52,0xF8,0x12,0x10,0x67,0xCC,0x4B,0xF7,0xA5,0x76,0x55,0x77,0xF3,0x9E },
|
||||
{0x00,0x00,0x00,0x30,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
|
||||
{0x53,0x69,0x6E,0x67,0x6C,0x65,0x20,0x62,0x6C,0x6F,0x63,0x6B,0x20,0x6D,0x73,0x67 },
|
||||
{0xE4,0x09,0x5D,0x4F,0xB7,0xA7,0xB3,0x79,0x2D,0x61,0x75,0xA3,0x26,0x13,0x11,0xB8 },
|
||||
},
|
||||
|
||||
/* 128-bit key, 36-byte pt */
|
||||
{
|
||||
16, 36,
|
||||
{0x76,0x91,0xBE,0x03,0x5E,0x50,0x20,0xA8,0xAC,0x6E,0x61,0x85,0x29,0xF9,0xA0,0xDC },
|
||||
{0x00,0xE0,0x01,0x7B,0x27,0x77,0x7F,0x3F,0x4A,0x17,0x86,0xF0,0x00,0x00,0x00,0x00 },
|
||||
{0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,
|
||||
0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1A,0x1B,0x1C,0x1D,0x1E,0x1F,
|
||||
0x20,0x21,0x22,0x23},
|
||||
{0xC1,0xCF,0x48,0xA8,0x9F,0x2F,0xFD,0xD9,0xCF,0x46,0x52,0xE9,0xEF,0xDB,0x72,0xD7,
|
||||
0x45,0x40,0xA4,0x2B,0xDE,0x6D,0x78,0x36,0xD5,0x9A,0x5C,0xEA,0xAE,0xF3,0x10,0x53,
|
||||
0x25,0xB2,0x07,0x2F },
|
||||
},
|
||||
};
|
||||
int idx, err, x;
|
||||
unsigned char buf[64];
|
||||
symmetric_CTR ctr;
|
||||
|
||||
/* AES can be under rijndael or aes... try to find it */
|
||||
if ((idx = find_cipher("aes")) == -1) {
|
||||
if ((idx = find_cipher("rijndael")) == -1) {
|
||||
return CRYPT_NOP;
|
||||
}
|
||||
}
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
if ((err = ctr_start(idx, tests[x].IV, tests[x].key, tests[x].keylen, 0, CTR_COUNTER_BIG_ENDIAN|LTC_CTR_RFC3686, &ctr)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if ((err = ctr_encrypt(tests[x].pt, buf, tests[x].msglen, &ctr)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
ctr_done(&ctr);
|
||||
if (compare_testvector(buf, tests[x].msglen, tests[x].ct, tests[x].msglen, "CTR", x)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
||||
|
||||
|
||||
|
59
thirdparty/libtomcrypt/modes/ecb/ecb_decrypt.c
vendored
Normal file
59
thirdparty/libtomcrypt/modes/ecb/ecb_decrypt.c
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ecb_decrypt.c
|
||||
ECB implementation, decrypt a block, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_ECB_MODE
|
||||
|
||||
/**
|
||||
ECB decrypt
|
||||
@param ct Ciphertext
|
||||
@param pt [out] Plaintext
|
||||
@param len The number of octets to process (must be multiple of the cipher block size)
|
||||
@param ecb ECB state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ecb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_ECB *ecb)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(ecb != NULL);
|
||||
if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if (len % cipher_descriptor[ecb->cipher].block_length) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* check for accel */
|
||||
if (cipher_descriptor[ecb->cipher].accel_ecb_decrypt != NULL) {
|
||||
return cipher_descriptor[ecb->cipher].accel_ecb_decrypt(ct, pt, len / cipher_descriptor[ecb->cipher].block_length, &ecb->key);
|
||||
} else {
|
||||
while (len) {
|
||||
if ((err = cipher_descriptor[ecb->cipher].ecb_decrypt(ct, pt, &ecb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
pt += cipher_descriptor[ecb->cipher].block_length;
|
||||
ct += cipher_descriptor[ecb->cipher].block_length;
|
||||
len -= cipher_descriptor[ecb->cipher].block_length;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
40
thirdparty/libtomcrypt/modes/ecb/ecb_done.c
vendored
Normal file
40
thirdparty/libtomcrypt/modes/ecb/ecb_done.c
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ecb_done.c
|
||||
ECB implementation, finish chain, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_ECB_MODE
|
||||
|
||||
/** Terminate the chain
|
||||
@param ecb The ECB chain to terminate
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int ecb_done(symmetric_ECB *ecb)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(ecb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[ecb->cipher].done(&ecb->key);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
59
thirdparty/libtomcrypt/modes/ecb/ecb_encrypt.c
vendored
Normal file
59
thirdparty/libtomcrypt/modes/ecb/ecb_encrypt.c
vendored
Normal file
@ -0,0 +1,59 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ecb_encrypt.c
|
||||
ECB implementation, encrypt a block, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_ECB_MODE
|
||||
|
||||
/**
|
||||
ECB encrypt
|
||||
@param pt Plaintext
|
||||
@param ct [out] Ciphertext
|
||||
@param len The number of octets to process (must be multiple of the cipher block size)
|
||||
@param ecb ECB state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ecb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_ECB *ecb)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(ecb != NULL);
|
||||
if ((err = cipher_is_valid(ecb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if (len % cipher_descriptor[ecb->cipher].block_length) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* check for accel */
|
||||
if (cipher_descriptor[ecb->cipher].accel_ecb_encrypt != NULL) {
|
||||
return cipher_descriptor[ecb->cipher].accel_ecb_encrypt(pt, ct, len / cipher_descriptor[ecb->cipher].block_length, &ecb->key);
|
||||
} else {
|
||||
while (len) {
|
||||
if ((err = cipher_descriptor[ecb->cipher].ecb_encrypt(pt, ct, &ecb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
pt += cipher_descriptor[ecb->cipher].block_length;
|
||||
ct += cipher_descriptor[ecb->cipher].block_length;
|
||||
len -= cipher_descriptor[ecb->cipher].block_length;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
46
thirdparty/libtomcrypt/modes/ecb/ecb_start.c
vendored
Normal file
46
thirdparty/libtomcrypt/modes/ecb/ecb_start.c
vendored
Normal file
@ -0,0 +1,46 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ecb_start.c
|
||||
ECB implementation, start chain, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_ECB_MODE
|
||||
|
||||
/**
|
||||
Initialize a ECB context
|
||||
@param cipher The index of the cipher desired
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
||||
@param ecb The ECB state to initialize
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ecb_start(int cipher, const unsigned char *key, int keylen, int num_rounds, symmetric_ECB *ecb)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(ecb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
ecb->cipher = cipher;
|
||||
ecb->blocklen = cipher_descriptor[cipher].block_length;
|
||||
return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ecb->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
41
thirdparty/libtomcrypt/modes/f8/f8_decrypt.c
vendored
Normal file
41
thirdparty/libtomcrypt/modes/f8/f8_decrypt.c
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_decrypt.c
|
||||
F8 implementation, decrypt data, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/**
|
||||
F8 decrypt
|
||||
@param ct Ciphertext
|
||||
@param pt [out] Plaintext
|
||||
@param len Length of ciphertext (octets)
|
||||
@param f8 F8 state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f8_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_F8 *f8)
|
||||
{
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
return f8_encrypt(ct, pt, len, f8);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
40
thirdparty/libtomcrypt/modes/f8/f8_done.c
vendored
Normal file
40
thirdparty/libtomcrypt/modes/f8/f8_done.c
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_done.c
|
||||
F8 implementation, finish chain, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/** Terminate the chain
|
||||
@param f8 The F8 chain to terminate
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int f8_done(symmetric_F8 *f8)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[f8->cipher].done(&f8->key);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
101
thirdparty/libtomcrypt/modes/f8/f8_encrypt.c
vendored
Normal file
101
thirdparty/libtomcrypt/modes/f8/f8_encrypt.c
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_encrypt.c
|
||||
F8 implementation, encrypt data, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/**
|
||||
F8 encrypt
|
||||
@param pt Plaintext
|
||||
@param ct [out] Ciphertext
|
||||
@param len Length of plaintext (octets)
|
||||
@param f8 F8 state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f8_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_F8 *f8)
|
||||
{
|
||||
int err, x;
|
||||
unsigned char buf[MAXBLOCKSIZE];
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen/padlen valid? */
|
||||
if (f8->blocklen < 0 || f8->blocklen > (int)sizeof(f8->IV) ||
|
||||
f8->padlen < 0 || f8->padlen > (int)sizeof(f8->IV)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
zeromem(buf, sizeof(buf));
|
||||
|
||||
/* make sure the pad is empty */
|
||||
if (f8->padlen == f8->blocklen) {
|
||||
/* xor of IV, MIV and blockcnt == what goes into cipher */
|
||||
STORE32H(f8->blockcnt, (buf+(f8->blocklen-4)));
|
||||
++(f8->blockcnt);
|
||||
for (x = 0; x < f8->blocklen; x++) {
|
||||
f8->IV[x] ^= f8->MIV[x] ^ buf[x];
|
||||
}
|
||||
if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(f8->IV, f8->IV, &f8->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
f8->padlen = 0;
|
||||
}
|
||||
|
||||
#ifdef LTC_FAST
|
||||
if (f8->padlen == 0) {
|
||||
while (len >= (unsigned long)f8->blocklen) {
|
||||
STORE32H(f8->blockcnt, (buf+(f8->blocklen-4)));
|
||||
++(f8->blockcnt);
|
||||
for (x = 0; x < f8->blocklen; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(&ct[x])) = *(LTC_FAST_TYPE_PTR_CAST(&pt[x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&f8->IV[x]));
|
||||
*(LTC_FAST_TYPE_PTR_CAST(&f8->IV[x])) ^= *(LTC_FAST_TYPE_PTR_CAST(&f8->MIV[x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&buf[x]));
|
||||
}
|
||||
if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(f8->IV, f8->IV, &f8->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
len -= x;
|
||||
pt += x;
|
||||
ct += x;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
while (len > 0) {
|
||||
if (f8->padlen == f8->blocklen) {
|
||||
/* xor of IV, MIV and blockcnt == what goes into cipher */
|
||||
STORE32H(f8->blockcnt, (buf+(f8->blocklen-4)));
|
||||
++(f8->blockcnt);
|
||||
for (x = 0; x < f8->blocklen; x++) {
|
||||
f8->IV[x] ^= f8->MIV[x] ^ buf[x];
|
||||
}
|
||||
if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(f8->IV, f8->IV, &f8->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
f8->padlen = 0;
|
||||
}
|
||||
*ct++ = *pt++ ^ f8->IV[f8->padlen++];
|
||||
--len;
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
44
thirdparty/libtomcrypt/modes/f8/f8_getiv.c
vendored
Normal file
44
thirdparty/libtomcrypt/modes/f8/f8_getiv.c
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ofb_getiv.c
|
||||
F8 implementation, get IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/**
|
||||
Get the current initialization vector
|
||||
@param IV [out] The destination of the initialization vector
|
||||
@param len [in/out] The max size and resulting size of the initialization vector
|
||||
@param f8 The F8 state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f8_getiv(unsigned char *IV, unsigned long *len, symmetric_F8 *f8)
|
||||
{
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
if ((unsigned long)f8->blocklen > *len) {
|
||||
*len = f8->blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, f8->IV, f8->blocklen);
|
||||
*len = f8->blocklen;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
50
thirdparty/libtomcrypt/modes/f8/f8_setiv.c
vendored
Normal file
50
thirdparty/libtomcrypt/modes/f8/f8_setiv.c
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_setiv.c
|
||||
F8 implementation, set IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/**
|
||||
Set an initialization vector
|
||||
@param IV The initialization vector
|
||||
@param len The length of the vector (in octets)
|
||||
@param f8 The F8 state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f8_setiv(const unsigned char *IV, unsigned long len, symmetric_F8 *f8)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(f8->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (len != (unsigned long)f8->blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* force next block */
|
||||
f8->padlen = 0;
|
||||
return cipher_descriptor[f8->cipher].ecb_encrypt(IV, f8->IV, &f8->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
96
thirdparty/libtomcrypt/modes/f8/f8_start.c
vendored
Normal file
96
thirdparty/libtomcrypt/modes/f8/f8_start.c
vendored
Normal file
@ -0,0 +1,96 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_start.c
|
||||
F8 implementation, start chain, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
/**
|
||||
Initialize an F8 context
|
||||
@param cipher The index of the cipher desired
|
||||
@param IV The initialization vector
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param salt_key The salting key for the IV
|
||||
@param skeylen The length of the salting key (octets)
|
||||
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
||||
@param f8 The F8 state to initialize
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int f8_start( int cipher, const unsigned char *IV,
|
||||
const unsigned char *key, int keylen,
|
||||
const unsigned char *salt_key, int skeylen,
|
||||
int num_rounds, symmetric_F8 *f8)
|
||||
{
|
||||
int x, err;
|
||||
unsigned char tkey[MAXBLOCKSIZE];
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(salt_key != NULL);
|
||||
LTC_ARGCHK(f8 != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef LTC_FAST
|
||||
if (cipher_descriptor[cipher].block_length % sizeof(LTC_FAST_TYPE)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* copy details */
|
||||
f8->blockcnt = 0;
|
||||
f8->cipher = cipher;
|
||||
f8->blocklen = cipher_descriptor[cipher].block_length;
|
||||
f8->padlen = f8->blocklen;
|
||||
|
||||
/* now get key ^ salt_key [extend salt_ket with 0x55 as required to match length] */
|
||||
zeromem(tkey, sizeof(tkey));
|
||||
for (x = 0; x < keylen && x < (int)sizeof(tkey); x++) {
|
||||
tkey[x] = key[x];
|
||||
}
|
||||
for (x = 0; x < skeylen && x < (int)sizeof(tkey); x++) {
|
||||
tkey[x] ^= salt_key[x];
|
||||
}
|
||||
for (; x < keylen && x < (int)sizeof(tkey); x++) {
|
||||
tkey[x] ^= 0x55;
|
||||
}
|
||||
|
||||
/* now encrypt with tkey[0..keylen-1] the IV and use that as the IV */
|
||||
if ((err = cipher_descriptor[cipher].setup(tkey, keylen, num_rounds, &f8->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* encrypt IV */
|
||||
if ((err = cipher_descriptor[f8->cipher].ecb_encrypt(IV, f8->MIV, &f8->key)) != CRYPT_OK) {
|
||||
cipher_descriptor[f8->cipher].done(&f8->key);
|
||||
return err;
|
||||
}
|
||||
zeromem(tkey, sizeof(tkey));
|
||||
zeromem(f8->IV, sizeof(f8->IV));
|
||||
|
||||
/* terminate this cipher */
|
||||
cipher_descriptor[f8->cipher].done(&f8->key);
|
||||
|
||||
/* init the cipher */
|
||||
return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &f8->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
74
thirdparty/libtomcrypt/modes/f8/f8_test_mode.c
vendored
Normal file
74
thirdparty/libtomcrypt/modes/f8/f8_test_mode.c
vendored
Normal file
@ -0,0 +1,74 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file f8_test_mode.c
|
||||
F8 implementation, test, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_F8_MODE
|
||||
|
||||
int f8_test_mode(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
static const unsigned char key[16] = { 0x23, 0x48, 0x29, 0x00, 0x84, 0x67, 0xbe, 0x18,
|
||||
0x6c, 0x3d, 0xe1, 0x4a, 0xae, 0x72, 0xd6, 0x2c };
|
||||
static const unsigned char salt[4] = { 0x32, 0xf2, 0x87, 0x0d };
|
||||
static const unsigned char IV[16] = { 0x00, 0x6e, 0x5c, 0xba, 0x50, 0x68, 0x1d, 0xe5,
|
||||
0x5c, 0x62, 0x15, 0x99, 0xd4, 0x62, 0x56, 0x4a };
|
||||
static const unsigned char pt[39] = { 0x70, 0x73, 0x65, 0x75, 0x64, 0x6f, 0x72, 0x61,
|
||||
0x6e, 0x64, 0x6f, 0x6d, 0x6e, 0x65, 0x73, 0x73,
|
||||
0x20, 0x69, 0x73, 0x20, 0x74, 0x68, 0x65, 0x20,
|
||||
0x6e, 0x65, 0x78, 0x74, 0x20, 0x62, 0x65, 0x73,
|
||||
0x74, 0x20, 0x74, 0x68, 0x69, 0x6e, 0x67 };
|
||||
static const unsigned char ct[39] = { 0x01, 0x9c, 0xe7, 0xa2, 0x6e, 0x78, 0x54, 0x01,
|
||||
0x4a, 0x63, 0x66, 0xaa, 0x95, 0xd4, 0xee, 0xfd,
|
||||
0x1a, 0xd4, 0x17, 0x2a, 0x14, 0xf9, 0xfa, 0xf4,
|
||||
0x55, 0xb7, 0xf1, 0xd4, 0xb6, 0x2b, 0xd0, 0x8f,
|
||||
0x56, 0x2c, 0x0e, 0xef, 0x7c, 0x48, 0x02 };
|
||||
unsigned char buf[39];
|
||||
symmetric_F8 f8;
|
||||
int err, idx;
|
||||
|
||||
idx = find_cipher("aes");
|
||||
if (idx == -1) {
|
||||
idx = find_cipher("rijndael");
|
||||
if (idx == -1) return CRYPT_NOP;
|
||||
}
|
||||
|
||||
/* initialize the context */
|
||||
if ((err = f8_start(idx, IV, key, sizeof(key), salt, sizeof(salt), 0, &f8)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* encrypt block */
|
||||
if ((err = f8_encrypt(pt, buf, sizeof(pt), &f8)) != CRYPT_OK) {
|
||||
f8_done(&f8);
|
||||
return err;
|
||||
}
|
||||
f8_done(&f8);
|
||||
|
||||
/* compare */
|
||||
if (compare_testvector(buf, sizeof(ct), ct, sizeof(ct), "f8", 0)) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
49
thirdparty/libtomcrypt/modes/lrw/lrw_decrypt.c
vendored
Normal file
49
thirdparty/libtomcrypt/modes/lrw/lrw_decrypt.c
vendored
Normal file
@ -0,0 +1,49 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file lrw_decrypt.c
|
||||
LRW_MODE implementation, Decrypt blocks, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
|
||||
/**
|
||||
LRW decrypt blocks
|
||||
@param ct The ciphertext
|
||||
@param pt [out] The plaintext
|
||||
@param len The length in octets, must be a multiple of 16
|
||||
@param lrw The LRW state
|
||||
*/
|
||||
int lrw_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_LRW *lrw)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(lrw != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (cipher_descriptor[lrw->cipher].accel_lrw_decrypt != NULL) {
|
||||
return cipher_descriptor[lrw->cipher].accel_lrw_decrypt(ct, pt, len, lrw->IV, lrw->tweak, &lrw->key);
|
||||
}
|
||||
|
||||
return lrw_process(ct, pt, len, LRW_DECRYPT, lrw);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
40
thirdparty/libtomcrypt/modes/lrw/lrw_done.c
vendored
Normal file
40
thirdparty/libtomcrypt/modes/lrw/lrw_done.c
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file lrw_done.c
|
||||
LRW_MODE implementation, Free resources, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
|
||||
/**
|
||||
Terminate a LRW state
|
||||
@param lrw The state to terminate
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int lrw_done(symmetric_LRW *lrw)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(lrw != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[lrw->cipher].done(&lrw->key);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
48
thirdparty/libtomcrypt/modes/lrw/lrw_encrypt.c
vendored
Normal file
48
thirdparty/libtomcrypt/modes/lrw/lrw_encrypt.c
vendored
Normal file
@ -0,0 +1,48 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file lrw_encrypt.c
|
||||
LRW_MODE implementation, Encrypt blocks, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
|
||||
/**
|
||||
LRW encrypt blocks
|
||||
@param pt The plaintext
|
||||
@param ct [out] The ciphertext
|
||||
@param len The length in octets, must be a multiple of 16
|
||||
@param lrw The LRW state
|
||||
*/
|
||||
int lrw_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_LRW *lrw)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(lrw != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (cipher_descriptor[lrw->cipher].accel_lrw_encrypt != NULL) {
|
||||
return cipher_descriptor[lrw->cipher].accel_lrw_encrypt(pt, ct, len, lrw->IV, lrw->tweak, &lrw->key);
|
||||
}
|
||||
|
||||
return lrw_process(pt, ct, len, LRW_ENCRYPT, lrw);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
43
thirdparty/libtomcrypt/modes/lrw/lrw_getiv.c
vendored
Normal file
43
thirdparty/libtomcrypt/modes/lrw/lrw_getiv.c
vendored
Normal file
@ -0,0 +1,43 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file lrw_getiv.c
|
||||
LRW_MODE implementation, Retrieve the current IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
|
||||
/**
|
||||
Get the IV for LRW
|
||||
@param IV [out] The IV, must be 16 octets
|
||||
@param len Length ... must be at least 16 :-)
|
||||
@param lrw The LRW state to read
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int lrw_getiv(unsigned char *IV, unsigned long *len, symmetric_LRW *lrw)
|
||||
{
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(lrw != NULL);
|
||||
if (*len < 16) {
|
||||
*len = 16;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
|
||||
XMEMCPY(IV, lrw->IV, 16);
|
||||
*len = 16;
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
118
thirdparty/libtomcrypt/modes/lrw/lrw_process.c
vendored
Normal file
118
thirdparty/libtomcrypt/modes/lrw/lrw_process.c
vendored
Normal file
@ -0,0 +1,118 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file lrw_process.c
|
||||
LRW_MODE implementation, Encrypt/decrypt blocks, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
|
||||
/**
|
||||
Process blocks with LRW, since decrypt/encrypt are largely the same they share this code.
|
||||
@param pt The "input" data
|
||||
@param ct [out] The "output" data
|
||||
@param len The length of the input, must be a multiple of 128-bits (16 octets)
|
||||
@param mode LRW_ENCRYPT or LRW_DECRYPT
|
||||
@param lrw The LRW state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int lrw_process(const unsigned char *pt, unsigned char *ct, unsigned long len, int mode, symmetric_LRW *lrw)
|
||||
{
|
||||
unsigned char prod[16];
|
||||
int x, err;
|
||||
#ifdef LTC_LRW_TABLES
|
||||
int y;
|
||||
#endif
|
||||
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(lrw != NULL);
|
||||
|
||||
if (len & 15) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
while (len) {
|
||||
/* copy pad */
|
||||
XMEMCPY(prod, lrw->pad, 16);
|
||||
|
||||
/* increment IV */
|
||||
for (x = 15; x >= 0; x--) {
|
||||
lrw->IV[x] = (lrw->IV[x] + 1) & 255;
|
||||
if (lrw->IV[x]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* update pad */
|
||||
#ifdef LTC_LRW_TABLES
|
||||
/* for each byte changed we undo it's affect on the pad then add the new product */
|
||||
for (; x < 16; x++) {
|
||||
#ifdef LTC_FAST
|
||||
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(lrw->pad + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][lrw->IV[x]][y])) ^ *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][(lrw->IV[x]-1)&255][y]));
|
||||
}
|
||||
#else
|
||||
for (y = 0; y < 16; y++) {
|
||||
lrw->pad[y] ^= lrw->PC[x][lrw->IV[x]][y] ^ lrw->PC[x][(lrw->IV[x]-1)&255][y];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#else
|
||||
gcm_gf_mult(lrw->tweak, lrw->IV, lrw->pad);
|
||||
#endif
|
||||
|
||||
/* xor prod */
|
||||
#ifdef LTC_FAST
|
||||
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(ct + x)) = *(LTC_FAST_TYPE_PTR_CAST(pt + x)) ^ *(LTC_FAST_TYPE_PTR_CAST(prod + x));
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < 16; x++) {
|
||||
ct[x] = pt[x] ^ prod[x];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* send through cipher */
|
||||
if (mode == LRW_ENCRYPT) {
|
||||
if ((err = cipher_descriptor[lrw->cipher].ecb_encrypt(ct, ct, &lrw->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
if ((err = cipher_descriptor[lrw->cipher].ecb_decrypt(ct, ct, &lrw->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
/* xor prod */
|
||||
#ifdef LTC_FAST
|
||||
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(ct + x)) = *(LTC_FAST_TYPE_PTR_CAST(ct + x)) ^ *(LTC_FAST_TYPE_PTR_CAST(prod + x));
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < 16; x++) {
|
||||
ct[x] = ct[x] ^ prod[x];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* move to next */
|
||||
pt += 16;
|
||||
ct += 16;
|
||||
len -= 16;
|
||||
}
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
77
thirdparty/libtomcrypt/modes/lrw/lrw_setiv.c
vendored
Normal file
77
thirdparty/libtomcrypt/modes/lrw/lrw_setiv.c
vendored
Normal file
@ -0,0 +1,77 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file lrw_setiv.c
|
||||
LRW_MODE implementation, Set the current IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
|
||||
/**
|
||||
Set the IV for LRW
|
||||
@param IV The IV, must be 16 octets
|
||||
@param len Length ... must be 16 :-)
|
||||
@param lrw The LRW state to update
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int lrw_setiv(const unsigned char *IV, unsigned long len, symmetric_LRW *lrw)
|
||||
{
|
||||
int err;
|
||||
#ifdef LTC_LRW_TABLES
|
||||
unsigned char T[16];
|
||||
int x, y;
|
||||
#endif
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(lrw != NULL);
|
||||
|
||||
if (len != 16) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if ((err = cipher_is_valid(lrw->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* copy the IV */
|
||||
XMEMCPY(lrw->IV, IV, 16);
|
||||
|
||||
/* check if we have to actually do work */
|
||||
if (cipher_descriptor[lrw->cipher].accel_lrw_encrypt != NULL && cipher_descriptor[lrw->cipher].accel_lrw_decrypt != NULL) {
|
||||
/* we have accelerators, let's bail since they don't use lrw->pad anyways */
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#ifdef LTC_LRW_TABLES
|
||||
XMEMCPY(T, &lrw->PC[0][IV[0]][0], 16);
|
||||
for (x = 1; x < 16; x++) {
|
||||
#ifdef LTC_FAST
|
||||
for (y = 0; y < 16; y += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(T + y)) ^= *(LTC_FAST_TYPE_PTR_CAST(&lrw->PC[x][IV[x]][y]));
|
||||
}
|
||||
#else
|
||||
for (y = 0; y < 16; y++) {
|
||||
T[y] ^= lrw->PC[x][IV[x]][y];
|
||||
}
|
||||
#endif
|
||||
}
|
||||
XMEMCPY(lrw->pad, T, 16);
|
||||
#else
|
||||
gcm_gf_mult(lrw->tweak, IV, lrw->pad);
|
||||
#endif
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
101
thirdparty/libtomcrypt/modes/lrw/lrw_start.c
vendored
Normal file
101
thirdparty/libtomcrypt/modes/lrw/lrw_start.c
vendored
Normal file
@ -0,0 +1,101 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file lrw_start.c
|
||||
LRW_MODE implementation, start mode, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
|
||||
/**
|
||||
Initialize the LRW context
|
||||
@param cipher The cipher desired, must be a 128-bit block cipher
|
||||
@param IV The index value, must be 128-bits
|
||||
@param key The cipher key
|
||||
@param keylen The length of the cipher key in octets
|
||||
@param tweak The tweak value (second key), must be 128-bits
|
||||
@param num_rounds The number of rounds for the cipher (0 == default)
|
||||
@param lrw [out] The LRW state
|
||||
@return CRYPT_OK on success.
|
||||
*/
|
||||
int lrw_start( int cipher,
|
||||
const unsigned char *IV,
|
||||
const unsigned char *key, int keylen,
|
||||
const unsigned char *tweak,
|
||||
int num_rounds,
|
||||
symmetric_LRW *lrw)
|
||||
{
|
||||
int err;
|
||||
#ifdef LTC_LRW_TABLES
|
||||
unsigned char B[16];
|
||||
int x, y, z, t;
|
||||
#endif
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(tweak != NULL);
|
||||
LTC_ARGCHK(lrw != NULL);
|
||||
|
||||
#ifdef LTC_FAST
|
||||
if (16 % sizeof(LTC_FAST_TYPE)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* is cipher valid? */
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if (cipher_descriptor[cipher].block_length != 16) {
|
||||
return CRYPT_INVALID_CIPHER;
|
||||
}
|
||||
|
||||
/* schedule key */
|
||||
if ((err = cipher_descriptor[cipher].setup(key, keylen, num_rounds, &lrw->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
lrw->cipher = cipher;
|
||||
|
||||
/* copy the IV and tweak */
|
||||
XMEMCPY(lrw->tweak, tweak, 16);
|
||||
|
||||
#ifdef LTC_LRW_TABLES
|
||||
/* setup tables */
|
||||
/* generate the first table as it has no shifting (from which we make the other tables) */
|
||||
zeromem(B, 16);
|
||||
for (y = 0; y < 256; y++) {
|
||||
B[0] = y;
|
||||
gcm_gf_mult(tweak, B, &lrw->PC[0][y][0]);
|
||||
}
|
||||
|
||||
/* now generate the rest of the tables based the previous table */
|
||||
for (x = 1; x < 16; x++) {
|
||||
for (y = 0; y < 256; y++) {
|
||||
/* now shift it right by 8 bits */
|
||||
t = lrw->PC[x-1][y][15];
|
||||
for (z = 15; z > 0; z--) {
|
||||
lrw->PC[x][y][z] = lrw->PC[x-1][y][z-1];
|
||||
}
|
||||
lrw->PC[x][y][0] = gcm_shift_table[t<<1];
|
||||
lrw->PC[x][y][1] ^= gcm_shift_table[(t<<1)+1];
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* generate first pad */
|
||||
return lrw_setiv(IV, 16, lrw);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
134
thirdparty/libtomcrypt/modes/lrw/lrw_test.c
vendored
Normal file
134
thirdparty/libtomcrypt/modes/lrw/lrw_test.c
vendored
Normal file
@ -0,0 +1,134 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file lrw_test.c
|
||||
LRW_MODE implementation, test LRW, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_LRW_MODE
|
||||
|
||||
/**
|
||||
Test LRW against specs
|
||||
@return CRYPT_OK if goodly
|
||||
*/
|
||||
int lrw_test(void)
|
||||
{
|
||||
#ifndef LTC_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
static const struct {
|
||||
unsigned char key[16], tweak[16], IV[16], P[16], expected_tweak[16], C[16];
|
||||
} tests[] = {
|
||||
|
||||
{
|
||||
{ 0x45, 0x62, 0xac, 0x25, 0xf8, 0x28, 0x17, 0x6d, 0x4c, 0x26, 0x84, 0x14, 0xb5, 0x68, 0x01, 0x85 },
|
||||
{ 0x25, 0x8e, 0x2a, 0x05, 0xe7, 0x3e, 0x9d, 0x03, 0xee, 0x5a, 0x83, 0x0c, 0xcc, 0x09, 0x4c, 0x87 },
|
||||
{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 },
|
||||
{ 0x25, 0x8e, 0x2a, 0x05, 0xe7, 0x3e, 0x9d, 0x03, 0xee, 0x5a, 0x83, 0x0c, 0xcc, 0x09, 0x4c, 0x87 },
|
||||
{ 0xf1, 0xb2, 0x73, 0xcd, 0x65, 0xa3, 0xdf, 0x5f, 0xe9, 0x5d, 0x48, 0x92, 0x54, 0x63, 0x4e, 0xb8 }
|
||||
},
|
||||
|
||||
{
|
||||
{ 0x59, 0x70, 0x47, 0x14, 0xf5, 0x57, 0x47, 0x8c, 0xd7, 0x79, 0xe8, 0x0f, 0x54, 0x88, 0x79, 0x44 },
|
||||
{ 0x35, 0x23, 0xc2, 0xde, 0xc5, 0x69, 0x4f, 0xa8, 0x72, 0xa9, 0xac, 0xa7, 0x0b, 0x2b, 0xee, 0xbc },
|
||||
{ 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 },
|
||||
{ 0x1a, 0x91, 0xe1, 0x6f, 0x62, 0xb4, 0xa7, 0xd4, 0x39, 0x54, 0xd6, 0x53, 0x85, 0x95, 0xf7, 0x5e },
|
||||
{ 0x00, 0xc8, 0x2b, 0xae, 0x95, 0xbb, 0xcd, 0xe5, 0x27, 0x4f, 0x07, 0x69, 0xb2, 0x60, 0xe1, 0x36 },
|
||||
},
|
||||
|
||||
{
|
||||
{ 0x59, 0x70, 0x47, 0x14, 0xf5, 0x57, 0x47, 0x8c, 0xd7, 0x79, 0xe8, 0x0f, 0x54, 0x88, 0x79, 0x44 },
|
||||
{ 0x67, 0x53, 0xc9, 0x0c, 0xb7, 0xd8, 0xcd, 0xe5, 0x06, 0xa0, 0x47, 0x78, 0x1a, 0xad, 0x85, 0x11 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02 },
|
||||
{ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 },
|
||||
{ 0x1a, 0x91, 0xe1, 0x6f, 0x62, 0xb4, 0xa7, 0xd4, 0x39, 0x54, 0xd6, 0x53, 0x85, 0x95, 0xf7, 0x5e },
|
||||
{ 0x00, 0xc8, 0x2b, 0xae, 0x95, 0xbb, 0xcd, 0xe5, 0x27, 0x4f, 0x07, 0x69, 0xb2, 0x60, 0xe1, 0x36 },
|
||||
},
|
||||
|
||||
{
|
||||
|
||||
{ 0xd8, 0x2a, 0x91, 0x34, 0xb2, 0x6a, 0x56, 0x50, 0x30, 0xfe, 0x69, 0xe2, 0x37, 0x7f, 0x98, 0x47 },
|
||||
{ 0x4e, 0xb5, 0x5d, 0x31, 0x05, 0x97, 0x3a, 0x3f, 0x5e, 0x23, 0xda, 0xfb, 0x5a, 0x45, 0xd6, 0xc0 },
|
||||
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00 },
|
||||
{ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46 },
|
||||
{ 0x18, 0xc9, 0x1f, 0x6d, 0x60, 0x1a, 0x1a, 0x37, 0x5d, 0x0b, 0x0e, 0xf7, 0x3a, 0xd5, 0x74, 0xc4 },
|
||||
{ 0x76, 0x32, 0x21, 0x83, 0xed, 0x8f, 0xf1, 0x82, 0xf9, 0x59, 0x62, 0x03, 0x69, 0x0e, 0x5e, 0x01 },
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
int idx, err, x;
|
||||
symmetric_LRW lrw;
|
||||
unsigned char buf[2][16];
|
||||
|
||||
idx = find_cipher("aes");
|
||||
if (idx == -1) {
|
||||
idx = find_cipher("rijndael");
|
||||
if (idx == -1) {
|
||||
return CRYPT_NOP;
|
||||
}
|
||||
}
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
/* schedule it */
|
||||
if ((err = lrw_start(idx, tests[x].IV, tests[x].key, 16, tests[x].tweak, 0, &lrw)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* check pad against expected tweak */
|
||||
if (compare_testvector(tests[x].expected_tweak, 16, lrw.pad, 16, "LRW Tweak", x)) {
|
||||
lrw_done(&lrw);
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
/* process block */
|
||||
if ((err = lrw_encrypt(tests[x].P, buf[0], 16, &lrw)) != CRYPT_OK) {
|
||||
lrw_done(&lrw);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (compare_testvector(buf[0], 16, tests[x].C, 16, "LRW Encrypt", x)) {
|
||||
lrw_done(&lrw);
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
/* process block */
|
||||
if ((err = lrw_setiv(tests[x].IV, 16, &lrw)) != CRYPT_OK) {
|
||||
lrw_done(&lrw);
|
||||
return err;
|
||||
}
|
||||
|
||||
if ((err = lrw_decrypt(buf[0], buf[1], 16, &lrw)) != CRYPT_OK) {
|
||||
lrw_done(&lrw);
|
||||
return err;
|
||||
}
|
||||
|
||||
if (compare_testvector(buf[1], 16, tests[x].P, 16, "LRW Decrypt", x)) {
|
||||
lrw_done(&lrw);
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
if ((err = lrw_done(&lrw)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
41
thirdparty/libtomcrypt/modes/ofb/ofb_decrypt.c
vendored
Normal file
41
thirdparty/libtomcrypt/modes/ofb/ofb_decrypt.c
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ofb_decrypt.c
|
||||
OFB implementation, decrypt data, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_OFB_MODE
|
||||
|
||||
/**
|
||||
OFB decrypt
|
||||
@param ct Ciphertext
|
||||
@param pt [out] Plaintext
|
||||
@param len Length of ciphertext (octets)
|
||||
@param ofb OFB state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ofb_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long len, symmetric_OFB *ofb)
|
||||
{
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(ofb != NULL);
|
||||
return ofb_encrypt(ct, pt, len, ofb);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
40
thirdparty/libtomcrypt/modes/ofb/ofb_done.c
vendored
Normal file
40
thirdparty/libtomcrypt/modes/ofb/ofb_done.c
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ofb_done.c
|
||||
OFB implementation, finish chain, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_OFB_MODE
|
||||
|
||||
/** Terminate the chain
|
||||
@param ofb The OFB chain to terminate
|
||||
@return CRYPT_OK on success
|
||||
*/
|
||||
int ofb_done(symmetric_OFB *ofb)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(ofb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
cipher_descriptor[ofb->cipher].done(&ofb->key);
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
58
thirdparty/libtomcrypt/modes/ofb/ofb_encrypt.c
vendored
Normal file
58
thirdparty/libtomcrypt/modes/ofb/ofb_encrypt.c
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ofb_encrypt.c
|
||||
OFB implementation, encrypt data, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_OFB_MODE
|
||||
|
||||
/**
|
||||
OFB encrypt
|
||||
@param pt Plaintext
|
||||
@param ct [out] Ciphertext
|
||||
@param len Length of plaintext (octets)
|
||||
@param ofb OFB state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ofb_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long len, symmetric_OFB *ofb)
|
||||
{
|
||||
int err;
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(ofb != NULL);
|
||||
if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* is blocklen/padlen valid? */
|
||||
if (ofb->blocklen < 0 || ofb->blocklen > (int)sizeof(ofb->IV) ||
|
||||
ofb->padlen < 0 || ofb->padlen > (int)sizeof(ofb->IV)) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
while (len-- > 0) {
|
||||
if (ofb->padlen == ofb->blocklen) {
|
||||
if ((err = cipher_descriptor[ofb->cipher].ecb_encrypt(ofb->IV, ofb->IV, &ofb->key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
ofb->padlen = 0;
|
||||
}
|
||||
*ct++ = *pt++ ^ ofb->IV[(ofb->padlen)++];
|
||||
}
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
44
thirdparty/libtomcrypt/modes/ofb/ofb_getiv.c
vendored
Normal file
44
thirdparty/libtomcrypt/modes/ofb/ofb_getiv.c
vendored
Normal file
@ -0,0 +1,44 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ofb_getiv.c
|
||||
OFB implementation, get IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_OFB_MODE
|
||||
|
||||
/**
|
||||
Get the current initialization vector
|
||||
@param IV [out] The destination of the initialization vector
|
||||
@param len [in/out] The max size and resulting size of the initialization vector
|
||||
@param ofb The OFB state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ofb_getiv(unsigned char *IV, unsigned long *len, symmetric_OFB *ofb)
|
||||
{
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(len != NULL);
|
||||
LTC_ARGCHK(ofb != NULL);
|
||||
if ((unsigned long)ofb->blocklen > *len) {
|
||||
*len = ofb->blocklen;
|
||||
return CRYPT_BUFFER_OVERFLOW;
|
||||
}
|
||||
XMEMCPY(IV, ofb->IV, ofb->blocklen);
|
||||
*len = ofb->blocklen;
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
50
thirdparty/libtomcrypt/modes/ofb/ofb_setiv.c
vendored
Normal file
50
thirdparty/libtomcrypt/modes/ofb/ofb_setiv.c
vendored
Normal file
@ -0,0 +1,50 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ofb_setiv.c
|
||||
OFB implementation, set IV, Tom St Denis
|
||||
*/
|
||||
|
||||
#ifdef LTC_OFB_MODE
|
||||
|
||||
/**
|
||||
Set an initialization vector
|
||||
@param IV The initialization vector
|
||||
@param len The length of the vector (in octets)
|
||||
@param ofb The OFB state
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ofb_setiv(const unsigned char *IV, unsigned long len, symmetric_OFB *ofb)
|
||||
{
|
||||
int err;
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(ofb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(ofb->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (len != (unsigned long)ofb->blocklen) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* force next block */
|
||||
ofb->padlen = 0;
|
||||
return cipher_descriptor[ofb->cipher].ecb_encrypt(IV, ofb->IV, &ofb->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
58
thirdparty/libtomcrypt/modes/ofb/ofb_start.c
vendored
Normal file
58
thirdparty/libtomcrypt/modes/ofb/ofb_start.c
vendored
Normal file
@ -0,0 +1,58 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
@file ofb_start.c
|
||||
OFB implementation, start chain, Tom St Denis
|
||||
*/
|
||||
|
||||
|
||||
#ifdef LTC_OFB_MODE
|
||||
|
||||
/**
|
||||
Initialize a OFB context
|
||||
@param cipher The index of the cipher desired
|
||||
@param IV The initialization vector
|
||||
@param key The secret key
|
||||
@param keylen The length of the secret key (octets)
|
||||
@param num_rounds Number of rounds in the cipher desired (0 for default)
|
||||
@param ofb The OFB state to initialize
|
||||
@return CRYPT_OK if successful
|
||||
*/
|
||||
int ofb_start(int cipher, const unsigned char *IV, const unsigned char *key,
|
||||
int keylen, int num_rounds, symmetric_OFB *ofb)
|
||||
{
|
||||
int x, err;
|
||||
|
||||
LTC_ARGCHK(IV != NULL);
|
||||
LTC_ARGCHK(key != NULL);
|
||||
LTC_ARGCHK(ofb != NULL);
|
||||
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* copy details */
|
||||
ofb->cipher = cipher;
|
||||
ofb->blocklen = cipher_descriptor[cipher].block_length;
|
||||
for (x = 0; x < ofb->blocklen; x++) {
|
||||
ofb->IV[x] = IV[x];
|
||||
}
|
||||
|
||||
/* init the cipher */
|
||||
ofb->padlen = ofb->blocklen;
|
||||
return cipher_descriptor[cipher].setup(key, keylen, num_rounds, &ofb->key);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
156
thirdparty/libtomcrypt/modes/xts/xts_decrypt.c
vendored
Normal file
156
thirdparty/libtomcrypt/modes/xts/xts_decrypt.c
vendored
Normal file
@ -0,0 +1,156 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
|
||||
*/
|
||||
|
||||
#ifdef LTC_XTS_MODE
|
||||
|
||||
static int _tweak_uncrypt(const unsigned char *C, unsigned char *P, unsigned char *T, symmetric_xts *xts)
|
||||
{
|
||||
unsigned long x;
|
||||
int err;
|
||||
|
||||
/* tweak encrypt block i */
|
||||
#ifdef LTC_FAST
|
||||
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(&P[x])) = *(LTC_FAST_TYPE_PTR_CAST(&C[x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&T[x]));
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < 16; x++) {
|
||||
P[x] = C[x] ^ T[x];
|
||||
}
|
||||
#endif
|
||||
|
||||
err = cipher_descriptor[xts->cipher].ecb_decrypt(P, P, &xts->key1);
|
||||
|
||||
#ifdef LTC_FAST
|
||||
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(&P[x])) ^= *(LTC_FAST_TYPE_PTR_CAST(&T[x]));
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < 16; x++) {
|
||||
P[x] = P[x] ^ T[x];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* LFSR the tweak */
|
||||
xts_mult_x(T);
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
/** XTS Decryption
|
||||
@param ct [in] Ciphertext
|
||||
@param ptlen Length of plaintext (and ciphertext)
|
||||
@param pt [out] Plaintext
|
||||
@param tweak [in] The 128--bit encryption tweak (e.g. sector number)
|
||||
@param xts The XTS structure
|
||||
Returns CRYPT_OK upon success
|
||||
*/
|
||||
int xts_decrypt(const unsigned char *ct, unsigned long ptlen, unsigned char *pt, unsigned char *tweak,
|
||||
symmetric_xts *xts)
|
||||
{
|
||||
unsigned char PP[16], CC[16], T[16];
|
||||
unsigned long i, m, mo, lim;
|
||||
int err;
|
||||
|
||||
/* check inputs */
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(tweak != NULL);
|
||||
LTC_ARGCHK(xts != NULL);
|
||||
|
||||
/* check if valid */
|
||||
if ((err = cipher_is_valid(xts->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* get number of blocks */
|
||||
m = ptlen >> 4;
|
||||
mo = ptlen & 15;
|
||||
|
||||
/* must have at least one full block */
|
||||
if (m == 0) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (mo == 0) {
|
||||
lim = m;
|
||||
} else {
|
||||
lim = m - 1;
|
||||
}
|
||||
|
||||
if (cipher_descriptor[xts->cipher].accel_xts_decrypt && lim > 0) {
|
||||
|
||||
/* use accelerated decryption for whole blocks */
|
||||
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++) {
|
||||
if ((err = _tweak_uncrypt(ct, pt, T, xts)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
ct += 16;
|
||||
pt += 16;
|
||||
}
|
||||
}
|
||||
|
||||
/* if ptlen not divide 16 then */
|
||||
if (mo > 0) {
|
||||
XMEMCPY(CC, T, 16);
|
||||
xts_mult_x(CC);
|
||||
|
||||
/* PP = tweak decrypt block m-1 */
|
||||
if ((err = _tweak_uncrypt(ct, PP, CC, xts)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Pm = first ptlen % 16 bytes of PP */
|
||||
for (i = 0; i < mo; i++) {
|
||||
CC[i] = ct[16 + i];
|
||||
pt[16 + i] = PP[i];
|
||||
}
|
||||
for (; i < 16; i++) {
|
||||
CC[i] = PP[i];
|
||||
}
|
||||
|
||||
/* Pm-1 = Tweak uncrypt CC */
|
||||
if ((err = _tweak_uncrypt(CC, pt, T, xts)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
/* Decrypt the tweak back */
|
||||
if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak, &xts->key2)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
31
thirdparty/libtomcrypt/modes/xts/xts_done.c
vendored
Normal file
31
thirdparty/libtomcrypt/modes/xts/xts_done.c
vendored
Normal file
@ -0,0 +1,31 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
|
||||
*/
|
||||
|
||||
#ifdef LTC_XTS_MODE
|
||||
|
||||
/** Terminate XTS state
|
||||
@param xts The state to terminate
|
||||
*/
|
||||
void xts_done(symmetric_xts *xts)
|
||||
{
|
||||
LTC_ARGCHKVD(xts != NULL);
|
||||
cipher_descriptor[xts->cipher].done(&xts->key1);
|
||||
cipher_descriptor[xts->cipher].done(&xts->key2);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
157
thirdparty/libtomcrypt/modes/xts/xts_encrypt.c
vendored
Normal file
157
thirdparty/libtomcrypt/modes/xts/xts_encrypt.c
vendored
Normal file
@ -0,0 +1,157 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
|
||||
*/
|
||||
|
||||
#ifdef LTC_XTS_MODE
|
||||
|
||||
static int _tweak_crypt(const unsigned char *P, unsigned char *C, unsigned char *T, symmetric_xts *xts)
|
||||
{
|
||||
unsigned long x;
|
||||
int err;
|
||||
|
||||
/* tweak encrypt block i */
|
||||
#ifdef LTC_FAST
|
||||
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(&C[x])) = *(LTC_FAST_TYPE_PTR_CAST(&P[x])) ^ *(LTC_FAST_TYPE_PTR_CAST(&T[x]));
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < 16; x++) {
|
||||
C[x] = P[x] ^ T[x];
|
||||
}
|
||||
#endif
|
||||
|
||||
if ((err = cipher_descriptor[xts->cipher].ecb_encrypt(C, C, &xts->key1)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
#ifdef LTC_FAST
|
||||
for (x = 0; x < 16; x += sizeof(LTC_FAST_TYPE)) {
|
||||
*(LTC_FAST_TYPE_PTR_CAST(&C[x])) ^= *(LTC_FAST_TYPE_PTR_CAST(&T[x]));
|
||||
}
|
||||
#else
|
||||
for (x = 0; x < 16; x++) {
|
||||
C[x] = C[x] ^ T[x];
|
||||
}
|
||||
#endif
|
||||
|
||||
/* LFSR the tweak */
|
||||
xts_mult_x(T);
|
||||
|
||||
return CRYPT_OK;
|
||||
}
|
||||
|
||||
/** XTS Encryption
|
||||
@param pt [in] Plaintext
|
||||
@param ptlen Length of plaintext (and ciphertext)
|
||||
@param ct [out] Ciphertext
|
||||
@param tweak [in] The 128--bit encryption tweak (e.g. sector number)
|
||||
@param xts The XTS structure
|
||||
Returns CRYPT_OK upon success
|
||||
*/
|
||||
int xts_encrypt(const unsigned char *pt, unsigned long ptlen, unsigned char *ct, unsigned char *tweak,
|
||||
symmetric_xts *xts)
|
||||
{
|
||||
unsigned char PP[16], CC[16], T[16];
|
||||
unsigned long i, m, mo, lim;
|
||||
int err;
|
||||
|
||||
/* check inputs */
|
||||
LTC_ARGCHK(pt != NULL);
|
||||
LTC_ARGCHK(ct != NULL);
|
||||
LTC_ARGCHK(tweak != NULL);
|
||||
LTC_ARGCHK(xts != NULL);
|
||||
|
||||
/* check if valid */
|
||||
if ((err = cipher_is_valid(xts->cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* get number of blocks */
|
||||
m = ptlen >> 4;
|
||||
mo = ptlen & 15;
|
||||
|
||||
/* must have at least one full block */
|
||||
if (m == 0) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (mo == 0) {
|
||||
lim = m;
|
||||
} else {
|
||||
lim = m - 1;
|
||||
}
|
||||
|
||||
if (cipher_descriptor[xts->cipher].accel_xts_encrypt && lim > 0) {
|
||||
|
||||
/* use accelerated encryption for whole blocks */
|
||||
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++) {
|
||||
if ((err = _tweak_crypt(pt, ct, T, xts)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
ct += 16;
|
||||
pt += 16;
|
||||
}
|
||||
}
|
||||
|
||||
/* if ptlen not divide 16 then */
|
||||
if (mo > 0) {
|
||||
/* CC = tweak encrypt block m-1 */
|
||||
if ((err = _tweak_crypt(pt, CC, T, xts)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
/* Cm = first ptlen % 16 bytes of CC */
|
||||
for (i = 0; i < mo; i++) {
|
||||
PP[i] = pt[16 + i];
|
||||
ct[16 + i] = CC[i];
|
||||
}
|
||||
|
||||
for (; i < 16; i++) {
|
||||
PP[i] = CC[i];
|
||||
}
|
||||
|
||||
/* Cm-1 = Tweak encrypt PP */
|
||||
if ((err = _tweak_crypt(PP, ct, T, xts)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
/* Decrypt the tweak back */
|
||||
if ((err = cipher_descriptor[xts->cipher].ecb_decrypt(T, tweak, &xts->key2)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
61
thirdparty/libtomcrypt/modes/xts/xts_init.c
vendored
Normal file
61
thirdparty/libtomcrypt/modes/xts/xts_init.c
vendored
Normal file
@ -0,0 +1,61 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
|
||||
*/
|
||||
|
||||
#ifdef LTC_XTS_MODE
|
||||
|
||||
/** Start XTS mode
|
||||
@param cipher The index of the cipher to use
|
||||
@param key1 The encrypt key
|
||||
@param key2 The tweak encrypt key
|
||||
@param keylen The length of the keys (each) in octets
|
||||
@param num_rounds The number of rounds for the cipher (0 == default)
|
||||
@param xts [out] XTS structure
|
||||
Returns CRYPT_OK upon success.
|
||||
*/
|
||||
int xts_start(int cipher, const unsigned char *key1, const unsigned char *key2, unsigned long keylen, int num_rounds,
|
||||
symmetric_xts *xts)
|
||||
{
|
||||
int err;
|
||||
|
||||
/* check inputs */
|
||||
LTC_ARGCHK(key1 != NULL);
|
||||
LTC_ARGCHK(key2 != NULL);
|
||||
LTC_ARGCHK(xts != NULL);
|
||||
|
||||
/* check if valid */
|
||||
if ((err = cipher_is_valid(cipher)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
if (cipher_descriptor[cipher].block_length != 16) {
|
||||
return CRYPT_INVALID_ARG;
|
||||
}
|
||||
|
||||
/* schedule the two ciphers */
|
||||
if ((err = cipher_descriptor[cipher].setup(key1, keylen, num_rounds, &xts->key1)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
if ((err = cipher_descriptor[cipher].setup(key2, keylen, num_rounds, &xts->key2)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
xts->cipher = cipher;
|
||||
|
||||
return err;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
39
thirdparty/libtomcrypt/modes/xts/xts_mult_x.c
vendored
Normal file
39
thirdparty/libtomcrypt/modes/xts/xts_mult_x.c
vendored
Normal file
@ -0,0 +1,39 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
/**
|
||||
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
|
||||
*/
|
||||
|
||||
#ifdef LTC_XTS_MODE
|
||||
|
||||
/** multiply by x
|
||||
@param I The value to multiply by x (LFSR shift)
|
||||
*/
|
||||
void xts_mult_x(unsigned char *I)
|
||||
{
|
||||
int x;
|
||||
unsigned char t, tt;
|
||||
|
||||
for (x = t = 0; x < 16; x++) {
|
||||
tt = I[x] >> 7;
|
||||
I[x] = ((I[x] << 1) | t) & 0xFF;
|
||||
t = tt;
|
||||
}
|
||||
if (tt) {
|
||||
I[0] ^= 0x87;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
306
thirdparty/libtomcrypt/modes/xts/xts_test.c
vendored
Normal file
306
thirdparty/libtomcrypt/modes/xts/xts_test.c
vendored
Normal file
@ -0,0 +1,306 @@
|
||||
/* LibTomCrypt, modular cryptographic library -- Tom St Denis
|
||||
*
|
||||
* LibTomCrypt is a library that provides various cryptographic
|
||||
* algorithms in a highly modular and flexible manner.
|
||||
*
|
||||
* The library is free for all purposes without any express
|
||||
* guarantee it works.
|
||||
*/
|
||||
#include "tomcrypt.h"
|
||||
|
||||
#ifdef LTC_XTS_MODE
|
||||
|
||||
#ifndef LTC_NO_TEST
|
||||
static int _xts_test_accel_xts_encrypt(const unsigned char *pt, unsigned char *ct, unsigned long blocks,
|
||||
unsigned char *tweak, symmetric_key *skey1, symmetric_key *skey2)
|
||||
{
|
||||
int ret;
|
||||
symmetric_xts xts;
|
||||
int (*orig)(const unsigned char *, unsigned char *,
|
||||
unsigned long , unsigned char *, symmetric_key *,
|
||||
symmetric_key *);
|
||||
|
||||
/* AES can be under rijndael or aes... try to find it */
|
||||
if ((xts.cipher = find_cipher("aes")) == -1) {
|
||||
if ((xts.cipher = find_cipher("rijndael")) == -1) {
|
||||
return CRYPT_NOP;
|
||||
}
|
||||
}
|
||||
orig = cipher_descriptor[xts.cipher].accel_xts_encrypt;
|
||||
cipher_descriptor[xts.cipher].accel_xts_encrypt = NULL;
|
||||
|
||||
XMEMCPY(&xts.key1, skey1, sizeof(symmetric_key));
|
||||
XMEMCPY(&xts.key2, skey2, sizeof(symmetric_key));
|
||||
|
||||
ret = xts_encrypt(pt, blocks << 4, ct, tweak, &xts);
|
||||
cipher_descriptor[xts.cipher].accel_xts_encrypt = orig;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int _xts_test_accel_xts_decrypt(const unsigned char *ct, unsigned char *pt, unsigned long blocks,
|
||||
unsigned char *tweak, symmetric_key *skey1, symmetric_key *skey2)
|
||||
{
|
||||
int ret;
|
||||
symmetric_xts xts;
|
||||
int (*orig)(const unsigned char *, unsigned char *,
|
||||
unsigned long , unsigned char *, symmetric_key *,
|
||||
symmetric_key *);
|
||||
|
||||
/* AES can be under rijndael or aes... try to find it */
|
||||
if ((xts.cipher = find_cipher("aes")) == -1) {
|
||||
if ((xts.cipher = find_cipher("rijndael")) == -1) {
|
||||
return CRYPT_NOP;
|
||||
}
|
||||
}
|
||||
orig = cipher_descriptor[xts.cipher].accel_xts_decrypt;
|
||||
cipher_descriptor[xts.cipher].accel_xts_decrypt = NULL;
|
||||
|
||||
XMEMCPY(&xts.key1, skey1, sizeof(symmetric_key));
|
||||
XMEMCPY(&xts.key2, skey2, sizeof(symmetric_key));
|
||||
|
||||
ret = xts_decrypt(ct, blocks << 4, pt, tweak, &xts);
|
||||
cipher_descriptor[xts.cipher].accel_xts_decrypt = orig;
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
/**
|
||||
Source donated by Elliptic Semiconductor Inc (www.ellipticsemi.com) to the LibTom Projects
|
||||
|
||||
Returns CRYPT_OK upon success.
|
||||
*/
|
||||
int xts_test(void)
|
||||
{
|
||||
#ifdef LTC_NO_TEST
|
||||
return CRYPT_NOP;
|
||||
#else
|
||||
static const struct
|
||||
{
|
||||
int keylen;
|
||||
unsigned char key1[32];
|
||||
unsigned char key2[32];
|
||||
ulong64 seqnum;
|
||||
unsigned long PTLEN;
|
||||
unsigned char PTX[512], CTX[512];
|
||||
} tests[] = {
|
||||
|
||||
/* #1 32 byte key, 32 byte PTX */
|
||||
{
|
||||
32,
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
|
||||
0,
|
||||
32,
|
||||
{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 },
|
||||
{ 0x91,0x7c,0xf6,0x9e,0xbd,0x68,0xb2,0xec,0x9b,0x9f,0xe9,0xa3,0xea,0xdd,0xa6,0x92,0xcd,0x43,0xd2,0xf5,0x95,0x98,0xed,0x85,0x8c,0x02,0xc2,0x65,0x2f,0xbf,0x92,0x2e },
|
||||
},
|
||||
|
||||
/* #2, 32 byte key, 32 byte PTX */
|
||||
{
|
||||
32,
|
||||
{ 0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11 },
|
||||
{ 0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22,0x22 },
|
||||
CONST64(0x3333333333),
|
||||
32,
|
||||
{ 0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44 },
|
||||
{ 0xc4,0x54,0x18,0x5e,0x6a,0x16,0x93,0x6e,0x39,0x33,0x40,0x38,0xac,0xef,0x83,0x8b,0xfb,0x18,0x6f,0xff,0x74,0x80,0xad,0xc4,0x28,0x93,0x82,0xec,0xd6,0xd3,0x94,0xf0 },
|
||||
},
|
||||
|
||||
/* #5 from xts.7, 32 byte key, 32 byte PTX */
|
||||
{
|
||||
32,
|
||||
{ 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0 },
|
||||
{ 0xbf,0xbe,0xbd,0xbc,0xbb,0xba,0xb9,0xb8,0xb7,0xb6,0xb5,0xb4,0xb3,0xb2,0xb1,0xb0 },
|
||||
CONST64(0x123456789a),
|
||||
32,
|
||||
{ 0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44,0x44 },
|
||||
{ 0xb0,0x1f,0x86,0xf8,0xed,0xc1,0x86,0x37,0x06,0xfa,0x8a,0x42,0x53,0xe3,0x4f,0x28,0xaf,0x31,0x9d,0xe3,0x83,0x34,0x87,0x0f,0x4d,0xd1,0xf9,0x4c,0xbe,0x98,0x32,0xf1 },
|
||||
},
|
||||
|
||||
/* #4, 32 byte key, 512 byte PTX */
|
||||
{
|
||||
32,
|
||||
{ 0x27,0x18,0x28,0x18,0x28,0x45,0x90,0x45,0x23,0x53,0x60,0x28,0x74,0x71,0x35,0x26 },
|
||||
{ 0x31,0x41,0x59,0x26,0x53,0x58,0x97,0x93,0x23,0x84,0x62,0x64,0x33,0x83,0x27,0x95 },
|
||||
0,
|
||||
512,
|
||||
{
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
|
||||
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
|
||||
0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
|
||||
0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
|
||||
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
|
||||
0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
|
||||
0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,
|
||||
0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
|
||||
0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f,
|
||||
0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f,0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f,
|
||||
0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f,0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f,
|
||||
0x60,0x61,0x62,0x63,0x64,0x65,0x66,0x67,0x68,0x69,0x6a,0x6b,0x6c,0x6d,0x6e,0x6f,0x70,0x71,0x72,0x73,0x74,0x75,0x76,0x77,0x78,0x79,0x7a,0x7b,0x7c,0x7d,0x7e,0x7f,
|
||||
0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f,0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f,
|
||||
0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf,0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf,
|
||||
0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf,0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf,
|
||||
0xe0,0xe1,0xe2,0xe3,0xe4,0xe5,0xe6,0xe7,0xe8,0xe9,0xea,0xeb,0xec,0xed,0xee,0xef,0xf0,0xf1,0xf2,0xf3,0xf4,0xf5,0xf6,0xf7,0xf8,0xf9,0xfa,0xfb,0xfc,0xfd,0xfe,0xff,
|
||||
},
|
||||
{
|
||||
0x27,0xa7,0x47,0x9b,0xef,0xa1,0xd4,0x76,0x48,0x9f,0x30,0x8c,0xd4,0xcf,0xa6,0xe2,0xa9,0x6e,0x4b,0xbe,0x32,0x08,0xff,0x25,0x28,0x7d,0xd3,0x81,0x96,0x16,0xe8,0x9c,
|
||||
0xc7,0x8c,0xf7,0xf5,0xe5,0x43,0x44,0x5f,0x83,0x33,0xd8,0xfa,0x7f,0x56,0x00,0x00,0x05,0x27,0x9f,0xa5,0xd8,0xb5,0xe4,0xad,0x40,0xe7,0x36,0xdd,0xb4,0xd3,0x54,0x12,
|
||||
0x32,0x80,0x63,0xfd,0x2a,0xab,0x53,0xe5,0xea,0x1e,0x0a,0x9f,0x33,0x25,0x00,0xa5,0xdf,0x94,0x87,0xd0,0x7a,0x5c,0x92,0xcc,0x51,0x2c,0x88,0x66,0xc7,0xe8,0x60,0xce,
|
||||
0x93,0xfd,0xf1,0x66,0xa2,0x49,0x12,0xb4,0x22,0x97,0x61,0x46,0xae,0x20,0xce,0x84,0x6b,0xb7,0xdc,0x9b,0xa9,0x4a,0x76,0x7a,0xae,0xf2,0x0c,0x0d,0x61,0xad,0x02,0x65,
|
||||
0x5e,0xa9,0x2d,0xc4,0xc4,0xe4,0x1a,0x89,0x52,0xc6,0x51,0xd3,0x31,0x74,0xbe,0x51,0xa1,0x0c,0x42,0x11,0x10,0xe6,0xd8,0x15,0x88,0xed,0xe8,0x21,0x03,0xa2,0x52,0xd8,
|
||||
0xa7,0x50,0xe8,0x76,0x8d,0xef,0xff,0xed,0x91,0x22,0x81,0x0a,0xae,0xb9,0x9f,0x91,0x72,0xaf,0x82,0xb6,0x04,0xdc,0x4b,0x8e,0x51,0xbc,0xb0,0x82,0x35,0xa6,0xf4,0x34,
|
||||
0x13,0x32,0xe4,0xca,0x60,0x48,0x2a,0x4b,0xa1,0xa0,0x3b,0x3e,0x65,0x00,0x8f,0xc5,0xda,0x76,0xb7,0x0b,0xf1,0x69,0x0d,0xb4,0xea,0xe2,0x9c,0x5f,0x1b,0xad,0xd0,0x3c,
|
||||
0x5c,0xcf,0x2a,0x55,0xd7,0x05,0xdd,0xcd,0x86,0xd4,0x49,0x51,0x1c,0xeb,0x7e,0xc3,0x0b,0xf1,0x2b,0x1f,0xa3,0x5b,0x91,0x3f,0x9f,0x74,0x7a,0x8a,0xfd,0x1b,0x13,0x0e,
|
||||
0x94,0xbf,0xf9,0x4e,0xff,0xd0,0x1a,0x91,0x73,0x5c,0xa1,0x72,0x6a,0xcd,0x0b,0x19,0x7c,0x4e,0x5b,0x03,0x39,0x36,0x97,0xe1,0x26,0x82,0x6f,0xb6,0xbb,0xde,0x8e,0xcc,
|
||||
0x1e,0x08,0x29,0x85,0x16,0xe2,0xc9,0xed,0x03,0xff,0x3c,0x1b,0x78,0x60,0xf6,0xde,0x76,0xd4,0xce,0xcd,0x94,0xc8,0x11,0x98,0x55,0xef,0x52,0x97,0xca,0x67,0xe9,0xf3,
|
||||
0xe7,0xff,0x72,0xb1,0xe9,0x97,0x85,0xca,0x0a,0x7e,0x77,0x20,0xc5,0xb3,0x6d,0xc6,0xd7,0x2c,0xac,0x95,0x74,0xc8,0xcb,0xbc,0x2f,0x80,0x1e,0x23,0xe5,0x6f,0xd3,0x44,
|
||||
0xb0,0x7f,0x22,0x15,0x4b,0xeb,0xa0,0xf0,0x8c,0xe8,0x89,0x1e,0x64,0x3e,0xd9,0x95,0xc9,0x4d,0x9a,0x69,0xc9,0xf1,0xb5,0xf4,0x99,0x02,0x7a,0x78,0x57,0x2a,0xee,0xbd,
|
||||
0x74,0xd2,0x0c,0xc3,0x98,0x81,0xc2,0x13,0xee,0x77,0x0b,0x10,0x10,0xe4,0xbe,0xa7,0x18,0x84,0x69,0x77,0xae,0x11,0x9f,0x7a,0x02,0x3a,0xb5,0x8c,0xca,0x0a,0xd7,0x52,
|
||||
0xaf,0xe6,0x56,0xbb,0x3c,0x17,0x25,0x6a,0x9f,0x6e,0x9b,0xf1,0x9f,0xdd,0x5a,0x38,0xfc,0x82,0xbb,0xe8,0x72,0xc5,0x53,0x9e,0xdb,0x60,0x9e,0xf4,0xf7,0x9c,0x20,0x3e,
|
||||
0xbb,0x14,0x0f,0x2e,0x58,0x3c,0xb2,0xad,0x15,0xb4,0xaa,0x5b,0x65,0x50,0x16,0xa8,0x44,0x92,0x77,0xdb,0xd4,0x77,0xef,0x2c,0x8d,0x6c,0x01,0x7d,0xb7,0x38,0xb1,0x8d,
|
||||
0xeb,0x4a,0x42,0x7d,0x19,0x23,0xce,0x3f,0xf2,0x62,0x73,0x57,0x79,0xa4,0x18,0xf2,0x0a,0x28,0x2d,0xf9,0x20,0x14,0x7b,0xea,0xbe,0x42,0x1e,0xe5,0x31,0x9d,0x05,0x68,
|
||||
}
|
||||
},
|
||||
|
||||
/* #7, 32 byte key, 17 byte PTX */
|
||||
{
|
||||
32,
|
||||
{ 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0 },
|
||||
{ 0xbf,0xbe,0xbd,0xbc,0xbb,0xba,0xb9,0xb8,0xb7,0xb6,0xb5,0xb4,0xb3,0xb2,0xb1,0xb0 },
|
||||
CONST64(0x123456789a),
|
||||
17,
|
||||
{ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10 },
|
||||
{ 0x6c,0x16,0x25,0xdb,0x46,0x71,0x52,0x2d,0x3d,0x75,0x99,0x60,0x1d,0xe7,0xca,0x09,0xed },
|
||||
},
|
||||
|
||||
/* #15, 32 byte key, 25 byte PTX */
|
||||
{
|
||||
32,
|
||||
{ 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0 },
|
||||
{ 0xbf,0xbe,0xbd,0xbc,0xbb,0xba,0xb9,0xb8,0xb7,0xb6,0xb5,0xb4,0xb3,0xb2,0xb1,0xb0 },
|
||||
CONST64(0x123456789a),
|
||||
25,
|
||||
{ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18 },
|
||||
{ 0x8f,0x4d,0xcb,0xad,0x55,0x55,0x8d,0x7b,0x4e,0x01,0xd9,0x37,0x9c,0xd4,0xea,0x22,0xed,0xbf,0x9d,0xac,0xe4,0x5d,0x6f,0x6a,0x73 },
|
||||
},
|
||||
|
||||
/* #21, 32 byte key, 31 byte PTX */
|
||||
{
|
||||
32,
|
||||
{ 0xff,0xfe,0xfd,0xfc,0xfb,0xfa,0xf9,0xf8,0xf7,0xf6,0xf5,0xf4,0xf3,0xf2,0xf1,0xf0 },
|
||||
{ 0xbf,0xbe,0xbd,0xbc,0xbb,0xba,0xb9,0xb8,0xb7,0xb6,0xb5,0xb4,0xb3,0xb2,0xb1,0xb0 },
|
||||
CONST64(0x123456789a),
|
||||
31,
|
||||
{ 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f,0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e },
|
||||
{ 0xd0,0x5b,0xc0,0x90,0xa8,0xe0,0x4f,0x1b,0x3d,0x3e,0xcd,0xd5,0xba,0xec,0x0f,0xd4,0xed,0xbf,0x9d,0xac,0xe4,0x5d,0x6f,0x6a,0x73,0x06,0xe6,0x4b,0xe5,0xdd,0x82 },
|
||||
},
|
||||
|
||||
};
|
||||
unsigned char OUT[512], Torg[16], T[16];
|
||||
ulong64 seq;
|
||||
symmetric_xts xts;
|
||||
int i, j, k, err, idx;
|
||||
unsigned long len;
|
||||
|
||||
/* AES can be under rijndael or aes... try to find it */
|
||||
if ((idx = find_cipher("aes")) == -1) {
|
||||
if ((idx = find_cipher("rijndael")) == -1) {
|
||||
return CRYPT_NOP;
|
||||
}
|
||||
}
|
||||
for (k = 0; k < 4; ++k) {
|
||||
cipher_descriptor[idx].accel_xts_encrypt = NULL;
|
||||
cipher_descriptor[idx].accel_xts_decrypt = NULL;
|
||||
if (k & 0x1) {
|
||||
cipher_descriptor[idx].accel_xts_encrypt = _xts_test_accel_xts_encrypt;
|
||||
}
|
||||
if (k & 0x2) {
|
||||
cipher_descriptor[idx].accel_xts_decrypt = _xts_test_accel_xts_decrypt;
|
||||
}
|
||||
for (j = 0; j < 2; j++) {
|
||||
for (i = 0; i < (int)(sizeof(tests) / sizeof(tests[0])); i++) {
|
||||
/* skip the cases where
|
||||
* the length is smaller than 2*blocklen
|
||||
* or the length is not a multiple of 32
|
||||
*/
|
||||
if ((j == 1) && ((tests[i].PTLEN < 32) || (tests[i].PTLEN % 32))) {
|
||||
continue;
|
||||
}
|
||||
if ((k > 0) && (j == 1)) {
|
||||
continue;
|
||||
}
|
||||
len = tests[i].PTLEN / 2;
|
||||
|
||||
err = xts_start(idx, tests[i].key1, tests[i].key2, tests[i].keylen / 2, 0, &xts);
|
||||
if (err != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
seq = tests[i].seqnum;
|
||||
STORE64L(seq, Torg);
|
||||
XMEMSET(Torg + 8, 0, 8);
|
||||
|
||||
XMEMCPY(T, Torg, sizeof(T));
|
||||
if (j == 0) {
|
||||
err = xts_encrypt(tests[i].PTX, tests[i].PTLEN, OUT, T, &xts);
|
||||
if (err != CRYPT_OK) {
|
||||
xts_done(&xts);
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
err = xts_encrypt(tests[i].PTX, len, OUT, T, &xts);
|
||||
if (err != CRYPT_OK) {
|
||||
xts_done(&xts);
|
||||
return err;
|
||||
}
|
||||
err = xts_encrypt(&tests[i].PTX[len], len, &OUT[len], T, &xts);
|
||||
if (err != CRYPT_OK) {
|
||||
xts_done(&xts);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
if (compare_testvector(OUT, tests[i].PTLEN, tests[i].CTX, tests[i].PTLEN, "XTS encrypt", i)) {
|
||||
xts_done(&xts);
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
XMEMCPY(T, Torg, sizeof(T));
|
||||
if (j == 0) {
|
||||
err = xts_decrypt(tests[i].CTX, tests[i].PTLEN, OUT, T, &xts);
|
||||
if (err != CRYPT_OK) {
|
||||
xts_done(&xts);
|
||||
return err;
|
||||
}
|
||||
} else {
|
||||
err = xts_decrypt(tests[i].CTX, len, OUT, T, &xts);
|
||||
if (err != CRYPT_OK) {
|
||||
xts_done(&xts);
|
||||
return err;
|
||||
}
|
||||
err = xts_decrypt(&tests[i].CTX[len], len, &OUT[len], T, &xts);
|
||||
if (err != CRYPT_OK) {
|
||||
xts_done(&xts);
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
if (compare_testvector(OUT, tests[i].PTLEN, tests[i].PTX, tests[i].PTLEN, "XTS decrypt", i)) {
|
||||
xts_done(&xts);
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
xts_done(&xts);
|
||||
}
|
||||
}
|
||||
}
|
||||
return CRYPT_OK;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* ref: HEAD -> master, tag: v1.18.2 */
|
||||
/* git commit: 7e7eb695d581782f04b24dc444cbfde86af59853 */
|
||||
/* commit time: 2018-07-01 22:49:01 +0200 */
|
Reference in New Issue
Block a user