Have sodium_memcmp(a,b,s) return -1 if a != b, document return value.
This commit is contained in:
parent
d140634ce0
commit
1ca05f6b16
@ -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