From db5555bb15096cd399cef29566bf433f31ee5d88 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 25 Dec 2019 11:25:05 +0300 Subject: [PATCH] crypto: internalize aes functions into the keys package This is the only user of it and no one outside should care about these details. --- pkg/crypto/{ => keys}/aes256.go | 10 +++++----- pkg/crypto/keys/nep2.go | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) rename pkg/crypto/{ => keys}/aes256.go (87%) diff --git a/pkg/crypto/aes256.go b/pkg/crypto/keys/aes256.go similarity index 87% rename from pkg/crypto/aes256.go rename to pkg/crypto/keys/aes256.go index bb0c97e96..2aa3cd1a3 100644 --- a/pkg/crypto/aes256.go +++ b/pkg/crypto/keys/aes256.go @@ -1,12 +1,12 @@ -package crypto +package keys import ( "crypto/aes" "crypto/cipher" ) -// AESEncrypt encrypts the key with the given source. -func AESEncrypt(src, key []byte) ([]byte, error) { +// aesEncrypt encrypts the key with the given source. +func aesEncrypt(src, key []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { return nil, err @@ -19,8 +19,8 @@ func AESEncrypt(src, key []byte) ([]byte, error) { return out, nil } -// AESDecrypt decrypts the encrypted source with the given key. -func AESDecrypt(crypted, key []byte) ([]byte, error) { +// aesDecrypt decrypts the encrypted source with the given key. +func aesDecrypt(crypted, key []byte) ([]byte, error) { block, err := aes.NewCipher(key) if err != nil { return nil, err diff --git a/pkg/crypto/keys/nep2.go b/pkg/crypto/keys/nep2.go index 29f1c5661..5d8144439 100644 --- a/pkg/crypto/keys/nep2.go +++ b/pkg/crypto/keys/nep2.go @@ -57,7 +57,7 @@ func NEP2Encrypt(priv *PrivateKey, passphrase string) (s string, err error) { derivedKey2 := derivedKey[32:] xr := xor(priv.Bytes(), derivedKey1) - encrypted, err := crypto.AESEncrypt(xr, derivedKey2) + encrypted, err := aesEncrypt(xr, derivedKey2) if err != nil { return s, err } @@ -98,7 +98,7 @@ func NEP2Decrypt(key, passphrase string) (s string, err error) { derivedKey2 := derivedKey[32:] encryptedBytes := b[7:] - decrypted, err := crypto.AESDecrypt(encryptedBytes, derivedKey2) + decrypted, err := aesDecrypt(encryptedBytes, derivedKey2) if err != nil { return s, err }