dropbear: cherry-pick upstream patches
[openwrt/openwrt.git] / package / network / services / dropbear / patches / 005-const-parameter-mp_int.patch
1 From 01415ef8269e594a647f67ea0729ca8b590679de Mon Sep 17 00:00:00 2001
2 From: Francois Perrad <francois.perrad@gadz.org>
3 Date: Thu, 22 Dec 2022 10:19:54 +0100
4 Subject: const parameter mp_int
5
6 ---
7 bignum.c | 2 +-
8 bignum.h | 2 +-
9 buffer.c | 2 +-
10 buffer.h | 2 +-
11 dbrandom.c | 2 +-
12 dbrandom.h | 2 +-
13 dbutil.c | 2 +-
14 dbutil.h | 2 +-
15 genrsa.c | 4 ++--
16 9 files changed, 10 insertions(+), 10 deletions(-)
17
18 --- a/bignum.c
19 +++ b/bignum.c
20 @@ -93,7 +93,7 @@ void bytes_to_mp(mp_int *mp, const unsig
21
22 /* hash the ssh representation of the mp_int mp */
23 void hash_process_mp(const struct ltc_hash_descriptor *hash_desc,
24 - hash_state *hs, mp_int *mp) {
25 + hash_state *hs, const mp_int *mp) {
26 buffer * buf;
27
28 buf = buf_new(512 + 20); /* max buffer is a 4096 bit key,
29 --- a/bignum.h
30 +++ b/bignum.h
31 @@ -33,6 +33,6 @@ void m_mp_alloc_init_multi(mp_int **mp,
32 void m_mp_free_multi(mp_int **mp, ...) ATTRIB_SENTINEL;
33 void bytes_to_mp(mp_int *mp, const unsigned char* bytes, unsigned int len);
34 void hash_process_mp(const struct ltc_hash_descriptor *hash_desc,
35 - hash_state *hs, mp_int *mp);
36 + hash_state *hs, const mp_int *mp);
37
38 #endif /* DROPBEAR_BIGNUM_H_ */
39 --- a/buffer.c
40 +++ b/buffer.c
41 @@ -299,7 +299,7 @@ void buf_putbytes(buffer *buf, const uns
42
43 /* for our purposes we only need positive (or 0) numbers, so will
44 * fail if we get negative numbers */
45 -void buf_putmpint(buffer* buf, mp_int * mp) {
46 +void buf_putmpint(buffer* buf, const mp_int * mp) {
47 size_t written;
48 unsigned int len, pad = 0;
49 TRACE2(("enter buf_putmpint"))
50 --- a/buffer.h
51 +++ b/buffer.h
52 @@ -65,7 +65,7 @@ void buf_putint(buffer* buf, unsigned in
53 void buf_putstring(buffer* buf, const char* str, unsigned int len);
54 void buf_putbufstring(buffer *buf, const buffer* buf_str);
55 void buf_putbytes(buffer *buf, const unsigned char *bytes, unsigned int len);
56 -void buf_putmpint(buffer* buf, mp_int * mp);
57 +void buf_putmpint(buffer* buf, const mp_int * mp);
58 int buf_getmpint(buffer* buf, mp_int* mp);
59 unsigned int buf_getint(buffer* buf);
60
61 --- a/dbrandom.c
62 +++ b/dbrandom.c
63 @@ -347,7 +347,7 @@ void genrandom(unsigned char* buf, unsig
64 * rand must be an initialised *mp_int for the result.
65 * the result rand satisfies: 0 < rand < max
66 * */
67 -void gen_random_mpint(mp_int *max, mp_int *rand) {
68 +void gen_random_mpint(const mp_int *max, mp_int *rand) {
69
70 unsigned char *randbuf = NULL;
71 unsigned int len = 0;
72 --- a/dbrandom.h
73 +++ b/dbrandom.h
74 @@ -30,6 +30,6 @@
75 void seedrandom(void);
76 void genrandom(unsigned char* buf, unsigned int len);
77 void addrandom(const unsigned char * buf, unsigned int len);
78 -void gen_random_mpint(mp_int *max, mp_int *rand);
79 +void gen_random_mpint(const mp_int *max, mp_int *rand);
80
81 #endif /* DROPBEAR_RANDOM_H_ */
82 --- a/dbutil.c
83 +++ b/dbutil.c
84 @@ -442,7 +442,7 @@ void printhex(const char * label, const
85 }
86 }
87
88 -void printmpint(const char *label, mp_int *mp) {
89 +void printmpint(const char *label, const mp_int *mp) {
90 buffer *buf = buf_new(1000);
91 buf_putmpint(buf, mp);
92 fprintf(stderr, "%d bits ", mp_count_bits(mp));
93 --- a/dbutil.h
94 +++ b/dbutil.h
95 @@ -53,7 +53,7 @@ void dropbear_trace3(const char* format,
96 void dropbear_trace4(const char* format, ...) ATTRIB_PRINTF(1,2);
97 void dropbear_trace5(const char* format, ...) ATTRIB_PRINTF(1,2);
98 void printhex(const char * label, const unsigned char * buf, int len);
99 -void printmpint(const char *label, mp_int *mp);
100 +void printmpint(const char *label, const mp_int *mp);
101 void debug_start_net(void);
102 extern int debug_trace;
103 #endif
104 --- a/genrsa.c
105 +++ b/genrsa.c
106 @@ -34,7 +34,7 @@
107 #if DROPBEAR_RSA
108
109 static void getrsaprime(mp_int* prime, mp_int *primeminus,
110 - mp_int* rsa_e, unsigned int size_bytes);
111 + const mp_int* rsa_e, unsigned int size_bytes);
112
113 /* mostly taken from libtomcrypt's rsa key generation routine */
114 dropbear_rsa_key * gen_rsa_priv_key(unsigned int size) {
115 @@ -89,7 +89,7 @@ dropbear_rsa_key * gen_rsa_priv_key(unsi
116
117 /* return a prime suitable for p or q */
118 static void getrsaprime(mp_int* prime, mp_int *primeminus,
119 - mp_int* rsa_e, unsigned int size_bytes) {
120 + const mp_int* rsa_e, unsigned int size_bytes) {
121
122 unsigned char *buf;
123 int trials;