comparison signkey.c @ 842:7f8f8f2b7a35

Merge
author Matt Johnston <matt@ucc.asn.au>
date Fri, 01 Nov 2013 00:14:48 +0800
parents d4ce5269a439
children b298bb438625
comparison
equal deleted inserted replaced
839:33207ed1174b 842:7f8f8f2b7a35
101 TRACE(("signkey_type_from_name unexpected key type.")) 101 TRACE(("signkey_type_from_name unexpected key type."))
102 102
103 return DROPBEAR_SIGNKEY_NONE; 103 return DROPBEAR_SIGNKEY_NONE;
104 } 104 }
105 105
106 #ifdef DROPBEAR_ECDSA 106 /* Returns a pointer to the key part specific to "type" */
107 ecc_key ** 107 void **
108 signkey_ecc_key_ptr(sign_key *key, enum signkey_type ecc_type) { 108 signkey_key_ptr(sign_key *key, enum signkey_type type) {
109 switch (ecc_type) { 109 switch (type) {
110 #ifdef DROPBEAR_ECC_256
110 case DROPBEAR_SIGNKEY_ECDSA_NISTP256: 111 case DROPBEAR_SIGNKEY_ECDSA_NISTP256:
111 return &key->ecckey256; 112 return (void**)&key->ecckey256;
113 #endif
114 #ifdef DROPBEAR_ECC_384
112 case DROPBEAR_SIGNKEY_ECDSA_NISTP384: 115 case DROPBEAR_SIGNKEY_ECDSA_NISTP384:
113 return &key->ecckey384; 116 return (void**)&key->ecckey384;
117 #endif
118 #ifdef DROPBEAR_ECC_521
114 case DROPBEAR_SIGNKEY_ECDSA_NISTP521: 119 case DROPBEAR_SIGNKEY_ECDSA_NISTP521:
115 return &key->ecckey521; 120 return (void**)&key->ecckey521;
121 #endif
122 #ifdef DROPBEAR_RSA
123 case DROPBEAR_SIGNKEY_RSA:
124 return (void**)&key->rsakey;
125 #endif
126 #ifdef DROPBEAR_DSS
127 case DROPBEAR_SIGNKEY_DSS:
128 return (void**)&key->dsskey;
129 #endif
116 default: 130 default:
117 return NULL; 131 return NULL;
118 } 132 }
119 } 133 }
120 #endif
121 134
122 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail. 135 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail.
123 * type should be set by the caller to specify the type to read, and 136 * type should be set by the caller to specify the type to read, and
124 * on return is set to the type read (useful when type = _ANY) */ 137 * on return is set to the type read (useful when type = _ANY) */
125 int buf_get_pub_key(buffer *buf, sign_key *key, int *type) { 138 int buf_get_pub_key(buffer *buf, sign_key *key, enum signkey_type *type) {
126 139
127 unsigned char* ident; 140 unsigned char* ident;
128 unsigned int len; 141 unsigned int len;
129 int keytype; 142 int keytype;
130 int ret = DROPBEAR_FAILURE; 143 int ret = DROPBEAR_FAILURE;
167 } 180 }
168 } 181 }
169 #endif 182 #endif
170 #ifdef DROPBEAR_ECDSA 183 #ifdef DROPBEAR_ECDSA
171 { 184 {
172 ecc_key **eck = signkey_ecc_key_ptr(key, keytype); 185 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
173 if (eck) { 186 if (eck) {
174 if (*eck) { 187 if (*eck) {
175 ecc_free(*eck); 188 ecc_free(*eck);
176 *eck = NULL; 189 *eck = NULL;
177 } 190 }
190 } 203 }
191 204
192 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail. 205 /* returns DROPBEAR_SUCCESS on success, DROPBEAR_FAILURE on fail.
193 * type should be set by the caller to specify the type to read, and 206 * type should be set by the caller to specify the type to read, and
194 * on return is set to the type read (useful when type = _ANY) */ 207 * on return is set to the type read (useful when type = _ANY) */
195 int buf_get_priv_key(buffer *buf, sign_key *key, int *type) { 208 int buf_get_priv_key(buffer *buf, sign_key *key, enum signkey_type *type) {
196 209
197 unsigned char* ident; 210 unsigned char* ident;
198 unsigned int len; 211 unsigned int len;
199 int keytype; 212 int keytype;
200 int ret = DROPBEAR_FAILURE; 213 int ret = DROPBEAR_FAILURE;
235 } 248 }
236 } 249 }
237 #endif 250 #endif
238 #ifdef DROPBEAR_ECDSA 251 #ifdef DROPBEAR_ECDSA
239 { 252 {
240 ecc_key **eck = signkey_ecc_key_ptr(key, keytype); 253 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, keytype);
241 if (eck) { 254 if (eck) {
242 if (*eck) { 255 if (*eck) {
243 ecc_free(*eck); 256 ecc_free(*eck);
244 *eck = NULL; 257 *eck = NULL;
245 } 258 }
256 return ret; 269 return ret;
257 270
258 } 271 }
259 272
260 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */ 273 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */
261 void buf_put_pub_key(buffer* buf, sign_key *key, int type) { 274 void buf_put_pub_key(buffer* buf, sign_key *key, enum signkey_type type) {
262 275
263 buffer *pubkeys; 276 buffer *pubkeys;
264 277
265 TRACE2(("enter buf_put_pub_key")) 278 TRACE2(("enter buf_put_pub_key"))
266 pubkeys = buf_new(MAX_PUBKEY_SIZE); 279 pubkeys = buf_new(MAX_PUBKEY_SIZE);
274 if (type == DROPBEAR_SIGNKEY_RSA) { 287 if (type == DROPBEAR_SIGNKEY_RSA) {
275 buf_put_rsa_pub_key(pubkeys, key->rsakey); 288 buf_put_rsa_pub_key(pubkeys, key->rsakey);
276 } 289 }
277 #endif 290 #endif
278 #ifdef DROPBEAR_ECDSA 291 #ifdef DROPBEAR_ECDSA
292 if (type == DROPBEAR_SIGNKEY_ECDSA_NISTP256
293 || type == DROPBEAR_SIGNKEY_ECDSA_NISTP384
294 || type == DROPBEAR_SIGNKEY_ECDSA_NISTP521)
279 { 295 {
280 ecc_key **eck = signkey_ecc_key_ptr(key, type); 296 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, type);
281 if (eck) { 297 if (eck) {
282 buf_put_ecdsa_pub_key(pubkeys, *eck); 298 buf_put_ecdsa_pub_key(pubkeys, *eck);
283 } 299 }
284 } 300 }
285 #endif 301 #endif
291 buf_free(pubkeys); 307 buf_free(pubkeys);
292 TRACE2(("leave buf_put_pub_key")) 308 TRACE2(("leave buf_put_pub_key"))
293 } 309 }
294 310
295 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */ 311 /* type is either DROPBEAR_SIGNKEY_DSS or DROPBEAR_SIGNKEY_RSA */
296 void buf_put_priv_key(buffer* buf, sign_key *key, int type) { 312 void buf_put_priv_key(buffer* buf, sign_key *key, enum signkey_type type) {
297 313
298 TRACE(("enter buf_put_priv_key")) 314 TRACE(("enter buf_put_priv_key"))
299 TRACE(("type is %d", type)) 315 TRACE(("type is %d", type))
300 316
301 #ifdef DROPBEAR_DSS 317 #ifdef DROPBEAR_DSS
312 return; 328 return;
313 } 329 }
314 #endif 330 #endif
315 #ifdef DROPBEAR_ECDSA 331 #ifdef DROPBEAR_ECDSA
316 { 332 {
317 ecc_key **eck = signkey_ecc_key_ptr(key, type); 333 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, type);
318 if (eck) { 334 if (eck) {
319 buf_put_ecdsa_priv_key(buf, *eck); 335 buf_put_ecdsa_priv_key(buf, *eck);
320 TRACE(("leave buf_put_priv_key: ecdsa done")) 336 TRACE(("leave buf_put_priv_key: ecdsa done"))
321 return; 337 return;
322 } 338 }
450 #else 466 #else
451 return sign_key_sha1_fingerprint(keyblob, keybloblen); 467 return sign_key_sha1_fingerprint(keyblob, keybloblen);
452 #endif 468 #endif
453 } 469 }
454 470
455 void buf_put_sign(buffer* buf, sign_key *key, int type, 471 void buf_put_sign(buffer* buf, sign_key *key, enum signkey_type type,
456 buffer *data_buf) { 472 buffer *data_buf) {
457 buffer *sigblob; 473 buffer *sigblob;
458 sigblob = buf_new(MAX_PUBKEY_SIZE); 474 sigblob = buf_new(MAX_PUBKEY_SIZE);
459 475
460 #ifdef DROPBEAR_DSS 476 #ifdef DROPBEAR_DSS
467 buf_put_rsa_sign(sigblob, key->rsakey, data_buf); 483 buf_put_rsa_sign(sigblob, key->rsakey, data_buf);
468 } 484 }
469 #endif 485 #endif
470 #ifdef DROPBEAR_ECDSA 486 #ifdef DROPBEAR_ECDSA
471 { 487 {
472 ecc_key **eck = signkey_ecc_key_ptr(key, type); 488 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, type);
473 if (eck) { 489 if (eck) {
474 buf_put_ecdsa_sign(sigblob, *eck, data_buf); 490 buf_put_ecdsa_sign(sigblob, *eck, data_buf);
475 } 491 }
476 } 492 }
477 #endif 493 #endif
518 return buf_rsa_verify(buf, key->rsakey, data_buf); 534 return buf_rsa_verify(buf, key->rsakey, data_buf);
519 } 535 }
520 #endif 536 #endif
521 #ifdef DROPBEAR_ECDSA 537 #ifdef DROPBEAR_ECDSA
522 { 538 {
523 ecc_key **eck = signkey_ecc_key_ptr(key, type); 539 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, type);
524 if (eck) { 540 if (eck) {
525 return buf_ecdsa_verify(buf, *eck, data_buf); 541 return buf_ecdsa_verify(buf, *eck, data_buf);
526 } 542 }
527 } 543 }
528 #endif 544 #endif