comparison ecc.c @ 768:6e6ce39da2fc ecc

A bit of debugging output
author Matt Johnston <matt@ucc.asn.au>
date Tue, 09 Apr 2013 22:47:03 +0800
parents e465ed10c51d
children 70625eed40c9
comparison
equal deleted inserted replaced
767:e465ed10c51d 768:6e6ce39da2fc
140 /* For the "ephemeral public key octet string" in ECDH (rfc5656 section 4) */ 140 /* For the "ephemeral public key octet string" in ECDH (rfc5656 section 4) */
141 ecc_key * buf_get_ecc_raw_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve) { 141 ecc_key * buf_get_ecc_raw_pubkey(buffer *buf, const struct dropbear_ecc_curve *curve) {
142 ecc_key *key = NULL; 142 ecc_key *key = NULL;
143 int ret = DROPBEAR_FAILURE; 143 int ret = DROPBEAR_FAILURE;
144 const unsigned int size = curve->dp->size; 144 const unsigned int size = curve->dp->size;
145 unsigned char first;
146
147 TRACE(("enter buf_get_ecc_raw_pubkey"))
148
145 buf_setpos(buf, 0); 149 buf_setpos(buf, 0);
146 unsigned int len = buf->len; 150 first = buf_getbyte(buf);
147 unsigned char first = buf_getbyte(buf);
148 if (first == 2 || first == 3) { 151 if (first == 2 || first == 3) {
149 dropbear_log(LOG_WARNING, "Dropbear doesn't support ECC point compression"); 152 dropbear_log(LOG_WARNING, "Dropbear doesn't support ECC point compression");
150 return NULL; 153 return NULL;
151 } 154 }
152 if (first != 4 || len != 1+2*size) { 155 if (first != 4 || buf->len != 1+2*size) {
156 TRACE(("leave, wrong size"))
153 return NULL; 157 return NULL;
154 } 158 }
155 159
156 key = new_ecc_key(); 160 key = new_ecc_key();
157 key->dp = curve->dp; 161 key->dp = curve->dp;
158 162
159 if (mp_read_unsigned_bin(key->pubkey.x, buf_getptr(buf, size), size) != MP_OKAY) { 163 if (mp_read_unsigned_bin(key->pubkey.x, buf_getptr(buf, size), size) != MP_OKAY) {
164 TRACE(("failed to read x"))
160 goto out; 165 goto out;
161 } 166 }
162 buf_incrpos(buf, size); 167 buf_incrpos(buf, size);
163 168
164 if (mp_read_unsigned_bin(key->pubkey.y, buf_getptr(buf, size), size) != MP_OKAY) { 169 if (mp_read_unsigned_bin(key->pubkey.y, buf_getptr(buf, size), size) != MP_OKAY) {
170 TRACE(("failed to read y"))
165 goto out; 171 goto out;
166 } 172 }
167 buf_incrpos(buf, size); 173 buf_incrpos(buf, size);
168 174
169 mp_set(key->pubkey.z, 1); 175 mp_set(key->pubkey.z, 1);
170 176
171 if (ecc_is_point(key) != CRYPT_OK) { 177 if (ecc_is_point(key) != CRYPT_OK) {
178 TRACE(("failed, not a point"))
172 goto out; 179 goto out;
173 } 180 }
174 181
175 // SEC1 3.2.3.1 Check that Q != 0 182 // SEC1 3.2.3.1 Check that Q != 0
176 if (mp_cmp_d(key->pubkey.x, 0) == LTC_MP_EQ) { 183 if (mp_cmp_d(key->pubkey.x, 0) == LTC_MP_EQ) {
184 TRACE(("failed, x == 0"))
177 goto out; 185 goto out;
178 } 186 }
179 if (mp_cmp_d(key->pubkey.y, 0) == LTC_MP_EQ) { 187 if (mp_cmp_d(key->pubkey.y, 0) == LTC_MP_EQ) {
188 TRACE(("failed, y == 0"))
180 goto out; 189 goto out;
181 } 190 }
182 191
183 ret = DROPBEAR_SUCCESS; 192 ret = DROPBEAR_SUCCESS;
184 193