Skip to content

Commit 73514dc

Browse files
committed
Add tests for deprecated APIs
Signed-off-by: Steffen Jaeckel <s@jaeckel.eu>
1 parent 4f591b2 commit 73514dc

File tree

6 files changed

+50
-0
lines changed

6 files changed

+50
-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: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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+
ENSURE(ltc_ecc_curves[0].OID != NULL);
17+
18+
DO(ecc_find_curve(ltc_ecc_curves[0].OID, &dp));
19+
DO(ecc_make_key_ex(&yarrow_prng, find_prng ("yarrow"), &key, dp));
20+
21+
len = sizeof(buf);
22+
DO(ecc_sign_hash(data16, 16, buf, &len, &yarrow_prng, find_prng ("yarrow"), &key));
23+
stat = 0;
24+
DO(ecc_verify_hash(buf, len, data16, 16, &stat, &key));
25+
26+
SHOULD_FAIL(ecc_verify_hash_rfc7518(buf, len, data16, 16, &stat, &key));
27+
28+
len = sizeof(buf);
29+
DO(ecc_sign_hash_rfc7518(data16, 16, buf, &len, &yarrow_prng, find_prng ("yarrow"), &key));
30+
stat = 0;
31+
DO(ecc_verify_hash_rfc7518(buf, len, data16, 16, &stat, &key));
32+
33+
SHOULD_FAIL(ecc_verify_hash(buf, len, data16, 16, &stat, &key));
34+
}
35+
#endif
36+
37+
int deprecated_test(void)
38+
{
39+
#ifdef LTC_MECC
40+
s_ecc_test();
41+
#endif
42+
return 0;
43+
}

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)