// GoGOST -- Pure Go GOST cryptographic functions library
-// Copyright (C) 2015-2020 Sergey Matveev <stargrave@stargrave.org>
+// Copyright (C) 2015-2022 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
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)
}
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 {