Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Delta Between Two Patch Sets: src/pkg/crypto/openpgp/packet/private_key.go

Issue 4639049: code review 4639049: crypto/openpgp: add ElGamal support. (Closed)
Left Patch Set: Created 13 years, 9 months ago
Right Patch Set: diff -r e3c9fecaef4e https://go.googlecode.com/hg/ Created 13 years, 9 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
Right: Side by side diff | Download
« no previous file with change/comment | « src/pkg/crypto/openpgp/packet/packet.go ('k') | src/pkg/crypto/openpgp/packet/private_key_test.go » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
(no file at all)
1 // Copyright 2011 The Go Authors. All rights reserved. 1 // Copyright 2011 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style 2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file. 3 // license that can be found in the LICENSE file.
4 4
5 package packet 5 package packet
6 6
7 import ( 7 import (
8 "big" 8 "big"
9 "bytes" 9 "bytes"
10 "crypto/cipher" 10 "crypto/cipher"
11 "crypto/dsa" 11 "crypto/dsa"
12 "crypto/openpgp/elgamal"
12 "crypto/openpgp/error" 13 "crypto/openpgp/error"
13 "crypto/openpgp/s2k" 14 "crypto/openpgp/s2k"
14 "crypto/rsa" 15 "crypto/rsa"
15 "crypto/sha1" 16 "crypto/sha1"
16 "io" 17 "io"
17 "io/ioutil" 18 "io/ioutil"
18 "os" 19 "os"
19 "strconv" 20 "strconv"
20 ) 21 )
21 22
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 218
218 return pk.parsePrivateKey(data) 219 return pk.parsePrivateKey(data)
219 } 220 }
220 221
221 func (pk *PrivateKey) parsePrivateKey(data []byte) (err os.Error) { 222 func (pk *PrivateKey) parsePrivateKey(data []byte) (err os.Error) {
222 switch pk.PublicKey.PubKeyAlgo { 223 switch pk.PublicKey.PubKeyAlgo {
223 case PubKeyAlgoRSA, PubKeyAlgoRSASignOnly, PubKeyAlgoRSAEncryptOnly: 224 case PubKeyAlgoRSA, PubKeyAlgoRSASignOnly, PubKeyAlgoRSAEncryptOnly:
224 return pk.parseRSAPrivateKey(data) 225 return pk.parseRSAPrivateKey(data)
225 case PubKeyAlgoDSA: 226 case PubKeyAlgoDSA:
226 return pk.parseDSAPrivateKey(data) 227 return pk.parseDSAPrivateKey(data)
228 case PubKeyAlgoElGamal:
229 return pk.parseElGamalPrivateKey(data)
227 } 230 }
228 panic("impossible") 231 panic("impossible")
229 } 232 }
230 233
231 func (pk *PrivateKey) parseRSAPrivateKey(data []byte) (err os.Error) { 234 func (pk *PrivateKey) parseRSAPrivateKey(data []byte) (err os.Error) {
232 rsaPub := pk.PublicKey.PublicKey.(*rsa.PublicKey) 235 rsaPub := pk.PublicKey.PublicKey.(*rsa.PublicKey)
233 rsaPriv := new(rsa.PrivateKey) 236 rsaPriv := new(rsa.PrivateKey)
234 rsaPriv.PublicKey = *rsaPub 237 rsaPriv.PublicKey = *rsaPub
235 238
236 buf := bytes.NewBuffer(data) 239 buf := bytes.NewBuffer(data)
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 return 273 return
271 } 274 }
272 275
273 dsaPriv.X = new(big.Int).SetBytes(x) 276 dsaPriv.X = new(big.Int).SetBytes(x)
274 pk.PrivateKey = dsaPriv 277 pk.PrivateKey = dsaPriv
275 pk.Encrypted = false 278 pk.Encrypted = false
276 pk.encryptedData = nil 279 pk.encryptedData = nil
277 280
278 return nil 281 return nil
279 } 282 }
283
284 func (pk *PrivateKey) parseElGamalPrivateKey(data []byte) (err os.Error) {
285 pub := pk.PublicKey.PublicKey.(*elgamal.PublicKey)
286 priv := new(elgamal.PrivateKey)
287 priv.PublicKey = *pub
288
289 buf := bytes.NewBuffer(data)
290 x, _, err := readMPI(buf)
291 if err != nil {
292 return
293 }
294
295 priv.X = new(big.Int).SetBytes(x)
296 pk.PrivateKey = priv
297 pk.Encrypted = false
298 pk.encryptedData = nil
299
300 return nil
301 }
LEFTRIGHT

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b