]> Cypherpunks.ru repositories - gogost.git/blobdiff - gost3410/public.go
Remove excess gost3410.Mode
[gogost.git] / gost3410 / public.go
index 675431cf816f72bc4448c5916ef1fe3fb564ad9c..e2e3814e381e9dd8db2caf0408a67bd79fb65d86 100644 (file)
@@ -21,14 +21,14 @@ import (
 )
 
 type PublicKey struct {
-       C    *Curve
-       Mode Mode
-       X    *big.Int
-       Y    *big.Int
+       C *Curve
+       X *big.Int
+       Y *big.Int
 }
 
-func NewPublicKey(curve *Curve, mode Mode, raw []byte) (*PublicKey, error) {
-       key := make([]byte, 2*int(mode))
+func NewPublicKey(curve *Curve, raw []byte) (*PublicKey, error) {
+       pointSize := curve.PointSize()
+       key := make([]byte, 2*pointSize)
        if len(raw) != len(key) {
                return nil, fmt.Errorf("gogost/gost3410: len(key) != %d", len(key))
        }
@@ -37,27 +37,28 @@ func NewPublicKey(curve *Curve, mode Mode, raw []byte) (*PublicKey, error) {
        }
        return &PublicKey{
                curve,
-               mode,
-               bytes2big(key[int(mode) : 2*int(mode)]),
-               bytes2big(key[:int(mode)]),
+               bytes2big(key[pointSize : 2*pointSize]),
+               bytes2big(key[:pointSize]),
        }, nil
 }
 
 func (pub *PublicKey) Raw() []byte {
+       pointSize := pub.C.PointSize()
        raw := append(
-               pad(pub.Y.Bytes(), int(pub.Mode)),
-               pad(pub.X.Bytes(), int(pub.Mode))...,
+               pad(pub.Y.Bytes(), pointSize),
+               pad(pub.X.Bytes(), pointSize)...,
        )
        reverse(raw)
        return raw
 }
 
 func (pub *PublicKey) VerifyDigest(digest, signature []byte) (bool, error) {
-       if len(signature) != 2*int(pub.Mode) {
-               return false, fmt.Errorf("gogost/gost3410: len(signature) != %d", 2*int(pub.Mode))
+       pointSize := pub.C.PointSize()
+       if len(signature) != 2*pointSize {
+               return false, fmt.Errorf("gogost/gost3410: len(signature) != %d", 2*pointSize)
        }
-       s := bytes2big(signature[:pub.Mode])
-       r := bytes2big(signature[pub.Mode:])
+       s := bytes2big(signature[:pointSize])
+       r := bytes2big(signature[pointSize:])
        if r.Cmp(zero) <= 0 ||
                r.Cmp(pub.C.Q) >= 0 ||
                s.Cmp(zero) <= 0 ||