Genivia Home Documentation
smdevp.c File Reference

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

Functions

static int soap_smd_send (struct soap *soap, const char *buf, size_t len)
 Callback to intercept messages for digest or signature computation/verification. More...
 
static size_t soap_smd_recv (struct soap *soap, char *buf, size_t len)
 Callback to intercept messages for digest or signature computation/verification. More...
 
static int soap_smd_check (struct soap *soap, struct soap_smd_data *data, int err, const char *msg)
 Check result of init/update/final smdevp engine operations. More...
 
SOAP_FMAC1 size_t SOAP_FMAC2 soap_smd_size (int alg, const void *key)
 Returns the number of octets needed to store the digest or signature returned by soap_smd_end. More...
 
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_begin (struct soap *soap, int alg, const void *key, int keylen)
 Initiates a digest or signature computation. More...
 
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_end (struct soap *soap, char *buf, int *len)
 Completes a digest or signature computation. Also deallocates temporary storage allocated by soap_smd_begin(), so MUST be called after soap_smd_begin(). More...
 
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_init (struct soap *soap, struct soap_smd_data *data, int alg, const void *key, int keylen)
 Initiates a (signed) digest computation. More...
 
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_update (struct soap *soap, struct soap_smd_data *data, const char *buf, size_t len)
 Updates (signed) digest computation with message part. More...
 
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_final (struct soap *soap, struct soap_smd_data *data, char *buf, int *len)
 Finalizes (signed) digest computation, delete context and returns digest or signature. More...
 
SOAP_FMAC1 void SOAP_FMAC2 soap_smd_cleanup (struct soap *soap, struct soap_smd_data *data)
 Clear (signed) digest computation and delete context. More...
 

Function Documentation

SOAP_FMAC1 int SOAP_FMAC2 soap_smd_begin ( struct soap *  soap,
int  alg,
const void *  key,
int  keylen 
)

Initiates a digest or signature computation.

Parameters
soapcontext
[in]algis the digest or signature (sign/verification) algorithm used
[in]keyis a HMAC key or pointer to EVP_PKEY object or NULL for digests
[in]keylenis the length of the HMAC key or 0
Returns
SOAP_OK, SOAP_EOM, or SOAP_SSL_ERROR
static int soap_smd_check ( struct soap *  soap,
struct soap_smd_data data,
int  ok,
const char *  msg 
)
static

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

Parameters
soapcontext
[in,out]datasmdevp engine context
[in]okEVP error value
[in]msgerror message
Returns
SOAP_OK or SOAP_SSL_ERROR
SOAP_FMAC1 void SOAP_FMAC2 soap_smd_cleanup ( struct soap *  soap,
struct soap_smd_data data 
)

Clear (signed) digest computation and delete context.

Parameters
soapcontext
[in,out]datasmdevp engine context
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_end ( struct soap *  soap,
char *  buf,
int *  len 
)

Completes a digest or signature computation. Also deallocates temporary storage allocated by soap_smd_begin(), so MUST be called after soap_smd_begin().

Parameters
soapcontext
[in]bufcontains signature for verification (when using a SOAP_SMD_VRFY algorithm) or NULL for cleanup
[out]bufis populated with the digest or signature with maximum length soap_smd_size(alg, key)
[in]lenpoints to length of signature to verify (when using a SOAP_SMD_VRFY algorithm) or NULL for cleanup
[out]lenpoints to length of stored digest or signature (when not NULL)
Returns
SOAP_OK, SOAP_USER_ERROR, or SOAP_SSL_ERROR
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_final ( struct soap *  soap,
struct soap_smd_data data,
char *  buf,
int *  len 
)

Finalizes (signed) digest computation, delete context and returns digest or signature.

Parameters
soapcontext
[in,out]datasmdevp engine context
[in]bufcontains signature for verification (SOAP_SMD_VRFY algorithms) maximum length soap_smd_size(alg, key)
[out]bufis populated with the digest or signature of
[in]lenpoints to length of signature to verify (SOAP_SMD_VRFY algorithms)
[out]lenpoints to length of stored digest or signature (pass NULL if you are not interested in this value)
Returns
SOAP_OK or SOAP_SSL_ERROR
SOAP_FMAC1 int SOAP_FMAC2 soap_smd_init ( struct soap *  soap,
struct soap_smd_data data,
int  alg,
const void *  key,
int  keylen 
)

Initiates a (signed) digest computation.

Parameters
soapcontext
[in,out]datasmdevp engine context
[in]algis algorithm to use
[in]keyis key to use or NULL for digests
[in]keylenis length of HMAC key (when provided)
Returns
SOAP_OK or SOAP_SSL_ERROR
static size_t soap_smd_recv ( struct soap *  soap,
char *  buf,
size_t  len 
)
static

Callback to intercept messages for digest or signature computation/verification.

Parameters
soapcontext
[in]bufbuffer
[in]lenmax buffer length
Returns
message size in buffer or 0 on error.
static int soap_smd_send ( struct soap *  soap,
const char *  buf,
size_t  len 
)
static

Callback to intercept messages for digest or signature computation/verification.

Parameters
soapcontext
[in]bufmessage
[in]lenmessage length
Returns
SOAP_OK or SOAP_SSL_ERROR
SOAP_FMAC1 size_t SOAP_FMAC2 soap_smd_size ( int  alg,
const void *  key 
)

Returns the number of octets needed to store the digest or signature returned by soap_smd_end.

Parameters
[in]algis the digest or signature algorithm to be used
[in]keyis a pointer to an EVP_PKEY object for RSA/DSA signatures or NULL for digests and HMAC
Returns
size_t number of octets that is needed to hold digest or signature
See also
soap_smd_end

The values returned for digests are SOAP_SMD_MD5_SIZE, SOAP_SMD_SHA1_SIZE, SOAP_SMD_SHA256_SIZE, SOAP_SMD_SHA512_SIZE.

SOAP_FMAC1 int SOAP_FMAC2 soap_smd_update ( struct soap *  soap,
struct soap_smd_data data,
const char *  buf,
size_t  len 
)

Updates (signed) digest computation with message part.

Parameters
soapcontext
[in,out]datasmdevp engine context
[in]bufcontains message part
[in]lenof message part
Returns
SOAP_OK or SOAP_SSL_ERROR