00001
00029 #ifndef POLARSSL_PKCS11_H
00030 #define POLARSSL_PKCS11_H
00031
00032 #include "config.h"
00033
00034 #if defined(POLARSSL_PKCS11_C)
00035
00036 #include "x509_crt.h"
00037
00038 #include <pkcs11-helper-1.0/pkcs11h-certificate.h>
00039
00040 #if defined(_MSC_VER) && !defined(inline)
00041 #define inline _inline
00042 #else
00043 #if defined(__ARMCC_VERSION) && !defined(inline)
00044 #define inline __inline
00045 #endif
00046 #endif
00047
00048 #ifdef __cplusplus
00049 extern "C" {
00050 #endif
00051
00055 typedef struct {
00056 pkcs11h_certificate_t pkcs11h_cert;
00057 int len;
00058 } pkcs11_context;
00059
00068 int pkcs11_x509_cert_init( x509_crt *cert, pkcs11h_certificate_t pkcs11h_cert );
00069
00080 int pkcs11_priv_key_init( pkcs11_context *priv_key,
00081 pkcs11h_certificate_t pkcs11_cert );
00082
00089 void pkcs11_priv_key_free( pkcs11_context *priv_key );
00090
00107 int pkcs11_decrypt( pkcs11_context *ctx,
00108 int mode, size_t *olen,
00109 const unsigned char *input,
00110 unsigned char *output,
00111 size_t output_max_len );
00112
00129 int pkcs11_sign( pkcs11_context *ctx,
00130 int mode,
00131 int hash_id,
00132 unsigned int hashlen,
00133 const unsigned char *hash,
00134 unsigned char *sig );
00135
00139 static inline int ssl_pkcs11_decrypt( void *ctx, int mode, size_t *olen,
00140 const unsigned char *input, unsigned char *output,
00141 size_t output_max_len )
00142 {
00143 return pkcs11_decrypt( (pkcs11_context *) ctx, mode, olen, input, output,
00144 output_max_len );
00145 }
00146
00147 static inline int ssl_pkcs11_sign( void *ctx,
00148 int (*f_rng)(void *, unsigned char *, size_t), void *p_rng,
00149 int mode, int hash_id, unsigned int hashlen,
00150 const unsigned char *hash, unsigned char *sig )
00151 {
00152 ((void) f_rng);
00153 ((void) p_rng);
00154 return pkcs11_sign( (pkcs11_context *) ctx, mode, hash_id,
00155 hashlen, hash, sig );
00156 }
00157
00158 static inline size_t ssl_pkcs11_key_len( void *ctx )
00159 {
00160 return ( (pkcs11_context *) ctx )->len;
00161 }
00162
00163 #ifdef __cplusplus
00164 }
00165 #endif
00166
00167 #endif
00168
00169 #endif