arnaucube
arnaucube/go-iden3-cryptoPublic Self-hosted repository
Merge pull request #34 from iden3/feature/exp-comppoint-signy

Abstract & expose CompressedPointToSignAndY
Eduard S eduard@iden3.io
Mon, 21 Dec 2020 16:21:27 +0100
commit

a0722b9e8fd25f4647b0c0131f0090361d4a6b31

parent

0a5c6acba32bef64806f998598317d11032f1656

1 files changed, 15 insertions(+), 2 deletions(-)

jump to
M babyjub/babyjub.go → babyjub/babyjub.go

@@ -222,13 +222,26 @@

// Decompress a compressed Point into p, and also returns the decompressed // Point. Returns error if the compressed Point is invalid. func (p *Point) Decompress(leBuf [32]byte) (*Point, error) { + var sign bool + sign, p.Y = CompressedPointToSignAndY(leBuf) + return PointFromSignAndY(sign, p.Y) +} + +// CompressedPointToSignAndY returns the sign and coordinate Y from a given +// compressed point. This method does not check that the Point belongs to the +// BabyJubJub curve, thus does not return error in such case. This method is +// intended to obtain the sign and the Y coordinate without checking if the +// point belongs to the curve, if the objective is to uncompress a point +// Decompress method should be used instead. +func CompressedPointToSignAndY(leBuf [32]byte) (bool, *big.Int) { sign := false + y := big.NewInt(0) if (leBuf[31] & 0x80) != 0x00 { //nolint:gomnd sign = true leBuf[31] = leBuf[31] & 0x7F //nolint:gomnd } - utils.SetBigIntFromLEBytes(p.Y, leBuf[:]) - return PointFromSignAndY(sign, p.Y) + utils.SetBigIntFromLEBytes(y, leBuf[:]) + return sign, y } // PointFromSignAndY returns a Point from a Sign and the Y coordinate