]> git.immae.eu Git - github/fretlink/terraform-provider-statuscake.git/blobdiff - vendor/golang.org/x/crypto/openpgp/packet/public_key.go
Upgrade to 0.12
[github/fretlink/terraform-provider-statuscake.git] / vendor / golang.org / x / crypto / openpgp / packet / public_key.go
index ead26233dda713fe74d5f10d138d3d6d9ac12301..fcd5f5251963b330495862cb8ae7e01f99df66ee 100644 (file)
@@ -244,7 +244,12 @@ func NewECDSAPublicKey(creationTime time.Time, pub *ecdsa.PublicKey) *PublicKey
        }
 
        pk.ec.p.bytes = elliptic.Marshal(pub.Curve, pub.X, pub.Y)
-       pk.ec.p.bitLength = uint16(8 * len(pk.ec.p.bytes))
+
+       // The bit length is 3 (for the 0x04 specifying an uncompressed key)
+       // plus two field elements (for x and y), which are rounded up to the
+       // nearest byte. See https://tools.ietf.org/html/rfc6637#section-6
+       fieldBytes := (pub.Curve.Params().BitSize + 7) & ^7
+       pk.ec.p.bitLength = uint16(3 + fieldBytes + fieldBytes)
 
        pk.setFingerPrintAndKeyId()
        return pk
@@ -515,7 +520,7 @@ func (pk *PublicKey) VerifySignature(signed hash.Hash, sig *Signature) (err erro
        switch pk.PubKeyAlgo {
        case PubKeyAlgoRSA, PubKeyAlgoRSASignOnly:
                rsaPublicKey, _ := pk.PublicKey.(*rsa.PublicKey)
-               err = rsa.VerifyPKCS1v15(rsaPublicKey, sig.Hash, hashBytes, sig.RSASignature.bytes)
+               err = rsa.VerifyPKCS1v15(rsaPublicKey, sig.Hash, hashBytes, padToKeySize(rsaPublicKey, sig.RSASignature.bytes))
                if err != nil {
                        return errors.SignatureError("RSA verification failure")
                }
@@ -566,7 +571,7 @@ func (pk *PublicKey) VerifySignatureV3(signed hash.Hash, sig *SignatureV3) (err
        switch pk.PubKeyAlgo {
        case PubKeyAlgoRSA, PubKeyAlgoRSASignOnly:
                rsaPublicKey := pk.PublicKey.(*rsa.PublicKey)
-               if err = rsa.VerifyPKCS1v15(rsaPublicKey, sig.Hash, hashBytes, sig.RSASignature.bytes); err != nil {
+               if err = rsa.VerifyPKCS1v15(rsaPublicKey, sig.Hash, hashBytes, padToKeySize(rsaPublicKey, sig.RSASignature.bytes)); err != nil {
                        return errors.SignatureError("RSA verification failure")
                }
                return