]> Cypherpunks repositories - gogost.git/commitdiff
Fix various lint warnings and suggestions v6.0.1
authorSergey Matveev <stargrave@stargrave.org>
Tue, 6 Aug 2024 11:28:42 +0000 (14:28 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 6 Aug 2024 11:28:42 +0000 (14:28 +0300)
cmd/cer-selfsigned-example/main.go
gost28147/cipher.go
gost28147/mac.go
gost3410/curve.go
gost3410/private_test.go
gost34112012256/esptree.go
gost34112012256/tlstree.go
gost341194/hash.go
gost3412128/cipher_test.go
internal/gost34112012/hash.go
mgm/mode.go

index 7c927e6cb78336e97a1ba5cd09fd288e90da5cc4..3b39ea16e7ba81d2e341705460dbdcabcfaab5db 100644 (file)
@@ -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)
                }
index 47de2f8a68cd01554ee4b8f40fb43b4f6f1a35c7..845da79df14b621bdab418c8e86ccad2602fa5c9 100644 (file)
@@ -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 {
index 60c21cbdb05c96861bc4047f02b2ce244c264a27..d3a0612bb1f238ea7ed7454e6ebbdc99060c6993 100644 (file)
@@ -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
 }
index c1b93ed393fd8b6cb6fc7c8699d0c10992807fa3..bbc5d43e8ff558303786772d10b126634d51b257 100644 (file)
@@ -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) {
index 90126b726777d4130d9cfa62d95fe905fb6652fe..70c09815a35dd15e3aa82af973234dbbfe2bf5c5 100644 (file)
@@ -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) {
index da979db16bd2159a57fce9eade512d031693e7ac..8ea8e8b39ebfeacb81863d551b044158a8e95580 100644 (file)
@@ -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
index ddec8831de25c044fd38b4fdcb4ac2b1ced57f14..ecd3d83c44a4a42115a6063b4cc80d749c159480 100644 (file)
@@ -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 {
index 53eb49c6aaeff5e25bc2522605cf8f7ece917e66..e2f80589a2e6a68864613d5b54d141b5095de816 100644 (file)
@@ -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 {
index 9004d0210426d7ef0084466694eddb3475781f6a..196da9c4ce6ced690a6522ad6c4013c1b0585897 100644 (file)
@@ -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[:]) {
index d5db543c8f5af1a53e48e2d869918e775dfa0477..959581336a953a523e7e1a55c7c00f52848822d8 100644 (file)
@@ -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.
index 588e9ad2768092470839081cbf67845bcb93cdbc..a76be17f619f8f81212488df0c5a6e1c8745f084 100644 (file)
@@ -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) {