Bugfix: correct privkey serialization

This commit is contained in:
Pieter Wuille 2013-05-10 00:52:28 +02:00
parent 0a433ea23c
commit 4bef497b9c
1 changed files with 12 additions and 20 deletions

View File

@ -260,14 +260,11 @@ int static secp256k1_ecdsa_privkey_serialize(unsigned char *privkey, int *privke
0xCE,0x3D,0x01,0x01,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F,0x30,0x06,0x04,0x01,0x00,0x04,0x01,0x07,0x04,
0x21
};
static const unsigned char end[] = {
0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,0x8C,0xD0,
0x36,0x41,0x41,0x02,0x01,0x01,0xA1,0x24,0x03,0x22,0x00,0x03,0x18,0x39,0x05,0xAE,
0x25,0xE8,0x15,0x63,0x4C,0xE7,0xF5,0xD9,0xBE,0xDB,0xAA,0x2C,0x39,0x03,0x2A,0xB9,
0x8C,0x75,0xB5,0xE8,0x8F,0xE4,0x3F,0x8D,0xD8,0x24,0x6F,0x3C
0x21,0x02,0x79,0xBE,0x66,0x7E,0xF9,0xDC,0xBB,0xAC,0x55,0xA0,0x62,0x95,0xCE,0x87,
0x0B,0x07,0x02,0x9B,0xFC,0xDB,0x2D,0xCE,0x28,0xD9,0x59,0xF2,0x81,0x5B,0x16,0xF8,
0x17,0x98,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,
0x8C,0xD0,0x36,0x41,0x41,0x02,0x01,0x01,0xA1,0x24,0x03,0x22,0x00
};
unsigned char *ptr = privkey;
memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
@ -275,7 +272,6 @@ int static secp256k1_ecdsa_privkey_serialize(unsigned char *privkey, int *privke
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
int pubkeylen = 0;
secp256k1_ecdsa_pubkey_serialize(&r, ptr, &pubkeylen, 1); ptr += pubkeylen;
memcpy(ptr, end, sizeof(end)); ptr += sizeof(end);
*privkeylen = ptr - privkey;
} else {
static const unsigned char begin[] = {
@ -286,16 +282,13 @@ int static secp256k1_ecdsa_privkey_serialize(unsigned char *privkey, int *privke
0xCE,0x3D,0x01,0x01,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFE,0xFF,0xFF,0xFC,0x2F,0x30,0x06,0x04,0x01,0x00,0x04,0x01,0x07,0x04,
0x41
};
static const unsigned char end[] = {
0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,0x8C,0xD0,
0x36,0x41,0x41,0x02,0x01,0x01,0xA1,0x44,0x03,0x42,0x00,0x04,0x18,0x39,0x05,0xAE,
0x25,0xE8,0x15,0x63,0x4C,0xE7,0xF5,0xD9,0xBE,0xDB,0xAA,0x2C,0x39,0x03,0x2A,0xB9,
0x8C,0x75,0xB5,0xE8,0x8F,0xE4,0x3F,0x8D,0xD8,0x24,0x6F,0x3C,0x54,0x73,0xCC,0xD4,
0xAB,0x47,0x5E,0x6A,0x9E,0x66,0x20,0xB5,0x2F,0x5C,0xE2,0xFD,0x15,0xA2,0xDE,0x32,
0xCB,0xE9,0x05,0x15,0x4B,0x3A,0x05,0x84,0x4A,0xF7,0x07,0x85
0x41,0x04,0x79,0xBE,0x66,0x7E,0xF9,0xDC,0xBB,0xAC,0x55,0xA0,0x62,0x95,0xCE,0x87,
0x0B,0x07,0x02,0x9B,0xFC,0xDB,0x2D,0xCE,0x28,0xD9,0x59,0xF2,0x81,0x5B,0x16,0xF8,
0x17,0x98,0x48,0x3A,0xDA,0x77,0x26,0xA3,0xC4,0x65,0x5D,0xA4,0xFB,0xFC,0x0E,0x11,
0x08,0xA8,0xFD,0x17,0xB4,0x48,0xA6,0x85,0x54,0x19,0x9C,0x47,0xD0,0x8F,0xFB,0x10,
0xD4,0xB8,0x02,0x21,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
0xFF,0xFF,0xFF,0xFF,0xFE,0xBA,0xAE,0xDC,0xE6,0xAF,0x48,0xA0,0x3B,0xBF,0xD2,0x5E,
0x8C,0xD0,0x36,0x41,0x41,0x02,0x01,0x01,0xA1,0x44,0x03,0x42,0x00
};
unsigned char *ptr = privkey;
memcpy(ptr, begin, sizeof(begin)); ptr += sizeof(begin);
@ -303,7 +296,6 @@ int static secp256k1_ecdsa_privkey_serialize(unsigned char *privkey, int *privke
memcpy(ptr, middle, sizeof(middle)); ptr += sizeof(middle);
int pubkeylen = 0;
secp256k1_ecdsa_pubkey_serialize(&r, ptr, &pubkeylen, 0); ptr += pubkeylen;
memcpy(ptr, end, sizeof(end)); ptr += sizeof(end);
*privkeylen = ptr - privkey;
}
return 1;