@@ -10,6 +10,7 @@ package ocsp
10
10
import (
11
11
"crypto"
12
12
"crypto/ecdsa"
13
+ "crypto/ed25519"
13
14
"crypto/elliptic"
14
15
"crypto/rand"
15
16
"crypto/rsa"
@@ -151,6 +152,7 @@ var (
151
152
oidSignatureECDSAWithSHA256 = asn1.ObjectIdentifier {1 , 2 , 840 , 10045 , 4 , 3 , 2 }
152
153
oidSignatureECDSAWithSHA384 = asn1.ObjectIdentifier {1 , 2 , 840 , 10045 , 4 , 3 , 3 }
153
154
oidSignatureECDSAWithSHA512 = asn1.ObjectIdentifier {1 , 2 , 840 , 10045 , 4 , 3 , 4 }
155
+ oidSignatureEd25519 = asn1.ObjectIdentifier {1 , 3 , 101 , 112 }
154
156
)
155
157
156
158
var hashOIDs = map [crypto.Hash ]asn1.ObjectIdentifier {
@@ -179,6 +181,7 @@ var signatureAlgorithmDetails = []struct {
179
181
{x509 .ECDSAWithSHA256 , oidSignatureECDSAWithSHA256 , x509 .ECDSA , crypto .SHA256 },
180
182
{x509 .ECDSAWithSHA384 , oidSignatureECDSAWithSHA384 , x509 .ECDSA , crypto .SHA384 },
181
183
{x509 .ECDSAWithSHA512 , oidSignatureECDSAWithSHA512 , x509 .ECDSA , crypto .SHA512 },
184
+ {x509 .PureEd25519 , oidSignatureEd25519 , x509 .Ed25519 , crypto .Hash (0 ) /* no pre-hashing */ },
182
185
}
183
186
184
187
// TODO(rlb): This is also from crypto/x509, so same comment as AGL's below
@@ -211,8 +214,13 @@ func signingParamsForPublicKey(pub interface{}, requestedSigAlgo x509.SignatureA
211
214
err = errors .New ("x509: unknown elliptic curve" )
212
215
}
213
216
217
+ case ed25519.PublicKey :
218
+ pubType = x509 .Ed25519
219
+ hashFunc = crypto .Hash (0 )
220
+ sigAlgo .Algorithm = oidSignatureEd25519
221
+
214
222
default :
215
- err = errors .New ("x509: only RSA and ECDSA keys supported" )
223
+ err = errors .New ("x509: only RSA, ECDSA and Ed25519 keys supported" )
216
224
}
217
225
218
226
if err != nil {
@@ -753,14 +761,18 @@ func CreateResponse(issuer, responderCert *x509.Certificate, template Response,
753
761
return nil , err
754
762
}
755
763
764
+ signed := tbsResponseDataDER
756
765
hashFunc , signatureAlgorithm , err := signingParamsForPublicKey (priv .Public (), template .SignatureAlgorithm )
757
766
if err != nil {
758
767
return nil , err
759
768
}
769
+ if hashFunc != 0 {
770
+ responseHash := hashFunc .New ()
771
+ responseHash .Write (tbsResponseDataDER )
772
+ signed = responseHash .Sum (nil )
773
+ }
760
774
761
- responseHash := hashFunc .New ()
762
- responseHash .Write (tbsResponseDataDER )
763
- signature , err := priv .Sign (rand .Reader , responseHash .Sum (nil ), hashFunc )
775
+ signature , err := priv .Sign (rand .Reader , signed , hashFunc )
764
776
if err != nil {
765
777
return nil , err
766
778
}
0 commit comments