diff options
Diffstat (limited to 'src/include/gnunet_common.h')
-rw-r--r-- | src/include/gnunet_common.h | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/include/gnunet_common.h b/src/include/gnunet_common.h index 6d9652a16..76c2b9352 100644 --- a/src/include/gnunet_common.h +++ b/src/include/gnunet_common.h | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet. | 2 | This file is part of GNUnet. |
3 | Copyright (C) 2006-2013 GNUnet e.V. | 3 | Copyright (C) 2006-2020 GNUnet e.V. |
4 | 4 | ||
5 | GNUnet is free software: you can redistribute it and/or modify it | 5 | GNUnet is free software: you can redistribute it and/or modify it |
6 | under the terms of the GNU Affero General Public License as published | 6 | under the terms of the GNU Affero General Public License as published |
@@ -1089,6 +1089,9 @@ GNUNET_ntoh_double (double d); | |||
1089 | /** | 1089 | /** |
1090 | * Compare memory in @a a and @a b, where both must be of | 1090 | * Compare memory in @a a and @a b, where both must be of |
1091 | * the same pointer type. | 1091 | * the same pointer type. |
1092 | * | ||
1093 | * Do NOT use this function on arrays, it would only compare | ||
1094 | * the first element! | ||
1092 | */ | 1095 | */ |
1093 | #define GNUNET_memcmp(a, b) \ | 1096 | #define GNUNET_memcmp(a, b) \ |
1094 | ({ \ | 1097 | ({ \ |
@@ -1099,6 +1102,35 @@ GNUNET_ntoh_double (double d); | |||
1099 | 1102 | ||
1100 | 1103 | ||
1101 | /** | 1104 | /** |
1105 | * Compare memory in @a b1 and @a b2 in constant time, suitable for private | ||
1106 | * data. | ||
1107 | * | ||
1108 | * @param b1 some buffer of size @a len | ||
1109 | * @param b2 another buffer of size @a len | ||
1110 | * @param len number of bytes in @a b1 and @a b2 | ||
1111 | * @return 0 if buffers are equal, | ||
1112 | */ | ||
1113 | int | ||
1114 | GNUNET_memcmp_ct_ (const void *b1, | ||
1115 | const void *b2, | ||
1116 | size_t len); | ||
1117 | |||
1118 | /** | ||
1119 | * Compare memory in @a a and @a b in constant time, suitable for private | ||
1120 | * data. Both @a a and @a b must be of the same pointer type. | ||
1121 | * | ||
1122 | * Do NOT use this function on arrays, it would only compare | ||
1123 | * the first element! | ||
1124 | */ | ||
1125 | #define GNUNET_memcmp_priv(a, b) \ | ||
1126 | ({ \ | ||
1127 | const typeof (*b) * _a = (a); \ | ||
1128 | const typeof (*a) * _b = (b); \ | ||
1129 | GNUNET_memcmp_ct_ (_a, _b, sizeof(*a)); \ | ||
1130 | }) | ||
1131 | |||
1132 | |||
1133 | /** | ||
1102 | * Check that memory in @a a is all zeros. @a a must be a pointer. | 1134 | * Check that memory in @a a is all zeros. @a a must be a pointer. |
1103 | * | 1135 | * |
1104 | * @param a pointer to @a n bytes which should be tested for the | 1136 | * @param a pointer to @a n bytes which should be tested for the |