wickr-crypto-c
Data Structures | Functions
wickr_cipher_t

Data Structures

struct  wickr_cipher
 Represents a cipher that can be used in the crypto_engine. This meta object holds parameters for the cipher algorithms and maintains an identifier that can be used to look up the desired parameters for an algorithm. More...
 
struct  wickr_cipher_result
 
struct  wickr_cipher_key
 

Functions

const wickr_cipher_twickr_cipher_find (uint8_t cipher_id)
 
wickr_cipher_result_twickr_cipher_result_create (wickr_cipher_t cipher, wickr_buffer_t *iv, wickr_buffer_t *cipher_text, wickr_buffer_t *auth_tag)
 
wickr_cipher_result_twickr_cipher_result_copy (const wickr_cipher_result_t *result)
 
void wickr_cipher_result_destroy (wickr_cipher_result_t **result)
 
bool wickr_cipher_result_is_valid (const wickr_cipher_result_t *result)
 
wickr_buffer_twickr_cipher_result_serialize (const wickr_cipher_result_t *result)
 
wickr_cipher_result_twickr_cipher_result_from_buffer (const wickr_buffer_t *buffer)
 
wickr_cipher_key_twickr_cipher_key_create (wickr_cipher_t cipher, wickr_buffer_t *key_data)
 
wickr_cipher_key_twickr_cipher_key_copy (const wickr_cipher_key_t *key)
 
void wickr_cipher_key_destroy (wickr_cipher_key_t **key)
 
wickr_buffer_twickr_cipher_key_serialize (const wickr_cipher_key_t *key)
 
wickr_cipher_key_twickr_cipher_key_from_buffer (const wickr_buffer_t *buffer)
 

Detailed Description

Function Documentation

◆ wickr_cipher_find()

const wickr_cipher_t* wickr_cipher_find ( uint8_t  cipher_id)

Find a supported cipher by identifier. When cipher results are serialized they contain the identifier of the cipher that was used to create them as the first byte

Parameters
cipher_idthe identifier of the cipher
Returns
a cipher with identifier 'cipher_id'. NULL if cipher is not found

◆ wickr_cipher_key_copy()

wickr_cipher_key_t* wickr_cipher_key_copy ( const wickr_cipher_key_t key)

Copy a cipher key

Parameters
keythe key to copy
Returns
a newly allocated cipher key holding a deep copy of the properties of 'key'

◆ wickr_cipher_key_create()

wickr_cipher_key_t* wickr_cipher_key_create ( wickr_cipher_t  cipher,
wickr_buffer_t key_data 
)

Create a key from components

Parameters
cipherthe cipher this key is to be used by
key_dataa buffer representing the raw bytes of the key
Returns
a newly allocated cipher key that takes ownership over 'key_data'

◆ wickr_cipher_key_destroy()

void wickr_cipher_key_destroy ( wickr_cipher_key_t **  key)

Destroy a cipher key

Parameters
keya pointer to the key to destroy. All properties of '*key' will also be destroyed

◆ wickr_cipher_key_from_buffer()

wickr_cipher_key_t* wickr_cipher_key_from_buffer ( const wickr_buffer_t buffer)

Create a cipher key from serialized bytes

Parameters
buffera buffer created by 'wickr_cipher_key_serialize'
Returns
cipher key parsed from 'buffer'. This function makes a copy of all bytes as it is parsing, so the resulting cipher key owns its properties. Returns NULL on parsing failure

◆ wickr_cipher_key_serialize()

wickr_buffer_t* wickr_cipher_key_serialize ( const wickr_cipher_key_t key)

Serialize a cipher key

Parameters
keythe key to serialize to a buffer
Returns
a newly allocated buffer containing properties of 'key' in the following format: | CIPHER_ID | KEY_DATA |

◆ wickr_cipher_result_copy()

wickr_cipher_result_t* wickr_cipher_result_copy ( const wickr_cipher_result_t result)

Copy a cipher result

Parameters
resultthe source of the copy
Returns
A newly allocated cipher_result that contains deep copies of all the properties of 'result'

◆ wickr_cipher_result_create()

wickr_cipher_result_t* wickr_cipher_result_create ( wickr_cipher_t  cipher,
wickr_buffer_t iv,
wickr_buffer_t cipher_text,
wickr_buffer_t auth_tag 
)

Construct a cipher result from individual components.

Parameters
cipherthe cipher used in the cipher operation
ivthe initialization vector used in the cipher operation
cipher_textthe output bytes of a cipher function using 'cipher' and 'iv'
auth_tagthe authentication tag associated with 'cipher_text'. If 'cipher' is authenticated this property is required, otherwise it should be NULL
Returns
A newly allocated cipher result that takes ownership of the passed inputs, or NULL if allocation fails

◆ wickr_cipher_result_destroy()

void wickr_cipher_result_destroy ( wickr_cipher_result_t **  result)

Destroy a cipher result

Parameters
resulta pointer to the cipher result to destroy. Destruction will also destroy the individual properties of 'result'

◆ wickr_cipher_result_from_buffer()

wickr_cipher_result_t* wickr_cipher_result_from_buffer ( const wickr_buffer_t buffer)

Create a cipher result from a serialized cipher result buffer

Parameters
buffera buffer created by 'wickr_cipher_result_serialize'
Returns
cipher result parsed from 'buffer'. This function makes a copy of all bytes as it is parsing, so the resulting cipher result owns its properties. Returns NULL on parsing failure

◆ wickr_cipher_result_is_valid()

bool wickr_cipher_result_is_valid ( const wickr_cipher_result_t result)

Determine if a cipher result is formed correctly

Parameters
resultthe cipher result to validate
Returns
true if result is structured correctly, false if a required field is missing

◆ wickr_cipher_result_serialize()

wickr_buffer_t* wickr_cipher_result_serialize ( const wickr_cipher_result_t result)

Serialize a cipher result

Parameters
resultthe cipher result to serialize
Returns
a buffer containing bytes representing the cipher result in the following format: | CIPHER_ID | IV | AUTH_TAG (IF REQUIRED) | CIPHER_TEXT |