Index: cackey.c ================================================================== --- cackey.c +++ cackey.c @@ -2752,11 +2752,11 @@ * ... * */ static ssize_t cackey_signdecrypt(struct cackey_slot *slot, struct cackey_identity *identity, unsigned char *buf, size_t buflen, unsigned char *outbuf, size_t outbuflen, int padInput, int unpadOutput) { cackey_pcsc_id_type id_type; - unsigned char dyn_auth_template[10]; + unsigned char dyn_auth_template[10], *dyn_auth_tmpbuf; unsigned char *tmpbuf, *tmpbuf_s, *outbuf_s, *outbuf_p; unsigned char bytes_to_send, p1, class; unsigned char blocktype; cackey_ret send_ret; uint16_t respcode; @@ -2887,11 +2887,22 @@ dyn_auth_template[6] = 0x81; dyn_auth_template[7] = 0x82; dyn_auth_template[8] = (tmpbuflen & 0xff00) >> 8; dyn_auth_template[9] = tmpbuflen & 0x00ff; - send_ret = cackey_send_apdu(slot, 0x10, NISTSP800_73_3_INSTR_GENAUTH, NISTSP800_78_3_ALGO_RSA2048, identity->pcsc_identity->card.piv.key_id, sizeof(dyn_auth_template), dyn_auth_template, 0x00, NULL, NULL, NULL); + dyn_auth_tmpbuf = malloc(tmpbuflen + sizeof(dyn_auth_template)); + memcpy(dyn_auth_tmpbuf, dyn_auth_template, sizeof(dyn_auth_template)); + memcpy(dyn_auth_tmpbuf + sizeof(dyn_auth_template), tmpbuf, tmpbuflen); + + if (free_tmpbuf) { + free(tmpbuf); + } + + tmpbuflen += sizeof(dyn_auth_template); + tmpbuf = dyn_auth_tmpbuf; + free_tmpbuf = 1; + break; case CACKEY_ID_TYPE_CERT_ONLY: break; }