mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-19 18:15:18 -07:00
Merge branch 'master' of github.com:jedisct1/libsodium
* 'master' of github.com:jedisct1/libsodium: Have sodium_memcmp(a,b,s) return -1 if a != b, document return value.
This commit is contained in:
commit
4943275819
@ -173,6 +173,11 @@ In order to compare memory zones in constant time, Sodium provides:
|
||||
int sodium_memcmp(const void * const b1_, const void * const b2_,
|
||||
size_t size);
|
||||
|
||||
`sodium_memcmp()` returns `0` if `size` bytes at `b1_` and `b2_` are
|
||||
equal, another value if they are not. Unlike `memcmp()`,
|
||||
`sodium_memcmp()` cannot be used to put `b1_` and `b2_` into a defined
|
||||
order.
|
||||
|
||||
And a convenience function for converting a binary buffer to a
|
||||
hexadecimal string:
|
||||
|
||||
|
@ -38,7 +38,7 @@ sodium_memcmp(const void * const b1_, const void * const b2_, size_t size)
|
||||
for (i = 0U; i < size; i++) {
|
||||
d |= b1[i] ^ b2[i];
|
||||
}
|
||||
return (int) d;
|
||||
return (int) ((1 & ((d - 1) >> 8)) - 1);
|
||||
}
|
||||
|
||||
unsigned char *
|
||||
|
@ -1,6 +1,6 @@
|
||||
0
|
||||
0
|
||||
255
|
||||
-1
|
||||
0
|
||||
0
|
||||
30313233343536373839414243444546
|
||||
|
Loading…
Reference in New Issue
Block a user