Adds point compression, point serialization and binary encoder for each curve #17
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
G1Affine
andG2Affine
now exposes 3 methods:Bytes() [SizeOfG1Compressed]byte
: returns an array of bytes with compressed binary representation of the point. For curvesbls381
,bls377
andbw761
, as we have more than 3bits available on the most significant word of the coordinates, we follow BLS381 style encoding as specified in ZCash and draft IETF spec. That is:For
bn256
, as we only have 2 unused bits, we ignore the "uncompressed infinity" case:RawBytes() [SizeOfG1Uncompressed]byte
: returns an array of bytes with uncompressed binary representation of the pointSetBytes([]byte)
: sets point coordinates from bytes (can be either compressed or uncompressed form) .Similarly to field elements generated by
goff
,GT
exposesBytes()
andSetBytes()
.Additionally, each curve now exposes a
Encoder
andDecoder
object, with similar APIs tocbor.Encoder
,gob.Encoder
,json.Encoder
, etc, in othergo
projects. This allows library users to write, for example:The encoder only supports curve objects (
fr.Element
,fp.Element
,G1Affine
,G2Affine
,[]G1Affine
,[]G2Affine
) anduint64
for convenience.Notes:
IsOnCurve
orIsInCorrectSubgroup
e2.Sqrt()
is slow and do few memory allocations, making deserializing fromG2Affine
compressed points sub-optimal.