Use BE/LE functions for packing uint16.

Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
Pol Henarejos 2024-12-23 21:01:12 +01:00
parent 2a3ac550ec
commit 6d516b1b78
No known key found for this signature in database
GPG key ID: C0095B7870A4CCD3
5 changed files with 16 additions and 17 deletions

@ -1 +1 @@
Subproject commit d530ea69797a3c91063ab0411840c0be384d70d1
Subproject commit d78e97792682d2bfc73fade50fce74683680571e

View file

@ -70,8 +70,8 @@ int cmd_extras() {
gettimeofday(&tv, NULL);
#endif
struct tm *tm = localtime(&tv.tv_sec);
res_APDU[res_APDU_size++] = (tm->tm_year + 1900) >> 8;
res_APDU[res_APDU_size++] = (tm->tm_year + 1900) & 0xff;
put_uint16_t_be(tm->tm_year + 1900, res_APDU);
res_APDU_size += 2;
res_APDU[res_APDU_size++] = tm->tm_mon;
res_APDU[res_APDU_size++] = tm->tm_mday;
res_APDU[res_APDU_size++] = tm->tm_wday;
@ -110,8 +110,8 @@ int cmd_extras() {
}
uint16_t opts = get_device_options();
if (apdu.nc == 0) {
res_APDU[res_APDU_size++] = opts >> 8;
res_APDU[res_APDU_size++] = opts & 0xff;
put_uint16_t_be(opts, res_APDU);
res_APDU_size += 2;
}
else {
uint8_t newopts[] = { apdu.data[0], (opts & 0xff) };

View file

@ -22,12 +22,12 @@ int cmd_list_keys() {
/* First we send DEV private key */
/* Both below conditions should be always TRUE */
if (search_file(EF_PRKD_DEV)) {
res_APDU[res_APDU_size++] = EF_PRKD_DEV >> 8;
res_APDU[res_APDU_size++] = EF_PRKD_DEV & 0xff;
put_uint16_t_be(EF_PRKD_DEV, res_APDU + res_APDU_size);
res_APDU_size += 2;
}
if (search_file(EF_KEY_DEV)) {
res_APDU[res_APDU_size++] = EF_KEY_DEV >> 8;
res_APDU[res_APDU_size++] = EF_KEY_DEV & 0xff;
put_uint16_t_be(EF_KEY_DEV, res_APDU + res_APDU_size);
res_APDU_size += 2;
}
//first CC
for (int i = 0; i < dynamic_files; i++) {

View file

@ -119,8 +119,8 @@ int cmd_select() {
res_APDU[res_APDU_size++] = 0x85;
res_APDU[res_APDU_size++] = 5;
uint16_t opts = get_device_options();
res_APDU[res_APDU_size++] = opts >> 8;
res_APDU[res_APDU_size++] = opts & 0xff;
put_uint16_t_be(opts, res_APDU + res_APDU_size);
res_APDU_size += 2;
res_APDU[res_APDU_size++] = 0xFF;
res_APDU[res_APDU_size++] = HSM_VERSION_MAJOR;
res_APDU[res_APDU_size++] = HSM_VERSION_MINOR;

View file

@ -421,8 +421,7 @@ uint16_t asn1_build_cert_description(const uint8_t *label,
p += format_tlv_len(asn1_len_tag(0x4, sizeof(uint16_t)), p);
*p++ = 0x4;
p += format_tlv_len(sizeof(uint16_t), p);
*p++ = fid >> 8;
*p++ = fid & 0xff;
put_uint16_t_be(fid, p); p += sizeof(uint16_t);
return (uint16_t)(p - buf);
}
@ -498,8 +497,8 @@ uint16_t asn1_build_prkd_generic(const uint8_t *label,
p += format_tlv_len(asn1_len_tag(0x2, 2), p);
*p++ = 0x2;
p += format_tlv_len(2, p);
*p++ = (keysize >> 8) & 0xff;
*p++ = keysize & 0xff;
put_uint16_t_be(keysize, p);
p += 2;
}
//Seq 4
@ -518,8 +517,8 @@ uint16_t asn1_build_prkd_generic(const uint8_t *label,
if (key_type & PICO_KEYS_KEY_EC || key_type & PICO_KEYS_KEY_RSA) {
*p++ = 0x2;
p += format_tlv_len(2, p);
*p++ = (keysize >> 8) & 0xff;
*p++ = keysize & 0xff;
put_uint16_t_be(keysize, p);
p += 2;
}
return (uint16_t)(p - buf);
}