dsa patch for the go source tree
[epoint] / patches / dsa.diff
1 diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/private_key.go
2 --- a/src/pkg/crypto/openpgp/packet/private_key.go      Thu Nov 24 08:51:47 2011 -0800
3 +++ b/src/pkg/crypto/openpgp/packet/private_key.go      Tue Nov 29 17:21:15 2011 +0100
4 @@ -27,7 +27,7 @@
5         encryptedData []byte
6         cipher        CipherFunction
7         s2k           func(out, in []byte)
8 -       PrivateKey    interface{} // An *rsa.PrivateKey.
9 +       PrivateKey    interface{} // An *rsa.PrivateKey or *dsa.PrivateKey.
10         sha1Checksum  bool
11         iv            []byte
12  }
13 @@ -39,6 +39,13 @@
14         return pk
15  }
16  
17 +func NewDSAPrivateKey(currentTimeSecs uint32, priv *dsa.PrivateKey, isSubkey bool) *PrivateKey {
18 +       pk := new(PrivateKey)
19 +       pk.PublicKey = *NewDSAPublicKey(currentTimeSecs, &priv.PublicKey, isSubkey)
20 +       pk.PrivateKey = priv
21 +       return pk
22 +}
23 +
24  func (pk *PrivateKey) parse(r io.Reader) (err error) {
25         err = (&pk.PublicKey).parse(r)
26         if err != nil {
27 @@ -120,6 +127,8 @@
28         switch priv := pk.PrivateKey.(type) {
29         case *rsa.PrivateKey:
30                 err = serializeRSAPrivateKey(privateKeyBuf, priv)
31 +       case *dsa.PrivateKey:
32 +               err = serializeDSAPrivateKey(privateKeyBuf, priv)
33         default:
34                 err = error_.InvalidArgumentError("non-RSA private key")
35         }
36 @@ -171,6 +180,10 @@
37         return writeBig(w, priv.Precomputed.Qinv)
38  }
39  
40 +func serializeDSAPrivateKey(w io.Writer, priv *dsa.PrivateKey) error {
41 +       return writeBig(w, priv.X)
42 +}
43 +
44  // Decrypt decrypts an encrypted private key using a passphrase.
45  func (pk *PrivateKey) Decrypt(passphrase []byte) error {
46         if !pk.Encrypted {
47 diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/public_key.go
48 --- a/src/pkg/crypto/openpgp/packet/public_key.go       Thu Nov 24 08:51:47 2011 -0800
49 +++ b/src/pkg/crypto/openpgp/packet/public_key.go       Tue Nov 29 17:21:15 2011 +0100
50 @@ -52,6 +52,23 @@
51         return pk
52  }
53  
54 +// NewDSAPublicKey returns a PublicKey that wraps the given rsa.PublicKey.
55 +func NewDSAPublicKey(creationTimeSecs uint32, pub *dsa.PublicKey, isSubkey bool) *PublicKey {
56 +       pk := &PublicKey{
57 +               CreationTime: creationTimeSecs,
58 +               PubKeyAlgo:   PubKeyAlgoDSA,
59 +               PublicKey:    pub,
60 +               IsSubkey:     isSubkey,
61 +               p:            fromBig(pub.P),
62 +               q:            fromBig(pub.Q),
63 +               g:            fromBig(pub.G),
64 +               y:            fromBig(pub.Y),
65 +       }
66 +
67 +       pk.setFingerPrintAndKeyId()
68 +       return pk
69 +}
70 +
71  func (pk *PublicKey) parse(r io.Reader) (err error) {
72         // RFC 4880, section 5.5.2
73         var buf [6]byte