diff --git a/src/libopensc/card-isoApplet.c b/src/libopensc/card-isoApplet.c index d3364cb1..8b39f914 100644 --- a/src/libopensc/card-isoApplet.c +++ b/src/libopensc/card-isoApplet.c @@ -1207,7 +1207,7 @@ isoApplet_compute_signature(struct sc_card *card, if(drvdata->sec_env_alg_ref == ISOAPPLET_ALG_REF_ECDSA) { u8* p = NULL; - size_t len = drvdata->sec_env_ec_field_length / 4; + size_t len = (drvdata->sec_env_ec_field_length + 7) / 8 * 2; if (len > outlen) LOG_FUNC_RETURN(ctx, SC_ERROR_BUFFER_TOO_SMALL); diff --git a/src/libopensc/card-myeid.c b/src/libopensc/card-myeid.c index 63a35119..e8c28ec9 100644 --- a/src/libopensc/card-myeid.c +++ b/src/libopensc/card-myeid.c @@ -816,10 +816,10 @@ myeid_convert_ec_signature(struct sc_context *ctx, size_t s_len, unsigned char * if (*data != 0x30 || *(data + 1) != (datalen - 2) || *(data + 2) != 0x02) return SC_ERROR_INVALID_DATA; - buf = calloc(1, s_len/4); + buf = calloc(1, (s_len + 7)/8*2); if (!buf) LOG_FUNC_RETURN(ctx, SC_ERROR_OUT_OF_MEMORY); - buflen = s_len/4; + buflen = (s_len + 7)/8*2; r = sc_asn1_sig_value_sequence_to_rs(ctx, data, datalen, buf, buflen); LOG_TEST_RET(ctx, r, "Failed to cenvert Sig-Value to the raw RS format"); diff --git a/src/libopensc/pkcs15-sec.c b/src/libopensc/pkcs15-sec.c index 3b8764ff..3b3366b0 100644 --- a/src/libopensc/pkcs15-sec.c +++ b/src/libopensc/pkcs15-sec.c @@ -218,8 +218,8 @@ int sc_pkcs15_derive(struct sc_pkcs15_card *p15card, LOG_FUNC_RETURN(ctx, SC_ERROR_NOT_SUPPORTED); } - if (out == NULL || *poutlen < (prkey->field_length +7) / 8) { - *poutlen = (prkey->field_length +7) / 8; + if (out == NULL || *poutlen < (prkey->field_length + 7) / 8) { + *poutlen = (prkey->field_length + 7) / 8; r = 0; /* say no data to return */ goto out; }