mirror of
https://github.com/jedisct1/libsodium.git
synced 2024-12-24 12:36:01 -07:00
Add sodium_memcmp()
This commit is contained in:
parent
313e440209
commit
51fb0f4c64
@ -16,6 +16,9 @@ unsigned char *_sodium_alignedcalloc(unsigned char ** const unaligned_p,
|
||||
SODIUM_EXPORT
|
||||
void sodium_memzero(void * const pnt, const size_t len);
|
||||
|
||||
SODIUM_EXPORT
|
||||
int sodium_memcmp(const void * const b1_, const void * const b2_, size_t size);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -27,6 +27,20 @@ sodium_memzero(void * const pnt, const size_t len)
|
||||
#endif
|
||||
}
|
||||
|
||||
int
|
||||
sodium_memcmp(const void * const b1_, const void * const b2_, size_t size)
|
||||
{
|
||||
const unsigned char *b1 = b1_;
|
||||
const unsigned char *b2 = b2_;
|
||||
size_t i;
|
||||
unsigned char d = (unsigned char) 0U;
|
||||
|
||||
for (i = 0U; i < size; i++) {
|
||||
d |= b1[i] ^ b2[i];
|
||||
}
|
||||
return (int) d;
|
||||
}
|
||||
|
||||
unsigned char *
|
||||
_sodium_alignedcalloc(unsigned char ** const unaligned_p, const size_t len)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user