diff options
author | lloyd <[email protected]> | 2009-06-22 19:23:32 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2009-06-22 19:23:32 +0000 |
commit | c843de07db11df1087a9e711fe44b111fdcf95fa (patch) | |
tree | c274f99eeaa5a602172a4ff728b16ab7081d29c7 /src | |
parent | 41f381d1873bc343bf472e97f5bae718471365c9 (diff) |
Use an input insensitive implementation of same_mem instead of memcmp.
I don't know that having same_mem be sensitive to input would actually
allow any form of timing attack in the current codebase, but it seemed
like a prudent thing to do in any case.
Diffstat (limited to 'src')
-rw-r--r-- | src/utils/mem_ops.h | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/utils/mem_ops.h b/src/utils/mem_ops.h index f6557c744..0fcf34ba8 100644 --- a/src/utils/mem_ops.h +++ b/src/utils/mem_ops.h @@ -26,7 +26,14 @@ template<typename T> inline void set_mem(T* ptr, u32bit n, byte val) { std::memset(ptr, val, sizeof(T)*n); } template<typename T> inline bool same_mem(const T* p1, const T* p2, u32bit n) - { return (std::memcmp(p1, p2, sizeof(T)*n) == 0); } + { + bool is_same = true; + + for(u32bit i = 0; i != n; ++i) + is_same &= (p1[i] == p2[i]); + + return is_same; + } } |