cecies
Functions
encrypt.h File Reference

ECIES encryption implementation using Curve25516 or Curve448, AES256-GCM and MbedTLS. More...

#include <stddef.h>
#include <stdint.h>
#include "types.h"
Include dependency graph for encrypt.h:

Go to the source code of this file.

Functions

CECIES_API int cecies_curve25519_encrypt (const uint8_t *data, size_t data_length, int compress, cecies_curve25519_key public_key, uint8_t **output, size_t *output_length, int output_base64)
 
CECIES_API int cecies_curve448_encrypt (const uint8_t *data, size_t data_length, int compress, cecies_curve448_key public_key, uint8_t **output, size_t *output_length, int output_base64)
 

Detailed Description

ECIES encryption implementation using Curve25516 or Curve448, AES256-GCM and MbedTLS.

Author
Raphael Beck

Function Documentation

◆ cecies_curve25519_encrypt()

CECIES_API int cecies_curve25519_encrypt ( const uint8_t *  data,
size_t  data_length,
int  compress,
cecies_curve25519_key  public_key,
uint8_t **  output,
size_t *  output_length,
int  output_base64 
)

Encrypts the given data using ECIES over Curve25519 and AES256-GCM.

Parameters
dataThe data to encrypt.
data_lengthThe length of the data array.
compressShould the data be compressed before being encrypted? Pass any integer value between [0; 9] (where 0 is no compression at all and 9 is highest but slowest compression).
public_keyThe public key to encrypt the data with (hex-string format, as is the output of cecies_generate_curve25519_keypair()).
outputWhere to write the encrypted output into (this will ONLY be allocated if encryption succeeds; if the procedure fails in any way this is left untouched). On success: DO NOT FORGET TO FREE THIS YOURSELF! Use cecies_free() for freeing.
output_lengthWhere to write the output buffer length into.
output_base64Should the encrypted output bytes be base64-encoded for easy transmission over e.g. email? If you decide to base64-encode the encrypted data buffer, please be aware that a NUL-terminator is appended at the end to allow usage as a C-string but it will not be counted in output_length. Pass 0 for false, anything else for true.
Returns
0 if encryption succeeded; error codes as defined inside the header file or MbedTLS otherwise.

◆ cecies_curve448_encrypt()

CECIES_API int cecies_curve448_encrypt ( const uint8_t *  data,
size_t  data_length,
int  compress,
cecies_curve448_key  public_key,
uint8_t **  output,
size_t *  output_length,
int  output_base64 
)

Encrypts the given data using ECIES over Curve448 and AES256-GCM.

Parameters
dataThe data to encrypt.
data_lengthThe length of the data array.
compressShould the data be compressed before being encrypted? Pass any integer value between [0; 9] (where 0 is no compression at all and 9 is highest but slowest compression).
public_keyThe public key to encrypt the data with (hex-string format, as is the output of cecies_generate_curve448_keypair()).
outputWhere to write the encrypted output into (this will ONLY be allocated if encryption succeeds; if the procedure fails in any way this is left untouched). On success: DO NOT FORGET TO FREE THIS YOURSELF! Use cecies_free() for freeing.
output_lengthWhere to write the output buffer length into.
output_base64Should the encrypted output bytes be base64-encoded for easy transmission over e.g. email? If you decide to base64-encode the encrypted data buffer, please be aware that a NUL-terminator is appended at the end to allow usage as a C-string but it will not be counted in output_length. Pass 0 for false, anything else for true.
Returns
0 if encryption succeeded; error codes as defined inside the header file or MbedTLS otherwise.