Skip to content

Commit fbc323b

Browse files
committed
upgrade libtomcrypt
1 parent 5afaf62 commit fbc323b

14 files changed

+242
-134
lines changed

MAINTENANCE

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ sqlite3.c
3131
Update code from https://github.com/libtom/libtomcrypt
3232
------------------------------------------------------
3333

34-
Current HEAD: cfbd7f8d364e1438555ff2a247f7e17add11840e
35-
(from develop branch, 2020-08-29)
34+
Current HEAD: 1e629e6f64661a01b9f6164a50080c43cd4d7b84
35+
(from develop branch, 2023-06-22)
3636

3737
Use ./track_libtomcrypt.sh

aes.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,6 @@ const struct ltc_cipher_descriptor rijndael_desc =
4444
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
4545
};
4646

47-
const struct ltc_cipher_descriptor aes_desc =
48-
{
49-
"aes",
50-
6,
51-
16, 32, 16, 10,
52-
SETUP, ECB_ENC, ECB_DEC, ECB_TEST, ECB_DONE, ECB_KS,
53-
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
54-
};
55-
5647
#else
5748

5849
#define SETUP rijndael_enc_setup
@@ -69,15 +60,6 @@ const struct ltc_cipher_descriptor rijndael_enc_desc =
6960
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
7061
};
7162

72-
const struct ltc_cipher_descriptor aes_enc_desc =
73-
{
74-
"aes",
75-
6,
76-
16, 32, 16, 10,
77-
SETUP, ECB_ENC, NULL, NULL, ECB_DONE, ECB_KS,
78-
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL
79-
};
80-
8163
#endif
8264

8365
#define LTC_AES_TAB_C

compare_testvector.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ int compare_testvector(const void* is, const unsigned long is_len, const void* s
6464
}
6565
#if defined(LTC_TEST) && defined(LTC_TEST_DBG)
6666
if (res != 0) {
67-
fprintf(stderr, "Testvector #%i of %s failed:\n", which, what);
67+
fprintf(stderr, "Testvector #%i(0x%x) of %s failed:\n", which, which, what);
6868
s_print_hex("SHOULD", should, should_len);
6969
s_print_hex("IS ", is, is_len);
7070
#if LTC_TEST_DBG > 1
7171
} else {
72-
fprintf(stderr, "Testvector #%i of %s passed!\n", which, what);
72+
fprintf(stderr, "Testvector #%i(0x%x) of %s passed!\n", which, which, what);
7373
#endif
7474
}
7575
#else

