summaryrefslogtreecommitdiff
path: root/lib/lib2.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lib2.c')
-rw-r--r--lib/lib2.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/lib2.c b/lib/lib2.c
new file mode 100644
index 0000000..86dd823
--- /dev/null
+++ b/lib/lib2.c
@@ -0,0 +1,23 @@
+#include "lib2.h"
+
+/**
+ * appends PKCS#7 padding to string. devide string in blocks of size blocksize
+ * and append to last block so that it is also of blocksize length
+ */
+
+char *pkcs7_padding(char *string, int length_string, int blocksize)
+{
+ char *result = NULL;
+ int i;
+ int value = blocksize - (length_string % blocksize);
+
+ result = malloc(length_string+value+1);
+ memcpy(result, string, length_string);
+
+ for(i=0;i<value;i++) {
+ result[length_string+i] = (char) value;
+ }
+ result[length_string+i] = '\0';
+
+ return result;
+}