PolarSSL v1.2.11
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.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 
51 typedef struct {
52  pkcs11h_certificate_t pkcs11h_cert;
53  int len;
54 } pkcs11_context;
55 
64 int pkcs11_x509_cert_init( x509_cert *cert, pkcs11h_certificate_t pkcs11h_cert );
65 
76 int pkcs11_priv_key_init( pkcs11_context *priv_key,
77  pkcs11h_certificate_t pkcs11_cert );
78 
85 void pkcs11_priv_key_free( pkcs11_context *priv_key );
86 
103 int pkcs11_decrypt( pkcs11_context *ctx,
104  int mode, size_t *olen,
105  const unsigned char *input,
106  unsigned char *output,
107  size_t output_max_len );
108 
125 int pkcs11_sign( pkcs11_context *ctx,
126  int mode,
127  int hash_id,
128  unsigned int hashlen,
129  const unsigned char *hash,
130  unsigned char *sig );
131 
135 static inline int ssl_pkcs11_decrypt( void *ctx,
136  int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
137  int mode, size_t *olen, const unsigned char *input,
138  unsigned char *output, size_t output_max_len )
139 {
140  ((void) f_rng);
141  ((void) p_rng);
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, int hash_id, 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, hash_id,
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 #endif /* POLARSSL_PKCS11_C */
163 
164 #endif /* POLARSSL_PKCS11_H */