mirror of
https://github.com/status-im/nimbus-eth1.git
synced 2025-01-12 21:34:33 +00:00
simplify blscurve utils impl
This commit is contained in:
parent
397119468a
commit
c84e34cac6
@ -210,9 +210,9 @@ when BLS_BACKEND == Miracl:
|
|||||||
if input.len != 128:
|
if input.len != 128:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if not res.a.decodeFE input.toOpenArray(0, 63):
|
if res.a.decodeFE(input.toOpenArray(0, 63)) and
|
||||||
return false
|
res.b.decodeFE(input.toOpenArray(64, 127)):
|
||||||
res.b.decodeFE input.toOpenArray(64, 127)
|
result = true
|
||||||
|
|
||||||
else:
|
else:
|
||||||
func decodeFE*(res: var BLS_FE, input: openArray[byte]): bool =
|
func decodeFE*(res: var BLS_FE, input: openArray[byte]): bool =
|
||||||
@ -228,9 +228,9 @@ else:
|
|||||||
if input.len != 128:
|
if input.len != 128:
|
||||||
return false
|
return false
|
||||||
|
|
||||||
if not res.fp[0].decodeFE input.toOpenArray(0, 63):
|
if res.fp[0].decodeFE(input.toOpenArray(0, 63)) and
|
||||||
return false
|
res.fp[1].decodeFE(input.toOpenArray(64, 127)):
|
||||||
res.fp[1].decodeFE input.toOpenArray(64, 127)
|
result = true
|
||||||
|
|
||||||
# DecodePoint given encoded (x, y) coordinates in 128 bytes returns a valid G1 Point.
|
# DecodePoint given encoded (x, y) coordinates in 128 bytes returns a valid G1 Point.
|
||||||
func decodePoint*(g: var (BLS_G1 | BLS_G1P), data: openArray[byte]): bool =
|
func decodePoint*(g: var (BLS_G1 | BLS_G1P), data: openArray[byte]): bool =
|
||||||
@ -238,13 +238,9 @@ func decodePoint*(g: var (BLS_G1 | BLS_G1P), data: openArray[byte]): bool =
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
var x, y: BLS_FP
|
var x, y: BLS_FP
|
||||||
if not x.decodeFieldElement data.toOpenArray(0, 63):
|
if x.decodeFieldElement(data.toOpenArray(0, 63)) and
|
||||||
return false
|
y.decodeFieldElement(data.toOpenArray(64, 127)):
|
||||||
|
result = g.pack(x, y)
|
||||||
if not y.decodeFieldElement data.toOpenArray(64, 127):
|
|
||||||
return false
|
|
||||||
|
|
||||||
g.pack(x, y)
|
|
||||||
|
|
||||||
# EncodePoint encodes a point into 128 bytes.
|
# EncodePoint encodes a point into 128 bytes.
|
||||||
func encodePoint*(g: BLS_G1, output: var openArray[byte]): bool =
|
func encodePoint*(g: BLS_G1, output: var openArray[byte]): bool =
|
||||||
@ -252,13 +248,10 @@ func encodePoint*(g: BLS_G1, output: var openArray[byte]): bool =
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
var x, y: BLS_FP
|
var x, y: BLS_FP
|
||||||
if not g.unpack(x, y):
|
if g.unpack(x, y) and
|
||||||
return false
|
x.toBytes(output.toOpenArray(16, 63)) and
|
||||||
|
y.toBytes(output.toOpenArray(64+16, 127)):
|
||||||
if not x.toBytes output.toOpenArray(16, 63):
|
result = true
|
||||||
return false
|
|
||||||
|
|
||||||
y.toBytes output.toOpenArray(64+16, 127)
|
|
||||||
|
|
||||||
# DecodePoint given encoded (x, y) coordinates in 256 bytes returns a valid G2 Point.
|
# DecodePoint given encoded (x, y) coordinates in 256 bytes returns a valid G2 Point.
|
||||||
func decodePoint*(g: var (BLS_G2 | BLS_G2P), data: openArray[byte]): bool =
|
func decodePoint*(g: var (BLS_G2 | BLS_G2P), data: openArray[byte]): bool =
|
||||||
@ -266,19 +259,11 @@ func decodePoint*(g: var (BLS_G2 | BLS_G2P), data: openArray[byte]): bool =
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
var x0, x1, y0, y1: BLS_FP
|
var x0, x1, y0, y1: BLS_FP
|
||||||
if not x0.decodeFieldElement data.toOpenArray(0, 63):
|
if x0.decodeFieldElement(data.toOpenArray(0, 63)) and
|
||||||
return false
|
x1.decodeFieldElement(data.toOpenArray(64, 127)) and
|
||||||
|
y0.decodeFieldElement(data.toOpenArray(128, 191)) and
|
||||||
if not x1.decodeFieldElement data.toOpenArray(64, 127):
|
y1.decodeFieldElement(data.toOpenArray(192, 255)):
|
||||||
return false
|
result = g.pack(x0, x1, y0, y1)
|
||||||
|
|
||||||
if not y0.decodeFieldElement data.toOpenArray(128, 191):
|
|
||||||
return false
|
|
||||||
|
|
||||||
if not y1.decodeFieldElement data.toOpenArray(192, 255):
|
|
||||||
return false
|
|
||||||
|
|
||||||
g.pack(x0, x1, y0, y1)
|
|
||||||
|
|
||||||
# EncodePoint encodes a point into 256 bytes.
|
# EncodePoint encodes a point into 256 bytes.
|
||||||
func encodePoint*(g: BLS_G2, output: var openArray[byte]): bool =
|
func encodePoint*(g: BLS_G2, output: var openArray[byte]): bool =
|
||||||
@ -286,16 +271,9 @@ func encodePoint*(g: BLS_G2, output: var openArray[byte]): bool =
|
|||||||
return false
|
return false
|
||||||
|
|
||||||
var x0, x1, y0, y1: BLS_FP
|
var x0, x1, y0, y1: BLS_FP
|
||||||
if not g.unpack(x0, x1, y0, y1):
|
if g.unpack(x0, x1, y0, y1) and
|
||||||
return false
|
x0.toBytes(output.toOpenArray(16, 63)) and
|
||||||
|
x1.toBytes(output.toOpenArray(80, 127)) and
|
||||||
if not x0.toBytes output.toOpenArray(16, 63):
|
y0.toBytes(output.toOpenArray(144, 192)) and
|
||||||
return false
|
y1.toBytes(output.toOpenArray(208, 255)):
|
||||||
|
result = true
|
||||||
if not x1.toBytes output.toOpenArray(80, 127):
|
|
||||||
return false
|
|
||||||
|
|
||||||
if not y0.toBytes output.toOpenArray(144, 192):
|
|
||||||
return false
|
|
||||||
|
|
||||||
y1.toBytes output.toOpenArray(208, 255)
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user