mbed TLS v1.3.14
pkcs11.h
Go to the documentation of this file.
1 
26 #ifndef POLARSSL_PKCS11_H
27 #define POLARSSL_PKCS11_H
28 
29 #if !defined(POLARSSL_CONFIG_FILE)
30 #include "config.h"
31 #else
32 #include POLARSSL_CONFIG_FILE
33 #endif
34 
35 #if defined(POLARSSL_PKCS11_C)
36 
37 #include "x509_crt.h"
38 
39 #include <pkcs11-helper-1.0/pkcs11h-certificate.h>
40 
41 #if ( defined(__ARMCC_VERSION) || defined(_MSC_VER) ) && \
42  !defined(inline) && !defined(__cplusplus)
43 #define inline __inline
44 #endif
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
53 typedef struct {
54  pkcs11h_certificate_t pkcs11h_cert;
55  int len;
56 } pkcs11_context;
57 
66 int pkcs11_x509_cert_init( x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
67 
78 int pkcs11_priv_key_init( pkcs11_context *priv_key,
79  pkcs11h_certificate_t pkcs11_cert );
80 
87 void pkcs11_priv_key_free( pkcs11_context *priv_key );
88 
106 int pkcs11_decrypt( pkcs11_context *ctx,
107  int mode, size_t *olen,
108  const unsigned char *input,
109  unsigned char *output,
110  size_t output_max_len );
111 
128 int pkcs11_sign( pkcs11_context *ctx,
129  int mode,
130  md_type_t md_alg,
131  unsigned int hashlen,
132  const unsigned char *hash,
133  unsigned char *sig );
134 
138 static inline int ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
139  const unsigned char *input, unsigned char *output,
140  size_t output_max_len )
141 {
142  return pkcs11_decrypt( (pkcs11_context *) ctx, mode, olen, input, output,
143  output_max_len );
144 }
145 
146 static inline int ssl_pkcs11_sign( void *ctx,
147  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
148  int mode, md_type_t md_alg, unsigned int hashlen,
149  const unsigned char *hash, unsigned char *sig )
150 {
151  ((void) f_rng);
152  ((void) p_rng);
153  return pkcs11_sign( (pkcs11_context *) ctx, mode, md_alg,
154  hashlen, hash, sig );
155 }
156 
157 static inline size_t ssl_pkcs11_key_len( void *ctx )
158 {
159  return ( (pkcs11_context *) ctx )->len;
160 }
161 
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif /* POLARSSL_PKCS11_C */
167 
168 #endif /* POLARSSL_PKCS11_H */
Configuration options (set of defines)
md_type_t
Definition: md.h:45
Container for an X.509 certificate.
Definition: x509_crt.h:53
X.509 certificate parsing and writing.