OLD | NEW |
1 /* This Source Code Form is subject to the terms of the Mozilla Public | 1 /* This Source Code Form is subject to the terms of the Mozilla Public |
2 * License, v. 2.0. If a copy of the MPL was not distributed with this | 2 * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 #include "blapit.h" | 4 #include "blapit.h" |
5 #include "secport.h" | 5 #include "secport.h" |
6 #include "secerr.h" | 6 #include "secerr.h" |
7 | 7 |
8 /* | 8 /* |
9 * Prepare a buffer for any padded CBC encryption algorithm, growing to the | 9 * Prepare a buffer for any padded CBC encryption algorithm, growing to the |
10 * appropriate boundary and filling with the appropriate padding. | 10 * appropriate boundary and filling with the appropriate padding. |
11 * blockSize must be a power of 2. | 11 * blockSize must be a power of 2. |
12 * | 12 * |
13 * NOTE: If arena is non-NULL, we re-allocate from there, otherwise | 13 * NOTE: If arena is non-NULL, we re-allocate from there, otherwise |
14 * we assume (and use) XP memory (re)allocation. | 14 * we assume (and use) XP memory (re)allocation. |
15 */ | 15 */ |
16 unsigned char * | 16 unsigned char * |
17 CBC_PadBuffer(PRArenaPool *arena, unsigned char *inbuf, unsigned int inlen, | 17 CBC_PadBuffer(PLArenaPool *arena, unsigned char *inbuf, unsigned int inlen, |
18 unsigned int *outlen, int blockSize) | 18 unsigned int *outlen, int blockSize) |
19 { | 19 { |
20 unsigned char *outbuf; | 20 unsigned char *outbuf; |
21 unsigned int des_len; | 21 unsigned int des_len; |
22 unsigned int i; | 22 unsigned int i; |
23 unsigned char des_pad_len; | 23 unsigned char des_pad_len; |
24 | 24 |
25 /* | 25 /* |
26 * We need from 1 to blockSize bytes -- we *always* grow. | 26 * We need from 1 to blockSize bytes -- we *always* grow. |
27 * The extra bytes contain the value of the length of the padding: | 27 * The extra bytes contain the value of the length of the padding: |
(...skipping 12 matching lines...) Expand all Loading... |
40 return NULL; | 40 return NULL; |
41 } | 41 } |
42 | 42 |
43 des_pad_len = des_len - inlen; | 43 des_pad_len = des_len - inlen; |
44 for (i = inlen; i < des_len; i++) | 44 for (i = inlen; i < des_len; i++) |
45 outbuf[i] = des_pad_len; | 45 outbuf[i] = des_pad_len; |
46 | 46 |
47 *outlen = des_len; | 47 *outlen = des_len; |
48 return outbuf; | 48 return outbuf; |
49 } | 49 } |
OLD | NEW |