Skip to content

Commit 9b570f2

Browse files
committed
bindings/go: add EIP-2537 serialization.
1 parent 06c6820 commit 9b570f2

File tree

4 files changed

+65
-13
lines changed

4 files changed

+65
-13
lines changed

bindings/go/blst.go

+42-8
Original file line numberDiff line numberDiff line change
@@ -165,8 +165,10 @@ const BLST_SCALAR_BYTES = 256 / 8
165165
const BLST_FP_BYTES = 384 / 8
166166
const BLST_P1_COMPRESS_BYTES = BLST_FP_BYTES
167167
const BLST_P1_SERIALIZE_BYTES = BLST_FP_BYTES * 2
168+
const BLST_P1_SERIALIZE_EIP2537_BYTES = 64 * 2
168169
const BLST_P2_COMPRESS_BYTES = BLST_FP_BYTES * 2
169170
const BLST_P2_SERIALIZE_BYTES = BLST_FP_BYTES * 4
171+
const BLST_P2_SERIALIZE_EIP2537_BYTES = 128 * 2
170172

171173
type Scalar = C.blst_scalar
172174
type Fp = C.blst_fp
@@ -1705,11 +1707,22 @@ func (p1 *P1Affine) Serialize() []byte {
17051707
return out[:]
17061708
}
17071709

