-
Notifications
You must be signed in to change notification settings - Fork 6
/
dsa.go
56 lines (47 loc) · 952 Bytes
/
dsa.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
package putty
import (
"crypto/dsa"
"fmt"
"math/big"
)
func (k Key) readDSAPublicKey() (*dsa.PublicKey, error) {
var pub struct {
Header string
P *big.Int
Q *big.Int
G *big.Int
Pub *big.Int
}
err := unmarshal(k.PublicKey, &pub, false)
if err != nil {
return nil, err
}
if pub.Header != k.Algo {
return nil, fmt.Errorf("invalid header inside public key: %q: expected %q", pub.Header, k.Algo)
}
publicKey := &dsa.PublicKey{
Parameters: dsa.Parameters{
P: pub.P,
Q: pub.Q,
G: pub.G,
},
Y: pub.Pub,
}
return publicKey, nil
}
func (k Key) readDSAPrivateKey() (*dsa.PrivateKey, error) {
publicKey, err := k.readDSAPublicKey()
if err != nil {
return nil, err
}
var priv *big.Int
err = unmarshal(k.PrivateKey, &priv, k.Encryption != "none")
if err != nil {
return nil, err
}
privateKey := &dsa.PrivateKey{
PublicKey: *publicKey,
X: priv,
}
return privateKey, nil
}