Skip to content

Commit ae69892

Browse files
committed
improve mem_neq() documentation
1 parent 1655e63 commit ae69892

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

src/headers/tomcrypt_custom.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
#ifndef XMEMCMP
3434
#define XMEMCMP memcmp
3535
#endif
36+
/* A memory compare function that has to run in constant time,
37+
* c.f. mem_neq() API summary.
38+
*/
3639
#ifndef XMEM_NEQ
3740
#define XMEM_NEQ mem_neq
3841
#endif

src/misc/mem_neq.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,27 @@
1010

1111
/**
1212
@file mem_neq.c
13-
Compare two blocks of memory for inequality.
13+
Compare two blocks of memory for inequality in constant time.
1414
Steffen Jaeckel
1515
*/
1616

1717
/**
18-
Compare two blocks of memory for inequality.
18+
Compare two blocks of memory for inequality in constant time.
1919
2020
The usage is similar to that of standard memcmp, but you can only test
2121
if the memory is equal or not - you can not determine by how much the
2222
first different byte differs.
2323
24+
This function shall be used to compare results of cryptographic
25+
operations where inequality means most likely usage of a wrong key.
26+
The execution time has therefore to be constant as otherwise
27+
timing attacks could be possible.
28+
2429
@param a The first memory region
2530
@param b The second memory region
2631
@param len The length of the area to compare (octets)
2732
28-
@return 0 when a and b are equal for len bytes, else they are not equal.
33+
@return 0 when a and b are equal for len bytes, 1 they are not equal.
2934
*/
3035
int mem_neq(const void *a, const void *b, size_t len)
3136
{

0 commit comments

Comments
 (0)