]> Cypherpunks repositories - gogost.git/commitdiff
Use modern Go's clear()
authorSergey Matveev <stargrave@stargrave.org>
Tue, 16 Jul 2024 14:10:54 +0000 (17:10 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Tue, 16 Jul 2024 15:24:10 +0000 (18:24 +0300)
go.mod
internal/gost34112012/hash.go
mgm/mode.go
mgm/mul64.go

diff --git a/go.mod b/go.mod
index f77e39acbdd2e382f28b8470727fdd86356342a3..2b80ff57f4318c2cf5ef55abf1e1bbf892bfb855 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -1,5 +1,5 @@
 module go.cypherpunks.ru/gogost/v5
 
-go 1.20
+go 1.21
 
 require golang.org/x/crypto v0.16.0
index 40eb2f0d04c57d3629956b6a66acb3f88b410cee..ffd1bc0a5b5fddd6236dbac31fd5cb7f82270843 100644 (file)
@@ -264,8 +264,8 @@ func New(size int) *Hash {
 func (h *Hash) Reset() {
        h.n = 0
        h.buf = nil
+       clear(h.chk)
        for i := 0; i < BlockSize; i++ {
-               h.chk[i] = 0
                if h.size == 32 {
                        h.hsh[i] = 1
                } else {
index ba41973e0b04bcf604b64d58413c572ad262e1c2..588e9ad2768092470839081cbf67845bcb93cdbc 100644 (file)
@@ -110,9 +110,7 @@ func (mgm *MGM) validateSizes(text, additionalData []byte) {
 }
 
 func (mgm *MGM) auth(out, text, ad []byte) {
-       for i := 0; i < mgm.BlockSize; i++ {
-               mgm.sum[i] = 0
-       }
+       clear(mgm.sum)
        adLen := len(ad) * 8
        textLen := len(text) * 8
        mgm.icn[0] |= 0x80
@@ -129,9 +127,7 @@ func (mgm *MGM) auth(out, text, ad []byte) {
        }
        if len(ad) > 0 {
                copy(mgm.padded, ad)
-               for i := len(ad); i < mgm.BlockSize; i++ {
-                       mgm.padded[i] = 0
-               }
+               clear(mgm.padded[len(ad):])
                mgm.cipher.Encrypt(mgm.bufC, mgm.bufP)
                subtle.XORBytes(mgm.sum, mgm.sum, mgm.mul.Mul(mgm.bufC, mgm.padded))
                incr(mgm.bufP[:mgm.BlockSize/2])
index 11265e207f0f487bac1820c6a297dfde775859be..201710c8239766e4b8c08044eca0fcaf3cafc011 100644 (file)
@@ -57,9 +57,7 @@ func (mul *mul64) Mul(x, y []byte) []byte {
        }
        zBytes := mul.z.Bytes()
        rem := len(x) - len(zBytes)
-       for i := 0; i < rem; i++ {
-               mul.buf[i] = 0
-       }
+       clear(mul.buf[:rem])
        copy(mul.buf[rem:], zBytes)
        return mul.buf[:]
 }