pkcs_5_2.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ int pkcs_5_alg2(const unsigned char *password, unsigned long password_len,
3636
LTC_ARGCHK(out != NULL);
3737
LTC_ARGCHK(outlen != NULL);
3838

39+
if (iteration_count <= 0) {
40+
return CRYPT_INVALID_ARG;
41+
}
42+
3943
/* test hash IDX */
4044
if ((err = hash_is_valid(hash_idx)) != CRYPT_OK) {
4145
return err;

tomcrypt_cfg.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
/* This is the build config file.
55
*
6-
* With this you can setup what to inlcude/exclude automatically during any build. Just comment
6+
* With this you can setup what to include/exclude automatically during any build. Just comment
77
* out the line that #define's the word for the thing you want to remove. phew!
88
*/
99

@@ -91,6 +91,11 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
9191
#define ENDIAN_LITTLE
9292
#define ENDIAN_64BITWORD
9393
#define LTC_FAST
94+
#if defined(__SSE4_1__)
95+
#if __SSE4_1__ == 1
96+
#define LTC_AMD64_SSE4_1
97+
#endif
98+
#endif
9499
#endif
95100

96101
/* detect PPC32 */
@@ -105,7 +110,7 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
105110
#define ENDIAN_64BITWORD
106111
#if defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
107112
#define ENDIAN_BIG
108-
#endif
113+
#else
109114
#define ENDIAN_LITTLE
110115
#endif
111116
#endif
@@ -182,7 +187,8 @@ LTC_EXPORT int LTC_CALL XSTRCMP(const char *s1, const char *s2);
182187
defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ || \
183188
defined(__BIG_ENDIAN__) || \
184189
defined(__ARMEB__) || defined(__THUMBEB__) || defined(__AARCH64EB__) || \
185-
defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__)
190+
defined(_MIPSEB) || defined(__MIPSEB) || defined(__MIPSEB__) || \
191+
defined(__m68k__)
186192
#define ENDIAN_BIG
187193
#elif defined(_BYTE_ORDER) && _BYTE_ORDER == _LITTLE_ENDIAN || \
188194
defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN || \
@@ -288,6 +294,21 @@ typedef unsigned long ltc_mp_digit;
288294
#define LTC_HAVE_ROTATE_BUILTIN
289295
#endif
290296

297+
#if defined(__GNUC__)
298+
#define LTC_ALIGN(n) __attribute__((aligned(n)))
299+
#else
300+
#define LTC_ALIGN(n)
301+
#endif
302+
303+
/* Define `LTC_NO_NULL_TERMINATION_CHECK` in the user code
304+
* before including `tomcrypt.h` to disable this functionality.
305+
*/
306+
#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(LTC_NO_NULL_TERMINATION_CHECK)
307+
# define LTC_NULL_TERMINATED __attribute__((sentinel))
308+
#else
309+
# define LTC_NULL_TERMINATED
310+
#endif
311+
291312
#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 405)
292313
# define LTC_DEPRECATED(s) __attribute__((deprecated("replaced by " #s)))
293314
# define PRIVATE_LTC_DEPRECATED_PRAGMA(s) _Pragma(#s)
@@ -303,3 +324,5 @@ typedef unsigned long ltc_mp_digit;
303324
# define LTC_DEPRECATED(s)
304325
# define LTC_DEPRECATED_PRAGMA(s)
305326
#endif
327+
328+
#endif /* TOMCRYPT_CFG_H */

tomcrypt_cipher.h

Lines changed: 30 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ struct saferp_key {
3535

3636
#ifdef LTC_RIJNDAEL
3737
struct rijndael_key {
38-
ulong32 eK[60], dK[60];
38+
ulong32 eK[60] LTC_ALIGN(16);
39+
ulong32 dK[60] LTC_ALIGN(16);
3940
int Nr;
4041
};
4142
#endif
@@ -318,9 +319,9 @@ typedef struct {
318319
ctrlen;
319320

320321
/** The counter */
321-
unsigned char ctr[MAXBLOCKSIZE],
322+
unsigned char ctr[MAXBLOCKSIZE];
322323
/** The pad used to encrypt/decrypt */
323-
pad[MAXBLOCKSIZE];
324+
unsigned char pad[MAXBLOCKSIZE] LTC_ALIGN(16);
324325
/** The scheduled key */
325326
symmetric_key key;
326327
} symmetric_CTR;
@@ -688,18 +689,19 @@ extern const struct ltc_cipher_descriptor safer_k64_desc, safer_k128_desc, safer
688689
#endif
689690

690691
#ifdef LTC_RIJNDAEL
691-
692-
/* make aes an alias */
693-
#define aes_setup rijndael_setup
694-
#define aes_ecb_encrypt rijndael_ecb_encrypt
695-
#define aes_ecb_decrypt rijndael_ecb_decrypt
696-
#define aes_test rijndael_test
697-
#define aes_done rijndael_done
698-
#define aes_keysize rijndael_keysize
699-
700-
#define aes_enc_setup rijndael_enc_setup
701-
#define aes_enc_ecb_encrypt rijndael_enc_ecb_encrypt
702-
#define aes_enc_keysize rijndael_enc_keysize
692+
/* declare aes properly now */
693+
int aes_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
694+
int aes_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
695+
int aes_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
696+
int aes_test(void);
697+
void aes_done(symmetric_key *skey);
698+
int aes_keysize(int *keysize);
699+
int aes_enc_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
700+
int aes_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
701+
void aes_enc_done(symmetric_key *skey);
702+
int aes_enc_keysize(int *keysize);
703+
extern const struct ltc_cipher_descriptor aes_desc;
704+
extern const struct ltc_cipher_descriptor aes_enc_desc;
703705

704706
int rijndael_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
705707
int rijndael_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
@@ -711,8 +713,19 @@ int rijndael_enc_setup(const unsigned char *key, int keylen, int num_rounds, sym
711713
int rijndael_enc_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
712714
void rijndael_enc_done(symmetric_key *skey);
713715
int rijndael_enc_keysize(int *keysize);
714-
extern const struct ltc_cipher_descriptor rijndael_desc, aes_desc;
715-
extern const struct ltc_cipher_descriptor rijndael_enc_desc, aes_enc_desc;
716+
extern const struct ltc_cipher_descriptor rijndael_desc;
717+
extern const struct ltc_cipher_descriptor rijndael_enc_desc;
718+
#endif
719+
720+
#if defined(LTC_AES_NI) && defined(LTC_AMD64_SSE4_1)
721+
int aesni_is_supported(void);
722+
int aesni_setup(const unsigned char *key, int keylen, int num_rounds, symmetric_key *skey);
723+
int aesni_ecb_encrypt(const unsigned char *pt, unsigned char *ct, const symmetric_key *skey);
724+
int aesni_ecb_decrypt(const unsigned char *ct, unsigned char *pt, const symmetric_key *skey);
725+
int aesni_test(void);
726+
void aesni_done(symmetric_key *skey);
727+
int aesni_keysize(int *keysize);
728+
extern const struct ltc_cipher_descriptor aesni_desc;
716729
#endif
717730

718731
#ifdef LTC_XTEA

tomcrypt_custom.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114

115115
#define LTC_NO_MISC
116116
#define LTC_BASE64
117-
#endif
117+
#endif /* LTC_EASY */
118118

119119
/* The minimal set of functionality to run the tests */
120120
#ifdef LTC_MINIMAL
@@ -129,7 +129,7 @@
129129
#define LTC_TRY_URANDOM_FIRST
130130

131131
#undef LTC_NO_FILE
132-
#endif
132+
#endif /* LTC_MINIMAL */
133133

134134
/* Enable self-test test vector checking */
135135
#ifndef LTC_NO_TEST
@@ -179,6 +179,7 @@
179179
#define LTC_RC6
180180
#define LTC_SAFERP
181181
#define LTC_RIJNDAEL
182+
#define LTC_AES_NI
182183
#define LTC_XTEA
183184
/* _TABLES tells it to use tables during setup, _SMALL means to use the smaller scheduled key format
184185
* (saves 4KB of ram), _ALL_TABLES enables all tables during setup */
@@ -357,7 +358,7 @@
357358
#define LTC_YARROW_AES 2
358359
#endif
359360

360-
#endif
361+
#endif /* LTC_YARROW */
361362

362363
#ifdef LTC_FORTUNA
363364

@@ -553,7 +554,7 @@
553554
#define LTC_ECC_SECP384R1
554555
#define LTC_ECC_SECP521R1
555556
#endif
556-
#endif
557+
#endif /* LTC_MECC */
557558

558559
#if defined(LTC_DER)
559560
#ifndef LTC_DER_MAX_RECURSION
@@ -585,6 +586,11 @@
585586
#define LTC_PBES
586587
#endif
587588

589+
#if defined(LTC_CLEAN_STACK)
590+
/* if you're sure that you want to use it, remove the line below */
591+
#error LTC_CLEAN_STACK is considered as broken
592+
#endif
593+
588594
#if defined(LTC_PBES) && !defined(LTC_PKCS_5)
589595
#error LTC_PBES requires LTC_PKCS_5
590596
#endif
@@ -685,15 +691,13 @@
685691
#define LTC_MUTEX_UNLOCK(x)
686692
#define LTC_MUTEX_DESTROY(x)
687693

688-
#endif
694+
#endif /* LTC_PTHREAD */
689695

690696
/* Debuggers */
691697

692698
/* define this if you use Valgrind, note: it CHANGES the way SOBER-128 and RC4 work (see the code) */
693699
/* #define LTC_VALGRIND */
694700

695-
#endif
696-
697701
#ifndef LTC_NO_FILE
698702
/* buffer size for reading from a file via fread(..) */
699703
#ifndef LTC_FILE_READ_BUFSIZE
@@ -734,3 +738,5 @@
734738
#define LTC_ECC_SECP521R1
735739
#undef LTC_ECC521
736740
#endif
741+
742+
#endif /* TOMCRYPT_CUSTOM_H_ */

tomcrypt_hash.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,8 @@ int hash_memory(int hash,
494494
const unsigned char *in, unsigned long inlen,
495495
unsigned char *out, unsigned long *outlen);
496496
int hash_memory_multi(int hash, unsigned char *out, unsigned long *outlen,
497-
const unsigned char *in, unsigned long inlen, ...);
497+
const unsigned char *in, unsigned long inlen, ...)
498+
LTC_NULL_TERMINATED;
498499

499500
#ifndef LTC_NO_FILE
500501
int hash_filehandle(int hash, FILE *in, unsigned char *out, unsigned long *outlen);

0 commit comments

Comments
 (0)