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