diff options
author | rsiddharth <s@ricketyspace.net> | 2020-11-28 22:08:50 -0500 |
---|---|---|
committer | rsiddharth <s@ricketyspace.net> | 2020-11-28 22:08:50 -0500 |
commit | 40a42789d1cb1fb01f0c51bd9a222a0760ac9917 (patch) | |
tree | bbb31d3dc20170d331bf8cf11ef594238217189b | |
parent | db2847445c4cb65b8d22921ecb1b8fa08d38192b (diff) |
lib: blocks: add Pkcs7Padding
-rw-r--r-- | lib/blocks.go | 13 |
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 +} |