iasecc: when signing short data sequence with PSO_DST ...
... 'last-hash-step' APDU do not includes the 'pre-hash' and 'counter' data -- only the 'last-data-block'. git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@5401 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
parent
06347f3a44
commit
6c3b43f636
|
@ -2741,12 +2741,16 @@ iasecc_get_qsign_data (struct sc_context *ctx, const unsigned char *in, size_t i
|
||||||
out->counter[hh_size+ii] = (sha.Nl >> 8*(hh_size-1-ii)) &0xFF;
|
out->counter[hh_size+ii] = (sha.Nl >> 8*(hh_size-1-ii)) &0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (ii=0, out->counter_long=0; ii<sizeof(out->counter); ii++)
|
||||||
|
out->counter_long = out->counter_long*0x100 + out->counter[ii];
|
||||||
|
|
||||||
sc_log(ctx, "Pre SHA1:%s", sc_dump_hex(out->pre_hash, out->pre_hash_size));
|
sc_log(ctx, "Pre SHA1:%s", sc_dump_hex(out->pre_hash, out->pre_hash_size));
|
||||||
sc_log(ctx, "Pre counter:%s", sc_dump_hex(out->counter, sizeof(out->counter)));
|
sc_log(ctx, "Pre counter(%li):%s", out->counter_long, sc_dump_hex(out->counter, sizeof(out->counter)));
|
||||||
|
|
||||||
for (ii=0;ii<sha.num; ii++)
|
for (ii=0;ii<sha.num; ii++)
|
||||||
out->last_block[ii] = (sha.data[ii/hh_size] >> 8*(hh_size-1-(ii%hh_size))) &0xFF;
|
out->last_block[ii] = (sha.data[ii/hh_size] >> 8*(hh_size-1-(ii%hh_size))) &0xFF;
|
||||||
out->last_block_size = sha.num;
|
out->last_block_size = sha.num;
|
||||||
|
sc_log(ctx, "Last block(%i):%s", out->last_block_size, sc_dump_hex(out->last_block, out->last_block_size));
|
||||||
|
|
||||||
SHA1_Final(out->hash, &sha);
|
SHA1_Final(out->hash, &sha);
|
||||||
out->hash_size = SHA_DIGEST_LENGTH;
|
out->hash_size = SHA_DIGEST_LENGTH;
|
||||||
|
@ -2792,11 +2796,16 @@ iasecc_compute_signature_dst(struct sc_card *card,
|
||||||
|
|
||||||
memset(sbuf, 0, sizeof(sbuf));
|
memset(sbuf, 0, sizeof(sbuf));
|
||||||
sbuf[offs++] = 0x90;
|
sbuf[offs++] = 0x90;
|
||||||
sbuf[offs++] = qsign_data.hash_size + 8;
|
if (qsign_data.counter_long) {
|
||||||
memcpy(sbuf + offs, qsign_data.pre_hash, qsign_data.pre_hash_size);
|
sbuf[offs++] = qsign_data.hash_size + 8;
|
||||||
offs += qsign_data.pre_hash_size;
|
memcpy(sbuf + offs, qsign_data.pre_hash, qsign_data.pre_hash_size);
|
||||||
memcpy(sbuf + offs, qsign_data.counter, sizeof(qsign_data.counter));
|
offs += qsign_data.pre_hash_size;
|
||||||
offs += sizeof(qsign_data.counter);
|
memcpy(sbuf + offs, qsign_data.counter, sizeof(qsign_data.counter));
|
||||||
|
offs += sizeof(qsign_data.counter);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
sbuf[offs++] = 0;
|
||||||
|
}
|
||||||
|
|
||||||
sbuf[offs++] = 0x80;
|
sbuf[offs++] = 0x80;
|
||||||
sbuf[offs++] = qsign_data.last_block_size;
|
sbuf[offs++] = qsign_data.last_block_size;
|
||||||
|
|
|
@ -102,6 +102,7 @@ typedef struct iasecc_qsign_data {
|
||||||
size_t pre_hash_size;
|
size_t pre_hash_size;
|
||||||
|
|
||||||
unsigned char counter[8];
|
unsigned char counter[8];
|
||||||
|
unsigned long counter_long;
|
||||||
|
|
||||||
unsigned char last_block[64];
|
unsigned char last_block[64];
|
||||||
size_t last_block_size;
|
size_t last_block_size;
|
||||||
|
|
Loading…
Reference in New Issue