summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorrsiddharth <s@ricketyspace.net>2020-11-28 22:08:50 -0500
committerrsiddharth <s@ricketyspace.net>2020-11-28 22:08:50 -0500
commit40a42789d1cb1fb01f0c51bd9a222a0760ac9917 (patch)
treebbb31d3dc20170d331bf8cf11ef594238217189b /lib
parentdb2847445c4cb65b8d22921ecb1b8fa08d38192b (diff)
lib: blocks: add Pkcs7Padding
Diffstat (limited to 'lib')
-rw-r--r--lib/blocks.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/blocks.go b/lib/blocks.go
index 9436d3c..1ba811f 100644
--- a/lib/blocks.go
+++ b/lib/blocks.go
@@ -60,3 +60,16 @@ func BlocksEqual(a, b []byte) bool {
}
return true
}
+
+// 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
+func Pkcs7Padding(in []byte, k int) []byte {
+ lth := len(in)
+ pd := k - (lth % k) // padding character and padding length
+
+ for i := 0; i < pd; i++ {
+ in = append(in, byte(pd))
+ }
+ return in
+}