X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=gost3410%2Fprivate.go;h=8168fe00bbfda343b0d6f776cf4ccb04b5c1c773;hb=5fc90f4d05f0515cc91dd9feceb813e2b753cbb7;hp=4d73b07fc3f652c5c7018cea459503e47029f7f1;hpb=6d9056bfe4a2d69469a1e70f3bf08f89b377b06e;p=gogost.git diff --git a/gost3410/private.go b/gost3410/private.go index 4d73b07..8168fe0 100644 --- a/gost3410/private.go +++ b/gost3410/private.go @@ -1,5 +1,5 @@ // GoGOST -- Pure Go GOST cryptographic functions library -// Copyright (C) 2015-2021 Sergey Matveev +// Copyright (C) 2015-2022 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 @@ -28,8 +28,8 @@ type PrivateKey struct { Key *big.Int } -func NewPrivateKey(curve *Curve, raw []byte) (*PrivateKey, error) { - pointSize := curve.PointSize() +func NewPrivateKey(c *Curve, raw []byte) (*PrivateKey, error) { + pointSize := c.PointSize() if len(raw) != pointSize { return nil, fmt.Errorf("gogost/gost3410: len(key) != %d", pointSize) } @@ -41,15 +41,15 @@ func NewPrivateKey(curve *Curve, raw []byte) (*PrivateKey, error) { if k.Cmp(zero) == 0 { return nil, errors.New("gogost/gost3410: zero private key") } - return &PrivateKey{curve, k}, nil + return &PrivateKey{c, k.Mod(k, c.Q)}, nil } -func GenPrivateKey(curve *Curve, rand io.Reader) (*PrivateKey, error) { - raw := make([]byte, curve.PointSize()) +func GenPrivateKey(c *Curve, rand io.Reader) (*PrivateKey, error) { + raw := make([]byte, c.PointSize()) if _, err := io.ReadFull(rand, raw); err != nil { return nil, err } - return NewPrivateKey(curve, raw) + return NewPrivateKey(c, raw) } func (prv *PrivateKey) Raw() []byte {