From f1297ed8020ad97495f38583dbdb4a35ae3c678d Mon Sep 17 00:00:00 2001 From: rsiddharth Date: Sun, 6 Dec 2020 16:11:49 -0500 Subject: lib/aes: add AESEncryptCBC --- lib/aes.go | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/aes.go b/lib/aes.go index 83bd028..44f2350 100644 --- a/lib/aes.go +++ b/lib/aes.go @@ -3,6 +3,23 @@ package lib +func AESEncryptCBC(plain, key, iv []byte) []byte { + iter := len(plain) / 16 + + lc := iv + output := make([]byte, 0) + for i := 0; i < iter; i++ { + s := (i * 16) + e := (i * 16) + 16 + p := plain[s:e] + c := aesCipher(FixedXORBytes(p, lc), key) + output = append(output, c...) + + lc = c + } + return output +} + func AESDecryptCBC(cipher, key, iv []byte) []byte { iter := len(cipher) / 16 @@ -46,7 +63,6 @@ func AESDecryptECB(cipher, key []byte) []byte { return output } - func aesCipher(in, ky []byte) []byte { nb := 4 nr := 10 -- cgit v1.2.3