Skip to content

Commit ca4546e

Browse files
Modified values.OID (add secp256k1 and brainpoolP384r1)
1 parent 81f52dd commit ca4546e

File tree

8 files changed

+253
-8
lines changed

8 files changed

+253
-8
lines changed

packet/values/ecc.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ import (
1313
type OID []byte
1414

1515
var oidList = map[string][]byte{
16-
"NIST P-256": {0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07},
17-
"NIST P-384": {0x2b, 0x81, 0x04, 0x00, 0x22},
18-
"NIST P-521": {0x2b, 0x81, 0x04, 0x00, 0x23},
16+
"nistp256": {0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07},
17+
"secp256k1": {0x2b, 0x81, 0x04, 0x00, 0x0a},
18+
"nistp384": {0x2b, 0x81, 0x04, 0x00, 0x22},
19+
"nistp521": {0x2b, 0x81, 0x04, 0x00, 0x23},
1920
"brainpoolP256r1": {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x07},
21+
"brainpoolP384r1": {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B},
2022
"brainpoolP512r1": {0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D},
21-
"Ed25519": {0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01},
22-
"Curve25519": {0x2B, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01},
23+
"ed25519": {0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01},
24+
"cv25519": {0x2B, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01},
2325
}
2426

2527
//NewOID returns OID instance

packet/values/ecc_test.go

Lines changed: 147 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func TestEccNITSP256(t *testing.T) {
1212
data := []byte{0x08, 0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07}
1313
dump := "2a 86 48 ce 3d 03 01 07"
14-
note := "NIST P-256"
14+
note := "nistp256"
1515
reader := reader.New(data)
1616
oid, err := NewOID(reader)
1717
if err != nil {
@@ -35,7 +35,7 @@ func TestEccNITSP256(t *testing.T) {
3535
func TestEccNITSP384(t *testing.T) {
3636
data := []byte{0x05, 0x2b, 0x81, 0x04, 0x00, 0x22}
3737
dump := "2b 81 04 00 22"
38-
note := "NIST P-384"
38+
note := "nistp384"
3939
reader := reader.New(data)
4040
oid, err := NewOID(reader)
4141
if err != nil {
@@ -59,7 +59,151 @@ func TestEccNITSP384(t *testing.T) {
5959
func TestEccNITSP521(t *testing.T) {
6060
data := []byte{0x05, 0x2b, 0x81, 0x04, 0x00, 0x23}
6161
dump := "2b 81 04 00 23"
62-
note := "NIST P-521"
62+
note := "nistp521"
63+
reader := reader.New(data)
64+
oid, err := NewOID(reader)
65+
if err != nil {
66+
t.Errorf("OID = \"%v\", want nil.", err.Error())
67+
}
68+
i := oid.ToItem(true)
69+
if i.Name != "ECC OID" {
70+
t.Errorf("OID.Name = \"%v\", want \"ECC OID\".", i.Name)
71+
}
72+
if i.Value != note {
73+
t.Errorf("OID.Value = \"%v\", want \"%s\"", i.Value, note)
74+
}
75+
if i.Note != "" {
76+
t.Errorf("OID.Note = \"%v\", want \"\".", i.Note)
77+
}
78+
if i.Dump != dump {
79+
t.Errorf("OIS.Dump = \"%v\", want \"%s\".", i.Dump, dump)
80+
}
81+
}
82+
83+
func TestEccSecp256k1(t *testing.T) {
84+
data := []byte{0x05, 0x2b, 0x81, 0x04, 0x00, 0x0a}
85+
dump := "2b 81 04 00 0a"
86+
note := "secp256k1"
87+
reader := reader.New(data)
88+
oid, err := NewOID(reader)
89+
if err != nil {
90+
t.Errorf("OID = \"%v\", want nil.", err.Error())
91+
}
92+
i := oid.ToItem(true)
93+
if i.Name != "ECC OID" {
94+
t.Errorf("OID.Name = \"%v\", want \"ECC OID\".", i.Name)
95+
}
96+
if i.Value != note {
97+
t.Errorf("OID.Value = \"%v\", want \"%s\"", i.Value, note)
98+
}
99+
if i.Note != "" {
100+
t.Errorf("OID.Note = \"%v\", want \"\".", i.Note)
101+
}
102+
if i.Dump != dump {
103+
t.Errorf("OIS.Dump = \"%v\", want \"%s\".", i.Dump, dump)
104+
}
105+
}
106+
107+
func TestEccBrainpoolP256r1(t *testing.T) {
108+
data := []byte{0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x07}
109+
dump := "2b 24 03 03 02 08 01 01 07"
110+
note := "brainpoolP256r1"
111+
reader := reader.New(data)
112+
oid, err := NewOID(reader)
113+
if err != nil {
114+
t.Errorf("OID = \"%v\", want nil.", err.Error())
115+
}
116+
i := oid.ToItem(true)
117+
if i.Name != "ECC OID" {
118+
t.Errorf("OID.Name = \"%v\", want \"ECC OID\".", i.Name)
119+
}
120+
if i.Value != note {
121+
t.Errorf("OID.Value = \"%v\", want \"%s\"", i.Value, note)
122+
}
123+
if i.Note != "" {
124+
t.Errorf("OID.Note = \"%v\", want \"\".", i.Note)
125+
}
126+
if i.Dump != dump {
127+
t.Errorf("OIS.Dump = \"%v\", want \"%s\".", i.Dump, dump)
128+
}
129+
}
130+
131+
func TestEccBrainpoolP384r1(t *testing.T) {
132+
data := []byte{0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0B}
133+
dump := "2b 24 03 03 02 08 01 01 0b"
134+
note := "brainpoolP384r1"
135+
reader := reader.New(data)
136+
oid, err := NewOID(reader)
137+
if err != nil {
138+
t.Errorf("OID = \"%v\", want nil.", err.Error())
139+
}
140+
i := oid.ToItem(true)
141+
if i.Name != "ECC OID" {
142+
t.Errorf("OID.Name = \"%v\", want \"ECC OID\".", i.Name)
143+
}
144+
if i.Value != note {
145+
t.Errorf("OID.Value = \"%v\", want \"%s\"", i.Value, note)
146+
}
147+
if i.Note != "" {
148+
t.Errorf("OID.Note = \"%v\", want \"\".", i.Note)
149+
}
150+
if i.Dump != dump {
151+
t.Errorf("OIS.Dump = \"%v\", want \"%s\".", i.Dump, dump)
152+
}
153+
}
154+
155+
func TestEccBrainpoolP512r1(t *testing.T) {
156+
data := []byte{0x09, 0x2B, 0x24, 0x03, 0x03, 0x02, 0x08, 0x01, 0x01, 0x0D}
157+
dump := "2b 24 03 03 02 08 01 01 0d"
158+
note := "brainpoolP512r1"
159+
reader := reader.New(data)
160+
oid, err := NewOID(reader)
161+
if err != nil {
162+
t.Errorf("OID = \"%v\", want nil.", err.Error())
163+
}
164+
i := oid.ToItem(true)
165+
if i.Name != "ECC OID" {
166+
t.Errorf("OID.Name = \"%v\", want \"ECC OID\".", i.Name)
167+
}
168+
if i.Value != note {
169+
t.Errorf("OID.Value = \"%v\", want \"%s\"", i.Value, note)
170+
}
171+
if i.Note != "" {
172+
t.Errorf("OID.Note = \"%v\", want \"\".", i.Note)
173+
}
174+
if i.Dump != dump {
175+
t.Errorf("OIS.Dump = \"%v\", want \"%s\".", i.Dump, dump)
176+
}
177+
}
178+
179+
func TestEccEd25519(t *testing.T) {
180+
data := []byte{0x09, 0x2B, 0x06, 0x01, 0x04, 0x01, 0xDA, 0x47, 0x0F, 0x01}
181+
dump := "2b 06 01 04 01 da 47 0f 01"
182+
note := "ed25519"
183+
reader := reader.New(data)
184+
oid, err := NewOID(reader)
185+
if err != nil {
186+
t.Errorf("OID = \"%v\", want nil.", err.Error())
187+
}
188+
i := oid.ToItem(true)
189+
if i.Name != "ECC OID" {
190+
t.Errorf("OID.Name = \"%v\", want \"ECC OID\".", i.Name)
191+
}
192+
if i.Value != note {
193+
t.Errorf("OID.Value = \"%v\", want \"%s\"", i.Value, note)
194+
}
195+
if i.Note != "" {
196+
t.Errorf("OID.Note = \"%v\", want \"\".", i.Note)
197+
}
198+
if i.Dump != dump {
199+
t.Errorf("OIS.Dump = \"%v\", want \"%s\".", i.Dump, dump)
200+
}
201+
}
202+
203+
func TestEccCurve25519(t *testing.T) {
204+
data := []byte{0x0a, 0x2B, 0x06, 0x01, 0x04, 0x01, 0x97, 0x55, 0x01, 0x05, 0x01}
205+
dump := "2b 06 01 04 01 97 55 01 05 01"
206+
note := "cv25519"
63207
reader := reader.New(data)
64208
oid, err := NewOID(reader)
65209
if err != nil {
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
-----BEGIN PGP PUBLIC KEY BLOCK-----
2+
3+
mHMEWiEvNRMJKyQDAwIIAQELAwMEgdAtVaD0EsbEGTEPIwhlNAuW7vhNYtb50NSJ
4+
etZInXalvNMKDvj6zei/wRepgsLsLf3VdoYzDnl10+RGRa0f66uBZE89RJtdyTQY
5+
g0UW+BKs/hkdKvuh0vRggIFSdKPmtBlBbGljZSA8YWxpY2VAZXhhbXBsZS5jb20+
6+
iLAEExMJADgWIQSJgaqNbnJvfgSQ7dzjtpw6WlAYnwUCWiEvNQIbAwULCQgHAgYV
7+
CAkKCwIEFgIDAQIeAQIXgAAKCRDjtpw6WlAYn6JwAX9hku81g2oO71e82u6ezVbb
8+
umGXYd83TgkmoyPCtD3DsFHsUaD5yEmBbsHVYzWOax8BfjZdIRqozsT6/qmqznGy
9+
8uQ7YLRvgzKnt9NZyLgnwMfPe+/QpLqvD+aSHCU4f8MFo7h3BFohLzUSCSskAwMC
10+
CAEBCwMDBD5bYDW80HIhpop3Xp51YUVS9r40lIa18maWl5/YcnAZLQzkuZ0IrpAi
11+
XBw7riJKlT071hBlrmpa5Kzq9IBDeaowTw5+Ui0neQelhp0uIubDqdxNSnXQRrUh
12+
CmKoWwsFHwMBCQmImAQYEwkAIBYhBImBqo1ucm9+BJDt3OO2nDpaUBifBQJaIS81
13+
AhsMAAoJEOO2nDpaUBifJgIBf0SQp/OZNxf8dQ1QAYw54cEzjtwZ10/uAgufBmlL
14+
EVlylnDAbQ3fC6gLHL+g/HabzQF7BY0cAamO8jTREVdFto/9ByzhGe8OqoUOKfLv
15+
ZPeAaKW1193DmjYWFbJVTYgUOafH
16+
=RcpK
17+
-----END PGP PUBLIC KEY BLOCK-----
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
-----BEGIN PGP PRIVATE KEY BLOCK-----
2+
3+
lNYEWiEvNRMJKyQDAwIIAQELAwMEgdAtVaD0EsbEGTEPIwhlNAuW7vhNYtb50NSJ
4+
etZInXalvNMKDvj6zei/wRepgsLsLf3VdoYzDnl10+RGRa0f66uBZE89RJtdyTQY
5+
g0UW+BKs/hkdKvuh0vRggIFSdKPm/gcDAgM+KGpleRW8x4nqGtKs8RPU3zkvT5C6
6+
cIPvWj/eIP4OwNGwLiKVAF6UoyLofHeM4aCsQfO21rYPU9pECaF5y159uRE2NBIj
7+
iCe21El6cvTpXBkuRmZ0Jf3ier1P8JVStBlBbGljZSA8YWxpY2VAZXhhbXBsZS5j
8+
b20+iLAEExMJADgWIQSJgaqNbnJvfgSQ7dzjtpw6WlAYnwUCWiEvNQIbAwULCQgH
9+
AgYVCAkKCwIEFgIDAQIeAQIXgAAKCRDjtpw6WlAYn6JwAX9hku81g2oO71e82u6e
10+
zVbbumGXYd83TgkmoyPCtD3DsFHsUaD5yEmBbsHVYzWOax8BfjZdIRqozsT6/qmq
11+
znGy8uQ7YLRvgzKnt9NZyLgnwMfPe+/QpLqvD+aSHCU4f8MFo5zaBFohLzUSCSsk
12+
AwMCCAEBCwMDBD5bYDW80HIhpop3Xp51YUVS9r40lIa18maWl5/YcnAZLQzkuZ0I
13+
rpAiXBw7riJKlT071hBlrmpa5Kzq9IBDeaowTw5+Ui0neQelhp0uIubDqdxNSnXQ
14+
RrUhCmKoWwsFHwMBCQn+BwMC5pm2+X3GglnHtZCnmdfc5QSvBaDAOmdeF7iJ+jJv
15+
SnDor17ZYJy/bcQnbv7T/ZWYCsyAoqTr0+4FtR27+EYPOf7J+L1ZYgJqgkDVibQ0
16+
dt4+oP/iGIJ+LggCp47hQF+ImAQYEwkAIBYhBImBqo1ucm9+BJDt3OO2nDpaUBif
17+
BQJaIS81AhsMAAoJEOO2nDpaUBifJgIBf0SQp/OZNxf8dQ1QAYw54cEzjtwZ10/u
18+
AgufBmlLEVlylnDAbQ3fC6gLHL+g/HabzQF7BY0cAamO8jTREVdFto/9ByzhGe8O
19+
qoUOKfLvZPeAaKW1193DmjYWFbJVTYgUOafH
20+
=FfUZ
21+
-----END PGP PRIVATE KEY BLOCK-----

testdata/cv25519/cv25519-pubkey.asc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
-----BEGIN PGP PUBLIC KEY BLOCK-----
2+
3+
mDMEWiE3oBYJKwYBBAHaRw8BAQdAFItthhMa7Wxm1oKPqQ4y2ffKdAVkBvacFFTW
4+
MFUIHsO0GUFsaWNlIDxhbGljZUBleGFtcGxlLmNvbT6IkAQTFggAOBYhBPF43b93
5+
KTSu8cVV/7eRwa4y0/P8BQJaITegAhsDBQsJCAcCBhUICQoLAgQWAgMBAh4BAheA
6+
AAoJELeRwa4y0/P8P9IA/3wJAX9uZrMXExLOY83c0q/QguIV7Ar7g8Upyo6me36a
7+
AP9undT7Cr99IV9/04ZrqAFS0Qo4VuiT91LRMwXETZNADrg4BFohN6ASCisGAQQB
8+
l1UBBQEBB0DjJ4Yh47UGexN9K+JR4Av568MYY/MUe927YnSeQgTrJQMBCAeIeAQY
9+
FggAIBYhBPF43b93KTSu8cVV/7eRwa4y0/P8BQJaITegAhsMAAoJELeRwa4y0/P8
10+
afAA/0SuaJp9x4xNVZ5GejTJHKpM1MsvXtCfclYACgoQ4hr7AP0RUB5RyqDZUQxT
11+
l1w3Kih8Ke8+ulR9Kg4MQnt2/EBTAQ==
12+
=FWaF
13+
-----END PGP PUBLIC KEY BLOCK-----

testdata/cv25519/cv25519-seckey.asc

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
-----BEGIN PGP PRIVATE KEY BLOCK-----
2+
3+
lIYEWiE3oBYJKwYBBAHaRw8BAQdAFItthhMa7Wxm1oKPqQ4y2ffKdAVkBvacFFTW
4+
MFUIHsP+BwMCGKhseH90/JTDvQV6cWC/wlCtJksIMyAh8mRhTvzqy9FLasLQgNb8
5+
UbZMvSk88osw0C7TCcndxM4AVhdwH8CSlOPJUODoWE+exJzoXkBDEbQZQWxpY2Ug
6+
PGFsaWNlQGV4YW1wbGUuY29tPoiQBBMWCAA4FiEE8Xjdv3cpNK7xxVX/t5HBrjLT
7+
8/wFAlohN6ACGwMFCwkIBwIGFQgJCgsCBBYCAwECHgECF4AACgkQt5HBrjLT8/w/
8+
0gD/fAkBf25msxcTEs5jzdzSr9CC4hXsCvuDxSnKjqZ7fpoA/26d1PsKv30hX3/T
9+
hmuoAVLRCjhW6JP3UtEzBcRNk0AOnIsEWiE3oBIKKwYBBAGXVQEFAQEHQOMnhiHj
10+
tQZ7E30r4lHgC/nrwxhj8xR73btidJ5CBOslAwEIB/4HAwLw/gk/+uCEAsMrWQI+
11+
W2FI8nL0DQsdlb37eg/5QYTX/p5/iut4wcR/RTy96B70Y8WxbpF5mfSm4XOlCjIZ
12+
ziEZ3aHyGAgI+5NRDNust6zJiHgEGBYIACAWIQTxeN2/dyk0rvHFVf+3kcGuMtPz
13+
/AUCWiE3oAIbDAAKCRC3kcGuMtPz/GnwAP9ErmiafceMTVWeRno0yRyqTNTLL17Q
14+
n3JWAAoKEOIa+wD9EVAeUcqg2VEMU5dcNyoofCnvPrpUfSoODEJ7dvxAUwE=
15+
=gJGy
16+
-----END PGP PRIVATE KEY BLOCK-----
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-----BEGIN PGP PUBLIC KEY BLOCK-----
2+
3+
mE8EWiEwoxMFK4EEAAoCAwRVxZqhS0QH5jEjxXH/a+DK+zOMUCMW7Iq0CzjrIak5
4+
bhN8CIBiL8EzXQ4Mbe/SsHHI5iNlHuPTHZqnsSVAIBZrtBlBbGljZSA8YWxpY2VA
5+
ZXhhbXBsZS5jb20+iJAEExMIADgWIQTTzi9L5ApebrL3R3TOk3hssBuJOQUCWiEw
6+
owIbAwULCQgHAgYVCAkKCwIEFgIDAQIeAQIXgAAKCRDOk3hssBuJOf+NAQCz33Io
7+
SjcXfXMzbUXeyf/TjUzBD8xrpM+hLY7yuWYKggEAyPNAR9v+uB3wmJDCZJ/qDiZr
8+
VfvWyiC7SItbJXAKdfi4UwRaITCjEgUrgQQACgIDBE+EjeNtNbSwRIOV6yjYSgkh
9+
ngnodkrJeaMl5JstaJpxJKxYsEXqlk5qWUnp8BDvgLeeSJOGACUZyMsdy9Hbz7cD
10+
AQgHiHgEGBMIACAWIQTTzi9L5ApebrL3R3TOk3hssBuJOQUCWiEwowIbDAAKCRDO
11+
k3hssBuJOVtMAP4xyZx8rTG+K7ycEItUo4OzwXwT7euglBakzZ6o49onnwD+OegV
12+
fVCuFkKb0rbHKpfAI3WpPfxpOfghV58D9J+mwRM=
13+
=/HIO
14+
-----END PGP PUBLIC KEY BLOCK-----
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
-----BEGIN PGP PRIVATE KEY BLOCK-----
2+
3+
lKIEWiEwoxMFK4EEAAoCAwRVxZqhS0QH5jEjxXH/a+DK+zOMUCMW7Iq0CzjrIak5
4+
bhN8CIBiL8EzXQ4Mbe/SsHHI5iNlHuPTHZqnsSVAIBZr/gcDAgHbt3mCGCckx8bf
5+
AkjTkLc1TET9UKKkfkPXy1mqyNqrviE7XDFJOLg09SvyYOEWs4yQsugN6yRFVSZr
6+
j9L3DAH/MSQaIH0G0OhubjnA9cy0GUFsaWNlIDxhbGljZUBleGFtcGxlLmNvbT6I
7+
kAQTEwgAOBYhBNPOL0vkCl5usvdHdM6TeGywG4k5BQJaITCjAhsDBQsJCAcCBhUI
8+
CQoLAgQWAgMBAh4BAheAAAoJEM6TeGywG4k5/40BALPfcihKNxd9czNtRd7J/9ON
9+
TMEPzGukz6EtjvK5ZgqCAQDI80BH2/64HfCYkMJkn+oOJmtV+9bKILtIi1slcAp1
10+
+JymBFohMKMSBSuBBAAKAgMET4SN4201tLBEg5XrKNhKCSGeCeh2Ssl5oyXkmy1o
11+
mnEkrFiwReqWTmpZSenwEO+At55Ik4YAJRnIyx3L0dvPtwMBCAf+BwMCZ9hIpfnM
12+
gy3HMs1sNo7EY8SRcZeqfYGENHdzN9Hy+u2NwZm42xvWqfrjm6twwnTFTsof44BR
13+
xvksUkm0uQiyex/WuvzruznxQssPAWym8oh4BBgTCAAgFiEE084vS+QKXm6y90d0
14+
zpN4bLAbiTkFAlohMKMCGwwACgkQzpN4bLAbiTlbTAD+McmcfK0xviu8nBCLVKOD
15+
s8F8E+3roJQWpM2eqOPaJ58A/jnoFX1QrhZCm9K2xyqXwCN1qT38aTn4IVefA/Sf
16+
psET
17+
=huoU
18+
-----END PGP PRIVATE KEY BLOCK-----

0 commit comments

Comments
 (0)