Add sodium_memcmp()

This commit is contained in:
Frank Denis 2013-04-23 11:56:10 -07:00
parent 313e440209
commit 51fb0f4c64
2 changed files with 17 additions and 0 deletions

View File

@ -16,6 +16,9 @@ unsigned char *_sodium_alignedcalloc(unsigned char ** const unaligned_p,
SODIUM_EXPORT SODIUM_EXPORT
void sodium_memzero(void * const pnt, const size_t len); 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -27,6 +27,20 @@ sodium_memzero(void * const pnt, const size_t len)
#endif #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 * unsigned char *
_sodium_alignedcalloc(unsigned char ** const unaligned_p, const size_t len) _sodium_alignedcalloc(unsigned char ** const unaligned_p, const size_t len)
{ {