MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / unPad16

Function unPad16

libcppcryptfs/util/pad16.cpp:46–75  ·  view source on GitHub ↗

unPad16 - remove padding

Source from the content-addressed store, hash-verified

44
45// unPad16 - remove padding
46int unPad16(BYTE *padded, int len) {
47 int oldLen = len;
48 if (oldLen % 16 != 0) {
49 return -1;
50 }
51 // The last byte is always a padding byte
52 BYTE padByte = padded[oldLen - 1];
53 // The padding byte's value is the padding length
54 int padLen = (int)(padByte);
55 // Padding must be at least 1 byte
56 if (padLen <= 0) {
57 return -1;
58 }
59 // Larger paddings make no sense
60 if (padLen > 16) {
61 return -1;
62 }
63 // All padding bytes must be identical
64 for (int i = oldLen - padLen; i < oldLen; i++) {
65 if (padded[i] != padByte) {
66 return -1;
67 }
68 }
69 int newLen = oldLen - padLen;
70 // Padding an empty string makes no sense
71 if (newLen == 0) {
72 return -1;
73 }
74 return newLen;
75}

Callers 1

decrypt_filenameFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected