rand.read > io.readFull

This commit is contained in:
19byte 2024-03-04 19:33:10 +08:00 committed by GitHub
parent 31f81ddee0
commit 248155eea0
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -159,9 +159,9 @@ func (s *AESEncryptedStorage) writeEncryptedStorage(creds map[string]storedCrede
return nil return nil
} }
func randBytes(size int) (blk []byte, err error) { func (s *AESEncryptedStorage) randBytes() (nonce []byte, err error) {
blk = make([]byte, size) nonce = make([]byte, s.gcmNS)
_, err = rand.Read(blk) _, err = io.ReadFull(rand.Reader, nonce)
return return
} }
@ -173,7 +173,7 @@ func (s *AESEncryptedStorage) encrypt(plaintext []byte, additionalData []byte) (
// key because of the risk of a repeat. // key because of the risk of a repeat.
var n []byte var n []byte
if n, err = randBytes(s.gcmNS); err != nil { if n, err = s.randBytes(); err != nil {
return return
} }
return append(n, s.gcm.Seal(nil, n, plaintext, additionalData)...), n, nil return append(n, s.gcm.Seal(nil, n, plaintext, additionalData)...), n, nil