Use BE/LE functions for packing uint16.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
parent
d530ea6979
commit
8e68e6cae9
5 changed files with 15 additions and 18 deletions
|
|
@ -73,8 +73,7 @@ uint8_t format_tlv_len(uint16_t len, uint8_t *out) {
|
|||
}
|
||||
if (out) {
|
||||
*out++ = 0x82;
|
||||
*out++ = (len >> 8) & 0xff;
|
||||
*out++ = len & 0xff;
|
||||
put_uint16_t_be(len, out);
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -181,16 +181,15 @@ int sm_wrap() {
|
|||
else {
|
||||
memmove(res_APDU + 4, res_APDU, res_APDU_size);
|
||||
res_APDU[1] = 0x82;
|
||||
res_APDU[2] = (uint8_t)(res_APDU_size >> 8);
|
||||
res_APDU[3] = (uint8_t)(res_APDU_size & 0xff);
|
||||
put_uint16_t_be(res_APDU_size, res_APDU + 2);
|
||||
res_APDU_size += 4;
|
||||
}
|
||||
res_APDU[0] = 0x87;
|
||||
}
|
||||
res_APDU[res_APDU_size++] = 0x99;
|
||||
res_APDU[res_APDU_size++] = 2;
|
||||
res_APDU[res_APDU_size++] = apdu.sw >> 8;
|
||||
res_APDU[res_APDU_size++] = apdu.sw & 0xff;
|
||||
put_uint16_t_be(apdu.sw, res_APDU + res_APDU_size);
|
||||
res_APDU_size += 2;
|
||||
memcpy(input + input_len, res_APDU, res_APDU_size);
|
||||
input_len += res_APDU_size;
|
||||
input[input_len++] = 0x80;
|
||||
|
|
|
|||
|
|
@ -56,13 +56,13 @@ void process_fci(const file_t *pe, int fmd) {
|
|||
if (pe->data) {
|
||||
if ((pe->type & FILE_DATA_FUNC) == FILE_DATA_FUNC) {
|
||||
uint16_t len = (uint16_t)((int (*)(const file_t *, int))(pe->data))(pe, 0);
|
||||
res_APDU[res_APDU_size++] = (len >> 8) & 0xff;
|
||||
res_APDU[res_APDU_size++] = len & 0xff;
|
||||
put_uint16_t_be(len, res_APDU + res_APDU_size);
|
||||
res_APDU_size += 2;
|
||||
}
|
||||
else {
|
||||
uint16_t v = file_get_size(pe);
|
||||
res_APDU[res_APDU_size++] = v >> 8;
|
||||
res_APDU[res_APDU_size++] = v & 0xff;
|
||||
put_uint16_t_be(v, res_APDU + res_APDU_size);
|
||||
res_APDU_size += 2;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
|
@ -493,8 +493,8 @@ int meta_add(uint16_t fid, const uint8_t *data, uint16_t len) {
|
|||
uint8_t *f = fdata + meta_offset;
|
||||
*f++ = fid & 0xff;
|
||||
f += format_tlv_len(len + 2, f);
|
||||
*f++ = fid >> 8;
|
||||
*f++ = fid & 0xff;
|
||||
put_uint16_t_be(fid, f);
|
||||
f += 2;
|
||||
memcpy(f, data, len);
|
||||
r = file_put_data(ef, fdata, ef_size);
|
||||
free(fdata);
|
||||
|
|
@ -509,8 +509,8 @@ int meta_add(uint16_t fid, const uint8_t *data, uint16_t len) {
|
|||
uint8_t *f = fdata + ef_size;
|
||||
*f++ = fid & 0x1f;
|
||||
f += format_tlv_len(len + 2, f);
|
||||
*f++ = fid >> 8;
|
||||
*f++ = fid & 0xff;
|
||||
put_uint16_t_be(fid, f);
|
||||
f += 2;
|
||||
memcpy(f, data, len);
|
||||
r = file_put_data(ef, fdata, ef_size + (uint16_t)asn1_len_tag(fid & 0x1f, len + 2));
|
||||
free(fdata);
|
||||
|
|
|
|||
|
|
@ -43,8 +43,8 @@ int phy_serialize_data(const phy_data_t *phy, uint8_t *data, uint16_t *len) {
|
|||
*p++ = phy->led_brightness;
|
||||
}
|
||||
*p++ = PHY_OPTS;
|
||||
*p++ = phy->opts >> 8;
|
||||
*p++ = phy->opts & 0xff;
|
||||
put_uint16_t_be(phy->opts, p);
|
||||
p += 2;
|
||||
if (phy->up_btn_present) {
|
||||
*p++ = PHY_UP_BTN;
|
||||
*p++ = phy->up_btn;
|
||||
|
|
|
|||
|
|
@ -558,8 +558,7 @@ void driver_exec_finished_hid(uint16_t size_next) {
|
|||
else {
|
||||
if (is_nitrokey) {
|
||||
memmove(apdu.rdata + 2, apdu.rdata, size_next - 2);
|
||||
apdu.rdata[0] = apdu.sw >> 8;
|
||||
apdu.rdata[1] = apdu.sw & 0xff;
|
||||
put_uint16_t_be(apdu.sw, apdu.rdata);
|
||||
}
|
||||
driver_exec_finished_cont_hid(ITF_HID_CTAP, size_next, 7);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue