]> Cypherpunks.ru repositories - gogost.git/commitdiff
Slightly more endianness documentation
authorSergey Matveev <stargrave@stargrave.org>
Wed, 5 Apr 2023 11:53:17 +0000 (14:53 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 5 Apr 2023 11:58:34 +0000 (14:58 +0300)
gost3410/curve.go
gost3410/private.go
gost3410/public.go
gost3410/ukm.go
gost34112012256/hash.go
gost34112012512/hash.go

index 42b7e465476f28cf6a9a8401370fd451e4628748..6cc113548e3d6fff5a0d851408ad4a70dd8f434d 100644 (file)
@@ -88,6 +88,8 @@ func NewCurve(p, q, a, b, x, y, e, d, co *big.Int) (*Curve, error) {
        return &c, nil
 }
 
+// Get the size of the point's coordinate in bytes.
+// 32 for 256-bit curves, 64 for 512-bit ones.
 func (c *Curve) PointSize() int {
        return pointSize(c.P)
 }
index 7629563c1c736857c5033cb5a12f4a7126939bbb..983d8d2849399c80a5617e8a5917180f9b96eb75 100644 (file)
@@ -28,6 +28,7 @@ type PrivateKey struct {
        Key *big.Int
 }
 
+// Unmarshal little-endian private key. "raw" must be c.PointSize() length.
 func NewPrivateKey(c *Curve, raw []byte) (*PrivateKey, error) {
        pointSize := c.PointSize()
        if len(raw) != pointSize {
@@ -52,8 +53,9 @@ func GenPrivateKey(c *Curve, rand io.Reader) (*PrivateKey, error) {
        return NewPrivateKey(c, raw)
 }
 
-func (prv *PrivateKey) Raw() []byte {
-       raw := pad(prv.Key.Bytes(), prv.C.PointSize())
+// Marshal little-endian private key. raw will be prv.C.PointSize() length.
+func (prv *PrivateKey) Raw() (raw []byte) {
+       raw = pad(prv.Key.Bytes(), prv.C.PointSize())
        reverse(raw)
        return raw
 }
@@ -109,6 +111,7 @@ Retry:
        ), nil
 }
 
+// Sign the digest. opts argument is unused.
 func (prv *PrivateKey) Sign(rand io.Reader, digest []byte, opts crypto.SignerOpts) ([]byte, error) {
        return prv.SignDigest(digest, rand)
 }
index 957293e61f7830b266a7f0731729b989dac8d0d0..d2c01bc67acbd2990378f3bd3d1e578617a05e2b 100644 (file)
@@ -27,6 +27,7 @@ type PublicKey struct {
        Y *big.Int
 }
 
+// Unmarshal LE(X)||LE(Y) public key. "raw" must be 2*c.PointSize() length.
 func NewPublicKey(c *Curve, raw []byte) (*PublicKey, error) {
        pointSize := c.PointSize()
        key := make([]byte, 2*pointSize)
@@ -43,9 +44,10 @@ func NewPublicKey(c *Curve, raw []byte) (*PublicKey, error) {
        }, nil
 }
 
-func (pub *PublicKey) Raw() []byte {
+// Marshal LE(X)||LE(Y) public key. raw will be 2*pub.C.PointSize() length.
+func (pub *PublicKey) Raw() (raw []byte) {
        pointSize := pub.C.PointSize()
-       raw := append(
+       raw = append(
                pad(pub.Y.Bytes(), pointSize),
                pad(pub.X.Bytes(), pointSize)...,
        )
index ab6fab6b71d35f2008fc500a419be4fd143c94fd..772b178a80ccde5c58d990f2864423026673f4d0 100644 (file)
@@ -19,6 +19,7 @@ import (
        "math/big"
 )
 
+// Unmarshal little-endian UKM value.
 func NewUKM(raw []byte) *big.Int {
        t := make([]byte, len(raw))
        for i := 0; i < len(t); i++ {
index 9d7d83fab5063b22ff7702fd4b2d701f971eefd4..bae30fefcbf8a413d5932c0593ef747b956a2b7c 100644 (file)
@@ -14,7 +14,7 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // GOST R 34.11-2012 256-bit hash function.
-// RFC 6986.
+// RFC 6986. Big-endian hash output.
 package gost34112012256
 
 import (
index 9a04c8cd2d087dba6597c42bf65f787a08e1a787..b6f2729568b0bb353992e331280736b5baede92a 100644 (file)
@@ -14,7 +14,7 @@
 // along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
 // GOST R 34.11-2012 512-bit hash function.
-// RFC 6986.
+// RFC 6986. Big-endian hash output.
 package gost34112012512
 
 import (