mirror of
https://github.com/polhenarejos/pico-keys-sdk.git
synced 2026-08-26 14:37:49 +01:00
Bounds-checks each encoded authenticated TLV and ISO padding before appending to the fixed secure-messaging input buffer.
Signed-off-by: Pol Henarejos <pol.henarejos@cttc.es>
This commit is contained in:
@@ -282,6 +282,10 @@ int sm_verify(void) {
|
||||
tlv_ctx_init(apdu.data, (uint16_t)apdu.nc, &ctxi);
|
||||
while (tlv_walk(&ctxi, &p, &tag, &tag_len, &tag_data)) {
|
||||
if (tag & 0x1) {
|
||||
size_t encoded_len = 1 + tlv_format_len(tag_len, NULL) + tag_len;
|
||||
if (encoded_len > sizeof(input) - input_len) {
|
||||
return PICOKEYS_WRONG_LENGTH;
|
||||
}
|
||||
input[input_len++] = (uint8_t)tag;
|
||||
uint8_t tlen = tlv_format_len(tag_len, input + input_len);
|
||||
input_len += tlen;
|
||||
@@ -298,8 +302,12 @@ int sm_verify(void) {
|
||||
return PICOKEYS_WRONG_DATA;
|
||||
}
|
||||
if (some_added) {
|
||||
size_t padding_len = sm_blocksize - (input_len % sm_blocksize);
|
||||
if (padding_len > sizeof(input) - input_len) {
|
||||
return PICOKEYS_WRONG_LENGTH;
|
||||
}
|
||||
input[input_len++] = 0x80;
|
||||
input_len += (sm_blocksize - (input_len % sm_blocksize));
|
||||
input_len += padding_len - 1;
|
||||
}
|
||||
uint8_t signature[16];
|
||||
r = sm_sign(input, input_len, signature);
|
||||
|
||||
Reference in New Issue
Block a user