LDFLAGS = -X cypherpunks.ru/gogost.Version=$(VERSION)
gogost-streebog:
- GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/gogost/gost34112012/cmd/gogost-streebog
+ GOPATH=$(GOPATH) go build -ldflags "$(LDFLAGS)" cypherpunks.ru/gogost/cmd/gogost-streebog
bench:
GOPATH=$(GOPATH) go test -benchmem -bench . cypherpunks.ru/gogost/...
"encoding/hex"
"flag"
"fmt"
+ "hash"
"io"
"os"
"cypherpunks.ru/gogost"
- "cypherpunks.ru/gogost/gost34112012"
+ "cypherpunks.ru/gogost/gost34112012256"
+ "cypherpunks.ru/gogost/gost34112012512"
)
var (
- digestSize = flag.Int("size", 256, "Digest size (either 256 or 512)")
+ digestSize = flag.Int("size", 256, "Digest size in bits (either 256 or 512)")
version = flag.Bool("version", false, "Print version information")
)
fmt.Println(gogost.Version)
return
}
- h := gost34112012.New(*digestSize)
+ var h hash.Hash
+ if *digestSize == 256 {
+ h = gost34112012256.New()
+ } else {
+ h = gost34112012512.New()
+ }
io.Copy(h, os.Stdin)
fmt.Println(hex.EncodeToString(h.Sum(nil)))
}
--- /dev/null
+// GoGOST -- Pure Go GOST cryptographic functions library
+// Copyright (C) 2015-2016 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+// GOST R 34.11-2012 256-bit hash function.
+// RFC 6986.
+package gost34112012256
+
+import (
+ "cypherpunks.ru/gogost/internal/gost34112012"
+)
+
+const (
+ BlockSize = gost34112012.BlockSize
+ Size = 32
+)
+
+func New() *gost34112012.Hash {
+ return gost34112012.New(32)
+}
--- /dev/null
+// GoGOST -- Pure Go GOST cryptographic functions library
+// Copyright (C) 2015-2016 Sergey Matveev <stargrave@stargrave.org>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+// GOST R 34.11-2012 512-bit hash function.
+// RFC 6986.
+package gost34112012512
+
+import (
+ "cypherpunks.ru/gogost/internal/gost34112012"
+)
+
+const (
+ BlockSize = gost34112012.BlockSize
+ Size = 64
+)
+
+func New() *gost34112012.Hash {
+ return gost34112012.New(64)
+}
const (
BlockSize = 64
- Size = 64
)
var (
}
// Create new hash object with specified size digest size.
-// Size is either 512 or 256 (bits).
func New(size int) *Hash {
- if size != 256 && size != 512 {
- panic("size must be either 256 or 512")
+ if size != 32 && size != 64 {
+ panic("size must be either 32 or 64")
}
h := Hash{
size: size,
h.buf = nil
for i := 0; i < BlockSize; i++ {
h.chk[i] = 0
- if h.size == 256 {
+ if h.size == 32 {
h.hsh[i] = 1
} else {
h.hsh[i] = 0
}
func (h *Hash) Size() int {
- return h.size / 8
+ return h.size
}
func (h *Hash) Write(data []byte) (int, error) {
binary.LittleEndian.PutUint64(h.tmp[:], h.n+uint64(len(h.buf))*8)
hsh = g(0, hsh, h.tmp)
hsh = g(0, hsh, add512bit(h.chk, buf))
- if h.size == 256 {
+ if h.size == 32 {
return append(in, hsh[BlockSize/2:]...)
}
return append(in, hsh[:]...)
)
func TestHashInterface(t *testing.T) {
- h := New(512)
+ h := New(64)
var _ hash.Hash = h
}
func TestVectors(t *testing.T) {
- h512 := New(512)
- h256 := New(256)
+ h512 := New(64)
+ h256 := New(32)
// First vector
m := []byte{
}
func TestBlocksized(t *testing.T) {
- h := New(512)
+ h := New(64)
m := make([]byte, BlockSize)
for i := 0; i < BlockSize; i++ {
m[i] = byte(i)
}
func TestBehaviour(t *testing.T) {
- h := New(512)
+ h := New(64)
// Sum does not change the state
hsh1 := h.Sum(nil)
if bytes.Compare(h.Sum(nil), hsh1) != 0 {
}
func TestRandom(t *testing.T) {
- h := New(512)
+ h := New(64)
f := func(data []byte) bool {
h.Reset()
h.Write(data)
}
func BenchmarkHash(b *testing.B) {
- h := New(512)
+ h := New(64)
src := make([]byte, BlockSize+1)
rand.Read(src)
b.ResetTimer()