Upgrade libtomcrypt
This commit is contained in:
@@ -669,7 +669,7 @@ int ECB_TEST(void)
|
||||
unsigned char tmp[2][16];
|
||||
int i, y;
|
||||
|
||||
for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
|
||||
for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
|
||||
zeromem(&key, sizeof(key));
|
||||
if ((err = rijndael_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
|
||||
@@ -63,10 +63,19 @@ static LTC_INLINE int s_aesni_is_supported(void)
|
||||
a = 1;
|
||||
c = 0;
|
||||
|
||||
#if defined(_MSC_VER) && !defined(__clang__)
|
||||
int arr[4];
|
||||
__cpuidex(arr, a, c);
|
||||
a = arr[0];
|
||||
b = arr[1];
|
||||
c = arr[2];
|
||||
d = arr[3];
|
||||
#else
|
||||
__asm__ volatile ("cpuid"
|
||||
:"=a"(a), "=b"(b), "=c"(c), "=d"(d)
|
||||
:"a"(a), "c"(c)
|
||||
);
|
||||
#endif
|
||||
|
||||
is_supported = ((c >> 19) & 1) && ((c >> 25) & 1);
|
||||
initialized = 1;
|
||||
@@ -189,7 +198,7 @@ int AES_TEST(void)
|
||||
int y;
|
||||
#endif
|
||||
|
||||
for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
|
||||
for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
|
||||
zeromem(&key, sizeof(key));
|
||||
if ((err = AES_SETUP(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
|
||||
@@ -313,7 +313,7 @@ int aesni_test(void)
|
||||
unsigned char tmp[2][16];
|
||||
int i, y;
|
||||
|
||||
for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
|
||||
for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
|
||||
zeromem(&key, sizeof(key));
|
||||
if ((err = aesni_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
|
||||
@@ -1498,7 +1498,7 @@ int anubis_test(void)
|
||||
unsigned char buf[2][16];
|
||||
symmetric_key skey;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
|
||||
anubis_setup(tests[x].key, tests[x].keylen, 0, &skey);
|
||||
anubis_ecb_encrypt(tests[x].pt, buf[0], &skey);
|
||||
anubis_ecb_decrypt(buf[0], buf[1], &skey);
|
||||
|
||||
@@ -680,7 +680,7 @@ int camellia_test(void)
|
||||
int err;
|
||||
unsigned int x;
|
||||
|
||||
for (x = 0; x < sizeof(tests)/sizeof(tests[0]); x++) {
|
||||
for (x = 0; x < LTC_ARRAY_SIZE(tests); x++) {
|
||||
zeromem(&skey, sizeof(skey));
|
||||
if ((err = camellia_setup(tests[x].key, tests[x].keylen, 0, &skey)) != CRYPT_OK) {
|
||||
return err;
|
||||
|
||||
@@ -492,7 +492,7 @@ int cast5_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_
|
||||
#endif
|
||||
|
||||
#define FI cast5_FI
|
||||
LTC_INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
|
||||
static LTC_INLINE ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
|
||||
{
|
||||
ulong32 I;
|
||||
I = (Km + R);
|
||||
@@ -500,7 +500,7 @@ LTC_INLINE static ulong32 FI(ulong32 R, ulong32 Km, ulong32 Kr)
|
||||
return ((S1[LTC_BYTE(I, 3)] ^ S2[LTC_BYTE(I,2)]) - S3[LTC_BYTE(I,1)]) + S4[LTC_BYTE(I,0)];
|
||||
}
|
||||
|
||||
LTC_INLINE static ulong32 FII(ulong32 R, ulong32 Km, ulong32 Kr)
|
||||
static LTC_INLINE ulong32 FII(ulong32 R, ulong32 Km, ulong32 Kr)
|
||||
{
|
||||
ulong32 I;
|
||||
I = (Km ^ R);
|
||||
@@ -508,7 +508,7 @@ LTC_INLINE static ulong32 FII(ulong32 R, ulong32 Km, ulong32 Kr)
|
||||
return ((S1[LTC_BYTE(I, 3)] - S2[LTC_BYTE(I,2)]) + S3[LTC_BYTE(I,1)]) ^ S4[LTC_BYTE(I,0)];
|
||||
}
|
||||
|
||||
LTC_INLINE static ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
|
||||
static LTC_INLINE ulong32 FIII(ulong32 R, ulong32 Km, ulong32 Kr)
|
||||
{
|
||||
ulong32 I;
|
||||
I = (Km - R);
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
/* SPDX-License-Identifier: Unlicense */
|
||||
#include "tomcrypt_private.h"
|
||||
|
||||
#pragma clang diagnostic push
|
||||
#pragma clang diagnostic ignored "-Wconversion"
|
||||
#pragma clang diagnostic ignored "-Wshorten-64-to-32"
|
||||
|
||||
/**
|
||||
@file des.c
|
||||
DES code submitted by Dobes Vandermeer
|
||||
@@ -1381,14 +1385,14 @@ static void cookey(const ulong32 *raw1, ulong32 *keyout)
|
||||
for(i=0; i < 16; i++, raw1++)
|
||||
{
|
||||
raw0 = raw1++;
|
||||
*cook = (ulong32)((*raw0 & 0x00fc0000L) << 6);
|
||||
*cook |= (ulong32)((*raw0 & 0x00000fc0L) << 10);
|
||||
*cook |= (ulong32)((*raw1 & 0x00fc0000L) >> 10);
|
||||
*cook++ |= (ulong32)((*raw1 & 0x00000fc0L) >> 6);
|
||||
*cook = (ulong32)((*raw0 & 0x0003f000L) << 12);
|
||||
*cook |= (ulong32)((*raw0 & 0x0000003fL) << 16);
|
||||
*cook |= (ulong32)((*raw1 & 0x0003f000L) >> 4);
|
||||
*cook++ |= (ulong32) (*raw1 & 0x0000003fL);
|
||||
*cook = (*raw0 & 0x00fc0000L) << 6;
|
||||
*cook |= (*raw0 & 0x00000fc0L) << 10;
|
||||
*cook |= (*raw1 & 0x00fc0000L) >> 10;
|
||||
*cook++ |= (*raw1 & 0x00000fc0L) >> 6;
|
||||
*cook = (*raw0 & 0x0003f000L) << 12;
|
||||
*cook |= (*raw0 & 0x0000003fL) << 16;
|
||||
*cook |= (*raw1 & 0x0003f000L) >> 4;
|
||||
*cook++ |= (*raw1 & 0x0000003fL);
|
||||
}
|
||||
|
||||
XMEMCPY(keyout, dough, sizeof(dough));
|
||||
@@ -2018,7 +2022,7 @@ int des_test(void)
|
||||
symmetric_key skey;
|
||||
int i, err;
|
||||
|
||||
for (i = 0; i < (int)(sizeof(cases)/sizeof(cases[0])); i++)
|
||||
for (i = 0; i < (int)LTC_ARRAY_SIZE(cases); i++)
|
||||
{
|
||||
if ((err = des_setup(cases[i].key, 8, 0, &skey)) != CRYPT_OK) {
|
||||
return err;
|
||||
@@ -2125,7 +2129,7 @@ int des3_test(void)
|
||||
return err;
|
||||
}
|
||||
|
||||
for (i = 0; i < (int)(sizeof(cases)/sizeof(cases[0])); i++)
|
||||
for (i = 0; i < (int)LTC_ARRAY_SIZE(cases); i++)
|
||||
{
|
||||
if ((err = des3_setup(cases[i].key, 16, 0, &skey)) != CRYPT_OK) {
|
||||
return err;
|
||||
@@ -2243,3 +2247,4 @@ int des3_keysize(int *keysize)
|
||||
|
||||
#endif
|
||||
|
||||
#pragma clang diagnostic pop
|
||||
|
||||
@@ -226,7 +226,7 @@ int idea_test(void)
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
|
||||
if ((err = idea_setup(tests[x].key, 16, 8, &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -286,7 +286,7 @@ int kasumi_test(void)
|
||||
symmetric_key key;
|
||||
int err, x;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
|
||||
if ((err = kasumi_setup(tests[x].key, 16, 0, &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -794,7 +794,7 @@ int khazad_test(void)
|
||||
unsigned char buf[2][8];
|
||||
symmetric_key skey;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
|
||||
khazad_setup(tests[x].key, 16, 0, &skey);
|
||||
khazad_ecb_encrypt(tests[x].pt, buf[0], &skey);
|
||||
khazad_ecb_decrypt(buf[0], buf[1], &skey);
|
||||
|
||||
@@ -334,7 +334,7 @@ int kseed_test(void)
|
||||
unsigned char buf[2][16];
|
||||
symmetric_key skey;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
|
||||
kseed_setup(tests[x].key, 16, 0, &skey);
|
||||
kseed_ecb_encrypt(tests[x].pt, buf[0], &skey);
|
||||
kseed_ecb_decrypt(buf[0], buf[1], &skey);
|
||||
|
||||
@@ -242,7 +242,7 @@ int multi2_test(void)
|
||||
symmetric_key skey;
|
||||
int err, x;
|
||||
|
||||
for (x = 1; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
for (x = 1; x < (int)LTC_ARRAY_SIZE(tests); x++) {
|
||||
if ((err = multi2_setup(tests[x].key, 40, tests[x].rounds, &skey)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ int noekeon_test(void)
|
||||
unsigned char tmp[2][16];
|
||||
int err, i, y;
|
||||
|
||||
for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
|
||||
for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
|
||||
zeromem(&key, sizeof(key));
|
||||
if ((err = noekeon_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
|
||||
@@ -693,7 +693,7 @@ int serpent_test(void)
|
||||
symmetric_key key;
|
||||
int err, x;
|
||||
|
||||
for (x = 0; x < (int)(sizeof(tests)/sizeof(tests[0])); x++) {
|
||||
for (x = 0; x < (int)LTC_ARRAY_SIZE(tests); x++) {
|
||||
if ((err = serpent_setup(tests[x].key, tests[x].keylen, 0, &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ static const sm4_u8_t sm4_sbox_table[16][16] = {
|
||||
* S-box
|
||||
* defined in section 2.6 S-box
|
||||
*/
|
||||
LTC_INLINE static sm4_u8_t s_sm4_sbox(sm4_u8_t a)
|
||||
static LTC_INLINE sm4_u8_t s_sm4_sbox(sm4_u8_t a)
|
||||
{
|
||||
return sm4_sbox_table[(a >> 4) & 0x0f][a & 0x0f];
|
||||
}
|
||||
@@ -80,7 +80,7 @@ LTC_INLINE static sm4_u8_t s_sm4_sbox(sm4_u8_t a)
|
||||
* But we just convert a 32bit word byte by byte.
|
||||
* So it's OK if we don't convert the endian order
|
||||
*/
|
||||
LTC_INLINE static sm4_u32_t s_sm4_t(sm4_u32_t A)
|
||||
static LTC_INLINE sm4_u32_t s_sm4_t(sm4_u32_t A)
|
||||
{
|
||||
sm4_u8_t a[4];
|
||||
sm4_u8_t b[4];
|
||||
@@ -98,7 +98,7 @@ LTC_INLINE static sm4_u32_t s_sm4_t(sm4_u32_t A)
|
||||
/*
|
||||
* defined in section 6.2 (2) Linear transformation L
|
||||
*/
|
||||
LTC_INLINE static sm4_u32_t s_sm4_L62(sm4_u32_t B)
|
||||
static LTC_INLINE sm4_u32_t s_sm4_L62(sm4_u32_t B)
|
||||
{
|
||||
return B ^ ROLc(B, 2) ^ ROLc(B, 10) ^ ROLc(B, 18) ^ ROLc(B, 24);
|
||||
}
|
||||
@@ -106,7 +106,7 @@ LTC_INLINE static sm4_u32_t s_sm4_L62(sm4_u32_t B)
|
||||
/*
|
||||
* defined in section 6.2 Permutation T
|
||||
*/
|
||||
LTC_INLINE static sm4_u32_t s_sm4_T62(sm4_u32_t Z)
|
||||
static LTC_INLINE sm4_u32_t s_sm4_T62(sm4_u32_t Z)
|
||||
{
|
||||
return s_sm4_L62(s_sm4_t(Z));
|
||||
}
|
||||
@@ -137,7 +137,7 @@ static const sm4_u32_t sm4_CK[32] =
|
||||
/*
|
||||
* defined in section 7.3 (1) L'
|
||||
*/
|
||||
LTC_INLINE static sm4_u32_t s_sm4_L73(sm4_u32_t B)
|
||||
static LTC_INLINE sm4_u32_t s_sm4_L73(sm4_u32_t B)
|
||||
{
|
||||
return B ^ ROLc(B, 13) ^ ROLc(B, 23);
|
||||
}
|
||||
@@ -145,7 +145,7 @@ LTC_INLINE static sm4_u32_t s_sm4_L73(sm4_u32_t B)
|
||||
/*
|
||||
* defined in section 7.3 (1) T'
|
||||
*/
|
||||
LTC_INLINE static sm4_u32_t s_sm4_T73(sm4_u32_t Z)
|
||||
static LTC_INLINE sm4_u32_t s_sm4_T73(sm4_u32_t Z)
|
||||
{
|
||||
return s_sm4_L73(s_sm4_t(Z));
|
||||
}
|
||||
@@ -153,7 +153,7 @@ LTC_INLINE static sm4_u32_t s_sm4_T73(sm4_u32_t Z)
|
||||
/*
|
||||
* defined in section 7.3 Key Expansion
|
||||
*/
|
||||
LTC_INLINE static void s_sm4_mk2rk(sm4_u32_t rk[32], sm4_u8_t mk[16])
|
||||
static LTC_INLINE void s_sm4_mk2rk(sm4_u32_t rk[32], sm4_u8_t mk[16])
|
||||
{
|
||||
sm4_u32_t MK[4] = { 0 };
|
||||
sm4_u32_t K[4+32] = { 0 };
|
||||
@@ -175,7 +175,7 @@ LTC_INLINE static void s_sm4_mk2rk(sm4_u32_t rk[32], sm4_u8_t mk[16])
|
||||
/*
|
||||
* defined in section 6 Round Function F
|
||||
*/
|
||||
LTC_INLINE static sm4_u32_t s_sm4_F(sm4_u32_t X[4], sm4_u32_t rk)
|
||||
static LTC_INLINE sm4_u32_t s_sm4_F(sm4_u32_t X[4], sm4_u32_t rk)
|
||||
{
|
||||
return X[0] ^ s_sm4_T62(X[1] ^ X[2] ^ X[3] ^ rk);
|
||||
}
|
||||
@@ -183,7 +183,7 @@ LTC_INLINE static sm4_u32_t s_sm4_F(sm4_u32_t X[4], sm4_u32_t rk)
|
||||
/*
|
||||
* defined in section 7.1 (2) The reverse transformation
|
||||
*/
|
||||
LTC_INLINE static void s_sm4_R(sm4_u32_t Y[4], sm4_u32_t X[32+4])
|
||||
static LTC_INLINE void s_sm4_R(sm4_u32_t Y[4], sm4_u32_t X[32+4])
|
||||
{
|
||||
Y[0] = X[35];
|
||||
Y[1] = X[34];
|
||||
@@ -194,7 +194,7 @@ LTC_INLINE static void s_sm4_R(sm4_u32_t Y[4], sm4_u32_t X[32+4])
|
||||
/*
|
||||
* defined in section 7.1 (En)cryption
|
||||
*/
|
||||
LTC_INLINE static void s_sm4_crypt(sm4_u32_t Y[4], sm4_u32_t X[4+32], const sm4_u32_t rk[32])
|
||||
static LTC_INLINE void s_sm4_crypt(sm4_u32_t Y[4], sm4_u32_t X[4+32], const sm4_u32_t rk[32])
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -203,7 +203,7 @@ LTC_INLINE static void s_sm4_crypt(sm4_u32_t Y[4], sm4_u32_t X[4+32], const sm4_
|
||||
s_sm4_R(Y, X);
|
||||
}
|
||||
|
||||
LTC_INLINE static void s_sm4_setkey(struct sm4_key *sm4, const unsigned char *key)
|
||||
static LTC_INLINE void s_sm4_setkey(struct sm4_key *sm4, const unsigned char *key)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -229,7 +229,7 @@ int sm4_setup(const unsigned char *key, int keylen,
|
||||
/*
|
||||
* SM4 encryption.
|
||||
*/
|
||||
LTC_INLINE static void s_sm4_do(void *output, const void *input, const sm4_u32_t rk[32])
|
||||
static LTC_INLINE void s_sm4_do(void *output, const void *input, const sm4_u32_t rk[32])
|
||||
{
|
||||
sm4_u32_t Y[4];
|
||||
sm4_u32_t X[32+4];
|
||||
|
||||
@@ -150,7 +150,7 @@ int tea_test(void)
|
||||
symmetric_key skey;
|
||||
size_t i;
|
||||
int err, y;
|
||||
for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++) {
|
||||
for (i = 0; i < LTC_ARRAY_SIZE(tests); i++) {
|
||||
zeromem(&skey, sizeof(skey));
|
||||
|
||||
l = sizeof(key);
|
||||
@@ -166,8 +166,8 @@ int tea_test(void)
|
||||
tea_ecb_encrypt(ptct[0], tmp[0], &skey);
|
||||
tea_ecb_decrypt(tmp[0], tmp[1], &skey);
|
||||
|
||||
if (compare_testvector(tmp[0], 8, ptct[1], 8, "TEA Encrypt", (int)i) != 0 ||
|
||||
compare_testvector(tmp[1], 8, ptct[0], 8, "TEA Decrypt", (int)i) != 0) {
|
||||
if (compare_testvector(tmp[0], 8, ptct[1], 8, "TEA Encrypt", i) != 0 ||
|
||||
compare_testvector(tmp[1], 8, ptct[0], 8, "TEA Decrypt", i) != 0) {
|
||||
return CRYPT_FAIL_TESTVECTOR;
|
||||
}
|
||||
|
||||
|
||||
@@ -651,7 +651,7 @@ int twofish_test(void)
|
||||
unsigned char tmp[2][16];
|
||||
int err, i, y;
|
||||
|
||||
for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
|
||||
for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
|
||||
if ((err = twofish_setup(tests[i].key, tests[i].keylen, 0, &key)) != CRYPT_OK) {
|
||||
return err;
|
||||
}
|
||||
|
||||
@@ -197,7 +197,7 @@ int xtea_test(void)
|
||||
unsigned char tmp[2][8];
|
||||
symmetric_key skey;
|
||||
int i, err, y;
|
||||
for (i = 0; i < (int)(sizeof(tests)/sizeof(tests[0])); i++) {
|
||||
for (i = 0; i < (int)LTC_ARRAY_SIZE(tests); i++) {
|
||||
zeromem(&skey, sizeof(skey));
|
||||
if ((err = xtea_setup(tests[i].key, 16, 0, &skey)) != CRYPT_OK) {
|
||||
return err;
|
||||
|
||||
Reference in New Issue
Block a user