diff --git a/cryptobin/ca/create.go b/cryptobin/ca/create.go index 769bfa28..1aecfa76 100644 --- a/cryptobin/ca/create.go +++ b/cryptobin/ca/create.go @@ -174,44 +174,44 @@ func (this CA) CreatePrivateKey() CA { switch privateKey := this.privateKey.(type) { case *rsa.PrivateKey: - x509PrivateKey := x509.MarshalPKCS1PrivateKey(privateKey) + privateKeyBytes := x509.MarshalPKCS1PrivateKey(privateKey) privateBlock = &pem.Block{ Type: "RSA PRIVATE KEY", - Bytes: x509PrivateKey, + Bytes: privateKeyBytes, } case *ecdsa.PrivateKey: - x509PrivateKey, err := x509.MarshalECPrivateKey(privateKey) + privateKeyBytes, err := x509.MarshalECPrivateKey(privateKey) if err != nil { return this.AppendError(err) } privateBlock = &pem.Block{ Type: "EC PRIVATE KEY", - Bytes: x509PrivateKey, + Bytes: privateKeyBytes, } case ed25519.PrivateKey: - x509PrivateKey, err := x509.MarshalPKCS8PrivateKey(privateKey) + privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(privateKey) if err != nil { return this.AppendError(err) } privateBlock = &pem.Block{ Type: "PRIVATE KEY", - Bytes: x509PrivateKey, + Bytes: privateKeyBytes, } case *sm2.PrivateKey: - x509PrivateKey, err := sm2.MarshalPrivateKey(privateKey) + privateKeyBytes, err := sm2.MarshalPrivateKey(privateKey) if err != nil { return this.AppendError(err) } privateBlock = &pem.Block{ Type: "PRIVATE KEY", - Bytes: x509PrivateKey, + Bytes: privateKeyBytes, } default: diff --git a/cryptobin/dh/curve25519/create.go b/cryptobin/dh/curve25519/create.go index 4c30e903..55bd9569 100644 --- a/cryptobin/dh/curve25519/create.go +++ b/cryptobin/dh/curve25519/create.go @@ -35,14 +35,14 @@ func (this Curve25519) CreatePrivateKey() Curve25519 { return this.AppendError(err) } - privateKey, err := curve25519.MarshalPrivateKey(this.privateKey) + privateKeyBytes, err := curve25519.MarshalPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } privateBlock := &pem.Block{ Type: "PRIVATE KEY", - Bytes: privateKey, + Bytes: privateKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -64,7 +64,7 @@ func (this Curve25519) CreatePrivateKeyWithPassword(password string, opts ...any } // 生成私钥 - privateKey, err := curve25519.MarshalPrivateKey(this.privateKey) + privateKeyBytes, err := curve25519.MarshalPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -73,7 +73,7 @@ func (this Curve25519) CreatePrivateKeyWithPassword(password string, opts ...any privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - privateKey, + privateKeyBytes, []byte(password), opt, ) diff --git a/cryptobin/dh/dh/create.go b/cryptobin/dh/dh/create.go index 3376fe52..046807c6 100644 --- a/cryptobin/dh/dh/create.go +++ b/cryptobin/dh/dh/create.go @@ -35,14 +35,14 @@ func (this DH) CreatePrivateKey() DH { return this.AppendError(err) } - privateKey, err := dh.MarshalPrivateKey(this.privateKey) + privateKeyBytes, err := dh.MarshalPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } privateBlock := &pem.Block{ Type: "PRIVATE KEY", - Bytes: privateKey, + Bytes: privateKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -64,7 +64,7 @@ func (this DH) CreatePrivateKeyWithPassword(password string, opts ...any) DH { } // 生成私钥 - privateKey, err := dh.MarshalPrivateKey(this.privateKey) + privateKeyBytes, err := dh.MarshalPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -73,7 +73,7 @@ func (this DH) CreatePrivateKeyWithPassword(password string, opts ...any) DH { privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - privateKey, + privateKeyBytes, []byte(password), opt, ) diff --git a/cryptobin/dh/ecdh/create.go b/cryptobin/dh/ecdh/create.go index 253506a1..95bfb520 100644 --- a/cryptobin/dh/ecdh/create.go +++ b/cryptobin/dh/ecdh/create.go @@ -35,14 +35,14 @@ func (this ECDH) CreatePrivateKey() ECDH { return this.AppendError(err) } - privateKey, err := ecdh.MarshalPrivateKey(this.privateKey) + privateKeyBytes, err := ecdh.MarshalPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } privateBlock := &pem.Block{ Type: "PRIVATE KEY", - Bytes: privateKey, + Bytes: privateKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -64,7 +64,7 @@ func (this ECDH) CreatePrivateKeyWithPassword(password string, opts ...any) ECDH } // 生成私钥 - privateKey, err := ecdh.MarshalPrivateKey(this.privateKey) + privateKeyBytes, err := ecdh.MarshalPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -73,7 +73,7 @@ func (this ECDH) CreatePrivateKeyWithPassword(password string, opts ...any) ECDH privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - privateKey, + privateKeyBytes, []byte(password), opt, ) diff --git a/cryptobin/dsa/create.go b/cryptobin/dsa/create.go index c81bc054..4c11b756 100644 --- a/cryptobin/dsa/create.go +++ b/cryptobin/dsa/create.go @@ -91,7 +91,7 @@ func (this DSA) CreatePKCS1PrivateKeyWithPassword(password string, opts ...strin } // 生成私钥 - x509PrivateKey, err := dsa.MarshalPKCS1PrivateKey(this.privateKey) + privateKeyBytes, err := dsa.MarshalPKCS1PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -100,7 +100,7 @@ func (this DSA) CreatePKCS1PrivateKeyWithPassword(password string, opts ...strin privateBlock, err := pkcs1.EncryptPEMBlock( rand.Reader, "DSA PRIVATE KEY", - x509PrivateKey, + privateKeyBytes, []byte(password), cipher, ) @@ -173,7 +173,7 @@ func (this DSA) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any) } // 生成私钥 - x509PrivateKey, err := dsa.MarshalPKCS8PrivateKey(this.privateKey) + privateKeyBytes, err := dsa.MarshalPKCS8PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -182,7 +182,7 @@ func (this DSA) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any) privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - x509PrivateKey, + privateKeyBytes, []byte(password), opt, ) diff --git a/cryptobin/ecdh/create.go b/cryptobin/ecdh/create.go index 215cc19a..07a00688 100644 --- a/cryptobin/ecdh/create.go +++ b/cryptobin/ecdh/create.go @@ -37,14 +37,14 @@ func (this ECDH) CreatePrivateKey() ECDH { return this.AppendError(err) } - privateKey, err := x509.MarshalPKCS8PrivateKey(this.privateKey) + privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } privateBlock := &pem.Block{ Type: "PRIVATE KEY", - Bytes: privateKey, + Bytes: privateKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -66,7 +66,7 @@ func (this ECDH) CreatePrivateKeyWithPassword(password string, opts ...any) ECDH } // 生成私钥 - privateKey, err := x509.MarshalPKCS8PrivateKey(this.privateKey) + privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -75,7 +75,7 @@ func (this ECDH) CreatePrivateKeyWithPassword(password string, opts ...any) ECDH privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - privateKey, + privateKeyBytes, []byte(password), opt, ) @@ -119,19 +119,19 @@ func (this ECDH) CreateECDHPrivateKey() ECDH { return this.AppendError(err) } - priv, err := ecdh.FromPrivateKey(this.privateKey) + privateKey, err := ecdh.FromPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } - privateKey, err := ecdh_key.MarshalPrivateKey(priv) + privateKeyBytes, err := ecdh_key.MarshalPrivateKey(privateKey) if err != nil { return this.AppendError(err) } privateBlock := &pem.Block{ Type: "PRIVATE KEY", - Bytes: privateKey, + Bytes: privateKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -151,13 +151,13 @@ func (this ECDH) CreateECDHPrivateKeyWithPassword(password string, opts ...any) return this.AppendError(err) } - priv, err := ecdh.FromPrivateKey(this.privateKey) + privateKey, err := ecdh.FromPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } // 生成私钥 - privateKey, err := ecdh_key.MarshalPrivateKey(priv) + privateKeyBytes, err := ecdh_key.MarshalPrivateKey(privateKey) if err != nil { return this.AppendError(err) } @@ -166,7 +166,7 @@ func (this ECDH) CreateECDHPrivateKeyWithPassword(password string, opts ...any) privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - privateKey, + privateKeyBytes, []byte(password), opt, ) @@ -186,12 +186,12 @@ func (this ECDH) CreateECDHPublicKey() ECDH { return this.AppendError(err) } - pub, err := ecdh.FromPublicKey(this.publicKey) + publicKey, err := ecdh.FromPublicKey(this.publicKey) if err != nil { return this.AppendError(err) } - publicKeyBytes, err := ecdh_key.MarshalPublicKey(pub) + publicKeyBytes, err := ecdh_key.MarshalPublicKey(publicKey) if err != nil { return this.AppendError(err) } diff --git a/cryptobin/ecdsa/create.go b/cryptobin/ecdsa/create.go index 3ea8fd5b..2344f914 100644 --- a/cryptobin/ecdsa/create.go +++ b/cryptobin/ecdsa/create.go @@ -50,14 +50,14 @@ func (this ECDSA) CreatePKCS1PrivateKey() ECDSA { return this.AppendError(err) } - x509PrivateKey, err := x509.MarshalECPrivateKey(this.privateKey) + publicKeyBytes, err := x509.MarshalECPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } privateBlock := &pem.Block{ Type: "EC PRIVATE KEY", - Bytes: x509PrivateKey, + Bytes: publicKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -85,7 +85,7 @@ func (this ECDSA) CreatePKCS1PrivateKeyWithPassword(password string, opts ...str } // 生成私钥 - x509PrivateKey, err := x509.MarshalECPrivateKey(this.privateKey) + publicKeyBytes, err := x509.MarshalECPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -94,7 +94,7 @@ func (this ECDSA) CreatePKCS1PrivateKeyWithPassword(password string, opts ...str privateBlock, err := pkcs1.EncryptPEMBlock( rand.Reader, "EC PRIVATE KEY", - x509PrivateKey, + publicKeyBytes, []byte(password), cipher, ) @@ -116,14 +116,14 @@ func (this ECDSA) CreatePKCS8PrivateKey() ECDSA { return this.AppendError(err) } - x509PrivateKey, err := x509.MarshalPKCS8PrivateKey(this.privateKey) + publicKeyBytes, err := x509.MarshalPKCS8PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } privateBlock := &pem.Block{ Type: "PRIVATE KEY", - Bytes: x509PrivateKey, + Bytes: publicKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -145,7 +145,7 @@ func (this ECDSA) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any } // 生成私钥 - x509PrivateKey, err := x509.MarshalPKCS8PrivateKey(this.privateKey) + publicKeyBytes, err := x509.MarshalPKCS8PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -154,7 +154,7 @@ func (this ECDSA) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - x509PrivateKey, + publicKeyBytes, []byte(password), opt, ) @@ -176,14 +176,14 @@ func (this ECDSA) CreatePublicKey() ECDSA { return this.AppendError(err) } - x509PublicKey, err := x509.MarshalPKIXPublicKey(this.publicKey) + publicKeyBytes, err := x509.MarshalPKIXPublicKey(this.publicKey) if err != nil { return this.AppendError(err) } publicBlock := &pem.Block{ Type: "PUBLIC KEY", - Bytes: x509PublicKey, + Bytes: publicKeyBytes, } this.keyData = pem.EncodeToMemory(publicBlock) diff --git a/cryptobin/ed448/create.go b/cryptobin/ed448/create.go index 4c045d8a..27bcc98a 100644 --- a/cryptobin/ed448/create.go +++ b/cryptobin/ed448/create.go @@ -32,14 +32,14 @@ func (this ED448) CreatePrivateKey() ED448 { return this.AppendError(err) } - x509PrivateKey, err := ed448.MarshalPrivateKey(this.privateKey) + privateKeyBytes, err := ed448.MarshalPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } privateBlock := &pem.Block{ Type: "PRIVATE KEY", - Bytes: x509PrivateKey, + Bytes: privateKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -61,7 +61,7 @@ func (this ED448) CreatePrivateKeyWithPassword(password string, opts ...any) ED4 } // 生成私钥 - x509PrivateKey, err := ed448.MarshalPrivateKey(this.privateKey) + privateKeyBytes, err := ed448.MarshalPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -70,7 +70,7 @@ func (this ED448) CreatePrivateKeyWithPassword(password string, opts ...any) ED4 privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - x509PrivateKey, + privateKeyBytes, []byte(password), opt, ) @@ -90,14 +90,14 @@ func (this ED448) CreatePublicKey() ED448 { return this.AppendError(err) } - x509PublicKey, err := ed448.MarshalPublicKey(this.publicKey) + publicKeyBytes, err := ed448.MarshalPublicKey(this.publicKey) if err != nil { return this.AppendError(err) } publicBlock := &pem.Block{ Type: "PUBLIC KEY", - Bytes: x509PublicKey, + Bytes: publicKeyBytes, } this.keyData = pem.EncodeToMemory(publicBlock) diff --git a/cryptobin/eddsa/create.go b/cryptobin/eddsa/create.go index 55d5159d..be647faa 100644 --- a/cryptobin/eddsa/create.go +++ b/cryptobin/eddsa/create.go @@ -35,14 +35,14 @@ func (this EdDSA) CreatePrivateKey() EdDSA { return this.AppendError(err) } - x509PrivateKey, err := x509.MarshalPKCS8PrivateKey(this.privateKey) + privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } privateBlock := &pem.Block{ Type: "PRIVATE KEY", - Bytes: x509PrivateKey, + Bytes: privateKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -64,7 +64,7 @@ func (this EdDSA) CreatePrivateKeyWithPassword(password string, opts ...any) EdD } // 生成私钥 - x509PrivateKey, err := x509.MarshalPKCS8PrivateKey(this.privateKey) + privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -73,7 +73,7 @@ func (this EdDSA) CreatePrivateKeyWithPassword(password string, opts ...any) EdD privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - x509PrivateKey, + privateKeyBytes, []byte(password), opt, ) @@ -93,14 +93,14 @@ func (this EdDSA) CreatePublicKey() EdDSA { return this.AppendError(err) } - x509PublicKey, err := x509.MarshalPKIXPublicKey(this.publicKey) + publicKeyBytes, err := x509.MarshalPKIXPublicKey(this.publicKey) if err != nil { return this.AppendError(err) } publicBlock := &pem.Block{ Type: "PUBLIC KEY", - Bytes: x509PublicKey, + Bytes: publicKeyBytes, } this.keyData = pem.EncodeToMemory(publicBlock) diff --git a/cryptobin/elgamal/create.go b/cryptobin/elgamal/create.go index 9bc19fae..98ff5b20 100644 --- a/cryptobin/elgamal/create.go +++ b/cryptobin/elgamal/create.go @@ -91,7 +91,7 @@ func (this EIGamal) CreatePKCS1PrivateKeyWithPassword(password string, opts ...s } // 生成私钥 - x509PrivateKey, err := elgamal.MarshalPKCS1PrivateKey(this.privateKey) + privateKeyBytes, err := elgamal.MarshalPKCS1PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -100,7 +100,7 @@ func (this EIGamal) CreatePKCS1PrivateKeyWithPassword(password string, opts ...s privateBlock, err := pkcs1.EncryptPEMBlock( rand.Reader, "EIGamal PRIVATE KEY", - x509PrivateKey, + privateKeyBytes, []byte(password), cipher, ) @@ -173,7 +173,7 @@ func (this EIGamal) CreatePKCS8PrivateKeyWithPassword(password string, opts ...a } // 生成私钥 - x509PrivateKey, err := elgamal.MarshalPKCS8PrivateKey(this.privateKey) + privateKeyBytes, err := elgamal.MarshalPKCS8PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -182,7 +182,7 @@ func (this EIGamal) CreatePKCS8PrivateKeyWithPassword(password string, opts ...a privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - x509PrivateKey, + privateKeyBytes, []byte(password), opt, ) diff --git a/cryptobin/rsa/create.go b/cryptobin/rsa/create.go index 4d4c8d29..5eaed306 100644 --- a/cryptobin/rsa/create.go +++ b/cryptobin/rsa/create.go @@ -54,11 +54,11 @@ func (this RSA) CreatePKCS1PrivateKey() RSA { return this.AppendError(err) } - x509PrivateKey := x509.MarshalPKCS1PrivateKey(this.privateKey) + privateKeyBytes := x509.MarshalPKCS1PrivateKey(this.privateKey) privateBlock := &pem.Block{ Type: "RSA PRIVATE KEY", - Bytes: x509PrivateKey, + Bytes: privateKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -88,13 +88,13 @@ func (this RSA) CreatePKCS1PrivateKeyWithPassword(password string, opts ...strin } // 生成私钥 - x509PrivateKey := x509.MarshalPKCS1PrivateKey(this.privateKey) + privateKeyBytes := x509.MarshalPKCS1PrivateKey(this.privateKey) // 生成加密数据 privateBlock, err := pkcs1.EncryptPEMBlock( rand.Reader, "RSA PRIVATE KEY", - x509PrivateKey, + privateKeyBytes, []byte(password), cipher, ) @@ -114,11 +114,11 @@ func (this RSA) CreatePKCS1PublicKey() RSA { return this.AppendError(err) } - x509PublicKey := x509.MarshalPKCS1PublicKey(this.publicKey) + publicKeyBytes := x509.MarshalPKCS1PublicKey(this.publicKey) publicBlock := &pem.Block{ Type: "RSA PUBLIC KEY", - Bytes: x509PublicKey, + Bytes: publicKeyBytes, } this.keyData = pem.EncodeToMemory(publicBlock) @@ -135,14 +135,14 @@ func (this RSA) CreatePKCS8PrivateKey() RSA { return this.AppendError(err) } - x509PrivateKey, err := x509.MarshalPKCS8PrivateKey(this.privateKey) + privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } privateBlock := &pem.Block{ Type: "PRIVATE KEY", - Bytes: x509PrivateKey, + Bytes: privateKeyBytes, } this.keyData = pem.EncodeToMemory(privateBlock) @@ -164,7 +164,7 @@ func (this RSA) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any) } // 生成私钥 - x509PrivateKey, err := x509.MarshalPKCS8PrivateKey(this.privateKey) + privateKeyBytes, err := x509.MarshalPKCS8PrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -173,7 +173,7 @@ func (this RSA) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any) privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - x509PrivateKey, + privateKeyBytes, []byte(password), opt, ) @@ -193,14 +193,14 @@ func (this RSA) CreatePKCS8PublicKey() RSA { return this.AppendError(err) } - x509PublicKey, err := x509.MarshalPKIXPublicKey(this.publicKey) + publicKeyBytes, err := x509.MarshalPKIXPublicKey(this.publicKey) if err != nil { return this.AppendError(err) } publicBlock := &pem.Block{ Type: "PUBLIC KEY", - Bytes: x509PublicKey, + Bytes: publicKeyBytes, } this.keyData = pem.EncodeToMemory(publicBlock) diff --git a/cryptobin/sm2/create.go b/cryptobin/sm2/create.go index 4a15b860..86313cb5 100644 --- a/cryptobin/sm2/create.go +++ b/cryptobin/sm2/create.go @@ -54,7 +54,7 @@ func (this SM2) CreatePKCS1PrivateKey() SM2 { } privateBlock := &pem.Block{ - Type: "EC PRIVATE KEY", + Type: "SM2 PRIVATE KEY", Bytes: privateKeyBytes, } @@ -91,7 +91,7 @@ func (this SM2) CreatePKCS1PrivateKeyWithPassword(password string, opts ...strin // 生成加密数据 privateBlock, err := pkcs1.EncryptPEMBlock( rand.Reader, - "EC PRIVATE KEY", + "SM2 PRIVATE KEY", privateKeyBytes, []byte(password), cipher, @@ -144,7 +144,7 @@ func (this SM2) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any) } // 生成私钥 - x509PrivateKey, err := sm2.MarshalPrivateKey(this.privateKey) + privateKeyBytes, err := sm2.MarshalPrivateKey(this.privateKey) if err != nil { return this.AppendError(err) } @@ -153,7 +153,7 @@ func (this SM2) CreatePKCS8PrivateKeyWithPassword(password string, opts ...any) privateBlock, err := pkcs8.EncryptPEMBlock( rand.Reader, "ENCRYPTED PRIVATE KEY", - x509PrivateKey, + privateKeyBytes, []byte(password), opt, ) diff --git a/ecc/ecc.go b/ecc/ecc.go index 94428a9f..5fca79e1 100644 --- a/ecc/ecc.go +++ b/ecc/ecc.go @@ -72,6 +72,7 @@ var ( } ) +// curve list var paramsFromCurve = map[elliptic.Curve]*ECIESParams{ secp256k1.S256(): ECIES_AES128_SHA256, elliptic.P256(): ECIES_AES128_SHA256, @@ -190,13 +191,15 @@ func (priv *PrivateKey) GenerateShared(pub *PublicKey, skLen, macLen int) (sk [] return nil, ErrSharedKeyIsPointAtInfinity } + xBytes := x.Bytes() + sk = make([]byte, skLen + macLen) - skBytes := x.Bytes() - if len(skBytes) > len(sk) { - copy(sk[:], skBytes) + if len(xBytes) > len(sk) { + // copy xBytes last data to sk + copy(sk, xBytes[len(xBytes)-len(sk):]) } else { - copy(sk[len(sk)-len(skBytes):], skBytes) + copy(sk[len(sk)-len(xBytes):], xBytes) } return sk, nil @@ -290,7 +293,7 @@ func (priv *PrivateKey) Decrypt(c, s1, s2 []byte) (m []byte, err error) { } // 对称加密解出数据 / decrypt data - m, err = cipherDecrypt(params, Ke, c[mStart:mEnd]) + m, err = symDecrypt(params, Ke, c[mStart:mEnd]) return } @@ -343,7 +346,7 @@ func Encrypt(rand io.Reader, pub *PublicKey, m, s1, s2 []byte) (ct []byte, err e hash.Reset() // 对称加密数据 / Encrypt data - em, err := cipherEncrypt(rand, params, Ke, m) + em, err := symEncrypt(rand, params, Ke, m) if err != nil || len(em) <= params.BlockSize { return } @@ -437,21 +440,21 @@ func messageTag(hash func() hash.Hash, km, msg, shared []byte) []byte { } // Generate an initialisation vector for CTR mode. -func generateIV(params *ECIESParams, rand io.Reader) (iv []byte, err error) { +func generateIV(rand io.Reader, params *ECIESParams) (iv []byte, err error) { iv = make([]byte, params.BlockSize) _, err = io.ReadFull(rand, iv) return } -// cipherEncrypt carries out CTR encryption using the block cipher specified in the +// symEncrypt carries out CTR encryption using the block cipher specified in the // parameters. -func cipherEncrypt(rand io.Reader, params *ECIESParams, key, m []byte) (ct []byte, err error) { +func symEncrypt(rand io.Reader, params *ECIESParams, key, m []byte) (ct []byte, err error) { c, err := params.Cipher(key) if err != nil { return } - iv, err := generateIV(params, rand) + iv, err := generateIV(rand, params) if err != nil { return } @@ -466,9 +469,9 @@ func cipherEncrypt(rand io.Reader, params *ECIESParams, key, m []byte) (ct []byt return } -// cipherDecrypt carries out CTR decryption using the block cipher specified in +// symDecrypt carries out CTR decryption using the block cipher specified in // the parameters -func cipherDecrypt(params *ECIESParams, key, ct []byte) (m []byte, err error) { +func symDecrypt(params *ECIESParams, key, ct []byte) (m []byte, err error) { c, err := params.Cipher(key) if err != nil { return diff --git a/gost/curve.go b/gost/curve.go index bac6c80c..b416551c 100644 --- a/gost/curve.go +++ b/gost/curve.go @@ -155,16 +155,16 @@ func (c *Curve) Exp(degree, xS, yS *big.Int) (*big.Int, *big.Int, error) { return tx, ty, nil } -func (our *Curve) Equal(their *Curve) bool { - return our.P.Cmp(their.P) == 0 && - our.Q.Cmp(their.Q) == 0 && - our.A.Cmp(their.A) == 0 && - our.B.Cmp(their.B) == 0 && - our.X.Cmp(their.X) == 0 && - our.Y.Cmp(their.Y) == 0 && - ((our.E == nil && their.E == nil) || our.E.Cmp(their.E) == 0) && - ((our.D == nil && their.D == nil) || our.D.Cmp(their.D) == 0) && - our.Co.Cmp(their.Co) == 0 +func (c *Curve) Equal(x *Curve) bool { + return c.P.Cmp(x.P) == 0 && + c.Q.Cmp(x.Q) == 0 && + c.A.Cmp(x.A) == 0 && + c.B.Cmp(x.B) == 0 && + c.X.Cmp(x.X) == 0 && + c.Y.Cmp(x.Y) == 0 && + ((c.E == nil && x.E == nil) || c.E.Cmp(x.E) == 0) && + ((c.D == nil && x.D == nil) || c.D.Cmp(x.D) == 0) && + c.Co.Cmp(x.Co) == 0 } func (c *Curve) String() string { diff --git a/gost/ecdh.go b/gost/ecdh.go index 391b605a..d4559731 100644 --- a/gost/ecdh.go +++ b/gost/ecdh.go @@ -20,7 +20,7 @@ func ECDHWithUkm(priv *PrivateKey, pub *PublicKey, ukm []byte) ([]byte, error) { t[i] = ukm[len(ukm)-i-1] } - ukmBigint := BytesToBigint(t) + ukmBigint := bytesToBigint(t) keyX, keyY, err := priv.Curve.Exp(priv.D, pub.X, pub.Y) if err != nil { @@ -38,12 +38,12 @@ func ECDHWithUkm(priv *PrivateKey, pub *PublicKey, ukm []byte) ([]byte, error) { // use LE pointSize := priv.Curve.PointSize() - raw := append( - BytesPadding(keyY.Bytes(), pointSize), - BytesPadding(keyX.Bytes(), pointSize)..., - ) + raw := make([]byte, 2*pointSize) - Reverse(raw) + keyY.FillBytes(raw[ 0: pointSize]) + keyX.FillBytes(raw[pointSize:2*pointSize]) + + reverse(raw) return raw, nil } diff --git a/gost/gost.go b/gost/gost.go index daa46d41..2b30a421 100644 --- a/gost/gost.go +++ b/gost/gost.go @@ -60,8 +60,8 @@ func (pub *PublicKey) VerifyBytes(digest, signature []byte) (bool, error) { return false, fmt.Errorf("gost: len(signature)=%d != %d", len(signature), 2*pointSize) } - r := BytesToBigint(signature[:pointSize]) - s := BytesToBigint(signature[pointSize:]) + r := bytesToBigint(signature[:pointSize]) + s := bytesToBigint(signature[pointSize:]) verify, err := VerifyWithRS(pub, digest, r, s) if err != nil { @@ -120,10 +120,10 @@ func (priv *PrivateKey) SignBytes(rand io.Reader, digest []byte, opts crypto.Sig pointSize := priv.Curve.PointSize() - signed := append( - BytesPadding(r.Bytes(), pointSize), - BytesPadding(s.Bytes(), pointSize)..., - ) + signed := make([]byte, 2*pointSize) + + r.FillBytes(signed[ 0: pointSize]) + s.FillBytes(signed[pointSize:2*pointSize]) return signed, nil } @@ -135,7 +135,7 @@ func GenerateKey(rand io.Reader, curve *Curve) (*PrivateKey, error) { return nil, fmt.Errorf("gost: %w", err) } - k := BytesToBigint(private) + k := bytesToBigint(private) if k.Cmp(zero) == 0 { return nil, errors.New("gost: zero private key") } @@ -163,12 +163,7 @@ func GenerateKey(rand io.Reader, curve *Curve) (*PrivateKey, error) { // Unmarshal private key func NewPrivateKey(c *Curve, raw []byte) (*PrivateKey, error) { - pointSize := c.PointSize() - if len(raw) != pointSize { - return nil, fmt.Errorf("gost: len(key)=%d != %d", len(raw), pointSize) - } - - k := BytesToBigint(raw) + k := bytesToBigint(raw) if k.Cmp(zero) == 0 { return nil, errors.New("gost: zero private key") } @@ -186,38 +181,49 @@ func NewPrivateKey(c *Curve, raw []byte) (*PrivateKey, error) { Y: y, } - return &PrivateKey{pub, d}, nil + priv := &PrivateKey{ + PublicKey: pub, + D: d, + } + + return priv, nil } // Marshal private key -func ToPrivateKey(priv *PrivateKey) (raw []byte) { - return BytesPadding(priv.D.Bytes(), priv.Curve.PointSize()) +func ToPrivateKey(priv *PrivateKey) []byte { + return priv.D.Bytes() } // Unmarshal public key func NewPublicKey(c *Curve, raw []byte) (*PublicKey, error) { pointSize := c.PointSize() - key := make([]byte, 2*pointSize) - if len(raw) != len(key) { - return nil, fmt.Errorf("gost: len(key)=%d != %d", len(key), pointSize) + if len(raw) != 2*pointSize { + return nil, fmt.Errorf("gost: publicKey length too large or short.") } - return &PublicKey{ - c, - BytesToBigint(raw[:pointSize]), - BytesToBigint(raw[pointSize:]), - }, nil + x := bytesToBigint(raw[:pointSize]) + y := bytesToBigint(raw[pointSize:]) + + pub := &PublicKey{ + Curve: c, + X: x, + Y: y, + } + + return pub, nil } // Marshal public key func ToPublicKey(pub *PublicKey) []byte { pointSize := pub.Curve.PointSize() - return append( - BytesPadding(pub.X.Bytes(), pointSize), - BytesPadding(pub.Y.Bytes(), pointSize)..., - ) + buf := make([]byte, 2*pointSize) + + pub.X.FillBytes(buf[ 0: pointSize]) + pub.Y.FillBytes(buf[pointSize:2*pointSize]) + + return buf } // Sign hash @@ -262,7 +268,7 @@ func VerifyBytes(pub *PublicKey, hash, sig []byte) (bool, error) { // SignToRS func SignToRS(rand io.Reader, priv *PrivateKey, digest []byte) (*big.Int, *big.Int, error) { - e := BytesToBigint(digest) + e := bytesToBigint(digest) e.Mod(e, priv.Curve.Q) if e.Cmp(zero) == 0 { @@ -283,7 +289,7 @@ Retry: return nil, nil, fmt.Errorf("gost: %w", err) } - k = BytesToBigint(kRaw) + k = bytesToBigint(kRaw) k.Mod(k, priv.Curve.Q) if k.Cmp(zero) == 0 { goto Retry @@ -319,7 +325,7 @@ func VerifyWithRS(pub *PublicKey, digest []byte, r, s *big.Int) (bool, error) { return false, nil } - e := BytesToBigint(digest) + e := bytesToBigint(digest) e.Mod(e, pub.Curve.Q) if e.Cmp(zero) == 0 { e = big.NewInt(1) diff --git a/gost/key_pkcs1.go b/gost/key_pkcs1.go index f3dc868a..874889c0 100644 --- a/gost/key_pkcs1.go +++ b/gost/key_pkcs1.go @@ -1,9 +1,20 @@ package gost import ( + "fmt" "errors" + "encoding/asn1" ) +// Per RFC 5915 the NamedCurveOID is marked as ASN.1 OPTIONAL, however in +// most cases it is not. +type gostPrivateKey struct { + Version int + PrivateKey []byte + NamedCurveOID asn1.ObjectIdentifier `asn1:"optional,explicit,tag:0"` + PublicKey asn1.BitString `asn1:"optional,explicit,tag:1"` +} + // pkcs1 func ParseGostPrivateKey(der []byte) (*PrivateKey, error) { return parseGostPrivateKey(nil, der) @@ -18,3 +29,49 @@ func MarshalGostPrivateKey(key *PrivateKey) ([]byte, error) { return marshalGostPrivateKeyWithOID(key, oid) } + +func marshalGostPrivateKeyWithOID(key *PrivateKey, oid asn1.ObjectIdentifier) ([]byte, error) { + if !key.Curve.IsOnCurve(key.X, key.Y) { + return nil, errors.New("invalid gost key public key") + } + + privateKey := make([]byte, key.Curve.PointSize()) + + return asn1.Marshal(gostPrivateKey{ + Version: gostPrivKeyVersion, + PrivateKey: key.D.FillBytes(privateKey), + NamedCurveOID: oid, + PublicKey: asn1.BitString{ + Bytes: Marshal(key.Curve, key.X, key.Y), + }, + }) +} + +func parseGostPrivateKey(namedCurveOID *asn1.ObjectIdentifier, der []byte) (key *PrivateKey, err error) { + var privKey gostPrivateKey + if _, err := asn1.Unmarshal(der, &privKey); err != nil { + return nil, errors.New("gost: failed to parse EC private key: " + err.Error()) + } + + if privKey.Version != gostPrivKeyVersion { + return nil, fmt.Errorf("gost: unknown EC private key version %d", privKey.Version) + } + + var curve *Curve + if namedCurveOID != nil { + curve = NamedCurveFromOid(*namedCurveOID) + } else { + curve = NamedCurveFromOid(privKey.NamedCurveOID) + } + + if curve == nil { + return nil, errors.New("gost: unknown gost curve") + } + + priv, err := NewPrivateKey(curve, privKey.PrivateKey) + if err != nil { + return nil, err + } + + return priv, nil +} diff --git a/gost/key_pkcs8.go b/gost/key_pkcs8.go index 35eef850..ff45dd7d 100644 --- a/gost/key_pkcs8.go +++ b/gost/key_pkcs8.go @@ -1,7 +1,6 @@ package gost import ( - "fmt" "errors" "encoding/asn1" "crypto/x509/pkix" @@ -66,15 +65,6 @@ type publicKeyInfo struct { PublicKey asn1.BitString } -// Per RFC 5915 the NamedCurveOID is marked as ASN.1 OPTIONAL, however in -// most cases it is not. -type gostPrivateKey struct { - Version int - PrivateKey []byte - NamedCurveOID asn1.ObjectIdentifier `asn1:"optional,explicit,tag:0"` - PublicKey asn1.BitString `asn1:"optional,explicit,tag:1"` -} - // Marshal PublicKey func MarshalPublicKey(pub *PublicKey) ([]byte, error) { var publicKeyBytes []byte @@ -99,7 +89,7 @@ func MarshalPublicKey(pub *PublicKey) ([]byte, error) { return nil, errors.New("gost: invalid gost curve public key") } - publicKeyBytes = ToPublicKey(pub) + publicKeyBytes = Marshal(pub.Curve, pub.X, pub.Y) pkix := pkixPublicKey{ Algo: publicKeyAlgorithm, @@ -153,12 +143,18 @@ func ParsePublicKey(derBytes []byte) (pub *PublicKey, err error) { return } - pub, err = NewPublicKey(namedCurve, der) - if err != nil { + x, y := Unmarshal(namedCurve, der) + if x == nil || y == nil { err = errors.New("gost: failed to unmarshal gost curve point") return } + pub = &PublicKey{ + Curve: namedCurve, + X: x, + Y: y, + } + return } @@ -229,50 +225,3 @@ func ParsePrivateKey(derBytes []byte) (*PrivateKey, error) { return key, nil } - -func marshalGostPrivateKeyWithOID(key *PrivateKey, oid asn1.ObjectIdentifier) ([]byte, error) { - if !key.Curve.IsOnCurve(key.X, key.Y) { - return nil, errors.New("invalid gost key public key") - } - - privateKey := ToPrivateKey(key) - publicKey := ToPublicKey(&key.PublicKey) - - return asn1.Marshal(gostPrivateKey{ - Version: gostPrivKeyVersion, - PrivateKey: privateKey, - NamedCurveOID: oid, - PublicKey: asn1.BitString{ - Bytes: publicKey, - }, - }) -} - -func parseGostPrivateKey(namedCurveOID *asn1.ObjectIdentifier, der []byte) (key *PrivateKey, err error) { - var privKey gostPrivateKey - if _, err := asn1.Unmarshal(der, &privKey); err != nil { - return nil, errors.New("gost: failed to parse EC private key: " + err.Error()) - } - - if privKey.Version != gostPrivKeyVersion { - return nil, fmt.Errorf("gost: unknown EC private key version %d", privKey.Version) - } - - var curve *Curve - if namedCurveOID != nil { - curve = NamedCurveFromOid(*namedCurveOID) - } else { - curve = NamedCurveFromOid(privKey.NamedCurveOID) - } - - if curve == nil { - return nil, errors.New("gost: unknown gost curve") - } - - priv, err := NewPrivateKey(curve, privKey.PrivateKey) - if err != nil { - return nil, err - } - - return priv, nil -} diff --git a/gost/params.go b/gost/params.go index eecfec90..82e4bf30 100644 --- a/gost/params.go +++ b/gost/params.go @@ -5,37 +5,37 @@ import "math/big" var ( CurveGostR34102001ParamSetcc func() *Curve = func() *Curve { curve, _ := NewCurve( - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xC7, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x5f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x60, 0x61, 0x17, 0xa2, 0xf4, 0xbd, 0xe4, 0x28, 0xb7, 0x45, 0x8a, 0x54, 0xb6, 0xe8, 0x7b, 0x85, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0xc4, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x2d, 0x06, 0xB4, 0x26, 0x5e, 0xbc, 0x74, 0x9f, 0xf7, 0xd0, 0xf1, 0xf1, 0xf8, 0x82, 0x32, 0xe8, 0x16, 0x32, 0xe9, 0x08, 0x8f, 0xd4, 0x4b, 0x77, 0x87, 0xd5, 0xe4, 0x07, 0xe9, 0x55, 0x08, 0x0c, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xa2, 0x0e, 0x03, 0x4b, 0xf8, 0x81, 0x3e, 0xf5, 0xc1, 0x8d, 0x01, 0x10, 0x5e, 0x72, 0x6a, 0x17, 0xeb, 0x24, 0x8b, 0x26, 0x4a, 0xe9, 0x70, 0x6f, @@ -53,37 +53,37 @@ var ( // id-GostR3410-2001-TestParamSet CurveIdGostR34102001TestParamSet func() *Curve = func() *Curve { curve, _ := NewCurve( - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x31, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x50, 0xFE, 0x8A, 0x18, 0x92, 0x97, 0x61, 0x54, 0xC5, 0x9C, 0xFC, 0x19, 0x3A, 0xCC, 0xF5, 0xB3, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x5F, 0xBF, 0xF4, 0x98, 0xAA, 0x93, 0x8C, 0xE7, 0x39, 0xB8, 0xE0, 0x22, 0xFB, 0xAF, 0xEF, 0x40, 0x56, 0x3F, 0x6E, 0x6A, 0x34, 0x72, 0xFC, 0x2A, 0x51, 0x4C, 0x0C, 0xE9, 0xDA, 0xE2, 0x3B, 0x7E, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x08, 0xE2, 0xA8, 0xA0, 0xE6, 0x51, 0x47, 0xD4, 0xBD, 0x63, 0x16, 0x03, 0x0E, 0x16, 0xD1, 0x9C, 0x85, 0xC9, 0x7F, 0x0A, 0x9C, 0xA2, 0x67, 0x12, @@ -101,44 +101,44 @@ var ( // id-tc26-gost-3410-12-256-paramSetA CurveIdtc26gost341012256paramSetA func() *Curve = func() *Curve { curve, _ := NewCurve( - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0x97, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0F, 0xD8, 0xCD, 0xDF, 0xC8, 0x7B, 0x66, 0x35, 0xC1, 0x15, 0xAF, 0x55, 0x6C, 0x36, 0x0C, 0x67, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xC2, 0x17, 0x3F, 0x15, 0x13, 0x98, 0x16, 0x73, 0xAF, 0x48, 0x92, 0xC2, 0x30, 0x35, 0xA2, 0x7C, 0xE2, 0x5E, 0x20, 0x13, 0xBF, 0x95, 0xAA, 0x33, 0xB2, 0x2C, 0x65, 0x6F, 0x27, 0x7E, 0x73, 0x35, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x29, 0x5F, 0x9B, 0xAE, 0x74, 0x28, 0xED, 0x9C, 0xCC, 0x20, 0xE7, 0xC3, 0x59, 0xA9, 0xD4, 0x1A, 0x22, 0xFC, 0xCD, 0x91, 0x08, 0xE1, 0x7B, 0xF7, 0xBA, 0x93, 0x37, 0xA6, 0xF8, 0xAE, 0x95, 0x13, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x91, 0xE3, 0x84, 0x43, 0xA5, 0xE8, 0x2C, 0x0D, 0x88, 0x09, 0x23, 0x42, 0x57, 0x12, 0xB2, 0xBB, 0x65, 0x8B, 0x91, 0x96, 0x93, 0x2E, 0x02, 0xC7, 0x8B, 0x25, 0x82, 0xFE, 0x74, 0x2D, 0xAA, 0x28, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x32, 0x87, 0x94, 0x23, 0xAB, 0x1A, 0x03, 0x75, 0x89, 0x57, 0x86, 0xC4, 0xBB, 0x46, 0xE9, 0x56, 0x5F, 0xDE, 0x0B, 0x53, 0x44, 0x76, 0x67, 0x40, 0xAF, 0x26, 0x8A, 0xDB, 0x32, 0x32, 0x2E, 0x5C, }), bigInt1, - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x06, 0x05, 0xF6, 0xB7, 0xC1, 0x83, 0xFA, 0x81, 0x57, 0x8B, 0xC3, 0x9C, 0xFA, 0xD5, 0x18, 0x13, 0x2B, 0x9D, 0xF6, 0x28, 0x97, 0x00, 0x9A, 0xF7, @@ -154,37 +154,37 @@ var ( // id-tc26-gost-3410-12-256-paramSetB CurveIdtc26gost341012256paramSetB func() *Curve = func() *Curve { curve, _ := NewCurve( - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0x97, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x6C, 0x61, 0x10, 0x70, 0x99, 0x5A, 0xD1, 0x00, 0x45, 0x84, 0x1B, 0x09, 0xB7, 0x61, 0xB8, 0x93, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0x94, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xa6, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x8D, 0x91, 0xE4, 0x71, 0xE0, 0x98, 0x9C, 0xDA, 0x27, 0xDF, 0x50, 0x5A, 0x45, 0x3F, 0x2B, 0x76, 0x35, 0x29, 0x4F, 0x2D, 0xDF, 0x23, 0xE3, 0xB1, @@ -202,37 +202,37 @@ var ( // id-tc26-gost-3410-12-256-paramSetC CurveIdtc26gost341012256paramSetC func() *Curve = func() *Curve { curve, _ := NewCurve( - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x99, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x5F, 0x70, 0x0C, 0xFF, 0xF1, 0xA6, 0x24, 0xE5, 0xE4, 0x97, 0x16, 0x1B, 0xCC, 0x8A, 0x19, 0x8F, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0C, 0x96, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x3E, 0x1A, 0xF4, 0x19, 0xA2, 0x69, 0xA5, 0xF8, 0x66, 0xA7, 0xD3, 0xC2, 0x5C, 0x3D, 0xF8, 0x0A, 0xE9, 0x79, 0x25, 0x93, 0x73, 0xFF, 0x2B, 0x18, 0x2F, 0x49, 0xD4, 0xCE, 0x7E, 0x1B, 0xBC, 0x8B, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x3F, 0xA8, 0x12, 0x43, 0x59, 0xF9, 0x66, 0x80, 0xB8, 0x3D, 0x1C, 0x3E, 0xB2, 0xC0, 0x70, 0xE5, 0xC5, 0x45, 0xC9, 0x85, 0x8D, 0x03, 0xEC, 0xFB, @@ -250,37 +250,37 @@ var ( // id-tc26-gost-3410-12-256-paramSetD CurveIdtc26gost341012256paramSetD func() *Curve = func() *Curve { curve, _ := NewCurve( - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x9B, 0x9F, 0x60, 0x5F, 0x5A, 0x85, 0x81, 0x07, 0xAB, 0x1E, 0xC8, 0x5E, 0x6B, 0x41, 0xC8, 0xAA, 0xCF, 0x84, 0x6E, 0x86, 0x78, 0x90, 0x51, 0xD3, 0x79, 0x98, 0xF7, 0xB9, 0x02, 0x2D, 0x75, 0x9B, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x9B, 0x9F, 0x60, 0x5F, 0x5A, 0x85, 0x81, 0x07, 0xAB, 0x1E, 0xC8, 0x5E, 0x6B, 0x41, 0xC8, 0xAA, 0x58, 0x2C, 0xA3, 0x51, 0x1E, 0xDD, 0xFB, 0x74, 0xF0, 0x2F, 0x3A, 0x65, 0x98, 0x98, 0x0B, 0xB9, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x9B, 0x9F, 0x60, 0x5F, 0x5A, 0x85, 0x81, 0x07, 0xAB, 0x1E, 0xC8, 0x5E, 0x6B, 0x41, 0xC8, 0xAA, 0xCF, 0x84, 0x6E, 0x86, 0x78, 0x90, 0x51, 0xD3, 0x79, 0x98, 0xF7, 0xB9, 0x02, 0x2D, 0x75, 0x98, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, 0x5a, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x41, 0xEC, 0xE5, 0x57, 0x43, 0x71, 0x1A, 0x8C, 0x3C, 0xBF, 0x37, 0x83, 0xCD, 0x08, 0xC0, 0xEE, 0x4D, 0x4D, 0xC4, 0x40, 0xD4, 0x64, 0x1A, 0x8F, @@ -298,7 +298,7 @@ var ( // id-tc26-gost-3410-12-512-paramSetTest CurveIdtc26gost341012512paramSetTest func() *Curve = func() *Curve { curve, _ := NewCurve( - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x45, 0x31, 0xAC, 0xD1, 0xFE, 0x00, 0x23, 0xC7, 0x55, 0x0D, 0x26, 0x7B, 0x6B, 0x2F, 0xEE, 0x80, 0x92, 0x2B, 0x14, 0xB2, 0xFF, 0xB9, 0x0F, 0x04, @@ -308,7 +308,7 @@ var ( 0x35, 0xB8, 0x33, 0x6F, 0xAC, 0x22, 0x4D, 0xD8, 0x16, 0x64, 0xBB, 0xF5, 0x28, 0xBE, 0x63, 0x73, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x45, 0x31, 0xAC, 0xD1, 0xFE, 0x00, 0x23, 0xC7, 0x55, 0x0D, 0x26, 0x7B, 0x6B, 0x2F, 0xEE, 0x80, 0x92, 0x2B, 0x14, 0xB2, 0xFF, 0xB9, 0x0F, 0x04, @@ -319,7 +319,7 @@ var ( 0xD6, 0x44, 0xAA, 0xF1, 0x87, 0xE6, 0xE6, 0xDF, }), big.NewInt(7), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x1C, 0xFF, 0x08, 0x06, 0xA3, 0x11, 0x16, 0xDA, 0x29, 0xD8, 0xCF, 0xA5, 0x4E, 0x57, 0xEB, 0x74, 0x8B, 0xC5, 0xF3, 0x77, 0xE4, 0x94, 0x00, 0xFD, @@ -329,7 +329,7 @@ var ( 0xBC, 0x9E, 0x54, 0x0C, 0x2A, 0xDD, 0x68, 0x97, 0xFA, 0xD0, 0xA3, 0x08, 0x4F, 0x30, 0x2A, 0xDC, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x24, 0xD1, 0x9C, 0xC6, 0x45, 0x72, 0xEE, 0x30, 0xF3, 0x96, 0xBF, 0x6E, 0xBB, 0xFD, 0x7A, 0x6C, 0x52, 0x13, 0xB3, 0xB3, 0xD7, 0x05, 0x7C, 0xC8, @@ -339,7 +339,7 @@ var ( 0x8B, 0xC8, 0x49, 0x97, 0x7F, 0xAC, 0x33, 0xB4, 0xB5, 0x30, 0xF1, 0xB1, 0x20, 0x24, 0x8A, 0x9A, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x2B, 0xB3, 0x12, 0xA4, 0x3B, 0xD2, 0xCE, 0x6E, 0x0D, 0x02, 0x06, 0x13, 0xC8, 0x57, 0xAC, 0xDD, 0xCF, 0xBF, 0x06, 0x1E, 0x91, 0xE5, 0xF2, 0xC3, @@ -361,7 +361,7 @@ var ( // id-tc26-gost-3410-12-512-paramSetA CurveIdtc26gost341012512paramSetA func() *Curve = func() *Curve { curve, _ := NewCurve( - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -371,7 +371,7 @@ var ( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xC7, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -381,7 +381,7 @@ var ( 0x9B, 0x4B, 0x38, 0xAB, 0xFA, 0xD2, 0xB8, 0x5D, 0xCA, 0xCD, 0xB1, 0x41, 0x1F, 0x10, 0xB2, 0x75, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -391,7 +391,7 @@ var ( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xC4, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xE8, 0xC2, 0x50, 0x5D, 0xED, 0xFC, 0x86, 0xDD, 0xC1, 0xBD, 0x0B, 0x2B, 0x66, 0x67, 0xF1, 0xDA, 0x34, 0xB8, 0x25, 0x74, 0x76, 0x1C, 0xB0, 0xE8, @@ -401,7 +401,7 @@ var ( 0x86, 0x2E, 0xF9, 0xD4, 0xEB, 0xEE, 0x47, 0x61, 0x50, 0x31, 0x90, 0x78, 0x5A, 0x71, 0xC7, 0x60, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -411,7 +411,7 @@ var ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x75, 0x03, 0xCF, 0xE8, 0x7A, 0x83, 0x6A, 0xE3, 0xA6, 0x1B, 0x88, 0x16, 0xE2, 0x54, 0x50, 0xE6, 0xCE, 0x5E, 0x1C, 0x93, 0xAC, 0xF1, 0xAB, 0xC1, @@ -433,7 +433,7 @@ var ( // id-tc26-gost-3410-12-512-paramSetB CurveIdtc26gost341012512paramSetB func() *Curve = func() *Curve { curve, _ := NewCurve( - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -443,7 +443,7 @@ var ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6F, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -453,7 +453,7 @@ var ( 0x8B, 0x99, 0x67, 0x12, 0x10, 0x1B, 0xEA, 0x0E, 0xC6, 0x34, 0x6C, 0x54, 0x37, 0x4F, 0x25, 0xBD, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -463,7 +463,7 @@ var ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x6C, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x68, 0x7D, 0x1B, 0x45, 0x9D, 0xC8, 0x41, 0x45, 0x7E, 0x3E, 0x06, 0xCF, 0x6F, 0x5E, 0x25, 0x17, 0xB9, 0x7C, 0x7D, 0x61, 0x4A, 0xF1, 0x38, 0xBC, @@ -473,7 +473,7 @@ var ( 0x50, 0xF7, 0x8B, 0xEE, 0x1F, 0xA3, 0x10, 0x6E, 0xFB, 0x8C, 0xCB, 0xC7, 0xC5, 0x14, 0x01, 0x16, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, @@ -483,7 +483,7 @@ var ( 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x1A, 0x8F, 0x7E, 0xDA, 0x38, 0x9B, 0x09, 0x4C, 0x2C, 0x07, 0x1E, 0x36, 0x47, 0xA8, 0x94, 0x0F, 0x3C, 0x12, 0x3B, 0x69, 0x75, 0x78, 0xC2, 0x13, @@ -505,7 +505,7 @@ var ( // id-tc26-gost-3410-12-512-paramSetC CurveIdtc26gost341012512paramSetC func() *Curve = func() *Curve { curve, _ := NewCurve( - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -515,7 +515,7 @@ var ( 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFD, 0xC7, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x3F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, @@ -525,7 +525,7 @@ var ( 0xC8, 0xED, 0xA9, 0xE7, 0xA7, 0x69, 0xA1, 0x26, 0x94, 0x62, 0x3C, 0xEF, 0x47, 0xF0, 0x23, 0xED, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xDC, 0x92, 0x03, 0xE5, 0x14, 0xA7, 0x21, 0x87, 0x54, 0x85, 0xA5, 0x29, 0xD2, 0xC7, 0x22, 0xFB, 0x18, 0x7B, 0xC8, 0x98, 0x0E, 0xB8, 0x66, 0x64, @@ -535,7 +535,7 @@ var ( 0x2A, 0xD9, 0x7F, 0x95, 0x1F, 0xDA, 0x9F, 0x2A, 0x2E, 0xB6, 0x54, 0x6F, 0x39, 0x68, 0x9B, 0xD3, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xB4, 0xC4, 0xEE, 0x28, 0xCE, 0xBC, 0x6C, 0x2C, 0x8A, 0xC1, 0x29, 0x52, 0xCF, 0x37, 0xF1, 0x6A, 0xC7, 0xEF, 0xB6, 0xA9, 0xF6, 0x9F, 0x4B, 0x57, @@ -545,7 +545,7 @@ var ( 0x2B, 0x8C, 0xC7, 0xA5, 0xF5, 0xBF, 0x0A, 0x3C, 0x8D, 0x23, 0x19, 0xA5, 0x31, 0x25, 0x57, 0xE1, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xE2, 0xE3, 0x1E, 0xDF, 0xC2, 0x3D, 0xE7, 0xBD, 0xEB, 0xE2, 0x41, 0xCE, 0x59, 0x3E, 0xF5, 0xDE, 0x22, 0x95, 0xB7, 0xA9, 0xCB, 0xAE, 0xF0, 0x21, @@ -555,7 +555,7 @@ var ( 0xC6, 0xFB, 0x85, 0x48, 0x7E, 0xAE, 0x97, 0xAA, 0xC5, 0xBC, 0x79, 0x28, 0xC1, 0x95, 0x01, 0x48, }), - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0xF5, 0xCE, 0x40, 0xD9, 0x5B, 0x5E, 0xB8, 0x99, 0xAB, 0xBC, 0xCF, 0xF5, 0x91, 0x1C, 0xB8, 0x57, 0x79, 0x39, 0x80, 0x4D, 0x65, 0x27, 0x37, 0x8B, @@ -566,7 +566,7 @@ var ( 0xD0, 0x39, 0x6E, 0x9A, 0x9A, 0xDD, 0xC4, 0x0F, }), bigInt1, - BytesToBigint([]byte{ + bytesToBigint([]byte{ 0x9E, 0x4F, 0x5D, 0x8C, 0x01, 0x7D, 0x8D, 0x9F, 0x13, 0xA5, 0xCF, 0x3C, 0xDF, 0x5B, 0xFE, 0x4D, 0xAB, 0x40, 0x2D, 0x54, 0x19, 0x8E, 0x31, 0xEB, diff --git a/gost/utils.go b/gost/utils.go index e9d14341..68e3f2f0 100644 --- a/gost/utils.go +++ b/gost/utils.go @@ -4,18 +4,67 @@ import ( "math/big" ) -func Reverse(d []byte) { - for i, j := 0, len(d)-1; i < j; i, j = i+1, j-1 { - d[i], d[j] = d[j], d[i] +// Marshal converts a point on the curve into the uncompressed +func Marshal(curve *Curve, x, y *big.Int) []byte { + panicIfNotOnCurve(curve, x, y) + + byteLen := curve.PointSize() + + ret := make([]byte, 1+2*byteLen) + ret[0] = 4 // uncompressed point + + x.FillBytes(ret[1 :1+ byteLen]) + y.FillBytes(ret[1+byteLen:1+2*byteLen]) + + return ret +} + +// Unmarshal converts a point, serialized by Marshal, into an x, y pair. It is +// an error if the point is not in uncompressed form, is not on the curve, or is +// the point at infinity. On error, x = nil. +func Unmarshal(curve *Curve, data []byte) (x, y *big.Int) { + byteLen := curve.PointSize() + if len(data) != 1+2*byteLen { + return nil, nil + } + if data[0] != 4 { // uncompressed form + return nil, nil + } + + p := curve.Params().P + x = new(big.Int).SetBytes(data[1:1+byteLen]) + y = new(big.Int).SetBytes(data[1+byteLen:]) + if x.Cmp(p) >= 0 || y.Cmp(p) >= 0 { + return nil, nil } + + if !curve.IsOnCurve(x, y) { + return nil, nil + } + + return } -func BytesToBigint(d []byte) *big.Int { - return big.NewInt(0).SetBytes(d) +func panicIfNotOnCurve(curve *Curve, x, y *big.Int) { + // (0, 0) is the point at infinity by convention. It's ok to operate on it, + // although IsOnCurve is documented to return false for it. See Issue 37294. + if x.Sign() == 0 && y.Sign() == 0 { + return + } + + if !curve.IsOnCurve(x, y) { + panic("cryptobin/gost: attempted operation on invalid point") + } +} + +func reverse(d []byte) { + for i, j := 0, len(d)-1; i < j; i, j = i+1, j-1 { + d[i], d[j] = d[j], d[i] + } } -func BytesPadding(d []byte, size int) []byte { - return append(make([]byte, size-len(d)), d...) +func bytesToBigint(d []byte) *big.Int { + return new(big.Int).SetBytes(d) } func pointSize(p *big.Int) int {