diff options
author | rsiddharth <s@ricketyspace.net> | 2020-12-08 17:59:28 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-12-08 17:59:28 -0500 |
commit | dc6cca42113ea7e9a292175e1704061d742014dd (patch) | |
tree | 3b5e2ee16b74a745f70fbb0f0daf3de4101f4fbd /lib | |
parent | 7b29de2661a0a1e59d816544b7176b4ec8201468 (diff) |
lib/blocks: move isECB from ch. 8 in here as BlockIsECB
Diffstat (limited to 'lib')
-rw-r--r-- | lib/blocks.go | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/blocks.go b/lib/blocks.go index 1ba811f..452766b 100644 --- a/lib/blocks.go +++ b/lib/blocks.go @@ -61,6 +61,29 @@ func BlocksEqual(a, b []byte) bool { return true } +func BlockIsECB(bs []byte) []byte { + blocks := BreakIntoBlocks(bs, 16) + + for i := 0; i < len(blocks); i++ { + if hasMatchingBlock(i, blocks) { + return blocks[i] + } + } + return nil +} + +func hasMatchingBlock(id int, blocks [][]byte) bool { + for i := 0; i < len(blocks); i++ { + if i == id { + continue + } + if BlocksEqual(blocks[i], blocks[id]) { + return true + } + } + return false +} + // Performs PKCS#7 Padding on the input `in` and block size `k`. // Assumes 0 > `k` < 256 // Reference: https://tools.ietf.org/html/rfc5652#section-6.3 |