Browse Source

crypto/bn256/cloudflare: checks for nil pointers in Marshal functions (#19609)

* Added checks for nil pointers in Marshal functions

* Set nil pointer to identity in GT before marshaling
Antoine Rondelet 6 năm trước cách đây
mục cha
commit
9efc1a847e
1 tập tin đã thay đổi với 9 bổ sung0 xóa
  1. 9 0
      crypto/bn256/cloudflare/bn256.go

+ 9 - 0
crypto/bn256/cloudflare/bn256.go

@@ -100,6 +100,10 @@ func (e *G1) Marshal() []byte {
 	// Each value is a 256-bit number.
 	const numBytes = 256 / 8
 
+	if e.p == nil {
+		e.p = &curvePoint{}
+	}
+
 	e.p.MakeAffine()
 	ret := make([]byte, numBytes*2)
 	if e.p.IsInfinity() {
@@ -382,6 +386,11 @@ func (e *GT) Marshal() []byte {
 	// Each value is a 256-bit number.
 	const numBytes = 256 / 8
 
+	if e.p == nil {
+		e.p = &gfP12{}
+		e.p.SetOne()
+	}
+
 	ret := make([]byte, numBytes*12)
 	temp := &gfP{}