parseRSA parses an RSA key according to RFC 4253, section 6.6.
(in []byte)
| 158 | |
| 159 | // parseRSA parses an RSA key according to RFC 4253, section 6.6. |
| 160 | func parseRSA(in []byte) (*rsa.PublicKey, error) { |
| 161 | var w struct { |
| 162 | E *big.Int |
| 163 | N *big.Int |
| 164 | Rest []byte `ssh:"rest"` |
| 165 | } |
| 166 | if err := ssh.Unmarshal(in, &w); err != nil { |
| 167 | return nil, errors.Wrap(err, "error unmarshaling public key") |
| 168 | } |
| 169 | if w.E.BitLen() > 24 { |
| 170 | return nil, errors.New("invalid public key: exponent too large") |
| 171 | } |
| 172 | e := w.E.Int64() |
| 173 | if e < 3 || e&1 == 0 { |
| 174 | return nil, errors.New("invalid public key: incorrect exponent") |
| 175 | } |
| 176 | |
| 177 | var key rsa.PublicKey |
| 178 | key.E = int(e) |
| 179 | key.N = w.N |
| 180 | return &key, nil |
| 181 | } |
| 182 | |
| 183 | // parseECDSA parses an ECDSA key according to RFC 5656, section 3.1. |
| 184 | // |
no outgoing calls
no test coverage detected
searching dependent graphs…