diff options
author | rsiddharth <s@ricketyspace.net> | 2021-03-01 17:56:45 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2021-03-01 17:56:45 -0500 |
commit | 866b07783fa13e5b76ac3f8bb2221ed183ee155f (patch) | |
tree | dd0722e2c6a444060ced10b4f7b6ccfcf6030ed1 /lib | |
parent | e4f381aabc00c44ff669792510d71da11e7afa42 (diff) |
lib: add AESDecryptCTR
Diffstat (limited to 'lib')
-rw-r--r-- | lib/aes.go | 25 |
1 files changed, 25 insertions, 0 deletions
@@ -3,6 +3,31 @@ package lib +func AESDecryptCTR(cipher, key []byte, ctrFunc func() []byte) ([]byte, error) { + if len(key) != 16 { + return []byte{}, CPError{"key length != 16"} + } + iter := len(cipher) / 16 + if len(cipher)%16 != 0 { + iter += 1 + } + output := make([]byte, 0) + for i := 0; i < iter; i++ { + ib := ctrFunc() + if len(ib) != 16 { + return []byte{}, CPError{"ctr length != 16"} + } + s := (i * 16) + e := (i * 16) + 16 + if e > len(cipher) { + e = len(cipher) + } + c := cipher[s:e] + output = append(output, FixedXORBytes(aesCipher(ib, key)[0:len(c)], c)...) + } + return output, nil +} + func AESEncryptCBC(plain, key, iv []byte) []byte { // Pad input plain = Pkcs7Padding(plain, 16) |