libpcp
0.2.4
Main Page
Modules
Classes
Files
File List
include
pcp
pad.h
1
/*
2
This file is part of Pretty Curved Privacy (pcp1).
3
4
Copyright (C) 2013 T.Linden.
5
6
This program is free software: you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation, either version 3 of the License, or
9
(at your option) any later version.
10
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
GNU General Public License for more details.
15
16
You should have received a copy of the GNU General Public License
17
along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19
You can contact me by mail: <tlinden AT cpan DOT org>.
20
*/
21
22
23
#ifndef _HAVE_PCP_ZPADDING
24
#define _HAVE_PCP_ZPADDING
25
26
#include <stdio.h>
27
#include <string.h>
28
#include <stdlib.h>
29
#include <stdlib.h>
30
#include <limits.h>
31
32
#include "mem.h"
33
34
#ifdef DEBUG
35
#define ZPADCHAR 48
36
#else
37
#define ZPADCHAR 0
38
#endif
39
40
/* prepends a binary stream with a number of */
41
/* \0's as required by the secret_box and */
42
/* secret_box_open functions of libsodium. */
43
/* */
44
/* parameters: */
45
/* */
46
/* padded: destination array (ref) */
47
/* unpadded: source array without padding */
48
/* padlen: length of padding */
49
/* unpadlen: length of source array */
50
/* */
51
/* turns "efa5" into "00000000efa5" with padlen 8 */
52
/* */
53
/* if DEBUG is set, destination will be padded with */
54
/* the character '0', NOT the integer 0. */
55
/* */
56
/* allocates memory for padded and it is up to the */
57
/* user to free it after use. */
58
/* */
59
/* sample call: */
60
/* */
61
/* char unpadded[] = {0xef, 0xa5}; */
62
/* byte *padded; */
63
/* pcp_pad_prepend(&padded, unpadded, 8, 2); */
64
/* */
65
/* the result, padded, would be 10 bytes long, 8 */
66
/* bytes for the leading zeros and 2 for the content */
67
/* of the original unpadded. */
68
void
pcp_pad_prepend(byte **padded, byte *unpadded,
69
size_t
padlen,
size_t
unpadlen);
70
71
/* removes zero's of a binary stream, which is */
72
/* the reverse of pcp_pad_prepend(). */
73
/* */
74
/* parameters: */
75
/* */
76
/* unpadded: destination array (ref), with padding removed */
77
/* padded: source array with padding */
78
/* padlen: length of padding */
79
/* unpadlen: length of source array */
80
/* */
81
/* turns "00000000efa5" into "efa5" with padlen 8 */
82
/* */
83
/* allocates memory for unpadded and it is up to the */
84
/* user to free it after use. */
85
/* */
86
/* sample call: */
87
/* */
88
/* char padded[] = {0x0, 0x0, 0x0, 0x0, 0xef, 0xa5}; */
89
/* byte *unpadded; */
90
/* pcp_pad_remove(unpadded, padded, 4, 2); */
91
/* */
92
/* the result, unpadded would be 2 bytes long containing */
93
/* only the 2 bytes we want to have with zeros removed. */
94
void
pcp_pad_remove(byte **unpadded, byte *padded,
95
size_t
padlen,
size_t
unpadlen);
96
97
98
#endif
/* _HAVE_PCP_ZPADDING */
Generated on Sun Jan 11 2015 17:27:45 for libpcp by
1.8.3.1