Home | Documentation |
mecevp.c File Reference
updated Mon May 13 2024 by Robert van Engelen
|
#include "mecevp.h"
Functions | |
static int | soap_mec_upd (struct soap *soap, struct soap_mec_data *data, const char **s, size_t *n, int final) |
Update encryption/decryption state depending on the current algorithm. More... | |
static int | soap_mec_upd_enc (struct soap *soap, struct soap_mec_data *data, const char **s, size_t *n, int final) |
Update encryption state with input plain text (or raw) data and output in base64 format. More... | |
static int | soap_mec_upd_dec (struct soap *soap, struct soap_mec_data *data, const char **s, size_t *n, int final) |
Update decryption state with input cipher data in base64 format and output in plain text (or raw) format. More... | |
static int | soap_mec_check (struct soap *soap, struct soap_mec_data *data, int err, const char *msg) |
Check result of init/update/final mecevp engine operations. More... | |
static void | soap_mec_put_base64 (struct soap *soap, struct soap_mec_data *data, const unsigned char *s, int n) |
Write base64 formatted data stored in s of length n to internal buffer. More... | |
static void | soap_mec_end_base64 (struct soap *soap, struct soap_mec_data *data) |
End writing base64 formatted data to internal buffer. More... | |
static int | soap_mec_get_base64 (struct soap *soap, struct soap_mec_data *data, char *t, size_t *l, const char *s, size_t n, const char **r, size_t *k) |
Convert base64-formatted data from s[0..n-1] into raw data in t[0..l-1] where l is the max size and set equal or lower if data fits in t. If data does not fit r points to remainder in s[0..n-1] of size k. More... | |
static int | soap_mec_filtersend (struct soap *soap, const char **s, size_t *n) |
Callback to modify outbound messages by encrypting through the engine. More... | |
static int | soap_mec_filterrecv (struct soap *soap, char *buf, size_t *len, size_t maxlen) |
Callback to modify inbound messages by decrypting through the engine. More... | |
SOAP_FMAC1 int SOAP_FMAC2 | soap_mec_init (struct soap *soap, struct soap_mec_data *data, int alg, SOAP_MEC_KEY_TYPE *pkey, unsigned char *key, int *keylen) |
Initialize mecevp engine state and create context for encryption/decryption algorithm using a private/public key or symmetric secret key. More... | |
SOAP_FMAC1 int SOAP_FMAC2 | soap_mec_update (struct soap *soap, struct soap_mec_data *data, const char **s, size_t *n) |
Update mecevp engine state: encrypts plain text (or raw data) or decrypts cipher data in base64 format. More... | |
int | soap_mec_final (struct soap *soap, struct soap_mec_data *data, const char **s, size_t *n) |
Ends mecevp engine state: encrypt/decrypt remainder from buffers. More... | |
SOAP_FMAC1 void SOAP_FMAC2 | soap_mec_cleanup (struct soap *soap, struct soap_mec_data *data) |
Clean up mecevp engine and deallocate cipher context and buffers. More... | |
SOAP_FMAC1 int SOAP_FMAC2 | soap_mec_begin (struct soap *soap, struct soap_mec_data *data, int alg, SOAP_MEC_KEY_TYPE *pkey, unsigned char *key, int *keylen) |
Initialize the mecevp engine data and begin encryption or decryption message sequence using a private/public key or symmetric secret key. More... | |
SOAP_FMAC1 int SOAP_FMAC2 | soap_mec_start_alg (struct soap *soap, int alg, const unsigned char *key) |
Start encryption or decryption of current message. If key is non-NULL, use the symmetric key with alg. Use soap_mec_start only after soap_mec_begin. The soap_mec_start should be followed by a soap_mec_stop call. More... | |
SOAP_FMAC1 int SOAP_FMAC2 | soap_mec_start (struct soap *soap, const unsigned char *key) |
Start encryption or decryption of current message. If key is non-NULL, use the symmetric key with alg. Use soap_mec_start only after soap_mec_begin. The soap_mec_start should be followed by a soap_mec_stop call. More... | |
SOAP_FMAC1 int SOAP_FMAC2 | soap_mec_stop (struct soap *soap) |
Stops encryption or decryption of current message. Use after soap_mec_start. More... | |
SOAP_FMAC1 int SOAP_FMAC2 | soap_mec_end (struct soap *soap, struct soap_mec_data *data) |
Ends encryption or decryption of a sequence of message parts that began with soap_mec_begin. More... | |
SOAP_FMAC1 size_t SOAP_FMAC2 | soap_mec_size (int alg, SOAP_MEC_KEY_TYPE *pkey) |
Returns the number of octets needed to store the public/private key or the symmetric key, depending on the algorithm. More... | |
SOAP_FMAC1 int SOAP_FMAC2 soap_mec_begin | ( | struct soap * | soap, |
struct soap_mec_data * | data, | ||
int | alg, | ||
SOAP_MEC_KEY_TYPE * | pkey, | ||
unsigned char * | key, | ||
int * | keylen | ||
) |
Initialize the mecevp engine data and begin encryption or decryption message sequence using a private/public key or symmetric secret key.
soap | context | |
[in,out] | data | mecevp engine context |
[in] | alg | encryption/decryption algorithm |
[in] | pkey | public/private key or NULL |
[in,out] | key | secret key or encrypted ephemeral secret key set with envelope encryption, or NULL |
[in,out] | keylen | secret key length |
|
static |
Check result of init/update/final mecevp engine operations.
soap | context | |
[in,out] | data | mecevp engine context |
[in] | ok | EVP error value |
[in] | msg | error message |
SOAP_FMAC1 void SOAP_FMAC2 soap_mec_cleanup | ( | struct soap * | soap, |
struct soap_mec_data * | data | ||
) |
Clean up mecevp engine and deallocate cipher context and buffers.
soap | context | |
[in,out] | data | mecevp engine context |
SOAP_FMAC1 int SOAP_FMAC2 soap_mec_end | ( | struct soap * | soap, |
struct soap_mec_data * | data | ||
) |
Ends encryption or decryption of a sequence of message parts that began with soap_mec_begin.
soap | context | |
[in,out] | data | mecevp engine context |
|
static |
End writing base64 formatted data to internal buffer.
soap | context | |
[in,out] | data | mecevp engine context |
|
static |
Callback to modify inbound messages by decrypting through the engine.
soap | context | |
[in,out] | buf | encrypted message, afterwards contains decrypted content |
[in,out] | len | encrypted message size, afterwards set to decrypted content size |
[in] | maxlen | max length of allocated buf size to contain decrypted content |
|
static |
Callback to modify outbound messages by encrypting through the engine.
soap | context | |
[in,out] | s | plain text message, afterwards set to encrypted message |
[in,out] | n | plain text message size, afterwards set to encrypted message size |
int soap_mec_final | ( | struct soap * | soap, |
struct soap_mec_data * | data, | ||
const char ** | s, | ||
size_t * | n | ||
) |
Ends mecevp engine state: encrypt/decrypt remainder from buffers.
soap | context | |
[in,out] | data | mecevp engine context |
[out] | s | afterwards points to converted remaining data in streaming mode, or entire converted data in buffer mode (SOAP_MEC_STORE option) |
[out] | n | afterwards size of remaining data |
|
static |
Convert base64-formatted data from s[0..n-1] into raw data in t[0..l-1] where l is the max size and set equal or lower if data fits in t. If data does not fit r points to remainder in s[0..n-1] of size k.
soap | context | |
[in,out] | data | mecevp engine context |
[in] | t | raw data (converted from base64) |
[in,out] | l | max size of t[], afterwards actual size of data written to t[] |
[in] | s | data in base64 format |
[in] | n | size of base64 data |
[out] | r | if data does not fit in t[], points to s[] remainder to convert |
[out] | k | if data does not fit in t[], size of remainder in r[] |
SOAP_FMAC1 int SOAP_FMAC2 soap_mec_init | ( | struct soap * | soap, |
struct soap_mec_data * | data, | ||
int | alg, | ||
SOAP_MEC_KEY_TYPE * | pkey, | ||
unsigned char * | key, | ||
int * | keylen | ||
) |
Initialize mecevp engine state and create context for encryption/decryption algorithm using a private/public key or symmetric secret key.
soap | context | |
[in,out] | data | mecevp engine context |
[in] | alg | encryption/decryption algorithm |
[in] | pkey | public/private key or NULL |
[in,out] | key | secret key or encrypted ephemeral secret key set with envelope encryption, or NULL |
[in,out] | keylen | secret key length |
|
static |
Write base64 formatted data stored in s of length n to internal buffer.
soap | context | |
[in,out] | data | mecevp engine context |
[in] | s | data to convert |
[in] | n | length of data to convert |
SOAP_FMAC1 size_t SOAP_FMAC2 soap_mec_size | ( | int | alg, |
SOAP_MEC_KEY_TYPE * | pkey | ||
) |
Returns the number of octets needed to store the public/private key or the symmetric key, depending on the algorithm.
[in] | alg | is the algorithm to be used |
[in] | pkey | is a pointer to an EVP_PKEY object or NULL for symmetric keys |
SOAP_FMAC1 int SOAP_FMAC2 soap_mec_start | ( | struct soap * | soap, |
const unsigned char * | key | ||
) |
Start encryption or decryption of current message. If key is non-NULL, use the symmetric key with alg. Use soap_mec_start only after soap_mec_begin. The soap_mec_start should be followed by a soap_mec_stop call.
soap | context | |
[in] | key | secret DES/AES key or NULL |
SOAP_FMAC1 int SOAP_FMAC2 soap_mec_start_alg | ( | struct soap * | soap, |
int | alg, | ||
const unsigned char * | key | ||
) |
Start encryption or decryption of current message. If key is non-NULL, use the symmetric key with alg. Use soap_mec_start only after soap_mec_begin. The soap_mec_start should be followed by a soap_mec_stop call.
soap | context | |
[in] | alg | algorithm |
[in] | key | secret DES/AES key or NULL for private key |
SOAP_FMAC1 int SOAP_FMAC2 soap_mec_stop | ( | struct soap * | soap | ) |
Stops encryption or decryption of current message. Use after soap_mec_start.
soap | context |
|
static |
Update encryption/decryption state depending on the current algorithm.
soap | context | |
[in,out] | data | mecevp engine context |
[in,out] | s | input data to convert, afterwards points to converted data (original content is unchanged) |
[in,out] | n | size of input, afterwards size of output |
[in] | final | flag to indicate no more input, output is flushed to s |
|
static |
Update decryption state with input cipher data in base64 format and output in plain text (or raw) format.
soap | context | |
[in,out] | data | mecevp engine context |
[in,out] | s | input cipher data, afterwards points to output plain text |
[in,out] | n | size of input cipher data, afterwards size of plain text |
[in] | final | flag to indicate no more input, output is flushed to s |
|
static |
Update encryption state with input plain text (or raw) data and output in base64 format.
soap | context | |
[in,out] | data | mecevp engine context |
[in,out] | s | input plain text, afterwards points to output cipher data |
[in,out] | n | size of input text, afterwards size of cipher data |
[in] | final | flag to indicate no more input, output is flushed to s |
SOAP_FMAC1 int SOAP_FMAC2 soap_mec_update | ( | struct soap * | soap, |
struct soap_mec_data * | data, | ||
const char ** | s, | ||
size_t * | n | ||
) |
Update mecevp engine state: encrypts plain text (or raw data) or decrypts cipher data in base64 format.
soap | context | |
[in,out] | data | mecevp engine context |
[in,out] | s | input data to convert, afterwards points to converted data (original content is unchanged) |
[in,out] | n | size of input, afterwards size of output |