isoApplet: prototype of asn1_sig_value_sequence_to_rs() has changed
This commit is contained in:
parent
595be37fee
commit
877fa862d9
|
@ -47,6 +47,7 @@ struct isoApplet_drv_data
|
||||||
* If ECC is being used, the signatures generated by the card
|
* If ECC is being used, the signatures generated by the card
|
||||||
* have to be modified. */
|
* have to be modified. */
|
||||||
unsigned int sec_env_alg_ref;
|
unsigned int sec_env_alg_ref;
|
||||||
|
unsigned int sec_env_ec_field_length;
|
||||||
};
|
};
|
||||||
#define DRVDATA(card) ((struct isoApplet_drv_data *) ((card)->drv_data))
|
#define DRVDATA(card) ((struct isoApplet_drv_data *) ((card)->drv_data))
|
||||||
|
|
||||||
|
@ -191,11 +192,9 @@ isoApplet_init(sc_card_t *card)
|
||||||
|
|
||||||
LOG_FUNC_CALLED(card->ctx);
|
LOG_FUNC_CALLED(card->ctx);
|
||||||
|
|
||||||
drvdata=malloc(sizeof(*drvdata));
|
drvdata=calloc(1, sizeof(*drvdata));
|
||||||
if (!drvdata)
|
if (!drvdata)
|
||||||
LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
|
LOG_FUNC_RETURN(card->ctx, SC_ERROR_OUT_OF_MEMORY);
|
||||||
memset(drvdata, 0, sizeof(*drvdata));
|
|
||||||
drvdata->sec_env_alg_ref = 0;
|
|
||||||
|
|
||||||
card->drv_data = drvdata;
|
card->drv_data = drvdata;
|
||||||
card->cla = 0x00;
|
card->cla = 0x00;
|
||||||
|
@ -1106,6 +1105,7 @@ isoApplet_set_security_env(sc_card_t *card,
|
||||||
if( env->algorithm_flags & SC_ALGORITHM_ECDSA_RAW )
|
if( env->algorithm_flags & SC_ALGORITHM_ECDSA_RAW )
|
||||||
{
|
{
|
||||||
drvdata->sec_env_alg_ref = ISOAPPLET_ALG_REF_ECDSA;
|
drvdata->sec_env_alg_ref = ISOAPPLET_ALG_REF_ECDSA;
|
||||||
|
drvdata->sec_env_ec_field_length = env->algorithm_ref;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -1190,38 +1190,41 @@ isoApplet_compute_signature(struct sc_card *card,
|
||||||
const u8 *data, size_t datalen,
|
const u8 *data, size_t datalen,
|
||||||
u8 *out, size_t outlen)
|
u8 *out, size_t outlen)
|
||||||
{
|
{
|
||||||
|
struct sc_context *ctx = card->ctx;
|
||||||
struct isoApplet_drv_data *drvdata = DRVDATA(card);
|
struct isoApplet_drv_data *drvdata = DRVDATA(card);
|
||||||
int r;
|
int r;
|
||||||
|
|
||||||
LOG_FUNC_CALLED(card->ctx);
|
LOG_FUNC_CALLED(ctx);
|
||||||
|
|
||||||
r = iso_ops->compute_signature(card, data, datalen, out, outlen);
|
r = iso_ops->compute_signature(card, data, datalen, out, outlen);
|
||||||
if(r < 0)
|
if(r < 0)
|
||||||
{
|
{
|
||||||
LOG_FUNC_RETURN(card->ctx, r);
|
LOG_FUNC_RETURN(ctx, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we used ECDSA for the signature op, OpenSC thinks it has to
|
/* If ECDSA was used, the ASN.1 sequence of integers R,S returned by the
|
||||||
* convert it to {sequence{integer,integer}} which is already done by the
|
* card needs to be converted to the raw concatenation of R,S for PKCS#11. */
|
||||||
* card actually.
|
|
||||||
* To fix this, I strip the {sequence, sequence} structual information,
|
|
||||||
* which will be added again later.*/
|
|
||||||
if(drvdata->sec_env_alg_ref == ISOAPPLET_ALG_REF_ECDSA)
|
if(drvdata->sec_env_alg_ref == ISOAPPLET_ALG_REF_ECDSA)
|
||||||
{
|
{
|
||||||
u8* p = NULL;
|
u8* p = NULL;
|
||||||
size_t len;
|
size_t len = drvdata->sec_env_ec_field_length / 4;
|
||||||
|
|
||||||
r = sc_asn1_sig_value_sequence_to_rs(card->ctx, out, r, &p, &len);
|
if (len > outlen)
|
||||||
if(r < 0) {
|
LOG_FUNC_RETURN(ctx, SC_ERROR_BUFFER_TOO_SMALL);
|
||||||
if(p)
|
|
||||||
free(p);
|
p = calloc(1,len);
|
||||||
LOG_FUNC_RETURN(card->ctx, r);
|
if (!p)
|
||||||
|
LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY);
|
||||||
|
|
||||||
|
r = sc_asn1_sig_value_sequence_to_rs(ctx, out, r, p, len);
|
||||||
|
if (!r) {
|
||||||
|
memcpy(out, p, len);
|
||||||
|
r = len;
|
||||||
}
|
}
|
||||||
memcpy(out, p, len);
|
|
||||||
r = len;
|
|
||||||
free(p);
|
free(p);
|
||||||
}
|
}
|
||||||
LOG_FUNC_RETURN(card->ctx, r);
|
LOG_FUNC_RETURN(ctx, r);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct sc_card_driver *sc_get_driver(void)
|
static struct sc_card_driver *sc_get_driver(void)
|
||||||
|
|
Loading…
Reference in New Issue