diff --git a/lib/internal.h b/lib/internal.h index cb1d0c4f..b393a85f 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -281,4 +281,6 @@ static inline bool uint64_mult_overflow(uint64_t *u, uint64_t b, size_t size) #define KEY_EXTERNAL_VERIFICATION -1 #define KEY_VERIFIED 0 +size_t crypt_safe_alloc_size(const void *data); + #endif /* INTERNAL_H */ diff --git a/lib/utils_safe_memory.c b/lib/utils_safe_memory.c index 885a5518..5ee68d2d 100644 --- a/lib/utils_safe_memory.c +++ b/lib/utils_safe_memory.c @@ -107,3 +107,15 @@ void *crypt_safe_realloc(void *data, size_t size) crypt_safe_free(data); return new_data; } + +size_t crypt_safe_alloc_size(const void *data) +{ + const void *p; + + if (!data) + return 0; + + p = (const char *)data - OVERHEAD; + + return ((const struct safe_allocation *)p)->size; +}