aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/key_store_passphrase.go
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-01-21 06:55:13 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-01-21 23:35:43 +0800
commit1f8290ca44df31cc4c4b68b30eef412476ed24e0 (patch)
treed3cef09eedffc76848b43e8f339593578156545c /crypto/key_store_passphrase.go
parent4df2e1ef5c20ebd7004a595de7e6a032699106ad (diff)
downloadgo-tangerine-1f8290ca44df31cc4c4b68b30eef412476ed24e0.tar
go-tangerine-1f8290ca44df31cc4c4b68b30eef412476ed24e0.tar.gz
go-tangerine-1f8290ca44df31cc4c4b68b30eef412476ed24e0.tar.bz2
go-tangerine-1f8290ca44df31cc4c4b68b30eef412476ed24e0.tar.lz
go-tangerine-1f8290ca44df31cc4c4b68b30eef412476ed24e0.tar.xz
go-tangerine-1f8290ca44df31cc4c4b68b30eef412476ed24e0.tar.zst
go-tangerine-1f8290ca44df31cc4c4b68b30eef412476ed24e0.zip
Add ImportPreSaleKey
* ImportPreSaleKey takes a KeyStore, a presale key JSON (e.g. file content) and a password string. It stores the key in the given key store. * Refactored common AES decryption and moved some functions to crypto.go
Diffstat (limited to 'crypto/key_store_passphrase.go')
-rw-r--r--crypto/key_store_passphrase.go46
1 files changed, 1 insertions, 45 deletions
diff --git a/crypto/key_store_passphrase.go b/crypto/key_store_passphrase.go
index e30a0a785..913b68498 100644
--- a/crypto/key_store_passphrase.go
+++ b/crypto/key_store_passphrase.go
@@ -178,22 +178,10 @@ func DecryptKey(ks keyStorePassphrase, keyId *uuid.UUID, auth string) (keyBytes
if err != nil {
return nil, err
}
-
- AES256Block, err := aes.NewCipher(derivedKey)
+ plainText, err := aes_cbc_decrypt(derivedKey, cipherText, iv)
if err != nil {
return nil, err
}
-
- AES256CBCDecrypter := cipher.NewCBCDecrypter(AES256Block, iv)
- paddedPlainText := make([]byte, len(cipherText))
- AES256CBCDecrypter.CryptBlocks(paddedPlainText, cipherText)
-
- plainText := PKCS7Unpad(paddedPlainText)
- if plainText == nil {
- err = errors.New("Decryption failed: PKCS7Unpad failed after decryption")
- return nil, err
- }
-
keyBytes = plainText[:len(plainText)-32]
keyBytesHash := plainText[len(plainText)-32:]
if !bytes.Equal(Sha3(keyBytes), keyBytesHash) {
@@ -211,35 +199,3 @@ func getEntropyCSPRNG(n int) []byte {
}
return mainBuff
}
-
-// From https://leanpub.com/gocrypto/read#leanpub-auto-block-cipher-modes
-func PKCS7Pad(in []byte) []byte {
- padding := 16 - (len(in) % 16)
- if padding == 0 {
- padding = 16
- }
- for i := 0; i < padding; i++ {
- in = append(in, byte(padding))
- }
- return in
-}
-
-func PKCS7Unpad(in []byte) []byte {
- if len(in) == 0 {
- return nil
- }
-
- padding := in[len(in)-1]
- if int(padding) > len(in) || padding > aes.BlockSize {
- return nil
- } else if padding == 0 {
- return nil
- }
-
- for i := len(in) - 1; i > len(in)-int(padding)-1; i-- {
- if in[i] != padding {
- return nil
- }
- }
- return in[:len(in)-int(padding)]
-}