From bc0a4671d4545e183d1f75cb9a9950798a87f291 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Wed, 21 Aug 2019 20:17:41 +0300 Subject: [PATCH] _pkg.dev: drop crypto/aes, refs #307 Duplicated by pkg/crypto/aes256.go. --- _pkg.dev/crypto/aes/aes256.go | 93 ----------------------------------- 1 file changed, 93 deletions(-) delete mode 100755 _pkg.dev/crypto/aes/aes256.go diff --git a/_pkg.dev/crypto/aes/aes256.go b/_pkg.dev/crypto/aes/aes256.go deleted file mode 100755 index c23c48843..000000000 --- a/_pkg.dev/crypto/aes/aes256.go +++ /dev/null @@ -1,93 +0,0 @@ -package aes - -import ( - "crypto/aes" - "crypto/cipher" -) - -// Encrypt encrypts the key with the given source. -func Encrypt(src, key []byte) ([]byte, error) { - block, err := aes.NewCipher(key) - if err != nil { - return nil, err - } - - ecb := newECBEncrypter(block) - out := make([]byte, len(src)) - ecb.CryptBlocks(out, src) - - return out, nil -} - -// Decrypt decrypts the encrypted source with the given key. -func Decrypt(crypted, key []byte) ([]byte, error) { - block, err := aes.NewCipher(key) - if err != nil { - return nil, err - } - - blockMode := newECBDecrypter(block) - out := make([]byte, len(crypted)) - blockMode.CryptBlocks(out, crypted) - return out, nil -} - -type ecb struct { - b cipher.Block - blockSize int -} - -func newECB(b cipher.Block) *ecb { - return &ecb{ - b: b, - blockSize: b.BlockSize(), - } -} - -type ecbEncrypter ecb - -func newECBEncrypter(b cipher.Block) cipher.BlockMode { - return (*ecbEncrypter)(newECB(b)) -} - -func (ecb *ecbEncrypter) BlockSize() int { - return ecb.blockSize -} - -func (ecb *ecbEncrypter) CryptBlocks(dst, src []byte) { - if len(src)%ecb.blockSize != 0 { - panic("crypto/cipher: input not full blocks") - } - if len(dst) < len(src) { - panic("crypto/cipher: output smaller than input") - } - for len(src) > 0 { - ecb.b.Encrypt(dst, src[:ecb.blockSize]) - src = src[ecb.blockSize:] - dst = dst[ecb.blockSize:] - } -} - -type ecbDecrypter ecb - -func newECBDecrypter(b cipher.Block) cipher.BlockMode { - return (*ecbDecrypter)(newECB(b)) -} - -func (ecb ecbDecrypter) BlockSize() int { - return ecb.blockSize -} - -func (ecb *ecbDecrypter) CryptBlocks(dst, src []byte) { - if len(src)%ecb.blockSize != 0 { - panic("crypto/cipher: input not full blocks") - } - if len(dst) < len(src) { - panic("crypto/cipher: output smaller than input") - } - for len(src) > 0 { - ecb.b.Decrypt(dst, src[:ecb.blockSize]) - src = src[ecb.blockSize:] - dst = dst[ecb.blockSize:] - } -}