Genivia Home Documentation
mecevp.c File Reference

updated Mon May 13 2024 by Robert van Engelen
 
Functions
mecevp.c File Reference
#include "mecevp.h"
Include dependency graph for mecevp.c:

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

Function Documentation

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.

Parameters
soapcontext
[in,out]datamecevp engine context
[in]algencryption/decryption algorithm
[in]pkeypublic/private key or NULL
[in,out]keysecret key or encrypted ephemeral secret key set with envelope encryption, or NULL
[in,out]keylensecret key length
Returns
SOAP_OK or error code
static int soap_mec_check ( struct soap *  soap,
struct soap_mec_data data,
int  ok,
const char *  msg 
)
static

Check result of init/update/final mecevp engine operations.

Parameters
soapcontext
[in,out]datamecevp engine context
[in]okEVP error value
[in]msgerror message
Returns
SOAP_OK or SOAP_SSL_ERROR
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.

Parameters
soapcontext
[in,out]datamecevp engine context
Returns
SOAP_OK or SOAP_SSL_ERROR
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.

Parameters
soapcontext
[in,out]datamecevp engine context
Returns
SOAP_OK or error code
static void soap_mec_end_base64 ( struct soap *  soap,
struct soap_mec_data data 
)
static

End writing base64 formatted data to internal buffer.

Parameters
soapcontext
[in,out]datamecevp engine context
static int soap_mec_filterrecv ( struct soap *  soap,
char *  buf,
size_t *  len,
size_t  maxlen 
)
static

Callback to modify inbound messages by decrypting through the engine.

Parameters
soapcontext
[in,out]bufencrypted message, afterwards contains decrypted content
[in,out]lenencrypted message size, afterwards set to decrypted content size
[in]maxlenmax length of allocated buf size to contain decrypted content
Returns
SOAP_OK or SOAP_SSL_ERROR
static int soap_mec_filtersend ( struct soap *  soap,
const char **  s,
size_t *  n 
)
static

Callback to modify outbound messages by encrypting through the engine.

Parameters
soapcontext
[in,out]splain text message, afterwards set to encrypted message
[in,out]nplain text message size, afterwards set to encrypted message size
Returns
SOAP_OK or SOAP_SSL_ERROR
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.

Parameters
soapcontext
[in,out]datamecevp engine context
[out]safterwards points to converted remaining data in streaming mode, or entire converted data in buffer mode (SOAP_MEC_STORE option)
[out]nafterwards size of remaining data
Returns
SOAP_OK or SOAP_SSL_ERROR
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 
)
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.

Parameters
soapcontext
[in,out]datamecevp engine context
[in]traw data (converted from base64)
[in,out]lmax size of t[], afterwards actual size of data written to t[]
[in]sdata in base64 format
[in]nsize of base64 data
[out]rif data does not fit in t[], points to s[] remainder to convert
[out]kif data does not fit in t[], size of remainder in r[]
Returns
SOAP_OK or SOAP_SSL_ERROR
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.

Parameters
soapcontext
[in,out]datamecevp engine context
[in]algencryption/decryption algorithm
[in]pkeypublic/private key or NULL
[in,out]keysecret key or encrypted ephemeral secret key set with envelope encryption, or NULL
[in,out]keylensecret key length
Returns
SOAP_OK or SOAP_SSL_ERROR
static void soap_mec_put_base64 ( struct soap *  soap,
struct soap_mec_data data,
const unsigned char *  s,
int  n 
)
static

Write base64 formatted data stored in s of length n to internal buffer.

Parameters
soapcontext
[in,out]datamecevp engine context
[in]sdata to convert
[in]nlength 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.

Parameters
[in]algis the algorithm to be used
[in]pkeyis a pointer to an EVP_PKEY object or NULL for symmetric keys
Returns
size_t number of octets that is needed to hold the key.
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.

Parameters
soapcontext
[in]keysecret DES/AES key or NULL
Returns
SOAP_OK or error code
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.

Parameters
soapcontext
[in]algalgorithm
[in]keysecret DES/AES key or NULL for private key
Returns
SOAP_OK or error code
SOAP_FMAC1 int SOAP_FMAC2 soap_mec_stop ( struct soap *  soap)

Stops encryption or decryption of current message. Use after soap_mec_start.

Parameters
soapcontext
Returns
SOAP_OK or error code
static int soap_mec_upd ( struct soap *  soap,
struct soap_mec_data data,
const char **  s,
size_t *  n,
int  final 
)
static

Update encryption/decryption state depending on the current algorithm.

Parameters
soapcontext
[in,out]datamecevp engine context
[in,out]sinput data to convert, afterwards points to converted data (original content is unchanged)
[in,out]nsize of input, afterwards size of output
[in]finalflag to indicate no more input, output is flushed to s
Returns
SOAP_OK or SOAP_SSL_ERROR
static int soap_mec_upd_dec ( struct soap *  soap,
struct soap_mec_data data,
const char **  s,
size_t *  n,
int  final 
)
static

Update decryption state with input cipher data in base64 format and output in plain text (or raw) format.

Parameters
soapcontext
[in,out]datamecevp engine context
[in,out]sinput cipher data, afterwards points to output plain text
[in,out]nsize of input cipher data, afterwards size of plain text
[in]finalflag to indicate no more input, output is flushed to s
Returns
SOAP_OK or SOAP_SSL_ERROR
static int soap_mec_upd_enc ( struct soap *  soap,
struct soap_mec_data data,
const char **  s,
size_t *  n,
int  final 
)
static

Update encryption state with input plain text (or raw) data and output in base64 format.

Parameters
soapcontext
[in,out]datamecevp engine context
[in,out]sinput plain text, afterwards points to output cipher data
[in,out]nsize of input text, afterwards size of cipher data
[in]finalflag to indicate no more input, output is flushed to s
Returns
SOAP_OK or SOAP_SSL_ERROR
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.

Parameters
soapcontext
[in,out]datamecevp engine context
[in,out]sinput data to convert, afterwards points to converted data (original content is unchanged)
[in,out]nsize of input, afterwards size of output
Returns
SOAP_OK or SOAP_SSL_ERROR