X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=gost3410%2Fvko2012.go;fp=gost3410%2Fvko2012.go;h=7a30b4ed367d07a34cec98cffbd5a04f5219e33e;hb=c07494bbd559b9d00f391e28cfd070e18afe9900;hp=0000000000000000000000000000000000000000;hpb=107600dede989f0cc479b5a72c5f97e174307154;p=gogost.git diff --git a/gost3410/vko2012.go b/gost3410/vko2012.go new file mode 100644 index 0000000..7a30b4e --- /dev/null +++ b/gost3410/vko2012.go @@ -0,0 +1,47 @@ +// GoGOST -- Pure Go GOST cryptographic functions library +// Copyright (C) 2015-2019 Sergey Matveev +// +// 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, version 3 of the License. +// +// 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 . + +package gost3410 + +import ( + "math/big" + + "go.cypherpunks.ru/gogost/v4/gost34112012256" + "go.cypherpunks.ru/gogost/v4/gost34112012512" +) + +// RFC 7836 VKO GOST R 34.10-2012 256-bit key agreement function. +// UKM is user keying material, also called VKO-factor. +func (prv *PrivateKey) KEK2012256(pub *PublicKey, ukm *big.Int) ([]byte, error) { + key, err := prv.KEK(pub, ukm) + if err != nil { + return nil, err + } + h := gost34112012256.New() + h.Write(key) + return h.Sum(key[:0]), nil +} + +// RFC 7836 VKO GOST R 34.10-2012 512-bit key agreement function. +// UKM is user keying material, also called VKO-factor. +func (prv *PrivateKey) KEK2012512(pub *PublicKey, ukm *big.Int) ([]byte, error) { + key, err := prv.KEK(pub, ukm) + if err != nil { + return nil, err + } + h := gost34112012512.New() + h.Write(key) + return h.Sum(key[:0]), nil +}