gost3410/curve.go | 2 ++ gost3410/private.go | 7 +++++-- gost3410/public.go | 6 ++++-- gost3410/ukm.go | 1 + gost34112012256/hash.go | 2 +- gost34112012512/hash.go | 2 +- diff --git a/gost3410/curve.go b/gost3410/curve.go index 8dd656fcc8828a02253abf92822c89ed4e6768a185956ac619de772dd122e242..0bffe8ae0054efc36614dae7948452d2f09a16c6dfb158001700751d90244dc6 100644 --- a/gost3410/curve.go +++ b/gost3410/curve.go @@ -88,6 +88,8 @@ } 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) } diff --git a/gost3410/private.go b/gost3410/private.go index d14310be8f5080e749b0902733b5cd04aa151b48d119c1765c538bfafc253643..6494308748868e55206c554051ea20c0b477e8bfd9ba103887d43305abd8671b 100644 --- a/gost3410/private.go +++ b/gost3410/private.go @@ -28,6 +28,7 @@ C *Curve 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 @@ } 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 @@ pad(r.Bytes(), pointSize)..., ), 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) } diff --git a/gost3410/public.go b/gost3410/public.go index 1f02065590ce1fff9cb3aec473a3236825b17ae9d318bcbc1d3b9f037c260cce..2650208952213b91be58f199d83ebbe6805982d5c8dd37b3311b8b4b8172d1e9 100644 --- a/gost3410/public.go +++ b/gost3410/public.go @@ -27,6 +27,7 @@ X *big.Int 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 @@ bytes2big(key[:pointSize]), }, 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)..., ) diff --git a/gost3410/ukm.go b/gost3410/ukm.go index a031f52544a13616dfe9bea6c91cdb4e6dd5ef538086845f23f88515bc2cb681..fbae9e21dcf2d4b80fd06642ea13abff1563d17c204caaf95bd731d2fc195f40 100644 --- a/gost3410/ukm.go +++ b/gost3410/ukm.go @@ -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++ { diff --git a/gost34112012256/hash.go b/gost34112012256/hash.go index dd28ddadb50c9e7cc8a7c869cd6a9e125e225d347bab643320014d31559cc6bb..23bd53e584bf6e9a8baa80ba1d26d8b40d7a221fd7b99d006babbec36ea04864 100644 --- a/gost34112012256/hash.go +++ b/gost34112012256/hash.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // GOST R 34.11-2012 256-bit hash function. -// RFC 6986. +// RFC 6986. Big-endian hash output. package gost34112012256 import ( diff --git a/gost34112012512/hash.go b/gost34112012512/hash.go index ae58db8ddb1c4649644620af1c3347ddb72a7a988c69d602709053c93e50453e..50ab15d36cf17be31cfe8095e7f277cfa7a9ba45aae07c2c833f903bd923aedf 100644 --- a/gost34112012512/hash.go +++ b/gost34112012512/hash.go @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . // GOST R 34.11-2012 512-bit hash function. -// RFC 6986. +// RFC 6986. Big-endian hash output. package gost34112012512 import (