base64.c File Reference

Base64 module implementation file. More...

#include "base64.h"
#include "memory.h"
#include "log_util.h"
#include "definitions.h"
Include dependency graph for base64.c:

Go to the source code of this file.

Macros

#define PADDING_CHAR   '='
 
#define QUANTUM_SIZE   4
 
#define INPUT_GROUP_SIZE   3
 
#define UPPER_COUNT_PADDING   3
 

Functions

static E_MCL_ERROR_CODE _encode_with_table (const char *table, const mcl_uint8_t *data, mcl_size_t data_size, string_t **encoded_data)
 
static E_MCL_ERROR_CODE _decode_with_table (const mcl_uint8_t *table, const string_t *encoded_data, mcl_uint8_t **decoded_data, mcl_size_t *decoded_data_size)
 
static E_MCL_ERROR_CODE _decode_quantum (const mcl_uint8_t *table, const char *source, mcl_uint8_t *destination, mcl_size_t *padding)
 
E_MCL_ERROR_CODE base64_decode (const string_t *encoded_data, mcl_uint8_t **decoded_data, mcl_size_t *decoded_data_size)
 
E_MCL_ERROR_CODE base64_url_decode (const string_t *encoded_data, mcl_uint8_t **decoded_data, mcl_size_t *decoded_data_size)
 
E_MCL_ERROR_CODE base64_encode (const mcl_uint8_t *data, mcl_size_t data_size, string_t **encoded_data)
 
E_MCL_ERROR_CODE base64_url_encode (const mcl_uint8_t *data, mcl_size_t data_size, string_t **encoded_data)
 

Variables

