update ECDSA support

This commit is contained in:
NIIBE Yutaka
2013-03-09 10:08:32 +09:00
parent c90358dd5a
commit 4436903116
2 changed files with 20 additions and 10 deletions

View File

@@ -288,7 +288,7 @@ flash_key_alloc (void)
int int
flash_key_write (uint8_t *key_addr, const uint8_t *key_data, flash_key_write (uint8_t *key_addr, const uint8_t *key_data,
const uint8_t *modulus) const uint8_t *pubkey, int pubkey_len)
{ {
uint16_t hw; uint16_t hw;
uint32_t addr; uint32_t addr;
@@ -303,9 +303,9 @@ flash_key_write (uint8_t *key_addr, const uint8_t *key_data,
addr += 2; addr += 2;
} }
for (i = 0; i < KEY_CONTENT_LEN/2; i ++) for (i = 0; i < pubkey_len/2; i ++)
{ {
hw = modulus[i*2] | (modulus[i*2+1]<<8); hw = pubkey[i*2] | (pubkey[i*2+1]<<8);
if (flash_program_halfword (addr, hw) != 0) if (flash_program_halfword (addr, hw) != 0)
return -1; return -1;
addr += 2; addr += 2;

View File

@@ -743,6 +743,7 @@ gpg_do_write_prvkey (enum kind_of_key kk, const uint8_t *key_data, int key_len,
int pubkey_allocated_here = 0; int pubkey_allocated_here = 0;
uint8_t ks_pw1_len = 0; uint8_t ks_pw1_len = 0;
uint8_t ks_rc_len = 0; uint8_t ks_rc_len = 0;
int pubkey_len = KEY_CONTENT_LEN;
DEBUG_INFO ("Key import\r\n"); DEBUG_INFO ("Key import\r\n");
DEBUG_SHORT (key_len); DEBUG_SHORT (key_len);
@@ -753,8 +754,12 @@ gpg_do_write_prvkey (enum kind_of_key kk, const uint8_t *key_data, int key_len,
if (kk != GPG_KEY_FOR_AUTHENTICATION && key_len != KEY_CONTENT_LEN) if (kk != GPG_KEY_FOR_AUTHENTICATION && key_len != KEY_CONTENT_LEN)
return -1; return -1;
if (kk == GPG_KEY_FOR_AUTHENTICATION && key_len != 32) if (kk == GPG_KEY_FOR_AUTHENTICATION)
{
pubkey_len = key_len * 2;
if (key_len != 32)
return -1; return -1;
}
pd = (struct prvkey_data *)malloc (sizeof (struct prvkey_data)); pd = (struct prvkey_data *)malloc (sizeof (struct prvkey_data));
if (pd == NULL) if (pd == NULL)
@@ -779,9 +784,9 @@ gpg_do_write_prvkey (enum kind_of_key kk, const uint8_t *key_data, int key_len,
key_addr = flash_key_alloc (); key_addr = flash_key_alloc ();
if (key_addr == NULL) if (key_addr == NULL)
{ {
free (pd);
if (pubkey_allocated_here) if (pubkey_allocated_here)
free ((void *)pubkey); free ((void *)pubkey);
free (pd);
return -1; return -1;
} }
@@ -807,7 +812,7 @@ gpg_do_write_prvkey (enum kind_of_key kk, const uint8_t *key_data, int key_len,
encrypt (dek, iv, (uint8_t *)&kdi, sizeof (struct key_data_internal)); encrypt (dek, iv, (uint8_t *)&kdi, sizeof (struct key_data_internal));
r = flash_key_write (key_addr, (const uint8_t *)kdi.data, pubkey); r = flash_key_write (key_addr, (const uint8_t *)kdi.data, pubkey, pubkey_len);
if (pubkey_allocated_here) if (pubkey_allocated_here)
free ((void *)pubkey); free ((void *)pubkey);
@@ -1536,11 +1541,16 @@ gpg_do_public_key (uint8_t kk_byte)
} }
else else
{ /* ECDSA */ { /* ECDSA */
/* LEN = 2+1+64 */ /* LEN */
*res_p++ = 0x43; *res_p++ = 2 + 8 + 2 + 1 + 64;
{ {
/*TAG*/ /* LEN = 8 */
*res_p++ = 0x06; *res_p++ = 0x08;
memcpy (res_p, algorithm_attr_ecdsa+2, 8);
res_p += 8;
/*TAG*/ /* LEN = 1+64 */ /*TAG*/ /* LEN = 1+64 */
*res_p++ = 0x81; *res_p++ = 0x41; *res_p++ = 0x86; *res_p++ = 0x41;
*res_p++ = 0x04; /* No compression of EC point. */ *res_p++ = 0x04; /* No compression of EC point. */
/* 64-byte binary (big endian) */ /* 64-byte binary (big endian) */
memcpy (res_p, key_addr + KEY_CONTENT_LEN, 64); memcpy (res_p, key_addr + KEY_CONTENT_LEN, 64);