mbed TLS v1.3.11
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(_MSC_VER) && !defined(inline)
42 #define inline _inline
43 #else
44 #if defined(__ARMCC_VERSION) && !defined(inline)
45 #define inline __inline
46 #endif /* __ARMCC_VERSION */
47 #endif /*_MSC_VER */
48 
49 #ifdef __cplusplus
50 extern "C" {
51 #endif
52 
56 typedef struct {
57  pkcs11h_certificate_t pkcs11h_cert;
58  int len;
59 } pkcs11_context;
60 
69 int pkcs11_x509_cert_init( x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
70 
81 int pkcs11_priv_key_init( pkcs11_context *priv_key,
82  pkcs11h_certificate_t pkcs11_cert );
83 
90 void pkcs11_priv_key_free( pkcs11_context *priv_key );
91 
109 int pkcs11_decrypt( pkcs11_context *ctx,
110  int mode, size_t *olen,
111  const unsigned char *input,
112  unsigned char *output,
113  size_t output_max_len );
114 
131 int pkcs11_sign( pkcs11_context *ctx,
132  int mode,
133  md_type_t md_alg,
134  unsigned int hashlen,
135  const unsigned char *hash,
136  unsigned char *sig );
137 
141 static inline int ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
142  const unsigned char *input, unsigned char *output,
143  size_t output_max_len )
144 {
145  return pkcs11_decrypt( (pkcs11_context *) ctx, mode, olen, input, output,
146  output_max_len );
147 }
148 
149 static inline int ssl_pkcs11_sign( void *ctx,
150  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
151  int mode, md_type_t md_alg, unsigned int hashlen,
152  const unsigned char *hash, unsigned char *sig )
153 {
154  ((void) f_rng);
155  ((void) p_rng);
156  return pkcs11_sign( (pkcs11_context *) ctx, mode, md_alg,
157  hashlen, hash, sig );
158 }
159 
160 static inline size_t ssl_pkcs11_key_len( void *ctx )
161 {
162  return ( (pkcs11_context *) ctx )->len;
163 }
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* POLARSSL_PKCS11_C */
170 
171 #endif /* POLARSSL_PKCS11_H */
Configuration options (set of defines)
md_type_t
Definition: md.h:48
Container for an X.509 certificate.
Definition: x509_crt.h:53
X.509 certificate parsing and writing.