From c5a9d46386f917aa0ff1bfb711450f9af1d79a17 Mon Sep 17 00:00:00 2001 From: Frank Denis Date: Sun, 3 Aug 2014 21:15:04 -0700 Subject: [PATCH] Double check for crypto_auth_verify() --- src/libsodium/crypto_auth/hmacsha256/cp/verify_hmacsha256.c | 4 +++- src/libsodium/crypto_auth/hmacsha512/cp/verify_hmacsha512.c | 4 +++- .../crypto_auth/hmacsha512256/cp/verify_hmacsha512256.c | 4 +++- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/libsodium/crypto_auth/hmacsha256/cp/verify_hmacsha256.c b/src/libsodium/crypto_auth/hmacsha256/cp/verify_hmacsha256.c index b6cf4893..be9d34fd 100644 --- a/src/libsodium/crypto_auth/hmacsha256/cp/verify_hmacsha256.c +++ b/src/libsodium/crypto_auth/hmacsha256/cp/verify_hmacsha256.c @@ -1,9 +1,11 @@ #include "api.h" #include "crypto_verify_32.h" +#include "utils.h" int crypto_auth_verify(const unsigned char *h,const unsigned char *in,unsigned long long inlen,const unsigned char *k) { unsigned char correct[32]; crypto_auth(correct,in,inlen,k); - return crypto_verify_32(h,correct); + return crypto_verify_32(h,correct) | (-(h - correct == 0)) | + sodium_memcmp(correct,h,32); } diff --git a/src/libsodium/crypto_auth/hmacsha512/cp/verify_hmacsha512.c b/src/libsodium/crypto_auth/hmacsha512/cp/verify_hmacsha512.c index fccdc1a4..28e0dfbe 100644 --- a/src/libsodium/crypto_auth/hmacsha512/cp/verify_hmacsha512.c +++ b/src/libsodium/crypto_auth/hmacsha512/cp/verify_hmacsha512.c @@ -1,10 +1,12 @@ #include "api.h" #include "crypto_verify_64.h" +#include "utils.h" int crypto_auth_verify(const unsigned char *h, const unsigned char *in, unsigned long long inlen, const unsigned char *k) { unsigned char correct[64]; crypto_auth(correct,in,inlen,k); - return crypto_verify_64(h,correct); + return crypto_verify_64(h,correct) | (-(h - correct == 0)) | + sodium_memcmp(correct,h,64); } diff --git a/src/libsodium/crypto_auth/hmacsha512256/cp/verify_hmacsha512256.c b/src/libsodium/crypto_auth/hmacsha512256/cp/verify_hmacsha512256.c index 1e6e18db..6c263f34 100644 --- a/src/libsodium/crypto_auth/hmacsha512256/cp/verify_hmacsha512256.c +++ b/src/libsodium/crypto_auth/hmacsha512256/cp/verify_hmacsha512256.c @@ -1,10 +1,12 @@ #include "api.h" #include "crypto_verify_32.h" +#include "utils.h" int crypto_auth_verify(const unsigned char *h, const unsigned char *in, unsigned long long inlen, const unsigned char *k) { unsigned char correct[32]; crypto_auth(correct,in,inlen,k); - return crypto_verify_32(h,correct); + return crypto_verify_32(h,correct) | (-(h - correct == 0)) | + sodium_memcmp(correct,h,32); }