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:
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 */
|
Reference in New Issue
Block a user