From a2169368bbd92b77636e39b5cfe864a1236b083b Mon Sep 17 00:00:00 2001 From: Christian Grothoff Date: Thu, 28 Jan 2021 22:28:01 +0100 Subject: implement #6716 --- src/include/gnunet_common.h | 7 ++++++- src/include/gnunet_crypto_lib.h | 16 ++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'src/include') diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 707108289..4dab71f7f 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h @@ -256,7 +256,12 @@ struct GNUNET_ShortHashCode /** - * A UUID, a 128 bit random value. + * A UUID, a 128 bit "random" value. We OFTEN use + * timeflakes (see: https://github.com/anthonynsimon/timeflake), + * where only 80 bits are random and the rest encodes + * a timestamp to improve database access. + * + * See #GNUNET_CRYPTO_random_timeflake(). */ struct GNUNET_Uuid { diff --git a/src/include/gnunet_crypto_lib.h b/src/include/gnunet_crypto_lib.h index 5521dad3c..d01457b4a 100644 --- a/src/include/gnunet_crypto_lib.h +++ b/src/include/gnunet_crypto_lib.h @@ -475,6 +475,22 @@ GNUNET_CRYPTO_random_block (enum GNUNET_CRYPTO_Quality mode, void *buffer, size_t length); + +/** + * @ingroup crypto + * Fill UUID with a timeflake pseudo-random value. Note that + * timeflakes use only 80 bits of randomness and 48 bits + * to encode a timestamp in milliseconds. So what we return + * here is not a completely random number. + * + * @param mode desired quality of the random number + * @param uuid the value to fill + */ +void +GNUNET_CRYPTO_random_timeflake (enum GNUNET_CRYPTO_Quality mode, + struct GNUNET_Uuid *uuid); + + /** * @ingroup crypto * Produce a random value. -- cgit v1.2.3