libopensc: some usefull macros, crc32 calculation procedure

Introduce some usefull define macros, error code 'inconsistent configuration'.
Introduce procedure to calculate CRC32 digest,
to be used in minidriver to calculate the 'freshness' values.
This commit is contained in:
Viktor Tarasov 2012-05-29 11:29:44 +02:00
parent 9c882ff5c2
commit 9d5404bac6
8 changed files with 74 additions and 16 deletions

View File

@ -94,7 +94,7 @@ const char *sc_strerror(int error)
"Requested object not found",
"Not supported",
"Passphrase required",
"UNUSED",
"Inconsistent configuration",
"Decryption failed",
"Wrong padding",
"Unsupported card",

View File

@ -87,7 +87,7 @@ extern "C" {
#define SC_ERROR_OBJECT_NOT_FOUND -1407
#define SC_ERROR_NOT_SUPPORTED -1408
#define SC_ERROR_PASSPHRASE_REQUIRED -1409
/* Unused: -1410 */
#define SC_ERROR_INCONSISTENT_CONFIGURATION -1410
#define SC_ERROR_DECRYPT_FAILED -1411
#define SC_ERROR_WRONG_PADDING -1412
#define SC_ERROR_WRONG_CARD -1413

View File

@ -55,6 +55,11 @@
#define IASECC_ACLS_RSAKEY_PUT_DATA 5
#define IASECC_ACLS_RSAKEY_GET_DATA 6
#define IASECC_ACLS_KEYSET_EXTERNAL_AUTH 1
#define IASECC_ACLS_KEYSET_MUTUAL_AUTH 3
#define IASECC_ACLS_KEYSET_PUT_DATA 5
#define IASECC_ACLS_KEYSET_GET_DATA 6
#define IASECC_SDO_CHV_TAG 0x7F41
#define IASECC_SDO_CHV_TAG_SIZE_MAX 0x80
#define IASECC_SDO_CHV_TAG_SIZE_MIN 0x81

View File

@ -52,6 +52,7 @@
#define IASECC_FCP_TAG_SFID 0x88
#define IASECC_FCP_TAG_ACLS 0xA1
#define IASECC_FCP_TAG_ACLS_CONTACT 0x8C
#define IASECC_FCP_TAG_ACLS_CONTACTLESS 0x9C
#define IASECC_FCP_TYPE_EF 0x01
#define IASECC_FCP_TYPE_DF 0x38

View File

@ -294,4 +294,5 @@ sc_card_find_rsa_alg
sc_print_cache
sc_find_app
sc_remote_data_init
sc_crc32
sc_perform_pace

View File

@ -115,6 +115,7 @@ extern "C" {
/* Not clear if these need their own bits or not */
/* The PIV card does not support and hashes */
#define SC_ALGORITHM_ECDSA_RAW 0x00010000
#define SC_ALGORITHM_ECDH_CDH_RAW 0x00020000
#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
@ -754,6 +755,16 @@ typedef struct {
/** mutex functions to use (optional) */
sc_thread_context_t *thread_ctx;
} sc_context_param_t;
/**
* Repairs an already existing sc_context_t object. This may occur if
* multithreaded issues mean that another context in the same heap is deleted.
* @param ctx pointer to a sc_context_t pointer containing the (partial)
* context.
* @return SC_SUCCESS or an error value if an error occurred.
*/
int sc_context_repair(sc_context_t **ctx);
/**
* Creates a new sc_context_t object.
* @param ctx pointer to a sc_context_t pointer for the newly
@ -1244,6 +1255,13 @@ struct sc_algorithm_info * sc_card_find_ec_alg(sc_card_t *card,
struct sc_algorithm_info * sc_card_find_gostr3410_alg(sc_card_t *card,
unsigned int key_length);
/**
* Get CRC-32 digest
* @param value pointer to data used for CRC calculation
* @param len length of data used for CRC calculation
*/
unsigned sc_crc32(unsigned char *value, size_t len);
/**
* Used to initialize the @c sc_remote_data structure --
* reset the header of the 'remote APDUs' list, set the handlers

View File

@ -65,7 +65,7 @@ int sc_pkcs15_read_data_object(struct sc_pkcs15_card *p15card,
data_object->data = data;
data_object->data_len = len;
*data_object_out = data_object;
return 0;
return SC_SUCCESS;
}
static const struct sc_asn1_entry c_asn1_data[] = {
@ -129,7 +129,7 @@ int sc_pkcs15_decode_dodf_entry(struct sc_pkcs15_card *p15card,
SC_FUNC_RETURN(ctx, SC_LOG_DEBUG_NORMAL, SC_ERROR_OUT_OF_MEMORY);
memcpy(obj->data, &info, sizeof(info));
return 0;
return SC_SUCCESS;
}
int sc_pkcs15_encode_dodf_entry(sc_context_t *ctx,

View File

@ -813,6 +813,39 @@ void sc_remote_data_init(struct sc_remote_data *rdata)
rdata->free = sc_remote_apdu_free;
}
static unsigned long sc_CRC_tab32[256];
static int sc_CRC_tab32_initialized = 0;
unsigned sc_crc32(unsigned char *value, size_t len)
{
size_t ii, jj;
unsigned long crc;
unsigned long index, long_c;
if (!sc_CRC_tab32_initialized) {
for (ii=0; ii<256; ii++) {
crc = (unsigned long) ii;
for (jj=0; jj<8; jj++) {
if ( crc & 0x00000001L )
crc = ( crc >> 1 ) ^ 0xEDB88320l;
else
crc = crc >> 1;
}
sc_CRC_tab32[ii] = crc;
}
sc_CRC_tab32_initialized = 1;
}
crc = 0xffffffffL;
for (ii=0; ii<len; ii++) {
long_c = 0x000000ffL & (unsigned long) (*(value + ii));
index = crc ^ long_c;
crc = (crc >> 8) ^ sc_CRC_tab32[ index & 0xff ];
}
crc ^= 0xffffffff;
return crc%0xffff;
}
/**************************** mutex functions ************************/
int sc_mutex_create(const sc_context_t *ctx, void **mutex)