From 8ba7fbd06214906bc471a4270acab91902eaf363 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Tue, 13 Jan 2015 11:04:39 +0100 Subject: [PATCH] Mention that sodium_alloc() can be used with sodium data structures And explain how to deal with crypto_generichash_state --- src/libsodium/include/sodium/utils.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/libsodium/include/sodium/utils.h b/src/libsodium/include/sodium/utils.h index de7b6362..3b1502a4 100644 --- a/src/libsodium/include/sodium/utils.h +++ b/src/libsodium/include/sodium/utils.h @@ -65,9 +65,16 @@ int sodium_munlock(void * const addr, const size_t len); * - The returned address will not be aligned if the allocation size is not * a multiple of the required alignment. For this reason, these functions * are designed to store data, such as secret keys and messages. - * They should not be used to store pointers mixed with other types - * in portable code unless extreme care is taken to ensure correct - * pointers alignment. + * + * sodium_malloc() can be used to allocate any libsodium data structure, + * with the exception of crypto_generichash_state. + * + * The crypto_generichash_state structure is packed and its length is + * either 357 or 361 bytes. For this reason, when using sodium_malloc() to + * allocate a crypto_generichash_state structure, padding must be added in + * order to ensure proper alignment: + * state = sodium_malloc((sizeof(crypto_generichash_state) + * + (size_t) 63U) & ~(size_t) 63U); */ SODIUM_EXPORT