1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-22 14:28:07 +00:00

nem: Prevent underflow in NEM_DECRYPTED_SIZE

This commit is contained in:
Saleem Rashid 2017-12-15 21:35:19 +00:00 committed by Pavol Rusnak
parent 44480ca15d
commit 74e74f5eed

5
nem.h
View File

@ -55,7 +55,10 @@
#define NEM_ENCRYPTED_SIZE(size) (((size) + AES_BLOCK_SIZE) / AES_BLOCK_SIZE * AES_BLOCK_SIZE)
#define NEM_ENCRYPTED_PAYLOAD_SIZE(size) (AES_BLOCK_SIZE + NEM_SALT_SIZE + NEM_ENCRYPTED_SIZE(size))
#define NEM_DECRYPTED_SIZE(buffer, size) ((size) - ((buffer)[(size) - 1]))
#define _NEM_PADDING_SIZE(buffer, size) ((buffer)[(size) - 1])
#define NEM_PADDING_SIZE(buffer, size) (_NEM_PADDING_SIZE(buffer, size) > (size) ? (size) : _NEM_PADDING_SIZE(buffer, size))
#define NEM_DECRYPTED_SIZE(buffer, size) ((size) - NEM_PADDING_SIZE(buffer, size))
typedef struct {
ed25519_public_key public_key;