diff --git a/pico-keys-sdk b/pico-keys-sdk index d530ea6..d78e977 160000 --- a/pico-keys-sdk +++ b/pico-keys-sdk @@ -1 +1 @@ -Subproject commit d530ea69797a3c91063ab0411840c0be384d70d1 +Subproject commit d78e97792682d2bfc73fade50fce74683680571e diff --git a/src/hsm/cmd_extras.c b/src/hsm/cmd_extras.c index bacebce..84623cd 100644 --- a/src/hsm/cmd_extras.c +++ b/src/hsm/cmd_extras.c @@ -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) }; diff --git a/src/hsm/cmd_list_keys.c b/src/hsm/cmd_list_keys.c index 2dcca8a..6ceda5b 100644 --- a/src/hsm/cmd_list_keys.c +++ b/src/hsm/cmd_list_keys.c @@ -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++) { diff --git a/src/hsm/cmd_select.c b/src/hsm/cmd_select.c index 555f7b5..46c9fb3 100644 --- a/src/hsm/cmd_select.c +++ b/src/hsm/cmd_select.c @@ -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; diff --git a/src/hsm/cvc.c b/src/hsm/cvc.c index f91a043..448f5ed 100644 --- a/src/hsm/cvc.c +++ b/src/hsm/cvc.c @@ -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); }