Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef HSM_H
00031 #define HSM_H 1
00032
00033 #include <stdint.h>
00034
00035 #define HSM_MAX_SESSIONS 100
00036
00037
00038
00039
00040
00041 #define HSM_MAX_ALGONAME 16
00042
00043 #define HSM_ERROR_MSGSIZE 512
00044
00049 #define HSM_OK 0
00050 #define HSM_ERROR 0x10000001
00051 #define HSM_PIN_INCORRECT 0x10000002
00052 #define HSM_CONFIG_FILE_ERROR 0x10000003
00053 #define HSM_REPOSITORY_NOT_FOUND 0x10000004
00054 #define HSM_NO_REPOSITORIES 0x10000005
00055 #define HSM_MODULE_NOT_FOUND 0x10000006
00056
00057
00059 typedef struct {
00060 unsigned int use_pubkey;
00061 } hsm_config_t;
00062
00064 typedef struct {
00065 unsigned int id;
00066 char *name;
00067 char *token_label;
00068 char *path;
00069 void *handle;
00070 void *sym;
00071 hsm_config_t *config;
00072 } hsm_module_t;
00073
00075 typedef struct {
00076 hsm_module_t *module;
00077 unsigned long session;
00078 } hsm_session_t;
00079
00081 typedef struct {
00082 const hsm_module_t *module;
00083 unsigned long private_key;
00084 unsigned long public_key;
00085 } hsm_key_t;
00086
00088 typedef struct {
00089 char *id;
00090 unsigned long algorithm;
00091 char *algorithm_name;
00092 unsigned long keysize;
00093 } hsm_key_info_t;
00094
00096 typedef struct {
00097 hsm_session_t *session[HSM_MAX_SESSIONS];
00098 size_t session_count;
00101 int error;
00102
00105 const char *error_action;
00106
00108 char error_message[HSM_ERROR_MSGSIZE];
00109 } hsm_ctx_t;
00110
00111
00129 int
00130 hsm_open(const char *config,
00131 char *(pin_callback)(const char *repository, void *),
00132 void *data);
00133
00134
00142 char *
00143 hsm_prompt_pin(const char *repository, void *data);
00144
00145
00152 int
00153 hsm_close();
00154
00155
00161 hsm_ctx_t *
00162 hsm_create_context(void);
00163
00164
00171 void
00172 hsm_destroy_context(hsm_ctx_t *context);
00173
00174
00187 hsm_key_t **
00188 hsm_list_keys(hsm_ctx_t *context, size_t *count);
00189
00190
00204 hsm_key_t **
00205 hsm_list_keys_repository(hsm_ctx_t *context,
00206 size_t *count,
00207 const char *repository);
00208
00209
00214 size_t
00215 hsm_count_keys(hsm_ctx_t *context);
00216
00217
00223 size_t
00224 hsm_count_keys_repository(hsm_ctx_t *context,
00225 const char *repository);
00226
00227
00228
00238 hsm_key_t *
00239 hsm_find_key_by_id(hsm_ctx_t *context,
00240 const char *id);
00241
00255 hsm_key_t *
00256 hsm_generate_rsa_key(hsm_ctx_t *context,
00257 const char *repository,
00258 unsigned long keysize);
00259
00260
00271 int
00272 hsm_remove_key(hsm_ctx_t *context, hsm_key_t *key);
00273
00274
00279 void
00280 hsm_key_free(hsm_key_t *key);
00281
00282
00289 void
00290 hsm_key_list_free(hsm_key_t **key_list, size_t count);
00291
00292
00301 char *
00302 hsm_get_key_id(hsm_ctx_t *context,
00303 const hsm_key_t *key);
00304
00305
00315 hsm_key_info_t *
00316 hsm_get_key_info(hsm_ctx_t *context,
00317 const hsm_key_t *key);
00318
00319
00324 void
00325 hsm_key_info_free(hsm_key_info_t *key_info);
00326
00335 int
00336 hsm_random_buffer(hsm_ctx_t *ctx,
00337 unsigned char *buffer,
00338 unsigned long length);
00339
00340
00346 uint32_t
00347 hsm_random32(hsm_ctx_t *ctx);
00348
00349
00355 uint64_t
00356 hsm_random64(hsm_ctx_t *ctx);
00357
00358
00359
00360
00361
00362
00363
00375 int
00376 hsm_attach(const char *repository,
00377 const char *token_name,
00378 const char *path,
00379 const char *pin,
00380 const hsm_config_t *config);
00381
00387 int
00388 hsm_detach(const char *repository);
00389
00395 int
00396 hsm_token_attached(hsm_ctx_t *ctx,
00397 const char *repository);
00398
00407 char *
00408 hsm_get_error(hsm_ctx_t *gctx);
00409
00410
00411 void hsm_print_session(hsm_session_t *session);
00412 void hsm_print_ctx(hsm_ctx_t *gctx);
00413 void hsm_print_key(hsm_key_t *key);
00414 void hsm_print_error(hsm_ctx_t *ctx);
00415 void hsm_print_tokeninfo(hsm_ctx_t *gctx);
00416
00417 #endif