mbed TLS v2.1.0
pkcs11.h
Go to the documentation of this file.
1 
25 #ifndef MBEDTLS_PKCS11_H
26 #define MBEDTLS_PKCS11_H
27 
28 #if !defined(MBEDTLS_CONFIG_FILE)
29 #include "config.h"
30 #else
31 #include MBEDTLS_CONFIG_FILE
32 #endif
33 
34 #if defined(MBEDTLS_PKCS11_C)
35 
36 #include "x509_crt.h"
37 
38 #include <pkcs11-helper-1.0/pkcs11h-certificate.h>
39 
40 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && !defined(inline)
41 #define inline __inline
42 #endif
43 
44 #ifdef __cplusplus
45 extern "C" {
46 #endif
47 
51 typedef struct {
52  pkcs11h_certificate_t pkcs11h_cert;
53  int len;
54 } mbedtls_pkcs11_context;
55 
60 void mbedtls_pkcs11_init( mbedtls_pkcs11_context *ctx );
61 
70 int mbedtls_pkcs11_x509_cert_bind( mbedtls_x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
71 
82 int mbedtls_pkcs11_priv_key_bind( mbedtls_pkcs11_context *priv_key,
83  pkcs11h_certificate_t pkcs11_cert );
84 
91 void mbedtls_pkcs11_priv_key_free( mbedtls_pkcs11_context *priv_key );
92 
110 int mbedtls_pkcs11_decrypt( mbedtls_pkcs11_context *ctx,
111  int mode, size_t *olen,
112  const unsigned char *input,
113  unsigned char *output,
114  size_t output_max_len );
115 
132 int mbedtls_pkcs11_sign( mbedtls_pkcs11_context *ctx,
133  int mode,
134  mbedtls_md_type_t md_alg,
135  unsigned int hashlen,
136  const unsigned char *hash,
137  unsigned char *sig );
138 
142 static inline int mbedtls_ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
143  const unsigned char *input, unsigned char *output,
144  size_t output_max_len )
145 {
146  return mbedtls_pkcs11_decrypt( (mbedtls_pkcs11_context *) ctx, mode, olen, input, output,
147  output_max_len );
148 }
149 
150 static inline int mbedtls_ssl_pkcs11_sign( void *ctx,
151  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
152  int mode, mbedtls_md_type_t md_alg, unsigned int hashlen,
153  const unsigned char *hash, unsigned char *sig )
154 {
155  ((void) f_rng);
156  ((void) p_rng);
157  return mbedtls_pkcs11_sign( (mbedtls_pkcs11_context *) ctx, mode, md_alg,
158  hashlen, hash, sig );
159 }
160 
161 static inline size_t mbedtls_ssl_pkcs11_key_len( void *ctx )
162 {
163  return ( (mbedtls_pkcs11_context *) ctx )->len;
164 }
165 
166 #ifdef __cplusplus
167 }
168 #endif
169 
170 #endif /* MBEDTLS_PKCS11_C */
171 
172 #endif /* MBEDTLS_PKCS11_H */
Compatibility names (set of defines)
Container for an X.509 certificate.
Definition: x509_crt.h:52
mbedtls_md_type_t
Definition: md.h:43