Genivia - mecevp.c File Reference

|  | Home | Documentation | mecevp.c File Reference updated Thu Mar 21 2024 by Robert van Engelen |

- Main Page
- Related Pages
- Classes
- Files

- File List
- File Members

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

  | 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

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

  | soap | context
  [in,out] | data | mecevp engine context
  [in] | ok | EVP error value
  [in] | msg | error 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

  | soap | context
  [in,out] | data | mecevp 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

  | soap | context
  [in,out] | data | mecevp 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

  | soap | context
  [in,out] | data | mecevp 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

  | 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

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

  | 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

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

  | 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

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

  | 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[]

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

  | 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

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

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

Parameters

  [in] | alg | is the algorithm to be used
  [in] | pkey | is 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

  | soap | context
  [in] | key | secret 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

  | soap | context
  [in] | alg | algorithm
  [in] | key | secret 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

  soap | context

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

  | 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

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

  | 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

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

  | 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

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

  | 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

Returns
  SOAP_OK or SOAP_SSL_ERROR