base64.c File Reference

Base64 module implementation file. More...

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 MAX_PADDING_CHAR_COUNT   2
 
#define BASE64_BIT_COUNT_PER_CHARACTER   6
 
#define MASK_FOR_ENCODING   0x3FU
 
#define MASK_FOR_LOW_BYTE   0xFFU
 
#define BYTE_BIT_COUNT   8
 

Functions

static mcl_error_t _encode_with_table (const char *table, const mcl_uint8_t *data, mcl_size_t data_size, char **encoded_data)
 
static mcl_error_t _decode_with_table (const mcl_uint8_t *table, const char *encoded_data, mcl_uint8_t **decoded_data, mcl_size_t *decoded_data_size)
 
static mcl_error_t _decode_quantum (const mcl_uint8_t *table, const char *source, mcl_uint8_t *destination)
 
mcl_error_t base64_decode (const char *encoded_data, mcl_uint8_t **decoded_data, mcl_size_t *decoded_data_size)
 
mcl_error_t base64_url_decode (const char *encoded_data, mcl_uint8_t **decoded_data, mcl_size_t *decoded_data_size)
 
mcl_error_t base64_encode (const mcl_uint8_t *data, mcl_size_t data_size, char **encoded_data)
 
mcl_error_t base64_url_encode (const mcl_uint8_t *data, mcl_size_t data_size, char **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.

Definition in file base64.c.

Macro Definition Documentation

#define BASE64_BIT_COUNT_PER_CHARACTER   6

Definition at line 23 of file base64.c.

Referenced by _decode_quantum(), and _encode_with_table().

#define BYTE_BIT_COUNT   8

Definition at line 30 of file base64.c.

Referenced by _decode_quantum(), and _encode_with_table().

#define INPUT_GROUP_SIZE   3

Definition at line 19 of file base64.c.

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

#define MASK_FOR_ENCODING   0x3FU

Definition at line 26 of file base64.c.

Referenced by _encode_with_table().

#define MASK_FOR_LOW_BYTE   0xFFU

Definition at line 29 of file base64.c.

Referenced by _decode_quantum().

#define MAX_PADDING_CHAR_COUNT   2

Definition at line 22 of file base64.c.

Referenced by _decode_quantum(), and _decode_with_table().

#define PADDING_CHAR   '='

Definition at line 15 of file base64.c.

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

#define QUANTUM_SIZE   4

Definition at line 18 of file base64.c.

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

Function Documentation

static mcl_error_t _decode_quantum ( const mcl_uint8_t table,
const char *  source,
mcl_uint8_t destination 
)
static
static mcl_error_t _decode_with_table ( const mcl_uint8_t table,
const char *  encoded_data,
mcl_uint8_t **  decoded_data,
mcl_size_t decoded_data_size 
)
static
static mcl_error_t _encode_with_table ( const char *  table,
const mcl_uint8_t data,
mcl_size_t  data_size,
char **  encoded_data 
)
static
mcl_error_t base64_decode ( const char *  encoded_data,
mcl_uint8_t **  decoded_data,
mcl_size_t decoded_data_size 
)

This function is used for decoding a base64 encoded, zero-terminated string in encoded_data and return decoded data in decoded_data with size 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

Definition at line 93 of file base64.c.

References _decode_with_table(), base64_decode_table, MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.

Referenced by security_handler_base64_decode().

Here is the call graph for this function:

Here is the caller graph for this function:

mcl_error_t base64_encode ( const mcl_uint8_t data,
mcl_size_t  data_size,
char **  encoded_data 
)

This function is used for base64 encoding of data in data and return encoded data in encoded_data.

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.
Returns

Definition at line 119 of file base64.c.

References _encode_with_table(), base64_encode_table, MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.

Referenced by security_handler_base64_encode().

Here is the call graph for this function:

Here is the caller graph for this function:

mcl_error_t base64_url_decode ( const char *  encoded_data,
mcl_uint8_t **  decoded_data,
mcl_size_t decoded_data_size 
)

This function is used for decoding a base64 URL encoded, zero-terminated string in encoded_data and return decoded data in decoded_data with size 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

Definition at line 106 of file base64.c.

References _decode_with_table(), base64_url_decode_table, MCL_DEBUG_ENTRY, and MCL_DEBUG_LEAVE.

Here is the call graph for this function:

mcl_error_t base64_url_encode ( const mcl_uint8_t data,
mcl_size_t  data_size,
char **  encoded_data 
)

This function is used for base64 URL encoding of data in data and return encoded data in encoded_data.

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.
Returns

Definition at line 131 of file base64.c.

References _encode_with_table(), base64_url_encode_table, MCL_DEBUG_ENTRY, and MCL_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, 0xF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 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 37 of file base64.c.

Referenced by base64_decode().

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

Definition at line 33 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,
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,
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, 0x3F,
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 63 of file base64.c.

Referenced by base64_url_decode().

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

Definition at line 59 of file base64.c.

Referenced by base64_url_encode().