comparison dss.c @ 241:c5d3ef11155f

* use own assertions which should get logged properly
author Matt Johnston <matt@ucc.asn.au>
date Mon, 05 Sep 2005 15:16:10 +0000
parents c9483550701b
children 454a34b2dfd1 ed910547d449
comparison
equal deleted inserted replaced
238:e923801a7678 241:c5d3ef11155f
44 * These should be freed with dss_key_free. 44 * These should be freed with dss_key_free.
45 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 45 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
46 int buf_get_dss_pub_key(buffer* buf, dss_key *key) { 46 int buf_get_dss_pub_key(buffer* buf, dss_key *key) {
47 47
48 TRACE(("enter buf_get_dss_pub_key")) 48 TRACE(("enter buf_get_dss_pub_key"))
49 assert(key != NULL); 49 dropbear_assert(key != NULL);
50 key->p = m_malloc(sizeof(mp_int)); 50 key->p = m_malloc(sizeof(mp_int));
51 key->q = m_malloc(sizeof(mp_int)); 51 key->q = m_malloc(sizeof(mp_int));
52 key->g = m_malloc(sizeof(mp_int)); 52 key->g = m_malloc(sizeof(mp_int));
53 key->y = m_malloc(sizeof(mp_int)); 53 key->y = m_malloc(sizeof(mp_int));
54 m_mp_init_multi(key->p, key->q, key->g, key->y, NULL); 54 m_mp_init_multi(key->p, key->q, key->g, key->y, NULL);
78 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 78 * Returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
79 int buf_get_dss_priv_key(buffer* buf, dss_key *key) { 79 int buf_get_dss_priv_key(buffer* buf, dss_key *key) {
80 80
81 int ret = DROPBEAR_FAILURE; 81 int ret = DROPBEAR_FAILURE;
82 82
83 assert(key != NULL); 83 dropbear_assert(key != NULL);
84 84
85 ret = buf_get_dss_pub_key(buf, key); 85 ret = buf_get_dss_pub_key(buf, key);
86 if (ret == DROPBEAR_FAILURE) { 86 if (ret == DROPBEAR_FAILURE) {
87 return DROPBEAR_FAILURE; 87 return DROPBEAR_FAILURE;
88 } 88 }
135 * mpint g 135 * mpint g
136 * mpint y 136 * mpint y
137 */ 137 */
138 void buf_put_dss_pub_key(buffer* buf, dss_key *key) { 138 void buf_put_dss_pub_key(buffer* buf, dss_key *key) {
139 139
140 assert(key != NULL); 140 dropbear_assert(key != NULL);
141 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN); 141 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN);
142 buf_putmpint(buf, key->p); 142 buf_putmpint(buf, key->p);
143 buf_putmpint(buf, key->q); 143 buf_putmpint(buf, key->q);
144 buf_putmpint(buf, key->g); 144 buf_putmpint(buf, key->g);
145 buf_putmpint(buf, key->y); 145 buf_putmpint(buf, key->y);
147 } 147 }
148 148
149 /* Same as buf_put_dss_pub_key, but with the private "x" key appended */ 149 /* Same as buf_put_dss_pub_key, but with the private "x" key appended */
150 void buf_put_dss_priv_key(buffer* buf, dss_key *key) { 150 void buf_put_dss_priv_key(buffer* buf, dss_key *key) {
151 151
152 assert(key != NULL); 152 dropbear_assert(key != NULL);
153 buf_put_dss_pub_key(buf, key); 153 buf_put_dss_pub_key(buf, key);
154 buf_putmpint(buf, key->x); 154 buf_putmpint(buf, key->x);
155 155
156 } 156 }
157 157
170 DEF_MP_INT(val4); 170 DEF_MP_INT(val4);
171 char * string = NULL; 171 char * string = NULL;
172 int stringlen; 172 int stringlen;
173 173
174 TRACE(("enter buf_dss_verify")) 174 TRACE(("enter buf_dss_verify"))
175 assert(key != NULL); 175 dropbear_assert(key != NULL);
176 176
177 m_mp_init_multi(&val1, &val2, &val3, &val4, NULL); 177 m_mp_init_multi(&val1, &val2, &val3, &val4, NULL);
178 178
179 /* get blob, check length */ 179 /* get blob, check length */
180 string = buf_getstring(buf, &stringlen); 180 string = buf_getstring(buf, &stringlen);
308 DEF_MP_INT(dss_r); 308 DEF_MP_INT(dss_r);
309 DEF_MP_INT(dss_s); 309 DEF_MP_INT(dss_s);
310 hash_state hs; 310 hash_state hs;
311 311
312 TRACE(("enter buf_put_dss_sign")) 312 TRACE(("enter buf_put_dss_sign"))
313 assert(key != NULL); 313 dropbear_assert(key != NULL);
314 314
315 /* hash the data */ 315 /* hash the data */
316 sha1_init(&hs); 316 sha1_init(&hs);
317 sha1_process(&hs, data, len); 317 sha1_process(&hs, data, len);
318 sha1_done(&hs, msghash); 318 sha1_done(&hs, msghash);
378 378
379 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN); 379 buf_putstring(buf, SSH_SIGNKEY_DSS, SSH_SIGNKEY_DSS_LEN);
380 buf_putint(buf, 2*SHA1_HASH_SIZE); 380 buf_putint(buf, 2*SHA1_HASH_SIZE);
381 381
382 writelen = mp_unsigned_bin_size(&dss_r); 382 writelen = mp_unsigned_bin_size(&dss_r);
383 assert(writelen <= SHA1_HASH_SIZE); 383 dropbear_assert(writelen <= SHA1_HASH_SIZE);
384 /* need to pad to 160 bits with leading zeros */ 384 /* need to pad to 160 bits with leading zeros */
385 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) { 385 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) {
386 buf_putbyte(buf, 0); 386 buf_putbyte(buf, 0);
387 } 387 }
388 if (mp_to_unsigned_bin(&dss_r, buf_getwriteptr(buf, writelen)) 388 if (mp_to_unsigned_bin(&dss_r, buf_getwriteptr(buf, writelen))
391 } 391 }
392 mp_clear(&dss_r); 392 mp_clear(&dss_r);
393 buf_incrwritepos(buf, writelen); 393 buf_incrwritepos(buf, writelen);
394 394
395 writelen = mp_unsigned_bin_size(&dss_s); 395 writelen = mp_unsigned_bin_size(&dss_s);
396 assert(writelen <= SHA1_HASH_SIZE); 396 dropbear_assert(writelen <= SHA1_HASH_SIZE);
397 /* need to pad to 160 bits with leading zeros */ 397 /* need to pad to 160 bits with leading zeros */
398 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) { 398 for (i = 0; i < SHA1_HASH_SIZE - writelen; i++) {
399 buf_putbyte(buf, 0); 399 buf_putbyte(buf, 0);
400 } 400 }
401 if (mp_to_unsigned_bin(&dss_s, buf_getwriteptr(buf, writelen)) 401 if (mp_to_unsigned_bin(&dss_s, buf_getwriteptr(buf, writelen))