1710+
func (p1 *P1Affine) SerializeEip2537() []byte {
1711+
var out [BLST_P1_SERIALIZE_EIP2537_BYTES]byte
1712+
C.blst_p1_affine_serialize_eip2537((*C.byte)(&out[0]), p1)
1713+
return out[:]
1714+
}
1715+
17081716
func (p1 *P1Affine) Deserialize(in []byte) *P1Affine {
1709-
if len(in) != BLST_P1_SERIALIZE_BYTES {
1710-
return nil
1711-
}
1712-
if C.blst_p1_deserialize(p1, (*C.byte)(&in[0])) != C.BLST_SUCCESS {
1717+
if len(in) == BLST_P1_SERIALIZE_BYTES {
1718+
if C.blst_p1_deserialize(p1, (*C.byte)(&in[0])) != C.BLST_SUCCESS {
1719+
return nil
1720+
}
1721+
} else if len(in) == BLST_P1_SERIALIZE_EIP2537_BYTES {
1722+
if C.blst_p1_deserialize_eip2537(p1, (*C.byte)(&in[0])) != C.BLST_SUCCESS {
1723+
return nil
1724+
}
1725+
} else {
17131726
return nil
17141727
}
17151728
return p1
@@ -1797,6 +1810,11 @@ func (p1 *P1) Serialize() []byte {
17971810
C.blst_p1_serialize((*C.byte)(&out[0]), p1)
17981811
return out[:]
17991812
}
1813+
func (p1 *P1) SerializeEip2537() []byte {
1814+
var out [BLST_P1_SERIALIZE_EIP2537_BYTES]byte
1815+
C.blst_p1_serialize_eip2537((*C.byte)(&out[0]), p1)
1816+
return out[:]
1817+
}
18001818
func (p1 *P1) Compress() []byte {
18011819
var out [BLST_P1_COMPRESS_BYTES]byte
18021820
C.blst_p1_compress((*C.byte)(&out[0]), p1)
@@ -2367,11 +2385,22 @@ func (p2 *P2Affine) Serialize() []byte {
23672385
return out[:]
23682386
}
23692387

2388+
func (p2 *P2Affine) SerializeEip2537() []byte {
2389+
var out [BLST_P2_SERIALIZE_EIP2537_BYTES]byte
2390+
C.blst_p2_affine_serialize_eip2537((*C.byte)(&out[0]), p2)
2391+
return out[:]
2392+
}
2393+
23702394
func (p2 *P2Affine) Deserialize(in []byte) *P2Affine {
2371-
if len(in) != BLST_P2_SERIALIZE_BYTES {
2372-
return nil
2373-
}
2374-
if C.blst_p2_deserialize(p2, (*C.byte)(&in[0])) != C.BLST_SUCCESS {
2395+
if len(in) == BLST_P2_SERIALIZE_BYTES {
2396+
if C.blst_p2_deserialize(p2, (*C.byte)(&in[0])) != C.BLST_SUCCESS {
2397+
return nil
2398+
}
2399+
} else if len(in) == BLST_P2_SERIALIZE_EIP2537_BYTES {
2400+
if C.blst_p2_deserialize_eip2537(p2, (*C.byte)(&in[0])) != C.BLST_SUCCESS {
2401+
return nil
2402+
}
2403+
} else {
23752404
return nil
23762405
}
23772406
return p2
@@ -2459,6 +2488,11 @@ func (p2 *P2) Serialize() []byte {
24592488
C.blst_p2_serialize((*C.byte)(&out[0]), p2)
24602489
return out[:]
24612490
}
2491+
func (p2 *P2) SerializeEip2537() []byte {
2492+
var out [BLST_P2_SERIALIZE_EIP2537_BYTES]byte
2493+
C.blst_p2_serialize_eip2537((*C.byte)(&out[0]), p2)
2494+
return out[:]
2495+
}
24622496
func (p2 *P2) Compress() []byte {
24632497
var out [BLST_P2_COMPRESS_BYTES]byte
24642498
C.blst_p2_compress((*C.byte)(&out[0]), p2)

bindings/go/blst.tgo

+2
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,10 @@ const BLST_SCALAR_BYTES = 256 / 8
155155
const BLST_FP_BYTES = 384 / 8
156156
const BLST_P1_COMPRESS_BYTES = BLST_FP_BYTES
157157
const BLST_P1_SERIALIZE_BYTES = BLST_FP_BYTES * 2
158+
const BLST_P1_SERIALIZE_EIP2537_BYTES = 64 * 2
158159
const BLST_P2_COMPRESS_BYTES = BLST_FP_BYTES * 2
159160
const BLST_P2_SERIALIZE_BYTES = BLST_FP_BYTES * 4
161+
const BLST_P2_SERIALIZE_EIP2537_BYTES = 128 * 2
160162

161163
type Scalar = C.blst_scalar
162164
type Fp = C.blst_fp

bindings/go/blst_px.tgo

+20-4
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,22 @@ func (p1 *P1Affine) Serialize() []byte {
4545
return out[:]
4646
}
4747

48+
func (p1 *P1Affine) SerializeEip2537() []byte {
49+
var out [BLST_P1_SERIALIZE_EIP2537_BYTES]byte
50+
C.blst_p1_affine_serialize_eip2537((*C.byte)(&out[0]), p1)
51+
return out[:]
52+
}
53+
4854
func (p1 *P1Affine) Deserialize(in []byte) *P1Affine {
49-
if len(in) != BLST_P1_SERIALIZE_BYTES {
50-
return nil
51-
}
52-
if C.blst_p1_deserialize(p1, (*C.byte)(&in[0])) != C.BLST_SUCCESS {
55+
if len(in) == BLST_P1_SERIALIZE_BYTES {
56+
if C.blst_p1_deserialize(p1, (*C.byte)(&in[0])) != C.BLST_SUCCESS {
57+
return nil
58+
}
59+
} else if len(in) == BLST_P1_SERIALIZE_EIP2537_BYTES {
60+
if C.blst_p1_deserialize_eip2537(p1, (*C.byte)(&in[0])) != C.BLST_SUCCESS {
61+
return nil
62+
}
63+
} else {
5364
return nil
5465
}
5566
return p1
@@ -137,6 +148,11 @@ func (p1 *P1) Serialize() []byte {
137148
C.blst_p1_serialize((*C.byte)(&out[0]), p1)
138149
return out[:]
139150
}
151+
func (p1 *P1) SerializeEip2537() []byte {
152+
var out [BLST_P1_SERIALIZE_EIP2537_BYTES]byte
153+
C.blst_p1_serialize_eip2537((*C.byte)(&out[0]), p1)
154+
return out[:]
155+
}
140156
func (p1 *P1) Compress() []byte {
141157
var out [BLST_P1_COMPRESS_BYTES]byte
142158
C.blst_p1_compress((*C.byte)(&out[0]), p1)

bindings/go/generate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def remap(fout, fin, mapping, dont_touch, removeImports):
8181

8282
# These are strings that overlap with the mapping names but we don't
8383
# actually want to change. The second value should be a unique string.
84-
dont_touch = (('Fp12', 'foo1234'),)
84+
dont_touch = (('Fp12', 'foo1234'), ('2537', 'bar1234'))
8585

8686
# We're going to swap these names to get from min-pk to min-sig
8787
mapping = [('P1', 'P2'),

0 commit comments

Comments
 (0)