static const char base64_encode_table [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
 
static const mcl_uint8_t base64_decode_table []
 
static const char base64_url_encode_table [] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
 
static const mcl_uint8_t base64_url_decode_table []
 

Detailed Description

Base64 module implementation file.


Date
Aug 5, 2016

Definition in file base64.c.

Macro Definition Documentation

#define INPUT_GROUP_SIZE   3

Definition at line 24 of file base64.c.

Referenced by _decode_with_table(), and _encode_with_table().

#define PADDING_CHAR   '='

Definition at line 20 of file base64.c.

Referenced by _decode_quantum(), _decode_with_table(), and _encode_with_table().

#define QUANTUM_SIZE   4

Definition at line 23 of file base64.c.

Referenced by _decode_quantum(), _decode_with_table(), and _encode_with_table().

#define UPPER_COUNT_PADDING   3

Definition at line 27 of file base64.c.

Referenced by _decode_quantum().

Function Documentation

static E_MCL_ERROR_CODE _decode_quantum ( const mcl_uint8_t table,
const char *  source,
mcl_uint8_t destination,
mcl_size_t padding 
)
static

Definition at line 203 of file base64.c.

References ASSERT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, MCL_BAD_CONTENT_ENCODING, MCL_DEBUG, MCL_OK, PADDING_CHAR, QUANTUM_SIZE, and UPPER_COUNT_PADDING.

Referenced by _decode_with_table().

Here is the caller graph for this function:

static E_MCL_ERROR_CODE _decode_with_table ( const mcl_uint8_t table,
const string_t encoded_data,
mcl_uint8_t **  decoded_data,
mcl_size_t decoded_data_size 
)
static
static E_MCL_ERROR_CODE _encode_with_table ( const char *  table,
const mcl_uint8_t data,
mcl_size_t  data_size,
string_t **  encoded_data 
)
static

Definition at line 253 of file base64.c.

References ASSERT_CODE_MESSAGE, DEBUG_ENTRY, DEBUG_LEAVE, INPUT_GROUP_SIZE, MCL_DEBUG, MCL_MALLOC, MCL_NULL, MCL_NULL_CHAR, MCL_OK, MCL_OUT_OF_MEMORY, PADDING_CHAR, QUANTUM_SIZE, and string_initialize_dynamic().

Referenced by base64_encode(), and base64_url_encode().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE base64_decode ( const string_t encoded_data,
mcl_uint8_t **  decoded_data,
mcl_size_t decoded_data_size 
)

Given a base64 zero-terminated string at encoded_data, decode it and return a pointer in decoded_data to a newly allocated memory area holding decoded data. Size of decoded data is returned in variable pointed by decoded_data_size.

When decoded data length is 0, returns MCL_NULL in decoded_data.

Parameters
encoded_data[in] Zero-terminated string which is base64 encoded and has to be decoded.
decoded_data[out] Newly allocated memory holding decoded data.
decoded_data_size[out] Size of decoded data.
Returns
  • MCL_OK in case of success.
  • MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • MCL_BAD_CONTENT_ENCODING if provided encoded_data has invalid length (0 or not multiples of 4) or if the given encoded_data is invalidly encoded.

Definition at line 82 of file base64.c.

References _decode_with_table(), base64_decode_table, DEBUG_ENTRY, and DEBUG_LEAVE.

Referenced by security_handler_base64_decode().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE base64_encode ( const mcl_uint8_t data,
mcl_size_t  data_size,
string_t **  encoded_data 
)

Given a pointer to an input data and an input size, encode it with base64 and return a pointer in encoded_data to a newly allocated string area holding encoded data. Length of encoded data is also returned.

When encoded data length is 0, returns MCL_NULL in encoded_data.

Parameters
data[in] Input data that has to be base64 encoded.
data_size[in] Size of given input data.
encoded_data[out] Newly allocated string holding encoded data and its length.
Returns

Definition at line 102 of file base64.c.

References _encode_with_table(), base64_encode_table, DEBUG_ENTRY, and DEBUG_LEAVE.

Referenced by security_handler_base64_encode().

Here is the call graph for this function:

Here is the caller graph for this function:

E_MCL_ERROR_CODE base64_url_decode ( const string_t encoded_data,
mcl_uint8_t **  decoded_data,
mcl_size_t decoded_data_size 
)

Given a base64 URL zero-terminated string at encoded_data, decode it and return a pointer in decoded_data to a newly allocated memory area holding decoded data. Size of decoded data is returned in variable pointed by decoded_data_size.

When decoded data length is 0, returns MCL_NULL in decoded_data.

Parameters
encoded_data[in] Zero-terminated string which is base64 URL encoded and has to be decoded.
decoded_data[out] Newly allocated memory holding decoded data.
decoded_data_size[out] Size of decoded_data.
Returns
  • MCL_OK in case of success.
  • MCL_OUT_OF_MEMORY in case there is not enough memory in the system to proceed.
  • MCL_BAD_CONTENT_ENCODING if provided encoded_data has invalid length (0 or not multiples of 4) or if the given encoded_data is invalidly encoded.

Definition at line 92 of file base64.c.

References _decode_with_table(), base64_url_decode_table, DEBUG_ENTRY, and DEBUG_LEAVE.

Here is the call graph for this function:

E_MCL_ERROR_CODE base64_url_encode ( const mcl_uint8_t data,
mcl_size_t  data_size,
string_t **  encoded_data 
)

Given a pointer to an input data and an input size, encode it with base64 URL and return a pointer in encoded_data to a newly allocated string area holding encoded data. Length of encoded data is also returned.

When encoded data length is 0, returns MCL_NULL in encoded_data.

Parameters
data[in] Input data that has to be base64 URL encoded.
data_size[in] Size of given input data.
encoded_data[out] Newly allocated string holding encoded data and its length.
Returns

Definition at line 112 of file base64.c.

References _encode_with_table(), base64_url_encode_table, DEBUG_ENTRY, and DEBUG_LEAVE.

Referenced by _base64_encode_big_number(), and security_handler_base64_url_encode().

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const mcl_uint8_t base64_decode_table[]
static
Initial value:
=
{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x3E, 0xFF, 0xFF, 0xFF, 0x3F,
0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
0x0F, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27, 0x28,
0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F, 0x30, 0x31, 0x32, 0x33, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
}

Definition at line 32 of file base64.c.

Referenced by base64_decode().

const char base64_encode_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
static

Definition at line 30 of file base64.c.

Referenced by base64_encode().

const mcl_uint8_t base64_url_decode_table[]
static
Initial value:
=
{
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0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F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
}

Definition at line 56 of file base64.c.

Referenced by base64_url_decode().

const char base64_url_encode_table[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
static

Definition at line 54 of file base64.c.

Referenced by base64_url_encode().