aboutsummaryrefslogtreecommitdiffstats
path: root/crypto/crypto.go
diff options
context:
space:
mode:
authorGustav Simonsson <gustav.simonsson@gmail.com>2015-05-24 09:42:10 +0800
committerGustav Simonsson <gustav.simonsson@gmail.com>2015-06-24 12:03:23 +0800
commitd23ec6c4194e7c0f70372db58d49ec222dc4e22c (patch)
tree7bc662eec5dd034873887088825761a94ce989af /crypto/crypto.go
parent22c7ce0162f2d14a7340e00e93697780c91d2087 (diff)
downloadgo-tangerine-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar
go-tangerine-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar.gz
go-tangerine-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar.bz2
go-tangerine-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar.lz
go-tangerine-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar.xz
go-tangerine-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.tar.zst
go-tangerine-d23ec6c4194e7c0f70372db58d49ec222dc4e22c.zip
Change keystore to version 3
* Change password protection crypto in keystore to version 3 * Update KeyStoreTests/basic_tests.json * Add support for PBKDF2 with HMAC-SHA256 * Change MAC and encryption key to avoid unnecessary hashing * Add tests for test vectors in new wiki page defining version 3 * Add tests for new keystore tests in ethereum/tests repo * Move JSON loading util to common for use in both tests and crypto packages * Add backwards compatibility with key store version 1
Diffstat (limited to 'crypto/crypto.go')
-rw-r--r--crypto/crypto.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/crypto/crypto.go b/crypto/crypto.go
index 8f5597b09..153bbbc5d 100644
--- a/crypto/crypto.go
+++ b/crypto/crypto.go
@@ -258,19 +258,31 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error
return key, err
}
-func aesCBCDecrypt(key []byte, cipherText []byte, iv []byte) (plainText []byte, err error) {
+// AES-128 is selected due to size of encryptKey
+func aesCTRXOR(key, inText, iv []byte) ([]byte, error) {
aesBlock, err := aes.NewCipher(key)
if err != nil {
- return plainText, err
+ return nil, err
+ }
+ stream := cipher.NewCTR(aesBlock, iv)
+ outText := make([]byte, len(inText))
+ stream.XORKeyStream(outText, inText)
+ return outText, err
+}
+
+func aesCBCDecrypt(key, cipherText, iv []byte) ([]byte, error) {
+ aesBlock, err := aes.NewCipher(key)
+ if err != nil {
+ return nil, err
}
decrypter := cipher.NewCBCDecrypter(aesBlock, iv)
- paddedPlainText := make([]byte, len(cipherText))
- decrypter.CryptBlocks(paddedPlainText, cipherText)
- plainText = PKCS7Unpad(paddedPlainText)
- if plainText == nil {
+ paddedPlaintext := make([]byte, len(cipherText))
+ decrypter.CryptBlocks(paddedPlaintext, cipherText)
+ plaintext := PKCS7Unpad(paddedPlaintext)
+ if plaintext == nil {
err = errors.New("Decryption failed: PKCS7Unpad failed after AES decryption")
}
- return plainText, err
+ return plaintext, err
}
// From https://leanpub.com/gocrypto/read#leanpub-auto-block-cipher-modes