comparison dss.c @ 760:f336d232fc63 ecc

Make _sign and _verify functions take a buffer* rather than void* and int
author Matt Johnston <matt@ucc.asn.au>
date Sat, 06 Apr 2013 16:00:37 +0800
parents d6067dd60490
children 7dcb46da72d9
comparison
equal deleted inserted replaced
759:76fba0856749 760:f336d232fc63
159 } 159 }
160 160
161 #ifdef DROPBEAR_SIGNKEY_VERIFY 161 #ifdef DROPBEAR_SIGNKEY_VERIFY
162 /* Verify a DSS signature (in buf) made on data by the key given. 162 /* Verify a DSS signature (in buf) made on data by the key given.
163 * returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */ 163 * returns DROPBEAR_SUCCESS or DROPBEAR_FAILURE */
164 int buf_dss_verify(buffer* buf, dropbear_dss_key *key, const unsigned char* data, 164 int buf_dss_verify(buffer* buf, dropbear_dss_key *key, buffer *data_buf) {
165 unsigned int len) {
166
167 unsigned char msghash[SHA1_HASH_SIZE]; 165 unsigned char msghash[SHA1_HASH_SIZE];
168 hash_state hs; 166 hash_state hs;
169 int ret = DROPBEAR_FAILURE; 167 int ret = DROPBEAR_FAILURE;
170 DEF_MP_INT(val1); 168 DEF_MP_INT(val1);
171 DEF_MP_INT(val2); 169 DEF_MP_INT(val2);
185 goto out; 183 goto out;
186 } 184 }
187 185
188 /* hash the data */ 186 /* hash the data */
189 sha1_init(&hs); 187 sha1_init(&hs);
190 sha1_process(&hs, data, len); 188 sha1_process(&hs, data_buf->data, data_buf->len);
191 sha1_done(&hs, msghash); 189 sha1_done(&hs, msghash);
192 190
193 /* create the signature - s' and r' are the received signatures in buf */ 191 /* create the signature - s' and r' are the received signatures in buf */
194 /* w = (s')-1 mod q */ 192 /* w = (s')-1 mod q */
195 /* let val1 = s' */ 193 /* let val1 = s' */
258 } 256 }
259 #endif /* DROPBEAR_SIGNKEY_VERIFY */ 257 #endif /* DROPBEAR_SIGNKEY_VERIFY */
260 258
261 /* Sign the data presented with key, writing the signature contents 259 /* Sign the data presented with key, writing the signature contents
262 * to the buffer */ 260 * to the buffer */
263 void buf_put_dss_sign(buffer* buf, dropbear_dss_key *key, const unsigned char* data, 261 void buf_put_dss_sign(buffer* buf, dropbear_dss_key *key, buffer *data_buf) {
264 unsigned int len) {
265
266 unsigned char msghash[SHA1_HASH_SIZE]; 262 unsigned char msghash[SHA1_HASH_SIZE];
267 unsigned int writelen; 263 unsigned int writelen;
268 unsigned int i; 264 unsigned int i;
269 DEF_MP_INT(dss_k); 265 DEF_MP_INT(dss_k);
270 DEF_MP_INT(dss_m); 266 DEF_MP_INT(dss_m);
277 TRACE(("enter buf_put_dss_sign")) 273 TRACE(("enter buf_put_dss_sign"))
278 dropbear_assert(key != NULL); 274 dropbear_assert(key != NULL);
279 275
280 /* hash the data */ 276 /* hash the data */
281 sha1_init(&hs); 277 sha1_init(&hs);
282 sha1_process(&hs, data, len); 278 sha1_process(&hs, data_buf->data, data_buf->len);
283 sha1_done(&hs, msghash); 279 sha1_done(&hs, msghash);
284 280
285 m_mp_init_multi(&dss_k, &dss_temp1, &dss_temp2, &dss_r, &dss_s, 281 m_mp_init_multi(&dss_k, &dss_temp1, &dss_temp2, &dss_r, &dss_s,
286 &dss_m, NULL); 282 &dss_m, NULL);
287 /* the random number generator's input has included the private key which 283 /* the random number generator's input has included the private key which