github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/crypto/internal/nistec/p256.go (about) 1 // Copyright 2022 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 // Code generated by generate.go. DO NOT EDIT. 6 7 //go:build (!amd64 && !arm64 && !ppc64le && !s390x) || purego 8 9 package nistec 10 11 import ( 12 "github.com/shogo82148/std/crypto/internal/nistec/fiat" 13 ) 14 15 // P256Point is a P256 point. The zero value is NOT valid. 16 type P256Point struct { 17 // The point is represented in projective coordinates (X:Y:Z), 18 // where x = X/Z and y = Y/Z. 19 x, y, z *fiat.P256Element 20 } 21 22 // NewP256Point returns a new P256Point representing the point at infinity point. 23 func NewP256Point() *P256Point 24 25 // SetGenerator sets p to the canonical generator and returns p. 26 func (p *P256Point) SetGenerator() *P256Point 27 28 // Set sets p = q and returns p. 29 func (p *P256Point) Set(q *P256Point) *P256Point 30 31 // SetBytes sets p to the compressed, uncompressed, or infinity value encoded in 32 // b, as specified in SEC 1, Version 2.0, Section 2.3.4. If the point is not on 33 // the curve, it returns nil and an error, and the receiver is unchanged. 34 // Otherwise, it returns p. 35 func (p *P256Point) SetBytes(b []byte) (*P256Point, error) 36 37 // Bytes returns the uncompressed or infinity encoding of p, as specified in 38 // SEC 1, Version 2.0, Section 2.3.3. Note that the encoding of the point at 39 // infinity is shorter than all other encodings. 40 func (p *P256Point) Bytes() []byte 41 42 // BytesX returns the encoding of the x-coordinate of p, as specified in SEC 1, 43 // Version 2.0, Section 2.3.5, or an error if p is the point at infinity. 44 func (p *P256Point) BytesX() ([]byte, error) 45 46 // BytesCompressed returns the compressed or infinity encoding of p, as 47 // specified in SEC 1, Version 2.0, Section 2.3.3. Note that the encoding of the 48 // point at infinity is shorter than all other encodings. 49 func (p *P256Point) BytesCompressed() []byte 50 51 // Add sets q = p1 + p2, and returns q. The points may overlap. 52 func (q *P256Point) Add(p1, p2 *P256Point) *P256Point 53 54 // Double sets q = p + p, and returns q. The points may overlap. 55 func (q *P256Point) Double(p *P256Point) *P256Point 56 57 // Select sets q to p1 if cond == 1, and to p2 if cond == 0. 58 func (q *P256Point) Select(p1, p2 *P256Point, cond int) *P256Point 59 60 // ScalarMult sets p = scalar * q, and returns p. 61 func (p *P256Point) ScalarMult(q *P256Point, scalar []byte) (*P256Point, error) 62 63 // ScalarBaseMult sets p = scalar * B, where B is the canonical generator, and 64 // returns p. 65 func (p *P256Point) ScalarBaseMult(scalar []byte) (*P256Point, error)