blob: 7d9ddf9cd86fe9c6f5e479501001e4e76bd884ed [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * RFC 1521 base64 encoding/decoding
3 *
Bence Szépkúti1e148272020-08-07 13:07:28 +02004 * Copyright The Mbed TLS Contributors
Manuel Pégourié-Gonnard37ff1402015-09-04 14:21:07 +02005 * SPDX-License-Identifier: Apache-2.0
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License"); you may
8 * not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
15 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
Paul Bakker5121ce52009-01-03 21:22:43 +000018 */
19
Gilles Peskinedb09ef62020-06-03 01:43:33 +020020#include "common.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000021
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020022#if defined(MBEDTLS_BASE64_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000023
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000024#include "mbedtls/base64.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000025
Manuel Pégourié-Gonnard93866642015-06-22 19:21:23 +020026#include <stdint.h>
Paul Bakker5c2364c2012-10-01 14:41:15 +000027
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020028#if defined(MBEDTLS_SELF_TEST)
Rich Evans00ab4702015-02-06 13:43:58 +000029#include <string.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020030#if defined(MBEDTLS_PLATFORM_C)
Manuel Pégourié-Gonnard7f809972015-03-09 17:05:11 +000031#include "mbedtls/platform.h"
Paul Bakker7dc4c442014-02-01 22:50:26 +010032#else
Rich Evans00ab4702015-02-06 13:43:58 +000033#include <stdio.h>
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +020034#define mbedtls_printf printf
35#endif /* MBEDTLS_PLATFORM_C */
36#endif /* MBEDTLS_SELF_TEST */
Paul Bakker7dc4c442014-02-01 22:50:26 +010037
Paul Bakker5121ce52009-01-03 21:22:43 +000038static const unsigned char base64_enc_map[64] =
39{
40 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
41 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
42 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd',
43 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
44 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
45 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7',
46 '8', '9', '+', '/'
47};
48
Manuel Pégourié-Gonnard2d708342015-10-05 15:23:11 +010049#define BASE64_SIZE_T_MAX ( (size_t) -1 ) /* SIZE_T_MAX is not standard */
50
Paul Elliott3e790812021-02-25 12:28:49 +000051/*
Paul Elliott0544d492021-03-01 19:15:43 +000052 * Constant flow conditional assignment to unsigned char
Paul Elliottbe165bd2021-03-04 14:34:50 +000053 */
54static void mbedtls_base64_cond_assign_uchar( unsigned char * dest, const unsigned char * const src,
55 unsigned char condition )
Paul Elliottdadd10d2021-02-05 17:49:23 +000056{
Paul Elliott88f2eb62021-03-03 15:31:17 +000057 /* MSVC has a warning about unary minus on unsigned integer types,
58 * but this is well-defined and precisely what we want to do here. */
59#if defined(_MSC_VER)
60#pragma warning( push )
61#pragma warning( disable : 4146 )
62#endif
Paul Elliottdadd10d2021-02-05 17:49:23 +000063
Paul Elliott07fa1f12021-03-03 17:21:17 +000064 /* Generate bitmask from condition, mask will either be 0xFF or 0 */
Paul Elliott3ffd1342021-03-03 17:11:32 +000065 unsigned char mask = ( condition | -condition );
66 mask >>= 7;
67 mask = -mask;
Paul Elliott88f2eb62021-03-03 15:31:17 +000068
69#if defined(_MSC_VER)
70#pragma warning( pop )
71#endif
72
73 *dest = ( ( *src ) & mask ) | ( ( *dest ) & ~mask );
Paul Elliottdadd10d2021-02-05 17:49:23 +000074}
75
76/*
Paul Elliott3e790812021-02-25 12:28:49 +000077 * Constant flow check for equality
Paul Elliottbe165bd2021-03-04 14:34:50 +000078 */
79static unsigned char mbedtls_base64_eq( size_t in_a, size_t in_b )
Paul Elliottdadd10d2021-02-05 17:49:23 +000080{
Paul Elliott717ba772021-03-01 17:49:42 +000081 size_t difference = in_a ^ in_b;
Paul Elliottdadd10d2021-02-05 17:49:23 +000082
Paul Elliott3e790812021-02-25 12:28:49 +000083 /* MSVC has a warning about unary minus on unsigned integer types,
84 * but this is well-defined and precisely what we want to do here. */
85#if defined(_MSC_VER)
86#pragma warning( push )
87#pragma warning( disable : 4146 )
88#endif
89
Paul Elliottdadd10d2021-02-05 17:49:23 +000090 difference |= -difference;
Paul Elliott3e790812021-02-25 12:28:49 +000091
92#if defined(_MSC_VER)
93#pragma warning( pop )
94#endif
95
Paul Elliott717ba772021-03-01 17:49:42 +000096 /* cope with the varying size of size_t per platform */
97 difference >>= ( sizeof( difference ) * 8 - 1 );
98
Paul Elliottdadd10d2021-02-05 17:49:23 +000099 return (unsigned char) ( 1 ^ difference );
100}
101
102/*
Paul Elliott3e790812021-02-25 12:28:49 +0000103 * Constant flow lookup into table.
Paul Elliottbe165bd2021-03-04 14:34:50 +0000104 */
105static unsigned char mbedtls_base64_table_lookup( const unsigned char * const table,
106 const size_t table_size, const size_t table_index )
Paul Elliottdadd10d2021-02-05 17:49:23 +0000107{
108 size_t i;
109 unsigned char result = 0;
110
111 for( i = 0; i < table_size; ++i )
112 {
Paul Elliottbe165bd2021-03-04 14:34:50 +0000113 mbedtls_base64_cond_assign_uchar( &result, &table[i], mbedtls_base64_eq( i, table_index ) );
Paul Elliottdadd10d2021-02-05 17:49:23 +0000114 }
115
116 return result;
117}
118
Gilles Peskineab043352021-07-28 13:54:02 +0200119/* Return 0xff if low <= c <= high, 0 otherwise.
120 *
121 * Constant flow with respect to c.
122 */
123static unsigned char mask_of_range( unsigned char low, unsigned char high,
124 unsigned char c )
125{
126 unsigned low_mask = ( c - low ) >> 8;
127 unsigned high_mask = ( c - high - 1 ) >> 8;
128 return( ~low_mask & high_mask & 0xff );
129}
130
Paul Bakker5121ce52009-01-03 21:22:43 +0000131/*
132 * Encode a buffer into base64 format
133 */
Manuel Pégourié-Gonnardba561362015-06-02 16:30:35 +0100134int mbedtls_base64_encode( unsigned char *dst, size_t dlen, size_t *olen,
Paul Bakker23986e52011-04-24 08:57:21 +0000135 const unsigned char *src, size_t slen )
Paul Bakker5121ce52009-01-03 21:22:43 +0000136{
Paul Bakker23986e52011-04-24 08:57:21 +0000137 size_t i, n;
Paul Bakker5121ce52009-01-03 21:22:43 +0000138 int C1, C2, C3;
139 unsigned char *p;
140
141 if( slen == 0 )
Manuel Pégourié-Gonnard65fc6a82015-01-28 16:49:26 +0000142 {
Manuel Pégourié-Gonnardba561362015-06-02 16:30:35 +0100143 *olen = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000144 return( 0 );
Manuel Pégourié-Gonnard65fc6a82015-01-28 16:49:26 +0000145 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000146
Manuel Pégourié-Gonnard0aa45c22015-09-30 16:30:28 +0200147 n = slen / 3 + ( slen % 3 != 0 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000148
Manuel Pégourié-Gonnard2d708342015-10-05 15:23:11 +0100149 if( n > ( BASE64_SIZE_T_MAX - 1 ) / 4 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000150 {
Manuel Pégourié-Gonnard2d708342015-10-05 15:23:11 +0100151 *olen = BASE64_SIZE_T_MAX;
Manuel Pégourié-Gonnard0aa45c22015-09-30 16:30:28 +0200152 return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
Paul Bakker5121ce52009-01-03 21:22:43 +0000153 }
154
Manuel Pégourié-Gonnard0aa45c22015-09-30 16:30:28 +0200155 n *= 4;
156
Janos Follath98e28a72016-05-31 14:03:54 +0100157 if( ( dlen < n + 1 ) || ( NULL == dst ) )
Paul Bakker5121ce52009-01-03 21:22:43 +0000158 {
Manuel Pégourié-Gonnardba561362015-06-02 16:30:35 +0100159 *olen = n + 1;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200160 return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
Paul Bakker5121ce52009-01-03 21:22:43 +0000161 }
162
Paul Bakker66d5d072014-06-17 16:39:18 +0200163 n = ( slen / 3 ) * 3;
Paul Bakker5121ce52009-01-03 21:22:43 +0000164
165 for( i = 0, p = dst; i < n; i += 3 )
166 {
167 C1 = *src++;
168 C2 = *src++;
169 C3 = *src++;
170
Paul Elliottdadd10d2021-02-05 17:49:23 +0000171 *p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ),
172 ( ( C1 >> 2 ) & 0x3F ) );
173
174 *p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ),
175 ( ( ( ( C1 & 3 ) << 4 ) + ( C2 >> 4 ) ) & 0x3F ) );
176
177 *p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ),
178 ( ( ( ( C2 & 15 ) << 2 ) + ( C3 >> 6 ) ) & 0x3F ) );
179
180 *p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ),
181 ( C3 & 0x3F ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000182 }
183
184 if( i < slen )
185 {
186 C1 = *src++;
Paul Bakker66d5d072014-06-17 16:39:18 +0200187 C2 = ( ( i + 1 ) < slen ) ? *src++ : 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000188
Paul Elliottdadd10d2021-02-05 17:49:23 +0000189 *p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ),
190 ( ( C1 >> 2 ) & 0x3F ) );
191
192 *p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ),
193 ( ( ( ( C1 & 3 ) << 4 ) + ( C2 >> 4 ) ) & 0x3F ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000194
Paul Bakker66d5d072014-06-17 16:39:18 +0200195 if( ( i + 1 ) < slen )
Paul Elliottdadd10d2021-02-05 17:49:23 +0000196 *p++ = mbedtls_base64_table_lookup( base64_enc_map, sizeof( base64_enc_map ),
197 ( ( ( C2 & 15 ) << 2 ) & 0x3F ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000198 else *p++ = '=';
199
200 *p++ = '=';
201 }
202
Manuel Pégourié-Gonnardba561362015-06-02 16:30:35 +0100203 *olen = p - dst;
Paul Bakker5121ce52009-01-03 21:22:43 +0000204 *p = 0;
205
206 return( 0 );
207}
208
Gilles Peskineab043352021-07-28 13:54:02 +0200209/* Given a Base64 digit, return its value.
210 * If c is not a Base64 digit ('A'..'Z', 'a'..'z', '0'..'9', '+' or '/'),
211 * return -1.
212 *
213 * The implementation assumes that letters are consecutive (e.g. ASCII
214 * but not EBCDIC).
215 *
216 * The implementation is constant-flow (no branch or memory access depending
217 * on the value of c) unless the compiler inlines and optimizes a specific
218 * access.
219 */
220static signed char dec_value( unsigned char c )
221{
222 unsigned char val = 0;
223 /* For each range of digits, if c is in that range, mask val with
224 * the corresponding value. Since c can only be in a single range,
225 * only at most one masking will change val. Set val to one plus
226 * the desired value so that it stays 0 if c is in none of the ranges. */
227 val |= mask_of_range( 'A', 'Z', c ) & ( c - 'A' + 0 + 1 );
228 val |= mask_of_range( 'a', 'z', c ) & ( c - 'a' + 26 + 1 );
229 val |= mask_of_range( '0', '9', c ) & ( c - '0' + 52 + 1 );
230 val |= mask_of_range( '+', '+', c ) & ( c - '+' + 62 + 1 );
231 val |= mask_of_range( '/', '/', c ) & ( c - '/' + 63 + 1 );
232 /* At this point, val is 0 if c is an invalid digit and v+1 if c is
233 * a digit with the value v. */
234 return( val - 1 );
235}
236
Paul Bakker5121ce52009-01-03 21:22:43 +0000237/*
238 * Decode a base64-formatted buffer
239 */
Manuel Pégourié-Gonnardba561362015-06-02 16:30:35 +0100240int mbedtls_base64_decode( unsigned char *dst, size_t dlen, size_t *olen,
Paul Bakker23986e52011-04-24 08:57:21 +0000241 const unsigned char *src, size_t slen )
Paul Bakker5121ce52009-01-03 21:22:43 +0000242{
Paul Bakker5c2364c2012-10-01 14:41:15 +0000243 size_t i, n;
244 uint32_t j, x;
Paul Bakker5121ce52009-01-03 21:22:43 +0000245 unsigned char *p;
246
Manuel Pégourié-Gonnard64938c62014-10-15 21:45:39 +0200247 /* First pass: check for validity and get output length */
Paul Bakkerb9cfaa02013-10-11 18:58:55 +0200248 for( i = n = j = 0; i < slen; i++ )
Paul Bakker5121ce52009-01-03 21:22:43 +0000249 {
Manuel Pégourié-Gonnard64938c62014-10-15 21:45:39 +0200250 /* Skip spaces before checking for EOL */
251 x = 0;
252 while( i < slen && src[i] == ' ' )
253 {
254 ++i;
255 ++x;
256 }
257
258 /* Spaces at end of buffer are OK */
259 if( i == slen )
260 break;
261
Paul Bakker5121ce52009-01-03 21:22:43 +0000262 if( ( slen - i ) >= 2 &&
263 src[i] == '\r' && src[i + 1] == '\n' )
264 continue;
265
266 if( src[i] == '\n' )
267 continue;
268
Manuel Pégourié-Gonnard64938c62014-10-15 21:45:39 +0200269 /* Space inside a line is an error */
270 if( x != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200271 return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
Manuel Pégourié-Gonnard64938c62014-10-15 21:45:39 +0200272
Gilles Peskineb553eaa2021-07-28 11:33:04 +0200273 if( src[i] > 127 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200274 return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
Paul Bakker5121ce52009-01-03 21:22:43 +0000275
Gilles Peskineb553eaa2021-07-28 11:33:04 +0200276 if( src[i] == '=' )
277 {
278 if( ++j > 2 )
279 return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
280 }
281 else
282 {
283 if( j != 0 )
284 return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
Gilles Peskineab043352021-07-28 13:54:02 +0200285 if( dec_value( src[i] ) < 0 )
Gilles Peskineb553eaa2021-07-28 11:33:04 +0200286 return( MBEDTLS_ERR_BASE64_INVALID_CHARACTER );
287 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000288 n++;
289 }
290
291 if( n == 0 )
Simon Butchera45aa132015-10-05 00:26:36 +0100292 {
293 *olen = 0;
Paul Bakker5121ce52009-01-03 21:22:43 +0000294 return( 0 );
Simon Butchera45aa132015-10-05 00:26:36 +0100295 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000296
Simon Butchera29c5e9e2017-02-02 08:46:53 +0000297 /* The following expression is to calculate the following formula without
298 * risk of integer overflow in n:
299 * n = ( ( n * 6 ) + 7 ) >> 3;
300 */
Andres AG4623d832017-01-18 17:21:03 +0000301 n = ( 6 * ( n >> 3 ) ) + ( ( 6 * ( n & 0x7 ) + 7 ) >> 3 );
Paul Bakkerd5983182014-07-04 13:50:31 +0200302 n -= j;
Paul Bakker5121ce52009-01-03 21:22:43 +0000303
Manuel Pégourié-Gonnardba561362015-06-02 16:30:35 +0100304 if( dst == NULL || dlen < n )
Paul Bakker5121ce52009-01-03 21:22:43 +0000305 {
Manuel Pégourié-Gonnardba561362015-06-02 16:30:35 +0100306 *olen = n;
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200307 return( MBEDTLS_ERR_BASE64_BUFFER_TOO_SMALL );
Paul Bakker5121ce52009-01-03 21:22:43 +0000308 }
309
310 for( j = 3, n = x = 0, p = dst; i > 0; i--, src++ )
311 {
Manuel Pégourié-Gonnard64938c62014-10-15 21:45:39 +0200312 if( *src == '\r' || *src == '\n' || *src == ' ' )
Paul Bakker5121ce52009-01-03 21:22:43 +0000313 continue;
314
Gilles Peskineb553eaa2021-07-28 11:33:04 +0200315 if( *src == '=' )
316 {
317 --j;
318 x = x << 6;
319 }
320 else
321 {
Gilles Peskineab043352021-07-28 13:54:02 +0200322 x = ( x << 6 ) | ( dec_value( *src ) & 0x3F );
Gilles Peskineb553eaa2021-07-28 11:33:04 +0200323 }
Paul Bakker5121ce52009-01-03 21:22:43 +0000324
325 if( ++n == 4 )
326 {
327 n = 0;
Joe Subbianifbeb6922021-07-16 14:27:50 +0100328 if( j > 0 ) *p++ = MBEDTLS_BYTE_2( x );
329 if( j > 1 ) *p++ = MBEDTLS_BYTE_1( x );
330 if( j > 2 ) *p++ = MBEDTLS_BYTE_0( x );
Paul Bakker5121ce52009-01-03 21:22:43 +0000331 }
332 }
333
Manuel Pégourié-Gonnardba561362015-06-02 16:30:35 +0100334 *olen = p - dst;
Paul Bakker5121ce52009-01-03 21:22:43 +0000335
336 return( 0 );
337}
338
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200339#if defined(MBEDTLS_SELF_TEST)
Paul Bakker5121ce52009-01-03 21:22:43 +0000340
Paul Bakker5121ce52009-01-03 21:22:43 +0000341static const unsigned char base64_test_dec[64] =
342{
343 0x24, 0x48, 0x6E, 0x56, 0x87, 0x62, 0x5A, 0xBD,
344 0xBF, 0x17, 0xD9, 0xA2, 0xC4, 0x17, 0x1A, 0x01,
345 0x94, 0xED, 0x8F, 0x1E, 0x11, 0xB3, 0xD7, 0x09,
346 0x0C, 0xB6, 0xE9, 0x10, 0x6F, 0x22, 0xEE, 0x13,
347 0xCA, 0xB3, 0x07, 0x05, 0x76, 0xC9, 0xFA, 0x31,
348 0x6C, 0x08, 0x34, 0xFF, 0x8D, 0xC2, 0x6C, 0x38,
349 0x00, 0x43, 0xE9, 0x54, 0x97, 0xAF, 0x50, 0x4B,
350 0xD1, 0x41, 0xBA, 0x95, 0x31, 0x5A, 0x0B, 0x97
351};
352
353static const unsigned char base64_test_enc[] =
354 "JEhuVodiWr2/F9mixBcaAZTtjx4Rs9cJDLbpEG8i7hPK"
355 "swcFdsn6MWwINP+Nwmw4AEPpVJevUEvRQbqVMVoLlw==";
356
357/*
358 * Checkup routine
359 */
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200360int mbedtls_base64_self_test( int verbose )
Paul Bakker5121ce52009-01-03 21:22:43 +0000361{
Paul Bakker23986e52011-04-24 08:57:21 +0000362 size_t len;
Paul Bakker3c2122f2013-06-24 19:03:14 +0200363 const unsigned char *src;
364 unsigned char buffer[128];
Paul Bakker5121ce52009-01-03 21:22:43 +0000365
366 if( verbose != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200367 mbedtls_printf( " Base64 encoding test: " );
Paul Bakker5121ce52009-01-03 21:22:43 +0000368
Paul Bakker3c2122f2013-06-24 19:03:14 +0200369 src = base64_test_dec;
Paul Bakker5121ce52009-01-03 21:22:43 +0000370
Manuel Pégourié-Gonnardba561362015-06-02 16:30:35 +0100371 if( mbedtls_base64_encode( buffer, sizeof( buffer ), &len, src, 64 ) != 0 ||
Paul Bakker3c2122f2013-06-24 19:03:14 +0200372 memcmp( base64_test_enc, buffer, 88 ) != 0 )
Paul Bakker5121ce52009-01-03 21:22:43 +0000373 {
374 if( verbose != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200375 mbedtls_printf( "failed\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000376
377 return( 1 );
378 }
379
380 if( verbose != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200381 mbedtls_printf( "passed\n Base64 decoding test: " );
Paul Bakker5121ce52009-01-03 21:22:43 +0000382
Paul Bakker3c2122f2013-06-24 19:03:14 +0200383 src = base64_test_enc;
Paul Bakker5121ce52009-01-03 21:22:43 +0000384
Manuel Pégourié-Gonnardba561362015-06-02 16:30:35 +0100385 if( mbedtls_base64_decode( buffer, sizeof( buffer ), &len, src, 88 ) != 0 ||
Paul Bakker5121ce52009-01-03 21:22:43 +0000386 memcmp( base64_test_dec, buffer, 64 ) != 0 )
387 {
388 if( verbose != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200389 mbedtls_printf( "failed\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000390
391 return( 1 );
392 }
393
394 if( verbose != 0 )
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200395 mbedtls_printf( "passed\n\n" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000396
397 return( 0 );
398}
399
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200400#endif /* MBEDTLS_SELF_TEST */
Paul Bakker5121ce52009-01-03 21:22:43 +0000401
Manuel Pégourié-Gonnard2cf5a7c2015-04-08 12:49:31 +0200402#endif /* MBEDTLS_BASE64_C */