summaryrefslogtreecommitdiffstats
path: root/lib/blocks.go
diff options
context:
space:
mode:
Diffstat (limited to 'lib/blocks.go')
-rw-r--r--lib/blocks.go23
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