Skip to content

Commit 2b75e1c

Browse files
committed
Add tests for deprecated APIs
Signed-off-by: Steffen Jaeckel <[email protected]>
1 parent 2f03417 commit 2b75e1c

File tree

6 files changed

+53
-0
lines changed

6 files changed

+53
-0
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ jobs:
5353
- { BUILDNAME: 'NO_FAST', BUILDOPTIONS: '-DLTC_NO_FAST', BUILDSCRIPT: '.ci/run.sh' }
5454
- { BUILDNAME: 'NO_FAST+SMALL+NO_TABLES', BUILDOPTIONS: '-DLTC_NO_FAST -DLTC_SMALL_CODE -DLTC_NO_TABLES', BUILDSCRIPT: '.ci/run.sh' }
5555
- { BUILDNAME: 'NO_ASM', BUILDOPTIONS: '-DLTC_NO_ASM', BUILDSCRIPT: '.ci/run.sh' }
56+
- { BUILDNAME: 'NO_DEPRECATED_APIS', BUILDOPTIONS: '-DLTC_NO_DEPRECATED_APIS', BUILDSCRIPT: '.ci/run.sh' }
5657
- { BUILDNAME: 'NO_TIMING_RESISTANCE', BUILDOPTIONS: '-DLTC_NO_ECC_TIMING_RESISTANT -DLTC_NO_RSA_BLINDING', BUILDSCRIPT: '.ci/run.sh' }
5758
- { BUILDNAME: 'FORTUNA_CUSTOM_OPTIONS', BUILDOPTIONS: '-DLTC_FORTUNA_USE_ENCRYPT_ONLY -DLTC_FORTUNA_RESEED_RATELIMIT_STATIC', BUILDSCRIPT: '.ci/run.sh' }
5859
- { BUILDNAME: 'PTHREAD', BUILDOPTIONS: '-DLTC_PTHREAD', BUILDSCRIPT: '.ci/run.sh' }

src/misc/crypt/crypt.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,9 @@ const char *crypt_build_settings =
581581
#endif
582582
#if defined(LTC_CLOCK_GETTIME)
583583
" LTC_CLOCK_GETTIME "
584+
#endif
585+
#if defined(LTC_NO_DEPRECATED_APIS)
586+
" LTC_NO_DEPRECATED_APIS "
584587
#endif
585588
"\n"
586589
;

tests/deprecated_test.c

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/* LibTomCrypt, modular cryptographic library -- Tom St Denis */
2+
/* SPDX-License-Identifier: Unlicense */
3+
#define LTC_DEPRECATED(x)
4+
#include <tomcrypt_test.h>
5+
6+
#ifdef LTC_MECC
7+
static void s_ecc_test(void)
8+
{
9+
const ltc_ecc_curve* dp;
10+
unsigned char buf[128];
11+
unsigned long len;
12+
ecc_key key;
13+
int stat;
14+
unsigned char data16[16] = { 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1, 0xd1 };
15+
16+
/* We need an MPI provider for ECC */
17+
if (ltc_mp.name == NULL) return;
18+
19+
ENSURE(ltc_ecc_curves[0].OID != NULL);
20+
21+
DO(ecc_find_curve(ltc_ecc_curves[0].OID, &dp));
22+
DO(ecc_make_key_ex(&yarrow_prng, find_prng ("yarrow"), &key, dp));
23+
24+
len = sizeof(buf);
25+
DO(ecc_sign_hash(data16, 16, buf, &len, &yarrow_prng, find_prng ("yarrow"), &key));
26+
stat = 0;
27+
DO(ecc_verify_hash(buf, len, data16, 16, &stat, &key));
28+
29+
SHOULD_FAIL(ecc_verify_hash_rfc7518(buf, len, data16, 16, &stat, &key));
30+
31+
len = sizeof(buf);
32+
DO(ecc_sign_hash_rfc7518(data16, 16, buf, &len, &yarrow_prng, find_prng ("yarrow"), &key));
33+
stat = 0;
34+
DO(ecc_verify_hash_rfc7518(buf, len, data16, 16, &stat, &key));
35+
36+
SHOULD_FAIL(ecc_verify_hash(buf, len, data16, 16, &stat, &key));
37+
}
38+
#endif
39+
40+
int deprecated_test(void)
41+
{
42+
#ifdef LTC_MECC
43+
s_ecc_test();
44+
#endif
45+
return 0;
46+
}

tests/sources.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ base64_test.c
55
bcrypt_test.c
66
cipher_hash_test.c
77
common.c
8+
deprecated_test.c
89
der_test.c
910
dh_test.c
1011
dsa_test.c

tests/test.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ static const test_function test_functions[] =
3737
LTC_TEST_FN(file_test),
3838
LTC_TEST_FN(multi_test),
3939
LTC_TEST_FN(pem_test),
40+
LTC_TEST_FN(deprecated_test),
4041
/* keep the prng_test always at the end as
4142
* it has to be handled specially when
4243
* testing with LTC_PTHREAD enabled

tests/tomcrypt_test.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ int ssh_test(void);
4545
int bcrypt_test(void);
4646
int no_null_termination_check_test(void);
4747
int pk_oid_test(void);
48+
int deprecated_test(void);
4849

4950
#ifdef LTC_PKCS_1
5051
struct ltc_prng_descriptor* no_prng_desc_get(void);

0 commit comments

Comments
 (0)