diff --git a/pubkey/elgamal/key_pkcs1.go b/pubkey/elgamal/key_pkcs1.go index d936814..e20143e 100644 --- a/pubkey/elgamal/key_pkcs1.go +++ b/pubkey/elgamal/key_pkcs1.go @@ -94,7 +94,7 @@ func (this PKCS1Key) ParsePublicKey(der []byte) (*PublicKey, error) { !keyDer.ReadASN1Integer(publicKey.G) || !keyDer.ReadASN1Integer(q) || !keyDer.ReadASN1Integer(publicKey.Y) { - return nil, errors.New("cryptobin/elgamal: invalid EIGamal public key") + return nil, errors.New("cryptobin/elgamal: invalid ElGamal public key") } return publicKey, nil @@ -154,11 +154,11 @@ func (this PKCS1Key) ParsePrivateKey(der []byte) (*PrivateKey, error) { !keyDer.ReadASN1Integer(q) || !keyDer.ReadASN1Integer(privateKey.Y) || !keyDer.ReadASN1Integer(privateKey.X) { - return nil, errors.New("cryptobin/elgamal: invalid EIGamal private key") + return nil, errors.New("cryptobin/elgamal: invalid ElGamal private key") } if version != elgamalPrivKeyVersion { - return nil, fmt.Errorf("cryptobin/elgamal: unknown EIGamal private key version %d", version) + return nil, fmt.Errorf("cryptobin/elgamal: unknown ElGamal private key version %d", version) } return privateKey, nil diff --git a/pubkey/elgamal/key_pkcs8.go b/pubkey/elgamal/key_pkcs8.go index c7936f6..6d81ff2 100644 --- a/pubkey/elgamal/key_pkcs8.go +++ b/pubkey/elgamal/key_pkcs8.go @@ -13,14 +13,14 @@ import ( var ( // Unsure about this OID - // oidPublicKeyEIGamal = asn1.ObjectIdentifier{1, 3, 14, 7, 2, 1, 1} + // oidPublicKeyElGamal = asn1.ObjectIdentifier{1, 3, 14, 7, 2, 1, 1} // oidMD2WithRSA = asn1.ObjectIdentifier{1, 3, 14, 7, 2, 3, 1} // oidMD2WithElGamal = asn1.ObjectIdentifier{1, 3, 14, 7, 2, 3, 2} // cryptlib public-key algorithm - oidPublicKeyEIGamal = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1} - oidEIGamalWithSHA1 = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1, 1} - oidEIGamalWithRIPEMD160 = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1, 2} + oidPublicKeyElGamal = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1} + oidElGamalWithSHA1 = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1, 1} + oidElGamalWithRIPEMD160 = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1, 2} ) // elgamal Parameters @@ -91,7 +91,7 @@ func (this PKCS8Key) MarshalPublicKey(key *PublicKey) ([]byte, error) { return nil, errors.New("cryptobin/elgamal: failed to marshal algo param: " + err.Error()) } - publicKeyAlgorithm.Algorithm = oidPublicKeyEIGamal + publicKeyAlgorithm.Algorithm = oidPublicKeyElGamal publicKeyAlgorithm.Parameters.FullBytes = paramBytes var yInt cryptobyte.Builder @@ -130,7 +130,7 @@ func (this PKCS8Key) ParsePublicKey(der []byte) (*PublicKey, error) { return nil, asn1.SyntaxError{Msg: "trailing data"} } - algoEq := pki.Algorithm.Algorithm.Equal(oidPublicKeyEIGamal) + algoEq := pki.Algorithm.Algorithm.Equal(oidPublicKeyElGamal) if !algoEq { return nil, errors.New("cryptobin/elgamal: unknown public key algorithm") } @@ -142,7 +142,7 @@ func (this PKCS8Key) ParsePublicKey(der []byte) (*PublicKey, error) { y := new(big.Int) if !yDer.ReadASN1Integer(y) { - return nil, errors.New("cryptobin/elgamal: invalid EIGamal public key") + return nil, errors.New("cryptobin/elgamal: invalid ElGamal public key") } pub := &PublicKey{ @@ -155,13 +155,13 @@ func (this PKCS8Key) ParsePublicKey(der []byte) (*PublicKey, error) { if !paramsDer.ReadASN1(¶msDer, cryptobyte_asn1.SEQUENCE) || !paramsDer.ReadASN1Integer(pub.P) || !paramsDer.ReadASN1Integer(pub.G) { - return nil, errors.New("cryptobin/elgamal: invalid EIGamal public key") + return nil, errors.New("cryptobin/elgamal: invalid ElGamal public key") } if pub.Y.Sign() <= 0 || pub.G.Sign() <= 0 || pub.P.Sign() <= 0 { - return nil, errors.New("cryptobin/elgamal: zero or negative EIGamal parameter") + return nil, errors.New("cryptobin/elgamal: zero or negative ElGamal parameter") } return pub, nil @@ -194,7 +194,7 @@ func (this PKCS8Key) MarshalPrivateKey(key *PrivateKey) ([]byte, error) { } privKey.Algo = pkix.AlgorithmIdentifier{ - Algorithm: oidPublicKeyEIGamal, + Algorithm: oidPublicKeyElGamal, Parameters: asn1.RawValue{ FullBytes: paramBytes, }, @@ -226,7 +226,7 @@ func (this PKCS8Key) ParsePrivateKey(der []byte) (key *PrivateKey, err error) { return nil, err } - if !privKey.Algo.Algorithm.Equal(oidPublicKeyEIGamal) { + if !privKey.Algo.Algorithm.Equal(oidPublicKeyElGamal) { return nil, fmt.Errorf("cryptobin/elgamal: PKCS#8 wrapping contained private key with unknown algorithm: %v", privKey.Algo.Algorithm) } @@ -234,7 +234,7 @@ func (this PKCS8Key) ParsePrivateKey(der []byte) (key *PrivateKey, err error) { x := new(big.Int) if !xDer.ReadASN1Integer(x) { - return nil, errors.New("cryptobin/elgamal: invalid EIGamal public key") + return nil, errors.New("cryptobin/elgamal: invalid ElGamal public key") } priv := &PrivateKey{ @@ -251,7 +251,7 @@ func (this PKCS8Key) ParsePrivateKey(der []byte) (key *PrivateKey, err error) { if !paramsDer.ReadASN1(¶msDer, cryptobyte_asn1.SEQUENCE) || !paramsDer.ReadASN1Integer(priv.P) || !paramsDer.ReadASN1Integer(priv.G) { - return nil, errors.New("cryptobin/elgamal: invalid EIGamal private key") + return nil, errors.New("cryptobin/elgamal: invalid ElGamal private key") } // 算出 Y 值 @@ -259,7 +259,7 @@ func (this PKCS8Key) ParsePrivateKey(der []byte) (key *PrivateKey, err error) { if priv.Y.Sign() <= 0 || priv.G.Sign() <= 0 || priv.P.Sign() <= 0 || priv.X.Sign() <= 0 { - return nil, errors.New("cryptobin/elgamal: zero or negative EIGamal parameter") + return nil, errors.New("cryptobin/elgamal: zero or negative ElGamal parameter") } return priv, nil diff --git a/x509/x509.go b/x509/x509.go index 7c12836..7637bd8 100644 --- a/x509/x509.go +++ b/x509/x509.go @@ -270,15 +270,15 @@ func parsePublicKey(algo PublicKeyAlgorithm, keyData *publicKeyInfo) (any, error } return pub, nil - case EIGamal: + case ElGamal: keyBytes, err := asn1.Marshal(*keyData) if err != nil { - return nil, errors.New("x509: failed to unmarshal EIGamal publickey") + return nil, errors.New("x509: failed to unmarshal ElGamal publickey") } pub, err := elgamal.ParsePKCS8PublicKey(keyBytes) if err != nil { - return nil, errors.New("x509: failed to unmarshal EIGamal publickey") + return nil, errors.New("x509: failed to unmarshal ElGamal publickey") } return pub, nil @@ -361,8 +361,8 @@ const ( GOST3410WithGOST34112001 GOST3410WithGOST34112012256 GOST3410WithGOST34112012512 - EIGamalWithSHA1 - EIGamalWithRIPEMD160 + ElGamalWithSHA1 + ElGamalWithRIPEMD160 ) func (algo SignatureAlgorithm) isRSAPSS() bool { @@ -398,8 +398,8 @@ var algoName = [...]string{ GOST3410WithGOST34112001: "GOST3410-GOST34112001", GOST3410WithGOST34112012256: "GOST3410-GOST34112012256", GOST3410WithGOST34112012512: "GOST3410-GOST34112012512", - EIGamalWithSHA1: "EIGamal-SHA1", - EIGamalWithRIPEMD160: "EIGamal-RIPEMD160", + ElGamalWithSHA1: "ElGamal-SHA1", + ElGamalWithRIPEMD160: "ElGamal-RIPEMD160", } func (algo SignatureAlgorithm) String() string { @@ -419,7 +419,7 @@ const ( Ed25519 SM2 GOST3410 - EIGamal + ElGamal ) // OIDs for signature algorithms @@ -497,8 +497,8 @@ var ( oidSignatureGOST3410WithGOST34112012256 = asn1.ObjectIdentifier{1, 2, 643, 7, 1, 1, 3, 2} oidSignatureGOST3410WithGOST34112012512 = asn1.ObjectIdentifier{1, 2, 643, 7, 1, 1, 3, 3} - oidSignatureEIGamalWithSHA1 = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1, 1} - oidSignatureEIGamalWithRIPEMD160 = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1, 2} + oidSignatureElGamalWithSHA1 = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1, 1} + oidSignatureElGamalWithRIPEMD160 = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1, 2} oidSM3 = asn1.ObjectIdentifier{1, 2, 156, 10197, 1, 401, 1} oidSHA256 = asn1.ObjectIdentifier{2, 16, 840, 1, 101, 3, 4, 2, 1} @@ -554,8 +554,8 @@ var signatureAlgorithmDetails = []struct { {GOST3410WithGOST34112012256, oidSignatureGOST3410WithGOST34112012256, GOST3410, GOST34112012256}, {GOST3410WithGOST34112012512, oidSignatureGOST3410WithGOST34112012512, GOST3410, GOST34112012512}, - {EIGamalWithSHA1, oidSignatureEIGamalWithSHA1, EIGamal, SHA1}, - {EIGamalWithRIPEMD160, oidSignatureEIGamalWithRIPEMD160, EIGamal, RIPEMD160}, + {ElGamalWithSHA1, oidSignatureElGamalWithSHA1, ElGamal, SHA1}, + {ElGamalWithRIPEMD160, oidSignatureElGamalWithRIPEMD160, ElGamal, RIPEMD160}, } // pssParameters reflects the parameters in an AlgorithmIdentifier that @@ -694,7 +694,7 @@ var ( oidGost2012PublicKey256 = asn1.ObjectIdentifier{1, 2, 643, 7, 1, 1, 1, 1} oidGost2012PublicKey512 = asn1.ObjectIdentifier{1, 2, 643, 7, 1, 1, 1, 2} - oidPublicKeyEIGamal = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1} + oidPublicKeyElGamal = asn1.ObjectIdentifier{1, 3, 6, 1, 4, 1, 3029, 1, 2, 1} ) func getPublicKeyAlgorithmFromOID(oid asn1.ObjectIdentifier) PublicKeyAlgorithm { @@ -711,8 +711,8 @@ func getPublicKeyAlgorithmFromOID(oid asn1.ObjectIdentifier) PublicKeyAlgorithm oid.Equal(oidGost2012PublicKey256), oid.Equal(oidGost2012PublicKey512): return GOST3410 - case oid.Equal(oidPublicKeyEIGamal): - return EIGamal + case oid.Equal(oidPublicKeyElGamal): + return ElGamal } return UnknownPublicKeyAlgorithm @@ -1090,7 +1090,7 @@ func checkSignature(algo SignatureAlgorithm, signed, signature []byte, publicKey var hashType Hash switch algo { case SHA1WithRSA, DSAWithSHA1, ECDSAWithSHA1, - SM2WithSHA1, EIGamalWithSHA1: + SM2WithSHA1, ElGamalWithSHA1: hashType = SHA1 case SHA256WithRSA, SHA256WithRSAPSS, DSAWithSHA256, ECDSAWithSHA256, SM2WithSHA256: @@ -1111,7 +1111,7 @@ func checkSignature(algo SignatureAlgorithm, signed, signature []byte, publicKey hashType = GOST34112012256 case GOST3410WithGOST34112012512: hashType = GOST34112012512 - case EIGamalWithRIPEMD160: + case ElGamalWithRIPEMD160: hashType = RIPEMD160 default: return ErrUnsupportedAlgorithm @@ -2044,15 +2044,15 @@ func signingParamsForPublicKey(pub any, requestedSigAlgo SignatureAlgorithm) (ha } case *elgamal.PublicKey: - pubType = EIGamal + pubType = ElGamal hashFunc = SHA1 - sigAlgo.Algorithm = oidSignatureEIGamalWithSHA1 + sigAlgo.Algorithm = oidSignatureElGamalWithSHA1 sigAlgo.Parameters = asn1.RawValue{ Tag: 5, } default: - err = errors.New("x509: only RSA, SM2, GOST3410, EIGamal and ECDSA keys supported") + err = errors.New("x509: only RSA, SM2, GOST3410, ElGamal and ECDSA keys supported") } if err != nil { diff --git a/x509/x509_test.go b/x509/x509_test.go index 72de34a..15d7b1e 100644 --- a/x509/x509_test.go +++ b/x509/x509_test.go @@ -976,7 +976,7 @@ func Test_ELGamal(t *testing.T) { CommonName: "test.example.com", Organization: []string{"Test"}, }, - SignatureAlgorithm: EIGamalWithSHA1, + SignatureAlgorithm: ElGamalWithSHA1, } reqPem, err := CreateCertificateRequest(rand.Reader, &templateReq, privKey) @@ -1023,7 +1023,7 @@ func Test_ELGamal(t *testing.T) { NotBefore: time.Now(), NotAfter: time.Date(2028, time.October, 10, 12, 1, 1, 1, time.UTC), - SignatureAlgorithm: EIGamalWithSHA1, + SignatureAlgorithm: ElGamalWithSHA1, SubjectKeyId: []byte{1, 2, 3, 4}, KeyUsage: KeyUsageCertSign, @@ -1117,7 +1117,7 @@ func Test_ELGamal2(t *testing.T) { CommonName: "test.example.com", Organization: []string{"Test"}, }, - SignatureAlgorithm: EIGamalWithRIPEMD160, + SignatureAlgorithm: ElGamalWithRIPEMD160, } reqPem, err := CreateCertificateRequest(rand.Reader, &templateReq, privKey) @@ -1164,7 +1164,7 @@ func Test_ELGamal2(t *testing.T) { NotBefore: time.Now(), NotAfter: time.Date(2028, time.October, 10, 12, 1, 1, 1, time.UTC), - SignatureAlgorithm: EIGamalWithRIPEMD160, + SignatureAlgorithm: ElGamalWithRIPEMD160, SubjectKeyId: []byte{1, 2, 3, 4}, KeyUsage: KeyUsageCertSign,