pkcs11.h
Go to the documentation of this file.
#ifndef MBEDTLS_PKCS11_H
#define MBEDTLS_PKCS11_H
#if !defined(MBEDTLS_CONFIG_FILE)
#include "config.h"
#else
#include MBEDTLS_CONFIG_FILE
#endif
#if defined(MBEDTLS_PKCS11_C)
#include "x509_crt.h"
#include <pkcs11-helper-1.0/pkcs11h-certificate.h>
#if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
!defined(inline) && !defined(__cplusplus)
#define inline __inline
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
pkcs11h_certificate_t pkcs11h_cert;
int len;
} mbedtls_pkcs11_context;
void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx );
int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
int mbedtls_pkcs11_priv_key_bind( mbedtls_pkcs11_context *priv_key,
pkcs11h_certificate_t pkcs11_cert );
void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key );
int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
int mode, size_t *olen,
const unsigned char *input,
unsigned char *output,
size_t output_max_len );
int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
int mode,
mbedtls_md_type_t md_alg,
unsigned int hashlen,
const unsigned char *hash,
unsigned char *sig );
static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
const unsigned char *input, unsigned char *output,
size_t output_max_len )
{
return mbedtls_pkcs11_decrypt( (mbedtls_pkcs11_context *) ctx, mode, olen, input, output,
output_max_len );
}
static inline int mbedtls_ssl_pkcs11_sign( void *ctx,
int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
const unsigned char *hash, unsigned char *sig )
{
((void) f_rng);
((void) p_rng);
return mbedtls_pkcs11_sign( (mbedtls_pkcs11_context *) ctx, mode, md_alg,
hashlen, hash, sig );
}
static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx )
{
return ( (mbedtls_pkcs11_context *) ctx )->len;
}
#ifdef __cplusplus
}
#endif
#endif /* MBEDTLS_PKCS11_C */
#endif /* MBEDTLS_PKCS11_H */
mbedtls_ssl_pkcs11_sign
static int mbedtls_ssl_pkcs11_sign(void *ctx, int(*f_rng)(void *, unsigned char *, size_t), void *p_rng, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Definition: pkcs11.h:151
mbedtls_pkcs11_init
void mbedtls_pkcs11_init(mbedtls_pkcs11_context *ctx)
Initialize a mbedtls_pkcs11_context.
config.h
Configuration options (set of defines)
mbedtls_pkcs11_priv_key_bind
int mbedtls_pkcs11_priv_key_bind(mbedtls_pkcs11_context *priv_key, pkcs11h_certificate_t pkcs11_cert)
Set up a mbedtls_pkcs11_context storing the given certificate.
mbedtls_pkcs11_context
Context for PKCS #11 private keys.
Definition: pkcs11.h:52
mbedtls_pkcs11_x509_cert_bind
int mbedtls_pkcs11_x509_cert_bind(mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert)
Fill in a mbed TLS certificate, based on the given PKCS11 helper certificate.
mbedtls_pkcs11_sign
int mbedtls_pkcs11_sign(mbedtls_pkcs11_context *ctx, int mode, mbedtls_md_type_t md_alg, unsigned int hashlen, const unsigned char *hash, unsigned char *sig)
Do a private RSA to sign a message digest.
x509_crt.h
X.509 certificate parsing and writing.
mbedtls_pkcs11_decrypt
int mbedtls_pkcs11_decrypt(mbedtls_pkcs11_context *ctx, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
Do an RSA private key decrypt, then remove the message padding.
mbedtls_pkcs11_context::pkcs11h_cert
pkcs11h_certificate_t pkcs11h_cert
Definition: pkcs11.h:53
mbedtls_pkcs11_context::len
int len
Definition: pkcs11.h:54
mbedtls_x509_crt
Container for an X.509 certificate.
Definition: x509_crt.h:52
mbedtls_ssl_pkcs11_key_len
static size_t mbedtls_ssl_pkcs11_key_len(void *ctx)
Definition: pkcs11.h:162
mbedtls_ssl_pkcs11_decrypt
static int mbedtls_ssl_pkcs11_decrypt(void *ctx, int mode, size_t *olen, const unsigned char *input, unsigned char *output, size_t output_max_len)
SSL/TLS wrappers for PKCS#11 functions.
Definition: pkcs11.h:143
mbedtls_md_type_t
mbedtls_md_type_t
Definition: md.h:39
mbedtls_pkcs11_priv_key_free
void mbedtls_pkcs11_priv_key_free(mbedtls_pkcs11_context *priv_key)
Free the contents of the given private key context.