1EVP_EncodeInit(3) OpenSSL EVP_EncodeInit(3)
2
3
4
6 EVP_EncodeInit, EVP_EncodeUpdate, EVP_EncodeFinal, EVP_EncodeBlock,
7 EVP_DecodeInit, EVP_DecodeUpdate, EVP_DecodeFinal, EVP_DecodeBlock -
8 EVP base 64 encode/decode routines
9
11 #include <openssl/evp.h>
12
13 void EVP_EncodeInit(EVP_ENCODE_CTX *ctx);
14 void EVP_EncodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
15 const unsigned char *in, int inl);
16 void EVP_EncodeFinal(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl);
17 int EVP_EncodeBlock(unsigned char *t, const unsigned char *f, int n);
18
19 void EVP_DecodeInit(EVP_ENCODE_CTX *ctx);
20 int EVP_DecodeUpdate(EVP_ENCODE_CTX *ctx, unsigned char *out, int *outl,
21 const unsigned char *in, int inl);
22 int EVP_DecodeFinal(EVP_ENCODE_CTX *ctx, unsigned
23 char *out, int *outl);
24 int EVP_DecodeBlock(unsigned char *t, const unsigned char *f, int n);
25
27 The EVP encode routines provide a high level interface to base 64
28 encoding and decoding. Base 64 encoding converts binary data into a
29 printable form that uses the characters A-Z, a-z, 0-9, "+" and "/" to
30 represent the data. For every 3 bytes of binary data provided 4 bytes
31 of base 64 encoded data will be produced plus some occasional newlines
32 (see below). If the input data length is not a multiple of 3 then the
33 output data will be padded at the end using the "=" character.
34
35 Encoding of binary data is performed in blocks of 48 input bytes (or
36 less for the final block). For each 48 byte input block encoded 64
37 bytes of base 64 data is output plus an additional newline character
38 (i.e. 65 bytes in total). The final block (which may be less than 48
39 bytes) will output 4 bytes for every 3 bytes of input. If the data
40 length is not divisible by 3 then a full 4 bytes is still output for
41 the final 1 or 2 bytes of input. Similarly a newline character will
42 also be output.
43
44 EVP_EncodeInit() initialises ctx for the start of a new encoding
45 operation.
46
47 EVP_EncodeUpdate() encode inl bytes of data found in the buffer pointed
48 to by in. The output is stored in the buffer out and the number of
49 bytes output is stored in *outl. It is the caller's responsibility to
50 ensure that the buffer at out is sufficiently large to accommodate the
51 output data. Only full blocks of data (48 bytes) will be immediately
52 processed and output by this function. Any remainder is held in the ctx
53 object and will be processed by a subsequent call to EVP_EncodeUpdate()
54 or EVP_EncodeFinal(). To calculate the required size of the output
55 buffer add together the value of inl with the amount of unprocessed
56 data held in ctx and divide the result by 48 (ignore any remainder).
57 This gives the number of blocks of data that will be processed. Ensure
58 the output buffer contains 65 bytes of storage for each block, plus an
59 additional byte for a NUL terminator. EVP_EncodeUpdate() may be called
60 repeatedly to process large amounts of input data. In the event of an
61 error EVP_EncodeUpdate() will set *outl to 0.
62
63 EVP_EncodeFinal() must be called at the end of an encoding operation.
64 It will process any partial block of data remaining in the ctx object.
65 The output data will be stored in out and the length of the data
66 written will be stored in *outl. It is the caller's responsibility to
67 ensure that out is sufficiently large to accommodate the output data
68 which will never be more than 65 bytes plus an additional NUL
69 terminator (i.e. 66 bytes in total).
70
71 EVP_EncodeBlock() encodes a full block of input data in f and of length
72 dlen and stores it in t. For every 3 bytes of input provided 4 bytes of
73 output data will be produced. If dlen is not divisible by 3 then the
74 block is encoded as a final block of data and the output is padded such
75 that it is always divisible by 4. Additionally a NUL terminator
76 character will be added. For example if 16 bytes of input data is
77 provided then 24 bytes of encoded data is created plus 1 byte for a NUL
78 terminator (i.e. 25 bytes in total). The length of the data generated
79 without the NUL terminator is returned from the function.
80
81 EVP_DecodeInit() initialises ctx for the start of a new decoding
82 operation.
83
84 EVP_DecodeUpdate() decodes inl characters of data found in the buffer
85 pointed to by in. The output is stored in the buffer out and the number
86 of bytes output is stored in *outl. It is the caller's responsibility
87 to ensure that the buffer at out is sufficiently large to accommodate
88 the output data. This function will attempt to decode as much data as
89 possible in 4 byte chunks. Any whitespace, newline or carriage return
90 characters are ignored. Any partial chunk of unprocessed data (1, 2 or
91 3 bytes) that remains at the end will be held in the ctx object and
92 processed by a subsequent call to EVP_DecodeUpdate(). If any illegal
93 base 64 characters are encountered or if the base 64 padding character
94 "=" is encountered in the middle of the data then the function returns
95 -1 to indicate an error. A return value of 0 or 1 indicates successful
96 processing of the data. A return value of 0 additionally indicates that
97 the last input data characters processed included the base 64 padding
98 character "=" and therefore no more non-padding character data is
99 expected to be processed. For every 4 valid base 64 bytes processed
100 (ignoring whitespace, carriage returns and line feeds), 3 bytes of
101 binary output data will be produced (or less at the end of the data
102 where the padding character "=" has been used).
103
104 EVP_DecodeFinal() must be called at the end of a decoding operation. If
105 there is any unprocessed data still in ctx then the input data must not
106 have been a multiple of 4 and therefore an error has occurred. The
107 function will return -1 in this case. Otherwise the function returns 1
108 on success.
109
110 EVP_DecodeBlock() will decode the block of n characters of base 64 data
111 contained in f and store the result in t. Any leading whitespace will
112 be trimmed as will any trailing whitespace, newlines, carriage returns
113 or EOF characters. After such trimming the length of the data in f must
114 be divisbile by 4. For every 4 input bytes exactly 3 output bytes will
115 be produced. The output will be padded with 0 bits if necessary to
116 ensure that the output is always 3 bytes for every 4 input bytes. This
117 function will return the length of the data decoded or -1 on error.
118
120 EVP_EncodeBlock() returns the number of bytes encoded excluding the NUL
121 terminator.
122
123 EVP_DecodeUpdate() returns -1 on error and 0 or 1 on success. If 0 is
124 returned then no more non-padding base 64 characters are expected.
125
126 EVP_DecodeFinal() returns -1 on error or 1 on success.
127
128 EVP_DecodeBlock() returns the length of the data decoded or -1 on
129 error.
130
132 evp(3)
133
134
135
1361.0.2o 2019-09-10 EVP_EncodeInit(3)