diff options
author | Martin Willi <martin@revosec.ch> | 2015-04-14 11:57:17 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2015-04-14 12:02:51 +0200 |
commit | aa9b74931f4639628b369ffb290721f5ec263f69 (patch) | |
tree | b46293e2993cf75e44888b1bd8ef73d0e97e797e /src/libstrongswan/utils/utils.c | |
parent | b17f0beda805a8096de6a381a4845711a64a500e (diff) | |
parent | 161a015782dbd7acf291f621d50cde24a6ed813d (diff) | |
download | strongswan-aa9b74931f4639628b369ffb290721f5ec263f69.tar.bz2 strongswan-aa9b74931f4639628b369ffb290721f5ec263f69.tar.xz |
Merge branch 'const-memeq'
Introduce constant time memory comparing functions for cryptographic purposes,
and a tool to test such functions or crypto transforms relying on them.
Diffstat (limited to 'src/libstrongswan/utils/utils.c')
-rw-r--r-- | src/libstrongswan/utils/utils.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/libstrongswan/utils/utils.c b/src/libstrongswan/utils/utils.c index 02a720945..3d5e3dfc9 100644 --- a/src/libstrongswan/utils/utils.c +++ b/src/libstrongswan/utils/utils.c @@ -112,6 +112,25 @@ void memwipe_noinline(void *ptr, size_t n) /** * Described in header. */ +bool memeq_const(const void *x, const void *y, size_t len) +{ + const u_char *a, *b; + u_int bad = 0; + size_t i; + + a = (const u_char*)x; + b = (const u_char*)y; + + for (i = 0; i < len; i++) + { + bad |= a[i] != b[i]; + } + return !bad; +} + +/** + * Described in header. + */ void *memstr(const void *haystack, const char *needle, size_t n) { const u_char *pos = haystack; |