dsa patch for the go source tree
authornsz <nsz@port70.net>
Tue, 29 Nov 2011 16:22:43 +0000 (17:22 +0100)
committernsz <nsz@port70.net>
Tue, 29 Nov 2011 16:22:43 +0000 (17:22 +0100)
patches/dsa.diff [new file with mode: 0644]

diff --git a/patches/dsa.diff b/patches/dsa.diff
new file mode 100644 (file)
index 0000000..b1c7629
--- /dev/null
@@ -0,0 +1,73 @@
+diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/private_key.go
+--- a/src/pkg/crypto/openpgp/packet/private_key.go     Thu Nov 24 08:51:47 2011 -0800
++++ b/src/pkg/crypto/openpgp/packet/private_key.go     Tue Nov 29 17:21:15 2011 +0100
+@@ -27,7 +27,7 @@
+       encryptedData []byte
+       cipher        CipherFunction
+       s2k           func(out, in []byte)
+-      PrivateKey    interface{} // An *rsa.PrivateKey.
++      PrivateKey    interface{} // An *rsa.PrivateKey or *dsa.PrivateKey.
+       sha1Checksum  bool
+       iv            []byte
+ }
+@@ -39,6 +39,13 @@
+       return pk
+ }
++func NewDSAPrivateKey(currentTimeSecs uint32, priv *dsa.PrivateKey, isSubkey bool) *PrivateKey {
++      pk := new(PrivateKey)
++      pk.PublicKey = *NewDSAPublicKey(currentTimeSecs, &priv.PublicKey, isSubkey)
++      pk.PrivateKey = priv
++      return pk
++}
++
+ func (pk *PrivateKey) parse(r io.Reader) (err error) {
+       err = (&pk.PublicKey).parse(r)
+       if err != nil {
+@@ -120,6 +127,8 @@
+       switch priv := pk.PrivateKey.(type) {
+       case *rsa.PrivateKey:
+               err = serializeRSAPrivateKey(privateKeyBuf, priv)
++      case *dsa.PrivateKey:
++              err = serializeDSAPrivateKey(privateKeyBuf, priv)
+       default:
+               err = error_.InvalidArgumentError("non-RSA private key")
+       }
+@@ -171,6 +180,10 @@
+       return writeBig(w, priv.Precomputed.Qinv)
+ }
++func serializeDSAPrivateKey(w io.Writer, priv *dsa.PrivateKey) error {
++      return writeBig(w, priv.X)
++}
++
+ // Decrypt decrypts an encrypted private key using a passphrase.
+ func (pk *PrivateKey) Decrypt(passphrase []byte) error {
+       if !pk.Encrypted {
+diff -r 221f3eb76b52 src/pkg/crypto/openpgp/packet/public_key.go
+--- a/src/pkg/crypto/openpgp/packet/public_key.go      Thu Nov 24 08:51:47 2011 -0800
++++ b/src/pkg/crypto/openpgp/packet/public_key.go      Tue Nov 29 17:21:15 2011 +0100
+@@ -52,6 +52,23 @@
+       return pk
+ }
++// NewDSAPublicKey returns a PublicKey that wraps the given rsa.PublicKey.
++func NewDSAPublicKey(creationTimeSecs uint32, pub *dsa.PublicKey, isSubkey bool) *PublicKey {
++      pk := &PublicKey{
++              CreationTime: creationTimeSecs,
++              PubKeyAlgo:   PubKeyAlgoDSA,
++              PublicKey:    pub,
++              IsSubkey:     isSubkey,
++              p:            fromBig(pub.P),
++              q:            fromBig(pub.Q),
++              g:            fromBig(pub.G),
++              y:            fromBig(pub.Y),
++      }
++
++      pk.setFingerPrintAndKeyId()
++      return pk
++}
++
+ func (pk *PublicKey) parse(r io.Reader) (err error) {
+       // RFC 4880, section 5.5.2
+       var buf [6]byte