From: Sergey Matveev Date: Tue, 6 Aug 2024 11:28:42 +0000 (+0300) Subject: Fix various lint warnings and suggestions X-Git-Tag: v6.0.1^0 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=bde4340bd359c840db046a1f13ac7bdf4b6b9df8;p=gogost.git Fix various lint warnings and suggestions --- diff --git a/cmd/cer-selfsigned-example/main.go b/cmd/cer-selfsigned-example/main.go index 7c927e6..3b39ea1 100644 --- a/cmd/cer-selfsigned-example/main.go +++ b/cmd/cer-selfsigned-example/main.go @@ -120,14 +120,15 @@ func main() { var prv any if *reuseKey == "" { prvRaw := make([]byte, curve.PointSize()) - if _, err := io.ReadFull(rand.Reader, prvRaw); err != nil { + if _, err = io.ReadFull(rand.Reader, prvRaw); err != nil { log.Fatal(err) } prv, err = gost3410.NewPrivateKey(curve, prvRaw) if err != nil { log.Fatal(err) } - data, err := x509.MarshalPKCS8PrivateKey(prv) + var data []byte + data, err = x509.MarshalPKCS8PrivateKey(prv) if err != nil { log.Fatal(err) } diff --git a/gost28147/cipher.go b/gost28147/cipher.go index 47de2f8..845da79 100644 --- a/gost28147/cipher.go +++ b/gost28147/cipher.go @@ -52,9 +52,9 @@ var ( ) type Cipher struct { - key [KeySize]byte sbox *Sbox x [8]nv + key [KeySize]byte } func NewCipher(key []byte, sbox *Sbox) *Cipher { diff --git a/gost28147/mac.go b/gost28147/mac.go index 60c21cb..d3a0612 100644 --- a/gost28147/mac.go +++ b/gost28147/mac.go @@ -26,10 +26,10 @@ var SeqMAC = Seq([]uint8{ type MAC struct { c *Cipher - size int iv []byte prev []byte buf []byte + size int n1 nv n2 nv } diff --git a/gost3410/curve.go b/gost3410/curve.go index c1b93ed..bbc5d43 100644 --- a/gost3410/curve.go +++ b/gost3410/curve.go @@ -29,8 +29,6 @@ var ( ) type Curve struct { - Name string // Just simple identifier - P *big.Int // Characteristic of the underlying prime field Q *big.Int // Elliptic curve subgroup order @@ -51,6 +49,8 @@ type Curve struct { // Cached s/t parameters for Edwards curve points conversion edS *big.Int edT *big.Int + + Name string // Just simple identifier } func NewCurve(p, q, a, b, x, y, e, d, co *big.Int) (*Curve, error) { diff --git a/gost3410/private_test.go b/gost3410/private_test.go index 90126b7..70c0981 100644 --- a/gost3410/private_test.go +++ b/gost3410/private_test.go @@ -34,8 +34,8 @@ func TestSignerInterface(t *testing.T) { t.Fatal(err) } var _ crypto.Signer = prv - var _ crypto.Signer = &PrivateKeyReverseDigest{prv} - var _ crypto.Signer = &PrivateKeyReverseDigestAndSignature{prv} + var _ crypto.Signer = &PrivateKeyReverseDigest{} + var _ crypto.Signer = &PrivateKeyReverseDigestAndSignature{} } func TestSignerReverseDigest(t *testing.T) { diff --git a/gost34112012256/esptree.go b/gost34112012256/esptree.go index da979db..8ea8e8b 100644 --- a/gost34112012256/esptree.go +++ b/gost34112012256/esptree.go @@ -21,17 +21,14 @@ import ( type ESPTree struct { keyRoot []byte - isPrev [5]byte key []byte + isPrev [5]byte } func NewESPTree(keyRoot []byte) *ESPTree { key := make([]byte, len(keyRoot)) copy(key, keyRoot) - t := &ESPTree{ - keyRoot: key, - key: make([]byte, Size), - } + t := &ESPTree{keyRoot: key, key: make([]byte, Size)} t.isPrev[0]++ // invalidate cache t.DeriveCached([]byte{0x00, 0x00, 0x00, 0x00, 0x00}) return t diff --git a/gost34112012256/tlstree.go b/gost34112012256/tlstree.go index ddec883..ecd3d83 100644 --- a/gost34112012256/tlstree.go +++ b/gost34112012256/tlstree.go @@ -55,11 +55,11 @@ var ( ) type TLSTree struct { - params TLSTreeParams keyRoot []byte - seqNumPrev uint64 seq []byte key []byte + params TLSTreeParams + seqNumPrev uint64 } func NewTLSTree(params TLSTreeParams, keyRoot []byte) *TLSTree { diff --git a/gost341194/hash.go b/gost341194/hash.go index 53eb49c..e2f8058 100644 --- a/gost341194/hash.go +++ b/gost341194/hash.go @@ -57,11 +57,11 @@ var ( type Hash struct { sbox *gost28147.Sbox - size uint64 - hsh [BlockSize]byte chk *big.Int buf []byte + hsh [BlockSize]byte tmp [BlockSize]byte + size uint64 } func New(sbox *gost28147.Sbox) *Hash { diff --git a/gost3412128/cipher_test.go b/gost3412128/cipher_test.go index 9004d02..196da9c 100644 --- a/gost3412128/cipher_test.go +++ b/gost3412128/cipher_test.go @@ -25,7 +25,7 @@ import ( ) var ( - key []byte = []byte{ + Key []byte = []byte{ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, 0xfe, 0xdc, 0xba, 0x98, 0x76, 0x54, 0x32, 0x10, @@ -247,7 +247,7 @@ func TestC(t *testing.T) { } func TestRoundKeys(t *testing.T) { - c := NewCipher(key) + c := NewCipher(Key) if !bytes.Equal(c.ks[0][:], []byte{ 0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77, @@ -311,7 +311,7 @@ func TestRoundKeys(t *testing.T) { } func TestVectorEncrypt(t *testing.T) { - c := NewCipher(key) + c := NewCipher(Key) dst := make([]byte, BlockSize) c.Encrypt(dst, pt[:]) if !bytes.Equal(dst, ct[:]) { @@ -320,7 +320,7 @@ func TestVectorEncrypt(t *testing.T) { } func TestVectorDecrypt(t *testing.T) { - c := NewCipher(key) + c := NewCipher(Key) dst := make([]byte, BlockSize) c.Decrypt(dst, ct[:]) if !bytes.Equal(dst, pt[:]) { diff --git a/internal/gost34112012/hash.go b/internal/gost34112012/hash.go index d5db543..9595813 100644 --- a/internal/gost34112012/hash.go +++ b/internal/gost34112012/hash.go @@ -25,11 +25,11 @@ import ( const BlockSize = 64 type Hash struct { - size int buf []byte - n uint64 hsh []byte chk []byte + n uint64 + size int } // Create new hash object with specified size digest size. diff --git a/mgm/mode.go b/mgm/mode.go index 588e9ad..a76be17 100644 --- a/mgm/mode.go +++ b/mgm/mode.go @@ -32,16 +32,16 @@ type Mul interface { } type MGM struct { - MaxSize uint64 - BlockSize int - TagSize int cipher cipher.Block + mul Mul icn []byte bufP []byte bufC []byte padded []byte sum []byte - mul Mul + MaxSize uint64 + BlockSize int + TagSize int } func NewMGM(cipher cipher.Block, tagSize int) (cipher.AEAD, error) {