Skip to content

Commit a079810

Browse files
committed
add MP_NO_DEPRECATED conditional
Furthermore we need _MP_NO_DEPRECATED_WARNING to disable the warning on CI. The macro is intentionally prefixed by an underscore to emphasise that its only for internal usage.
1 parent 632601f commit a079810

File tree

4 files changed

+29
-16
lines changed

4 files changed

+29
-16
lines changed

bn_deprecated.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/* SPDX-License-Identifier: Unlicense */
88
#include <tommath_private.h>
9+
#ifndef MP_NO_DEPRECATED
910
#ifdef BN_FAST_MP_INVMOD_C
1011
int fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c)
1112
{
@@ -85,3 +86,4 @@ void bn_reverse(unsigned char *s, int len)
8586
}
8687
#endif
8788
#endif
89+
#endif

makefile_include.mk

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ endif
4949

5050
CFLAGS += -I./ -Wall -Wsign-compare -Wextra -Wshadow
5151

52+
CFLAGS += -D_MP_NO_DEPRECATED_WARNING
53+
5254
ifndef NO_ADDTL_WARNINGS
5355
# additional warnings
5456
CFLAGS += -Wdeclaration-after-statement -Wbad-function-cast -Wcast-align

tommath.h

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ extern int KARATSUBA_MUL_CUTOFF,
137137

138138
/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
139139
#define _MP_WARRAY_PRIVATE (1u << (((CHAR_BIT * sizeof(mp_word)) - (2 * MP_DIGIT_BIT)) + 1))
140-
#define MP_WARRAY (MP_DEPRECATED_PRAGMA("MP_WARRAY is an internal macro") _MP_WARRAY_PRIVATE)
141140

142141
/* the infamous mp_int structure */
143142
typedef struct {
@@ -148,23 +147,31 @@ typedef struct {
148147
/* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */
149148
typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
150149

151-
#if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 301)
152-
# define MP_DEPRECATED(x) __attribute__((deprecated("replaced by " #x)))
153-
# define _MP_DEPRECATED_PRAGMA(s) _Pragma(#s)
154-
# define MP_DEPRECATED_PRAGMA(s) _MP_DEPRECATED_PRAGMA(GCC warning s)
155-
#elif defined(_MSC_VER) && _MSC_VER >= 1500
156-
# define MP_DEPRECATED(x) __declspec(deprecated("replaced by " #x))
157-
# define MP_DEPRECATED_PRAGMA(s) __pragma(message(s))
158-
#else
159-
# define MP_DEPRECATED
160-
# define MP_DEPRECATED_PRAGMA(s)
150+
#ifndef MP_NO_DEPRECATED
151+
152+
# ifndef _MP_NO_DEPRECATED_WARNING
153+
# warning Deprecated functions are enabled, define MP_NO_DEPRECATED!
154+
# endif
155+
156+
# if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 301)
157+
# define MP_DEPRECATED(x) __attribute__((deprecated("replaced by " #x)))
158+
# define _MP_DEPRECATED_PRAGMA(s) _Pragma(#s)
159+
# define MP_DEPRECATED_PRAGMA(s) _MP_DEPRECATED_PRAGMA(GCC warning s)
160+
# elif defined(_MSC_VER) && _MSC_VER >= 1500
161+
# define MP_DEPRECATED(x) __declspec(deprecated("replaced by " #x))
162+
# define MP_DEPRECATED_PRAGMA(s) __pragma(message(s))
163+
# else
164+
# define MP_DEPRECATED
165+
# define MP_DEPRECATED_PRAGMA(s)
166+
# endif
167+
168+
# define DIGIT_BIT MP_DIGIT_BIT
169+
# define USED(m) (MP_DEPRECATED_PRAGMA("USED macro is deprecated, use z->used instead") (m)->used)
170+
# define DIGIT(m, k) (MP_DEPRECATED_PRAGMA("DIGIT macro is deprecated, use z->dp instead") (m)->dp[(k)])
171+
# define SIGN(m) (MP_DEPRECATED_PRAGMA("SIGN macro is deprecated, use z->sign instead") (m)->sign)
172+
# define MP_WARRAY (MP_DEPRECATED_PRAGMA("MP_WARRAY is an internal macro") _MP_WARRAY_PRIVATE)
161173
#endif
162174

163-
#define DIGIT_BIT (MP_DEPRECATED_PRAGMA("DIGIT_BIT macro is deprecated, MP_DIGIT_BIT instead") MP_DIGIT_BIT)
164-
#define USED(m) (MP_DEPRECATED_PRAGMA("USED macro is deprecated, use z->used instead") (m)->used)
165-
#define DIGIT(m, k) (MP_DEPRECATED_PRAGMA("DIGIT macro is deprecated, use z->dp instead") (m)->dp[(k)])
166-
#define SIGN(m) (MP_DEPRECATED_PRAGMA("SIGN macro is deprecated, use z->sign instead") (m)->sign)
167-
168175
/* error code to char* string */
169176
const char *mp_error_to_string(int code);
170177

tommath_private.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ int func_name (mp_int * a, type b) \
8989
}
9090

9191
/* deprecated functions */
92+
#ifndef MP_NO_DEPRECATED
9293
MP_DEPRECATED(s_mp_invmod_fast) int fast_mp_invmod(const mp_int *a, const mp_int *b, mp_int *c);
9394
MP_DEPRECATED(s_mp_montgomery_reduce_fast) int fast_mp_montgomery_reduce(mp_int *x, const mp_int *n, mp_digit rho);
9495
MP_DEPRECATED(s_mp_mul_digs_fast) int fast_s_mp_mul_digs(const mp_int *a, const mp_int *b, mp_int *c, int digs);
@@ -104,6 +105,7 @@ MP_DEPRECATED(s_mp_karatsuba_sqr) int mp_karatsuba_sqr(const mp_int *a, mp_int *
104105
MP_DEPRECATED(s_mp_toom_mul) int mp_toom_mul(const mp_int *a, const mp_int *b, mp_int *c);
105106
MP_DEPRECATED(s_mp_toom_sqr) int mp_toom_sqr(const mp_int *a, mp_int *b);
106107
MP_DEPRECATED(s_mp_reverse) void bn_reverse(unsigned char *s, int len);
108+
#endif
107109

108110
#ifdef __cplusplus
109111
}

0 commit comments

Comments
 (0)