openpgp: support 3DES encrypted private keys.
It appears that CentOS (and so I presume Fedora/RHEL too) default to encrypting private keys with 3DES so it looks like we need to support that. Fixes golang/go#3940. R=golang-dev, r CC=golang-dev https://golang.org/cl/6446121
This commit is contained in:
@@ -11,6 +11,7 @@ import (
|
|||||||
"code.google.com/p/go.crypto/openpgp/errors"
|
"code.google.com/p/go.crypto/openpgp/errors"
|
||||||
"crypto/aes"
|
"crypto/aes"
|
||||||
"crypto/cipher"
|
"crypto/cipher"
|
||||||
|
"crypto/des"
|
||||||
"io"
|
"io"
|
||||||
"math/big"
|
"math/big"
|
||||||
)
|
)
|
||||||
@@ -400,6 +401,7 @@ func (pka PublicKeyAlgorithm) CanSign() bool {
|
|||||||
type CipherFunction uint8
|
type CipherFunction uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
Cipher3DES CipherFunction = 2
|
||||||
CipherCAST5 CipherFunction = 3
|
CipherCAST5 CipherFunction = 3
|
||||||
CipherAES128 CipherFunction = 7
|
CipherAES128 CipherFunction = 7
|
||||||
CipherAES192 CipherFunction = 8
|
CipherAES192 CipherFunction = 8
|
||||||
@@ -409,6 +411,8 @@ const (
|
|||||||
// KeySize returns the key size, in bytes, of cipher.
|
// KeySize returns the key size, in bytes, of cipher.
|
||||||
func (cipher CipherFunction) KeySize() int {
|
func (cipher CipherFunction) KeySize() int {
|
||||||
switch cipher {
|
switch cipher {
|
||||||
|
case Cipher3DES:
|
||||||
|
return 24
|
||||||
case CipherCAST5:
|
case CipherCAST5:
|
||||||
return cast5.KeySize
|
return cast5.KeySize
|
||||||
case CipherAES128:
|
case CipherAES128:
|
||||||
@@ -424,6 +428,8 @@ func (cipher CipherFunction) KeySize() int {
|
|||||||
// blockSize returns the block size, in bytes, of cipher.
|
// blockSize returns the block size, in bytes, of cipher.
|
||||||
func (cipher CipherFunction) blockSize() int {
|
func (cipher CipherFunction) blockSize() int {
|
||||||
switch cipher {
|
switch cipher {
|
||||||
|
case Cipher3DES:
|
||||||
|
return des.BlockSize
|
||||||
case CipherCAST5:
|
case CipherCAST5:
|
||||||
return 8
|
return 8
|
||||||
case CipherAES128, CipherAES192, CipherAES256:
|
case CipherAES128, CipherAES192, CipherAES256:
|
||||||
@@ -435,6 +441,8 @@ func (cipher CipherFunction) blockSize() int {
|
|||||||
// new returns a fresh instance of the given cipher.
|
// new returns a fresh instance of the given cipher.
|
||||||
func (cipher CipherFunction) new(key []byte) (block cipher.Block) {
|
func (cipher CipherFunction) new(key []byte) (block cipher.Block) {
|
||||||
switch cipher {
|
switch cipher {
|
||||||
|
case Cipher3DES:
|
||||||
|
block, _ = des.NewTripleDESCipher(key)
|
||||||
case CipherCAST5:
|
case CipherCAST5:
|
||||||
block, _ = cast5.NewCipher(key)
|
block, _ = cast5.NewCipher(key)
|
||||||
case CipherAES128, CipherAES192, CipherAES256:
|
case CipherAES128, CipherAES192, CipherAES256:
|
||||||
|
|||||||
Reference in New Issue
Block a user