PolarSSL v1.3.9
pkcs11.h
Go to the documentation of this file.
1 
29 #ifndef POLARSSL_PKCS11_H
30 #define POLARSSL_PKCS11_H
31 
32 #if !defined(POLARSSL_CONFIG_FILE)
33 #include "config.h"
34 #else
35 #include POLARSSL_CONFIG_FILE
36 #endif
37 
38 #if defined(POLARSSL_PKCS11_C)
39 
40 #include "x509_crt.h"
41 
42 #include <pkcs11-helper-1.0/pkcs11h-certificate.h>
43 
44 #if defined(_MSC_VER) && !defined(inline)
45 #define inline _inline
46 #else
47 #if defined(__ARMCC_VERSION) && !defined(inline)
48 #define inline __inline
49 #endif /* __ARMCC_VERSION */
50 #endif /*_MSC_VER */
51 
52 #ifdef __cplusplus
53 extern "C" {
54 #endif
55 
59 typedef struct {
60  pkcs11h_certificate_t pkcs11h_cert;
61  int len;
62 } pkcs11_context;
63 
72 int pkcs11_x509_cert_init( x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
73 
84 int pkcs11_priv_key_init( pkcs11_context *priv_key,
85  pkcs11h_certificate_t pkcs11_cert );
86 
93 void pkcs11_priv_key_free( pkcs11_context *priv_key );
94 
112 int pkcs11_decrypt( pkcs11_context *ctx,
113  int mode, size_t *olen,
114  const unsigned char *input,
115  unsigned char *output,
116  size_t output_max_len );
117 
134 int pkcs11_sign( pkcs11_context *ctx,
135  int mode,
136  md_type_t md_alg,
137  unsigned int hashlen,
138  const unsigned char *hash,
139  unsigned char *sig );
140 
144 static inline int ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
145  const unsigned char *input, unsigned char *output,
146  size_t output_max_len )
147 {
148  return pkcs11_decrypt( (pkcs11_context *) ctx, mode, olen, input, output,
149  output_max_len );
150 }
151 
152 static inline int ssl_pkcs11_sign( void *ctx,
153  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
154  int mode, md_type_t md_alg, unsigned int hashlen,
155  const unsigned char *hash, unsigned char *sig )
156 {
157  ((void) f_rng);
158  ((void) p_rng);
159  return pkcs11_sign( (pkcs11_context *) ctx, mode, md_alg,
160  hashlen, hash, sig );
161 }
162 
163 static inline size_t ssl_pkcs11_key_len( void *ctx )
164 {
165  return ( (pkcs11_context *) ctx )->len;
166 }
167 
168 #ifdef __cplusplus
169 }
170 #endif
171 
172 #endif /* POLARSSL_PKCS11_C */
173 
174 #endif /* POLARSSL_PKCS11_H */