comparison rsa.c @ 1459:06d52bcb8094

Pointer parameter could be declared as pointing to const
author Francois Perrad <francois.perrad@gadz.org>
date Sat, 19 Aug 2017 17:16:13 +0200
parents c721e8c42d2a
children 5916af64acd4 36ab6b091ad3
comparison
equal deleted inserted replaced
1458:bdd3802c8ac6 1459:06d52bcb8094
36 #include "ssh.h" 36 #include "ssh.h"
37 #include "dbrandom.h" 37 #include "dbrandom.h"
38 38
39 #if DROPBEAR_RSA 39 #if DROPBEAR_RSA
40 40
41 static void rsa_pad_em(dropbear_rsa_key * key, 41 static void rsa_pad_em(const dropbear_rsa_key * key,
42 buffer *data_buf, mp_int * rsa_em); 42 const buffer *data_buf, mp_int * rsa_em);
43 43
44 /* Load a public rsa key from a buffer, initialising the values. 44 /* Load a public rsa key from a buffer, initialising the values.
45 * The key will have the same format as buf_put_rsa_key. 45 * The key will have the same format as buf_put_rsa_key.
46 * These should be freed with rsa_key_free. 46 * These should be freed with rsa_key_free.
47 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 47 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
145 * 145 *
146 * string "ssh-rsa" 146 * string "ssh-rsa"
147 * mp_int e 147 * mp_int e
148 * mp_int n 148 * mp_int n
149 */ 149 */
150 void buf_put_rsa_pub_key(buffer* buf, dropbear_rsa_key *key) { 150 void buf_put_rsa_pub_key(buffer* buf, const dropbear_rsa_key *key) {
151 151
152 TRACE(("enter buf_put_rsa_pub_key")) 152 TRACE(("enter buf_put_rsa_pub_key"))
153 dropbear_assert(key != NULL); 153 dropbear_assert(key != NULL);
154 154
155 buf_putstring(buf, SSH_SIGNKEY_RSA, SSH_SIGNKEY_RSA_LEN); 155 buf_putstring(buf, SSH_SIGNKEY_RSA, SSH_SIGNKEY_RSA_LEN);
159 TRACE(("leave buf_put_rsa_pub_key")) 159 TRACE(("leave buf_put_rsa_pub_key"))
160 160
161 } 161 }
162 162
163 /* Same as buf_put_rsa_pub_key, but with the private "x" key appended */ 163 /* Same as buf_put_rsa_pub_key, but with the private "x" key appended */
164 void buf_put_rsa_priv_key(buffer* buf, dropbear_rsa_key *key) { 164 void buf_put_rsa_priv_key(buffer* buf, const dropbear_rsa_key *key) {
165 165
166 TRACE(("enter buf_put_rsa_priv_key")) 166 TRACE(("enter buf_put_rsa_priv_key"))
167 167
168 dropbear_assert(key != NULL); 168 dropbear_assert(key != NULL);
169 buf_put_rsa_pub_key(buf, key); 169 buf_put_rsa_pub_key(buf, key);
183 } 183 }
184 184
185 #if DROPBEAR_SIGNKEY_VERIFY 185 #if DROPBEAR_SIGNKEY_VERIFY
186 /* Verify a signature in buf, made on data by the key given. 186 /* Verify a signature in buf, made on data by the key given.
187 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 187 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
188 int buf_rsa_verify(buffer * buf, dropbear_rsa_key *key, buffer *data_buf) { 188 int buf_rsa_verify(buffer * buf, const dropbear_rsa_key *key, const buffer *data_buf) {
189 unsigned int slen; 189 unsigned int slen;
190 DEF_MP_INT(rsa_s); 190 DEF_MP_INT(rsa_s);
191 DEF_MP_INT(rsa_mdash); 191 DEF_MP_INT(rsa_mdash);
192 DEF_MP_INT(rsa_em); 192 DEF_MP_INT(rsa_em);
193 int ret = DROPBEAR_FAILURE; 193 int ret = DROPBEAR_FAILURE;
238 238
239 #endif /* DROPBEAR_SIGNKEY_VERIFY */ 239 #endif /* DROPBEAR_SIGNKEY_VERIFY */
240 240
241 /* Sign the data presented with key, writing the signature contents 241 /* Sign the data presented with key, writing the signature contents
242 * to the buffer */ 242 * to the buffer */
243 void buf_put_rsa_sign(buffer* buf, dropbear_rsa_key *key, buffer *data_buf) { 243 void buf_put_rsa_sign(buffer* buf, const dropbear_rsa_key *key, const buffer *data_buf) {
244 unsigned int nsize, ssize; 244 unsigned int nsize, ssize;
245 unsigned int i; 245 unsigned int i;
246 DEF_MP_INT(rsa_s); 246 DEF_MP_INT(rsa_s);
247 DEF_MP_INT(rsa_tmp1); 247 DEF_MP_INT(rsa_tmp1);
248 DEF_MP_INT(rsa_tmp2); 248 DEF_MP_INT(rsa_tmp2);
344 * prefix is the ASN1 designator prefix, 344 * prefix is the ASN1 designator prefix,
345 * hex 30 21 30 09 06 05 2B 0E 03 02 1A 05 00 04 14 345 * hex 30 21 30 09 06 05 2B 0E 03 02 1A 05 00 04 14
346 * 346 *
347 * rsa_em must be a pointer to an initialised mp_int. 347 * rsa_em must be a pointer to an initialised mp_int.
348 */ 348 */
349 static void rsa_pad_em(dropbear_rsa_key * key, 349 static void rsa_pad_em(const dropbear_rsa_key * key,
350 buffer *data_buf, mp_int * rsa_em) { 350 const buffer *data_buf, mp_int * rsa_em) {
351 351
352 /* ASN1 designator (including the 0x00 preceding) */ 352 /* ASN1 designator (including the 0x00 preceding) */
353 const unsigned char rsa_asn1_magic[] = 353 const unsigned char rsa_asn1_magic[] =
354 {0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b, 354 {0x00, 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 0x2b,
355 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14}; 355 0x0e, 0x03, 0x02, 0x1a, 0x05, 0x00, 0x04, 0x14};