comparison keyimport.c @ 867:d2d624c951ca

- Increase buffer size, fixes converting 521bit ECC key - Fix assertion that key size is exactly curve size
author Matt Johnston <matt@ucc.asn.au>
date Wed, 27 Nov 2013 21:30:05 +0800
parents c19acba28590
children 25692c60479e
comparison
equal deleted inserted replaced
865:39d872718d4b 867:d2d624c951ca
1031 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, key->type); 1031 ecc_key **eck = (ecc_key**)signkey_key_ptr(key, key->type);
1032 const long curve_size = (*eck)->dp->size; 1032 const long curve_size = (*eck)->dp->size;
1033 int curve_oid_len = 0; 1033 int curve_oid_len = 0;
1034 const void* curve_oid = NULL; 1034 const void* curve_oid = NULL;
1035 unsigned long pubkey_size = 2*curve_size+1; 1035 unsigned long pubkey_size = 2*curve_size+1;
1036 unsigned int k_size;
1036 1037
1037 /* version. less than 10 bytes */ 1038 /* version. less than 10 bytes */
1038 buf_incrwritepos(seq_buf, 1039 buf_incrwritepos(seq_buf,
1039 ber_write_id_len(buf_getwriteptr(seq_buf, 10), 2, 1, 0)); 1040 ber_write_id_len(buf_getwriteptr(seq_buf, 10), 2, 1, 0));
1040 buf_putbyte(seq_buf, 1); 1041 buf_putbyte(seq_buf, 1);
1041 1042
1042 /* privateKey */ 1043 /* privateKey */
1043 dropbear_assert(mp_unsigned_bin_size((*eck)->k) == curve_size); 1044 k_size = mp_unsigned_bin_size((*eck)->k);
1045 dropbear_assert(k_size <= curve_size);
1044 buf_incrwritepos(seq_buf, 1046 buf_incrwritepos(seq_buf,
1045 ber_write_id_len(buf_getwriteptr(seq_buf, 10), 4, curve_size, 0)); 1047 ber_write_id_len(buf_getwriteptr(seq_buf, 10), 4, k_size, 0));
1046 mp_to_unsigned_bin((*eck)->k, buf_getwriteptr(seq_buf, curve_size)); 1048 mp_to_unsigned_bin((*eck)->k, buf_getwriteptr(seq_buf, k_size));
1047 buf_incrwritepos(seq_buf, curve_size); 1049 buf_incrwritepos(seq_buf, k_size);
1048 1050
1049 /* SECGCurveNames */ 1051 /* SECGCurveNames */
1050 switch (key->type) 1052 switch (key->type)
1051 { 1053 {
1052 case DROPBEAR_SIGNKEY_ECDSA_NISTP256: 1054 case DROPBEAR_SIGNKEY_ECDSA_NISTP256:
1083 } 1085 }
1084 buf_incrwritepos(seq_buf, pubkey_size); 1086 buf_incrwritepos(seq_buf, pubkey_size);
1085 1087
1086 buf_setpos(seq_buf, 0); 1088 buf_setpos(seq_buf, 0);
1087 1089
1088 outblob = (unsigned char*)m_malloc(200); 1090 outblob = (unsigned char*)m_malloc(1000);
1089 1091
1090 pos = 0; 1092 pos = 0;
1091 pos += ber_write_id_len(outblob+pos, 16, seq_buf->len, ASN1_CONSTRUCTED); 1093 pos += ber_write_id_len(outblob+pos, 16, seq_buf->len, ASN1_CONSTRUCTED);
1092 memcpy(&outblob[pos], seq_buf->data, seq_buf->len); 1094 memcpy(&outblob[pos], seq_buf->data, seq_buf->len);
1093 pos += seq_buf->len; 1095 pos += seq_buf->len;