// GoGOST -- Pure Go GOST cryptographic functions library
-// Copyright (C) 2015-2019 Sergey Matveev <stargrave@stargrave.org>
+// Copyright (C) 2015-2021 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
bigInt1 *big.Int = big.NewInt(1)
bigInt2 *big.Int = big.NewInt(2)
bigInt3 *big.Int = big.NewInt(3)
+ bigInt4 *big.Int = big.NewInt(4)
)
type Curve struct {
P *big.Int // Characteristic of the underlying prime field
Q *big.Int // Elliptic curve subgroup order
+ Co *big.Int // Cofactor
+
// Equation coefficients of the elliptic curve in canonical form
A *big.Int
B *big.Int
edT *big.Int
}
-func NewCurve(p, q, a, b, x, y, e, d *big.Int) (*Curve, error) {
+func NewCurve(p, q, a, b, x, y, e, d, co *big.Int) (*Curve, error) {
c := Curve{
Name: "unknown",
P: p,
r2.Mod(r2, c.P)
c.pos(r2)
if r1.Cmp(r2) != 0 {
- return nil, errors.New("Invalid curve parameters")
+ return nil, errors.New("gogost/gost3410: invalid curve parameters")
}
if e != nil && d != nil {
c.E = e
c.D = d
}
+ if co == nil {
+ c.Co = bigInt1
+ } else {
+ c.Co = co
+ }
return &c, nil
}
+func (c *Curve) PointSize() int {
+ return PointSize(c.P)
+}
+
func (c *Curve) pos(v *big.Int) {
if v.Cmp(zero) < 0 {
v.Add(v, c.P)
func (c *Curve) Exp(degree, xS, yS *big.Int) (*big.Int, *big.Int, error) {
if degree.Cmp(zero) == 0 {
- return nil, nil, errors.New("Bad degree value")
+ return nil, nil, errors.New("gogost/gost3410: zero degree value")
}
dg := big.NewInt(0).Sub(degree, bigInt1)
tx := big.NewInt(0).Set(xS)