From 9f3355e3239fed2b0110b0724e7ba1ed509b8a19 Mon Sep 17 00:00:00 2001 From: Sergey Matveev Date: Wed, 22 Jan 2020 16:37:58 +0300 Subject: [PATCH] Panic on all possible hash write errors --- VERSION | 2 +- cmd/streebog256/main.go | 4 +++- cmd/streebog512/main.go | 4 +++- gost3410/vko2001.go | 4 +++- gost3410/vko2012.go | 8 ++++++-- gost34112012256/kdf.go | 24 ++++++++++++++++++------ install.texi | 2 +- news.texi | 4 ++++ prfplus/gost.go | 4 +++- 9 files changed, 42 insertions(+), 14 deletions(-) diff --git a/VERSION b/VERSION index af8c8ec..f2c6cb6 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -4.2.2 +4.2.3 diff --git a/cmd/streebog256/main.go b/cmd/streebog256/main.go index efaae81..9db7c47 100644 --- a/cmd/streebog256/main.go +++ b/cmd/streebog256/main.go @@ -38,6 +38,8 @@ func main() { return } h := gost34112012256.New() - io.Copy(h, os.Stdin) + if _, err := io.Copy(h, os.Stdin); err != nil { + panic(err) + } fmt.Println(hex.EncodeToString(h.Sum(nil))) } diff --git a/cmd/streebog512/main.go b/cmd/streebog512/main.go index d705064..052592f 100644 --- a/cmd/streebog512/main.go +++ b/cmd/streebog512/main.go @@ -38,6 +38,8 @@ func main() { return } h := gost34112012512.New() - io.Copy(h, os.Stdin) + if _, err := io.Copy(h, os.Stdin); err != nil { + panic(err) + } fmt.Println(hex.EncodeToString(h.Sum(nil))) } diff --git a/gost3410/vko2001.go b/gost3410/vko2001.go index 02f976f..c9aeada 100644 --- a/gost3410/vko2001.go +++ b/gost3410/vko2001.go @@ -34,6 +34,8 @@ func (prv *PrivateKey) KEK2001(pub *PublicKey, ukm *big.Int) ([]byte, error) { return nil, err } h := gost341194.New(&gost28147.SboxIdGostR341194CryptoProParamSet) - h.Write(key) + if _, err = h.Write(key); err != nil { + return nil, err + } return h.Sum(key[:0]), nil } diff --git a/gost3410/vko2012.go b/gost3410/vko2012.go index 01f3e85..78b9af5 100644 --- a/gost3410/vko2012.go +++ b/gost3410/vko2012.go @@ -30,7 +30,9 @@ func (prv *PrivateKey) KEK2012256(pub *PublicKey, ukm *big.Int) ([]byte, error) return nil, err } h := gost34112012256.New() - h.Write(key) + if _, err = h.Write(key); err != nil { + return nil, err + } return h.Sum(key[:0]), nil } @@ -42,6 +44,8 @@ func (prv *PrivateKey) KEK2012512(pub *PublicKey, ukm *big.Int) ([]byte, error) return nil, err } h := gost34112012512.New() - h.Write(key) + if _, err = h.Write(key); err != nil { + return nil, err + } return h.Sum(key[:0]), nil } diff --git a/gost34112012256/kdf.go b/gost34112012256/kdf.go index 43c08ae..d818fb2 100644 --- a/gost34112012256/kdf.go +++ b/gost34112012256/kdf.go @@ -29,12 +29,24 @@ func NewKDF(key []byte) *KDF { } func (kdf *KDF) Derive(dst, label, seed []byte) (r []byte) { - kdf.h.Write([]byte{0x01}) - kdf.h.Write(label) - kdf.h.Write([]byte{0x00}) - kdf.h.Write(seed) - kdf.h.Write([]byte{0x01}) - kdf.h.Write([]byte{0x00}) + if _, err := kdf.h.Write([]byte{0x01}); err != nil { + panic(err) + } + if _, err := kdf.h.Write(label); err != nil { + panic(err) + } + if _, err := kdf.h.Write([]byte{0x00}); err != nil { + panic(err) + } + if _, err := kdf.h.Write(seed); err != nil { + panic(err) + } + if _, err := kdf.h.Write([]byte{0x01}); err != nil { + panic(err) + } + if _, err := kdf.h.Write([]byte{0x00}); err != nil { + panic(err) + } r = kdf.h.Sum(dst) kdf.h.Reset() return r diff --git a/install.texi b/install.texi index 93c181f..7cf962c 100644 --- a/install.texi +++ b/install.texi @@ -1,7 +1,7 @@ @node Download @unnumbered Download -@set VERSION 4.2.2 +@set VERSION 4.2.3 Preferable way is to download tarball with the signature from website and, for example, run tests with benchmarks: diff --git a/news.texi b/news.texi index eb34c76..d2d1e82 100644 --- a/news.texi +++ b/news.texi @@ -3,6 +3,10 @@ @table @strong +@anchor{Release 4.2.3} +@item 4.2.3 + Panic on all possible hash @code{Write} errors. + @anchor{Release 4.2.2} @item 4.2.2 More 34.10-2012 test vectors. diff --git a/prfplus/gost.go b/prfplus/gost.go index 86f4cac..4b1aed6 100644 --- a/prfplus/gost.go +++ b/prfplus/gost.go @@ -39,7 +39,9 @@ func (prf PRFIPsecPRFPlusGOSTR34112012) BlockSize() int { } func (prf PRFIPsecPRFPlusGOSTR34112012) Derive(salt []byte) []byte { - prf.h.Write(salt) + if _, err := prf.h.Write(salt); err != nil { + panic(err) + } sum := prf.h.Sum(nil) prf.h.Reset() return sum -- 2.44.0