#ifndef _OPENSC_H
#define _OPENSC_H
#include <stdio.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
#include "common/simclist.h"
#include "scconf/scconf.h"
#include "libopensc/errors.h"
#include "libopensc/types.h"
#ifdef ENABLE_SM
#include "libopensc/sm.h"
#endif
#if defined(_WIN32) && !(defined(__MINGW32__) && defined (__MINGW_PRINTF_FORMAT))
#define SC_FORMAT_LEN_SIZE_T "I"
#define SC_FORMAT_LEN_PTRDIFF_T "I"
#else
#define SC_FORMAT_LEN_SIZE_T "z"
#define SC_FORMAT_LEN_PTRDIFF_T "t"
#endif
#define SC_SEC_OPERATION_DECIPHER 0x0001
#define SC_SEC_OPERATION_SIGN 0x0002
#define SC_SEC_OPERATION_AUTHENTICATE 0x0003
#define SC_SEC_OPERATION_DERIVE 0x0004
#define SC_SEC_OPERATION_WRAP 0x0005
#define SC_SEC_OPERATION_UNWRAP 0x0006
#define SC_SEC_ENV_ALG_REF_PRESENT 0x0001
#define SC_SEC_ENV_FILE_REF_PRESENT 0x0002
#define SC_SEC_ENV_KEY_REF_PRESENT 0x0004
#define SC_SEC_ENV_KEY_REF_SYMMETRIC 0x0008
#define SC_SEC_ENV_ALG_PRESENT 0x0010
#define SC_SEC_ENV_TARGET_FILE_REF_PRESENT 0x0020
#define SC_SEC_ENV_MAX_PARAMS 10
#define SC_SEC_ENV_PARAM_IV 1
#define SC_SEC_ENV_PARAM_TARGET_FILE 2
#define SC_ALGORITHM_RSA 0
#define SC_ALGORITHM_DSA 1
#define SC_ALGORITHM_EC 2
#define SC_ALGORITHM_GOSTR3410 3
#define SC_ALGORITHM_DES 64
#define SC_ALGORITHM_3DES 65
#define SC_ALGORITHM_GOST 66
#define SC_ALGORITHM_AES 67
#define SC_ALGORITHM_UNDEFINED 68
#define SC_ALGORITHM_MD5 128
#define SC_ALGORITHM_SHA1 129
#define SC_ALGORITHM_GOSTR3411 130
#define SC_ALGORITHM_PBKDF2 192
#define SC_ALGORITHM_PBES2 256
#define SC_ALGORITHM_ONBOARD_KEY_GEN 0x80000000
#define SC_ALGORITHM_NEED_USAGE 0x40000000
#define SC_ALGORITHM_SPECIFIC_FLAGS 0x001FFFFF
#define SC_ALGORITHM_RSA_RAW 0x00000001
#define SC_ALGORITHM_RSA_PADS 0x0000001F
#define SC_ALGORITHM_RSA_PAD_NONE 0x00000001
#define SC_ALGORITHM_RSA_PAD_PKCS1 0x00000002
#define SC_ALGORITHM_RSA_PAD_ANSI 0x00000004
#define SC_ALGORITHM_RSA_PAD_ISO9796 0x00000008
#define SC_ALGORITHM_RSA_PAD_PSS 0x00000010
#define SC_ALGORITHM_RSA_HASH_NONE 0x00000100
#define SC_ALGORITHM_RSA_HASH_SHA1 0x00000200
#define SC_ALGORITHM_RSA_HASH_MD5 0x00000400
#define SC_ALGORITHM_RSA_HASH_MD5_SHA1 0x00000800
#define SC_ALGORITHM_RSA_HASH_RIPEMD160 0x00001000
#define SC_ALGORITHM_RSA_HASH_SHA256 0x00002000
#define SC_ALGORITHM_RSA_HASH_SHA384 0x00004000
#define SC_ALGORITHM_RSA_HASH_SHA512 0x00008000
#define SC_ALGORITHM_RSA_HASH_SHA224 0x00010000
#define SC_ALGORITHM_RSA_HASHES 0x0001FF00
#define SC_ALGORITHM_MGF1_SHA1 0x00100000
#define SC_ALGORITHM_MGF1_SHA256 0x00200000
#define SC_ALGORITHM_MGF1_SHA384 0x00400000
#define SC_ALGORITHM_MGF1_SHA512 0x00800000
#define SC_ALGORITHM_MGF1_SHA224 0x01000000
#define SC_ALGORITHM_MGF1_HASHES 0x01F00000
#define SC_ALGORITHM_GOSTR3410_RAW 0x00020000
#define SC_ALGORITHM_GOSTR3410_HASH_NONE SC_ALGORITHM_GOSTR3410_RAW
#define SC_ALGORITHM_GOSTR3410_HASH_GOSTR3411 0x00080000
#define SC_ALGORITHM_GOSTR3410_HASHES 0x000A0000
#define SC_ALGORITHM_ECDH_CDH_RAW 0x00200000
#define SC_ALGORITHM_ECDSA_RAW 0x00100000
#define SC_ALGORITHM_ECDSA_HASH_NONE SC_ALGORITHM_RSA_HASH_NONE
#define SC_ALGORITHM_ECDSA_HASH_SHA1 SC_ALGORITHM_RSA_HASH_SHA1
#define SC_ALGORITHM_ECDSA_HASH_SHA224 SC_ALGORITHM_RSA_HASH_SHA224
#define SC_ALGORITHM_ECDSA_HASH_SHA256 SC_ALGORITHM_RSA_HASH_SHA256
#define SC_ALGORITHM_ECDSA_HASH_SHA384 SC_ALGORITHM_RSA_HASH_SHA384
#define SC_ALGORITHM_ECDSA_HASH_SHA512 SC_ALGORITHM_RSA_HASH_SHA512
#define SC_ALGORITHM_ECDSA_HASHES (SC_ALGORITHM_ECDSA_HASH_SHA1 | \
SC_ALGORITHM_ECDSA_HASH_SHA224 | \
SC_ALGORITHM_ECDSA_HASH_SHA256 | \
SC_ALGORITHM_ECDSA_HASH_SHA384 | \
SC_ALGORITHM_ECDSA_HASH_SHA512)
#define SC_ALGORITHM_RAW_MASK (SC_ALGORITHM_RSA_RAW | \
SC_ALGORITHM_GOSTR3410_RAW | \
SC_ALGORITHM_ECDH_CDH_RAW | \
SC_ALGORITHM_ECDSA_RAW)
#define SC_ALGORITHM_EXT_EC_F_P 0x00000001
#define SC_ALGORITHM_EXT_EC_F_2M 0x00000002
#define SC_ALGORITHM_EXT_EC_ECPARAMETERS 0x00000004
#define SC_ALGORITHM_EXT_EC_NAMEDCURVE 0x00000008
#define SC_ALGORITHM_EXT_EC_UNCOMPRESES 0x00000010
#define SC_ALGORITHM_EXT_EC_COMPRESS 0x00000020
#define SC_ALGORITHM_AES_ECB 0x01000000
#define SC_ALGORITHM_AES_CBC 0x02000000
#define SC_ALGORITHM_AES_CBC_PAD 0x04000000
#define SC_ALGORITHM_AES_FLAGS 0x0F000000
#define SC_EVENT_CARD_INSERTED 0x0001
#define SC_EVENT_CARD_REMOVED 0x0002
#define SC_EVENT_CARD_EVENTS SC_EVENT_CARD_INSERTED|SC_EVENT_CARD_REMOVED
#define SC_EVENT_READER_ATTACHED 0x0004
#define SC_EVENT_READER_DETACHED 0x0008
#define SC_EVENT_READER_EVENTS SC_EVENT_READER_ATTACHED|SC_EVENT_READER_DETACHED
#define MAX_FILE_SIZE 65535
struct sc_supported_algo_info {
unsigned int reference;
unsigned int mechanism;
struct sc_object_id *parameters;
unsigned int operations;
struct sc_object_id algo_id;
unsigned int algo_ref;
};
typedef struct sc_sec_env_param {
unsigned int param_type;
void* value;
unsigned int value_len;
} sc_sec_env_param_t;
typedef struct sc_security_env {
unsigned long flags;
int operation;
unsigned int algorithm, algorithm_flags;
unsigned int algorithm_ref;
struct sc_path file_ref;
unsigned char key_ref[8];
size_t key_ref_len;
struct sc_path target_file_ref;
struct sc_supported_algo_info supported_algos[SC_MAX_SUPPORTED_ALGORITHMS];
struct sc_sec_env_param params[SC_SEC_ENV_MAX_PARAMS];
} sc_security_env_t;
struct sc_algorithm_id {
unsigned int algorithm;
struct sc_object_id oid;
void *params;
};
struct sc_pbkdf2_params {
u8 salt[16];
size_t salt_len;
int iterations;
size_t key_length;
struct sc_algorithm_id hash_alg;
};
struct sc_pbes2_params {
struct sc_algorithm_id derivation_alg;
struct sc_algorithm_id key_encr_alg;
};
struct sc_ec_parameters {
char *named_curve;
struct sc_object_id id;
struct sc_lv_data der;
int type;
size_t field_length;
};
typedef struct sc_algorithm_info {
unsigned int algorithm;
unsigned int key_length;
unsigned int flags;
union {
struct sc_rsa_info {
unsigned long exponent;
} _rsa;
struct sc_ec_info {
unsigned ext_flags;
struct sc_ec_parameters params;
} _ec;
} u;
} sc_algorithm_info_t;
typedef struct sc_app_info {
char *label;
struct sc_aid aid;
struct sc_ddo ddo;
struct sc_path path;
int rec_nr;
} sc_app_info_t;
struct sc_ef_atr {
unsigned char card_service;
unsigned char df_selection;
size_t unit_size;
unsigned char card_capabilities;
size_t max_command_apdu;
size_t max_response_apdu;
struct sc_aid aid;
unsigned char pre_issuing[6];
size_t pre_issuing_len;
unsigned char issuer_data[16];
size_t issuer_data_len;
struct sc_object_id allocation_oid;
unsigned status;
};
struct sc_card_cache {
struct sc_path current_path;
struct sc_file *current_ef;
struct sc_file *current_df;
int valid;
};
#define SC_PROTO_T0 0x00000001
#define SC_PROTO_T1 0x00000002
#define SC_PROTO_RAW 0x00001000
#define SC_PROTO_ANY 0xFFFFFFFF
struct sc_reader_driver {
const char *name;
const char *short_name;
struct sc_reader_operations *ops;
void *dll;
};
#define SC_READER_CARD_PRESENT 0x00000001
#define SC_READER_CARD_CHANGED 0x00000002
#define SC_READER_CARD_INUSE 0x00000004
#define SC_READER_CARD_EXCLUSIVE 0x00000008
#define SC_READER_HAS_WAITING_AREA 0x00000010
#define SC_READER_REMOVED 0x00000020
#define SC_READER_ENABLE_ESCAPE 0x00000040
#define SC_READER_CAP_DISPLAY 0x00000001
#define SC_READER_CAP_PIN_PAD 0x00000002
#define SC_READER_CAP_PACE_EID 0x00000004
#define SC_READER_CAP_PACE_ESIGN 0x00000008
#define SC_READER_CAP_PACE_DESTROY_CHANNEL 0x00000010
#define SC_READER_CAP_PACE_GENERIC 0x00000020
#define SC_READER_SHORT_APDU_MAX_SEND_SIZE 255
#define SC_READER_SHORT_APDU_MAX_RECV_SIZE 256
typedef struct sc_reader {
struct sc_context *ctx;
const struct sc_reader_driver *driver;
const struct sc_reader_operations *ops;
void *drv_data;
char *name;
char *vendor;
unsigned char version_major;
unsigned char version_minor;
unsigned long flags, capabilities;
unsigned int supported_protocols, active_protocol;
size_t max_send_size;
size_t max_recv_size;
struct sc_atr atr;
struct sc_uid uid;
struct _atr_info {
u8 *hist_bytes;
size_t hist_bytes_len;
int Fi, f, Di, N;
u8 FI, DI;
} atr_info;
} sc_reader_t;
#define SC_PIN_CMD_VERIFY 0
#define SC_PIN_CMD_CHANGE 1
#define SC_PIN_CMD_UNBLOCK 2
#define SC_PIN_CMD_GET_INFO 3
#define SC_PIN_CMD_GET_SESSION_PIN 4
#define SC_PIN_CMD_USE_PINPAD 0x0001
#define SC_PIN_CMD_NEED_PADDING 0x0002
#define SC_PIN_CMD_IMPLICIT_CHANGE 0x0004
#define SC_PIN_ENCODING_ASCII 0
#define SC_PIN_ENCODING_BCD 1
#define SC_PIN_ENCODING_GLP 2
#define SC_PIN_STATE_UNKNOWN -1
#define SC_PIN_STATE_LOGGED_OUT 0
#define SC_PIN_STATE_LOGGED_IN 1
struct sc_pin_cmd_pin {
const char *prompt;
const unsigned char *data;
int len;
size_t min_length;
size_t max_length;
size_t stored_length;
unsigned int encoding;
size_t pad_length;
unsigned char pad_char;
size_t offset;
size_t length_offset;
int max_tries;
int tries_left;
int logged_in;
struct sc_acl_entry acls[SC_MAX_SDO_ACLS];
};
struct sc_pin_cmd_data {
unsigned int cmd;
unsigned int flags;
unsigned int pin_type;
int pin_reference;
struct sc_pin_cmd_pin pin1, pin2;
struct sc_apdu *apdu;
};
struct sc_reader_operations {
int (*init)(struct sc_context *ctx);
int (*finish)(struct sc_context *ctx);
int (*detect_readers)(struct sc_context *ctx);
int (*cancel)(struct sc_context *ctx);
int (*release)(struct sc_reader *reader);
int (*detect_card_presence)(struct sc_reader *reader);
int (*connect)(struct sc_reader *reader);
int (*disconnect)(struct sc_reader *reader);
int (*transmit)(struct sc_reader *reader, sc_apdu_t *apdu);
int (*lock)(struct sc_reader *reader);
int (*unlock)(struct sc_reader *reader);
int (*set_protocol)(struct sc_reader *reader, unsigned int proto);
int (*display_message)(struct sc_reader *, const char *);
int (*perform_verify)(struct sc_reader *, struct sc_pin_cmd_data *);
int (*perform_pace)(struct sc_reader *reader,
void *establish_pace_channel_input,
void *establish_pace_channel_output);
int (*wait_for_event)(struct sc_context *ctx, unsigned int event_mask,
sc_reader_t **event_reader, unsigned int *event,
int timeout, void **reader_states);
int (*reset)(struct sc_reader *, int);
int (*use_reader)(struct sc_context *ctx, void *pcsc_context_handle, void *pcsc_card_handle);
};
#define SC_CARD_FLAG_VENDOR_MASK 0xFFFF0000
#define SC_CARD_FLAG_RNG 0x00000002
#define SC_CARD_FLAG_KEEP_ALIVE 0x00000004
#define SC_CARD_CAP_APDU_EXT 0x00000001
#define SC_CARD_CAP_RNG 0x00000004
#define SC_CARD_CAP_ISO7816_PIN_INFO 0x00000008
#define SC_CARD_CAP_USE_FCI_AC 0x00000010
#define SC_CARD_CAP_PROTECTED_AUTHENTICATION_PATH 0x00000100
#define SC_CARD_CAP_SESSION_PIN 0x00000200
#define SC_CARD_CAP_ONCARD_SESSION_OBJECTS 0x00000400
#define SC_CARD_CAP_WRAP_KEY 0x00000800
#define SC_CARD_CAP_UNWRAP_KEY 0x00001000
typedef struct sc_card {
struct sc_context *ctx;
struct sc_reader *reader;
struct sc_atr atr;
struct sc_uid uid;
int type;
unsigned long caps, flags;
int cla;
size_t max_send_size;
size_t max_recv_size;
struct sc_app_info *app[SC_MAX_CARD_APPS];
int app_count;
struct sc_ef_atr *ef_atr;
struct sc_algorithm_info *algorithms;
int algorithm_count;
int lock_count;
struct sc_card_driver *driver;
struct sc_card_operations *ops;
const char *name;
void *drv_data;
int max_pin_len;
struct sc_card_cache cache;
struct sc_serial_number serialnr;
struct sc_version version;
void *mutex;
#ifdef ENABLE_SM
struct sm_context sm_ctx;
#endif
unsigned int magic;
} sc_card_t;
struct sc_card_operations {
int (*match_card)(struct sc_card *card);
int (*init)(struct sc_card *card);
int (*finish)(struct sc_card *card);
int (*read_binary)(struct sc_card *card, unsigned int idx,
u8 * buf, size_t count, unsigned long flags);
int (*write_binary)(struct sc_card *card, unsigned int idx,
const u8 * buf, size_t count, unsigned long flags);
int (*update_binary)(struct sc_card *card, unsigned int idx,
const u8 * buf, size_t count, unsigned long flags);
int (*erase_binary)(struct sc_card *card, unsigned int idx,
size_t count, unsigned long flags);
int (*read_record)(struct sc_card *card, unsigned int rec_nr,
u8 * buf, size_t count, unsigned long flags);
int (*write_record)(struct sc_card *card, unsigned int rec_nr,
const u8 * buf, size_t count, unsigned long flags);
int (*append_record)(struct sc_card *card, const u8 * buf,
size_t count, unsigned long flags);
int (*update_record)(struct sc_card *card, unsigned int rec_nr,
const u8 * buf, size_t count, unsigned long flags);
int (*select_file)(struct sc_card *card, const struct sc_path *path,
struct sc_file **file_out);
int (*get_response)(struct sc_card *card, size_t *count, u8 *buf);
int (*get_challenge)(struct sc_card *card, u8 * buf, size_t count);
int (*verify)(struct sc_card *card, unsigned int type,
int ref_qualifier, const u8 *data, size_t data_len,
int *tries_left);
int (*logout)(struct sc_card *card);
int (*restore_security_env)(struct sc_card *card, int se_num);
int (*set_security_env)(struct sc_card *card,
const struct sc_security_env *env, int se_num);
int (*decipher)(struct sc_card *card, const u8 * crgram,
size_t crgram_len, u8 * out, size_t outlen);
int (*compute_signature)(struct sc_card *card, const u8 * data,
size_t data_len, u8 * out, size_t outlen);
int (*change_reference_data)(struct sc_card *card, unsigned int type,
int ref_qualifier,
const u8 *old, size_t oldlen,
const u8 *newref, size_t newlen,
int *tries_left);
int (*reset_retry_counter)(struct sc_card *card, unsigned int type,
int ref_qualifier,
const u8 *puk, size_t puklen,
const u8 *newref, size_t newlen);
int (*create_file)(struct sc_card *card, struct sc_file *file);
int (*delete_file)(struct sc_card *card, const struct sc_path *path);
int (*list_files)(struct sc_card *card, u8 *buf, size_t buflen);
int (*check_sw)(struct sc_card *card,unsigned int sw1,unsigned int sw2);
int (*card_ctl)(struct sc_card *card, unsigned long request,
void *data);
int (*process_fci)(struct sc_card *card, struct sc_file *file,
const u8 *buf, size_t buflen);
int (*construct_fci)(struct sc_card *card, const struct sc_file *file,
u8 *out, size_t *outlen);
int (*pin_cmd)(struct sc_card *, struct sc_pin_cmd_data *,
int *tries_left);
int (*get_data)(struct sc_card *, unsigned int, u8 *, size_t);
int (*put_data)(struct sc_card *, unsigned int, const u8 *, size_t);
int (*delete_record)(struct sc_card *card, unsigned int rec_nr);
int (*read_public_key)(struct sc_card *, unsigned,
struct sc_path *, unsigned, unsigned,
unsigned char **, size_t *);
int (*card_reader_lock_obtained)(struct sc_card *, int was_reset);
int (*wrap)(struct sc_card *card, u8 *out, size_t outlen);
int (*unwrap)(struct sc_card *card, const u8 *crgram, size_t crgram_len);
};
typedef struct sc_card_driver {
const char *name;
const char *short_name;
struct sc_card_operations *ops;
struct sc_atr_table *atr_map;
unsigned int natrs;
void *dll;
} sc_card_driver_t;
typedef struct {
unsigned int ver;
int (*create_mutex)(void **);
int (*lock_mutex)(void *);
int (*unlock_mutex)(void *);
int (*destroy_mutex)(void *);
unsigned long (*thread_id)(void);
} sc_thread_context_t;
#define SC_CTX_FLAG_TERMINATE 0x00000001
#define SC_CTX_FLAG_PARANOID_MEMORY 0x00000002
#define SC_CTX_FLAG_DEBUG_MEMORY 0x00000004
#define SC_CTX_FLAG_ENABLE_DEFAULT_DRIVER 0x00000008
#define SC_CTX_FLAG_DISABLE_POPUPS 0x00000010
#define SC_CTX_FLAG_DISABLE_COLORS 0x00000020
typedef struct sc_context {
scconf_context *conf;
scconf_block *conf_blocks[3];
char *app_name;
int debug;
unsigned long flags;
FILE *debug_file;
char *debug_filename;
char *preferred_language;
list_t readers;
struct sc_reader_driver *reader_driver;
void *reader_drv_data;
struct sc_card_driver *card_drivers[SC_MAX_CARD_DRIVERS];
struct sc_card_driver *forced_driver;
sc_thread_context_t *thread_ctx;
void *mutex;
unsigned int magic;
} sc_context_t;
int sc_transmit_apdu(struct sc_card *card, struct sc_apdu *apdu);
void sc_format_apdu(struct sc_card *card, struct sc_apdu *apdu,
int cse, int ins, int p1, int p2);
void sc_format_apdu_ex(struct sc_apdu *apdu,
u8 cla, u8 ins, u8 p1, u8 p2,
const u8 *data, size_t datalen,
u8 *resp, size_t resplen);
int sc_check_apdu(struct sc_card *, const struct sc_apdu *);
int sc_bytes2apdu(sc_context_t *ctx, const u8 *buf, size_t len, sc_apdu_t *apdu);
int sc_apdu2bytes(sc_context_t *ctx, const sc_apdu_t *apdu,
unsigned int proto, u8 *out, size_t outlen);
size_t sc_apdu_get_length(const sc_apdu_t *apdu, unsigned int proto);
int sc_check_sw(struct sc_card *card, unsigned int sw1, unsigned int sw2);
int sc_establish_context(sc_context_t **ctx, const char *app_name);
typedef struct {
unsigned int ver;
const char *app_name;
unsigned long flags;
sc_thread_context_t *thread_ctx;
} sc_context_param_t;
int sc_context_repair(sc_context_t **ctx);
int sc_context_create(sc_context_t **ctx, const sc_context_param_t *parm);
int sc_release_context(sc_context_t *ctx);
int sc_ctx_detect_readers(sc_context_t *ctx);
int sc_ctx_win32_get_config_value(const char *env,
const char *reg, const char *key,
void *out, size_t *out_size);
sc_reader_t *sc_ctx_get_reader(sc_context_t *ctx, unsigned int i);
int sc_ctx_use_reader(sc_context_t *ctx, void * pcsc_context_handle, void * pcsc_card_handle);
sc_reader_t *sc_ctx_get_reader_by_name(sc_context_t *ctx, const char *name);
sc_reader_t *sc_ctx_get_reader_by_id(sc_context_t *ctx, unsigned int id);
unsigned int sc_ctx_get_reader_count(sc_context_t *ctx);
int _sc_delete_reader(sc_context_t *ctx, sc_reader_t *reader);
int sc_ctx_log_to_file(sc_context_t *ctx, const char* filename);
int sc_set_card_driver(sc_context_t *ctx, const char *short_name);
int sc_connect_card(sc_reader_t *reader, struct sc_card **card);
int sc_disconnect_card(struct sc_card *card);
int sc_detect_card_presence(sc_reader_t *reader);
int sc_wait_for_event(sc_context_t *ctx, unsigned int event_mask,
sc_reader_t **event_reader, unsigned int *event,
int timeout, void **reader_states);
int sc_reset(struct sc_card *card, int do_cold_reset);
int sc_cancel(sc_context_t *ctx);
int sc_lock(struct sc_card *card);
int sc_unlock(struct sc_card *card);
size_t sc_get_max_recv_size(const sc_card_t *card);
size_t sc_get_max_send_size(const sc_card_t *card);
int sc_select_file(struct sc_card *card, const sc_path_t *path,
sc_file_t **file);
int sc_list_files(struct sc_card *card, u8 *buf, size_t buflen);
int sc_read_binary(struct sc_card *card, unsigned int idx, u8 * buf,
size_t count, unsigned long flags);
int sc_write_binary(struct sc_card *card, unsigned int idx, const u8 * buf,
size_t count, unsigned long flags);
int sc_update_binary(struct sc_card *card, unsigned int idx, const u8 * buf,
size_t count, unsigned long flags);
int sc_erase_binary(struct sc_card *card, unsigned int idx,
size_t count, unsigned long flags);
#define SC_RECORD_EF_ID_MASK 0x0001FUL
#define SC_RECORD_BY_REC_ID 0x00000UL
#define SC_RECORD_BY_REC_NR 0x00100UL
#define SC_RECORD_CURRENT 0UL
int sc_read_record(struct sc_card *card, unsigned int rec_nr, u8 * buf,
size_t count, unsigned long flags);
int sc_write_record(struct sc_card *card, unsigned int rec_nr, const u8 * buf,
size_t count, unsigned long flags);
int sc_append_record(struct sc_card *card, const u8 * buf, size_t count,
unsigned long flags);
int sc_update_record(struct sc_card *card, unsigned int rec_nr, const u8 * buf,
size_t count, unsigned long flags);
int sc_delete_record(struct sc_card *card, unsigned int rec_nr);
int sc_get_data(struct sc_card *, unsigned int, u8 *, size_t);
int sc_put_data(struct sc_card *, unsigned int, const u8 *, size_t);
int sc_get_challenge(struct sc_card *card, u8 * rndout, size_t len);
int sc_restore_security_env(struct sc_card *card, int se_num);
int sc_set_security_env(struct sc_card *card,
const struct sc_security_env *env, int se_num);
int sc_decipher(struct sc_card *card, const u8 * crgram, size_t crgram_len,
u8 * out, size_t outlen);
int sc_compute_signature(struct sc_card *card, const u8 * data,
size_t data_len, u8 * out, size_t outlen);
int sc_verify(struct sc_card *card, unsigned int type, int ref, const u8 *buf,
size_t buflen, int *tries_left);
int sc_logout(struct sc_card *card);
int sc_pin_cmd(struct sc_card *card, struct sc_pin_cmd_data *, int *tries_left);
int sc_change_reference_data(struct sc_card *card, unsigned int type,
int ref, const u8 *old, size_t oldlen,
const u8 *newref, size_t newlen,
int *tries_left);
int sc_reset_retry_counter(struct sc_card *card, unsigned int type,
int ref, const u8 *puk, size_t puklen,
const u8 *newref, size_t newlen);
int sc_build_pin(u8 *buf, size_t buflen, struct sc_pin_cmd_pin *pin, int pad);
int sc_create_file(struct sc_card *card, sc_file_t *file);
int sc_delete_file(struct sc_card *card, const sc_path_t *path);
int sc_card_ctl(struct sc_card *card, unsigned long command, void *arg);
int sc_file_valid(const sc_file_t *file);
sc_file_t * sc_file_new(void);
void sc_file_free(sc_file_t *file);
void sc_file_dup(sc_file_t **dest, const sc_file_t *src);
int sc_file_add_acl_entry(sc_file_t *file, unsigned int operation,
unsigned int method, unsigned long key_ref);
const struct sc_acl_entry * sc_file_get_acl_entry(const sc_file_t *file,
unsigned int operation);
void sc_file_clear_acl_entries(sc_file_t *file, unsigned int operation);
int sc_file_set_sec_attr(sc_file_t *file, const u8 *sec_attr,
size_t sec_attr_len);
int sc_file_set_prop_attr(sc_file_t *file, const u8 *prop_attr,
size_t prop_attr_len);
int sc_file_set_type_attr(sc_file_t *file, const u8 *type_attr,
size_t type_attr_len);
int sc_file_set_content(sc_file_t *file, const u8 *content,
size_t content_len);
int sc_unwrap(struct sc_card *card, const u8 * data,
size_t data_len, u8 * out, size_t outlen);
int sc_wrap(struct sc_card *card, const u8 * data,
size_t data_len, u8 * out, size_t outlen);
int sc_path_set(sc_path_t *path, int type, const u8 *id, size_t id_len,
int index, int count);
void sc_format_path(const char *path_in, sc_path_t *path_out);
const char *sc_print_path(const sc_path_t *path);
int sc_path_print(char *buf, size_t buflen, const sc_path_t *path);
int sc_compare_path(const sc_path_t *patha, const sc_path_t *pathb);
int sc_concatenate_path(sc_path_t *d, const sc_path_t *p1, const sc_path_t *p2);
int sc_append_path(sc_path_t *dest, const sc_path_t *src);
int sc_compare_path_prefix(const sc_path_t *prefix, const sc_path_t *path);
int sc_append_path_id(sc_path_t *dest, const u8 *id, size_t idlen);
int sc_append_file_id(sc_path_t *dest, unsigned int fid);
const sc_path_t *sc_get_mf_path(void);
int sc_hex_to_bin(const char *in, u8 *out, size_t *outlen);
int sc_bin_to_hex(const u8 *, size_t, char *, size_t, int separator);
size_t sc_right_trim(u8 *buf, size_t len);
scconf_block *sc_get_conf_block(sc_context_t *ctx, const char *name1, const char *name2, int priority);
void sc_init_oid(struct sc_object_id *oid);
int sc_format_oid(struct sc_object_id *oid, const char *in);
int sc_compare_oid(const struct sc_object_id *oid1, const struct sc_object_id *oid2);
int sc_valid_oid(const struct sc_object_id *oid);
int sc_base64_encode(const u8 *in, size_t inlen, u8 *out, size_t outlen,
size_t linelength);
int sc_base64_decode(const char *in, u8 *out, size_t outlen);
void sc_mem_clear(void *ptr, size_t len);
void *sc_mem_secure_alloc(size_t len);
void sc_mem_secure_free(void *ptr, size_t len);
int sc_mem_reverse(unsigned char *buf, size_t len);
int sc_get_cache_dir(sc_context_t *ctx, char *buf, size_t bufsize);
int sc_make_cache_dir(sc_context_t *ctx);
int sc_enum_apps(struct sc_card *card);
struct sc_app_info *sc_find_app(struct sc_card *card, struct sc_aid *aid);
void sc_free_apps(struct sc_card *card);
int sc_parse_ef_atr(struct sc_card *card);
void sc_free_ef_atr(struct sc_card *card);
int sc_parse_ef_gdo(struct sc_card *card,
unsigned char *iccsn, size_t *iccsn_len,
unsigned char *chn, size_t *chn_len);
int sc_update_dir(struct sc_card *card, sc_app_info_t *app);
void sc_invalidate_cache(struct sc_card *card);
void sc_print_cache(struct sc_card *card);
struct sc_algorithm_info * sc_card_find_rsa_alg(struct sc_card *card,
unsigned int key_length);
struct sc_algorithm_info * sc_card_find_ec_alg(struct sc_card *card,
unsigned int field_length, struct sc_object_id *curve_oid);
struct sc_algorithm_info * sc_card_find_gostr3410_alg(struct sc_card *card,
unsigned int key_length);
struct sc_algorithm_info * sc_card_find_alg(sc_card_t *card,
unsigned int algorithm, unsigned int key_length, void *param);
scconf_block *sc_match_atr_block(sc_context_t *ctx, struct sc_card_driver *driver, struct sc_atr *atr);
unsigned sc_crc32(const unsigned char *value, size_t len);
const u8 *sc_compacttlv_find_tag(const u8 *buf, size_t len, u8 tag, size_t *outlen);
void sc_remote_data_init(struct sc_remote_data *rdata);
int sc_copy_ec_params(struct sc_ec_parameters *, struct sc_ec_parameters *);
struct sc_card_error {
unsigned int SWs;
int errorno;
const char *errorstr;
};
extern const char *sc_get_version(void);
#define SC_IMPLEMENT_DRIVER_VERSION(a) \
static const char *drv_version = (a); \
const char *sc_driver_version()\
{ \
return drv_version; \
}
extern sc_card_driver_t *sc_get_iso7816_driver(void);
int iso7816_read_binary_sfid(sc_card_t *card, unsigned char sfid,
u8 **ef, size_t *ef_len);
int iso7816_write_binary_sfid(sc_card_t *card, unsigned char sfid,
u8 *ef, size_t ef_len);
int iso7816_update_binary_sfid(sc_card_t *card, unsigned char sfid,
u8 *ef, size_t ef_len);
int iso7816_logout(sc_card_t *card, unsigned char pin_reference);
#ifdef __cplusplus
}
#endif
#endif