cmd/cer-selfsigned-example/main.go | 5 +++-- gost28147/cipher.go | 2 +- gost28147/mac.go | 2 +- gost3410/curve.go | 4 ++-- gost3410/private_test.go | 4 ++-- gost34112012256/esptree.go | 7 ++----- gost34112012256/tlstree.go | 4 ++-- gost341194/hash.go | 4 ++-- gost3412128/cipher_test.go | 8 ++++---- internal/gost34112012/hash.go | 4 ++-- mgm/mode.go | 8 ++++---- diff --git a/cmd/cer-selfsigned-example/main.go b/cmd/cer-selfsigned-example/main.go index 448daa0097a26fa1de93a00333ca7bf7426a1371783c733afa9d3f9b7efe1e37..0b0fb52e709cdb695090b75ab6f5d4f40b13e97d246d680e967cb2f24f43d5a2 100644 --- a/cmd/cer-selfsigned-example/main.go +++ b/cmd/cer-selfsigned-example/main.go @@ -120,14 +120,15 @@ 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 15775ee7847ca589a5e857d299720e9f1ad18f3c35048ba88fc87bea739d213f..0371eb0082b7dbe1e5d57e796550f7a2a54626970fc7b2ce70006fa45ce4cdc2 100644 --- a/gost28147/cipher.go +++ b/gost28147/cipher.go @@ -52,9 +52,9 @@ }) ) 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 edb9fb9d26e71c20f545002d998897880c8d566832f148f03cfa25da2962e4fd..72c6fbc0a7b6092f988166e23813ad3caa3bab1e6b6ba2ebe88cd8edf662ed29 100644 --- a/gost28147/mac.go +++ b/gost28147/mac.go @@ -26,10 +26,10 @@ }) 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 d83e1bd31a432fdae014e5572a30714b2579c25c88fc9e61b86c315c76aaf883..286da3c96c99cc0e9da381f3497438809eeff35eef530b500ab51da8b4d44f9b 100644 --- a/gost3410/curve.go +++ b/gost3410/curve.go @@ -29,8 +29,6 @@ bigInt4 *big.Int = big.NewInt(4) ) 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 @@ // 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 86786ffebdbda34b363b2963a502943e7a7abe94c287b0e73b0fce23f6b6bbf9..6576c919dee74de45a3d10f6cfec59d8781aa6279db9aa6a25489e7a98bce8d2 100644 --- a/gost3410/private_test.go +++ b/gost3410/private_test.go @@ -34,8 +34,8 @@ if err != nil { 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 3cd5828c1d1a40cd50425a58b747129c5db404df0ff9ad7c338406cea661ee5f..045f7cf8afbd697184e69b5a967edaba2ca7c0e9ccbf2a2b82eb4bc0d41925d9 100644 --- a/gost34112012256/esptree.go +++ b/gost34112012256/esptree.go @@ -21,17 +21,14 @@ ) 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 ea56909d309c4d04b4ac4149f6c58dd58f559f34b99461b2b7bd6e4d609497ab..8de8c4527644c44c3bbf7081e09053b5794111d1d78bdbe7fff9c04f4d1d55ed 100644 --- a/gost34112012256/tlstree.go +++ b/gost34112012256/tlstree.go @@ -55,11 +55,11 @@ } ) 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 200f73d83bcd7d879698c6605b8cb16bef0f550e2dcc12cab7a4fed00fee915b..4bf6e68c468945b02283cb9c38ef2807111aac875cbb5eabb5cb252881706d00 100644 --- a/gost341194/hash.go +++ b/gost341194/hash.go @@ -57,11 +57,11 @@ ) 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 e8be11dee798c17aeb97d095da5b1c4ed14135f00902364e37e846782314d913..f8c849de48ea94101005bc503a1bce6f634128e0fc164e997926ea877bfcdfbe 100644 --- a/gost3412128/cipher_test.go +++ b/gost3412128/cipher_test.go @@ -25,7 +25,7 @@ "testing/quick" ) 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 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 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 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 305d2099fda2ebe1fa5438c6217b25712f42e5299d58da183be86748e608ac41..5fcc175b6feac3b8cdac5f514331452b16b77317baab46796701d1f45d9dce67 100644 --- a/internal/gost34112012/hash.go +++ b/internal/gost34112012/hash.go @@ -25,11 +25,11 @@ 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 6c01ca3d00c929d8dff1501e74088a96b5cecbf3fb939e99101e25fa62f41081..0084bf7ebb880babd22de684aa54b3de55feb82bf174cb1a7ada4ade9e043922 100644 --- a/mgm/mode.go +++ b/mgm/mode.go @@ -32,16 +32,16 @@ Mul(x, y []byte) []byte } 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) {