diff --git a/libsodium.vcxproj b/libsodium.vcxproj index 520e6dec..2e5ce2e3 100644 --- a/libsodium.vcxproj +++ b/libsodium.vcxproj @@ -359,6 +359,7 @@ + @@ -494,6 +495,8 @@ + + diff --git a/libsodium.vcxproj.filters b/libsodium.vcxproj.filters index dd597287..df34098d 100644 --- a/libsodium.vcxproj.filters +++ b/libsodium.vcxproj.filters @@ -147,6 +147,9 @@ Header Files + + Header Files + Header Files @@ -544,6 +547,12 @@ Source Files + + Source Files + + + Source Files + Source Files @@ -566,4 +575,4 @@ Source Files - \ No newline at end of file + diff --git a/src/libsodium/Makefile.am b/src/libsodium/Makefile.am index a0ec32a1..04c4040c 100644 --- a/src/libsodium/Makefile.am +++ b/src/libsodium/Makefile.am @@ -180,6 +180,9 @@ libsodium_la_SOURCES = \ crypto_verify/32/verify_32_api.c \ crypto_verify/32/ref/api.h \ crypto_verify/32/ref/verify_32.c \ + crypto_verify/64/verify_64_api.c \ + crypto_verify/64/ref/api.h \ + crypto_verify/64/ref/verify_64.c \ randombytes/randombytes.c \ randombytes/salsa20/randombytes_salsa20_random.c \ randombytes/sysrandom/randombytes_sysrandom.c \ diff --git a/src/libsodium/crypto_verify/64/ref/api.h b/src/libsodium/crypto_verify/64/ref/api.h new file mode 100644 index 00000000..1ffd2f82 --- /dev/null +++ b/src/libsodium/crypto_verify/64/ref/api.h @@ -0,0 +1,2 @@ + +#include "crypto_verify_64.h" diff --git a/src/libsodium/crypto_verify/64/ref/verify_64.c b/src/libsodium/crypto_verify/64/ref/verify_64.c new file mode 100644 index 00000000..730f598b --- /dev/null +++ b/src/libsodium/crypto_verify/64/ref/verify_64.c @@ -0,0 +1,72 @@ +#include "api.h" + +int crypto_verify_64(const unsigned char *x,const unsigned char *y) +{ + unsigned int differentbits = 0; +#define F(i) differentbits |= x[i] ^ y[i]; + F(0) + F(1) + F(2) + F(3) + F(4) + F(5) + F(6) + F(7) + F(8) + F(9) + F(10) + F(11) + F(12) + F(13) + F(14) + F(15) + F(16) + F(17) + F(18) + F(19) + F(20) + F(21) + F(22) + F(23) + F(24) + F(25) + F(26) + F(27) + F(28) + F(29) + F(30) + F(31) + F(32) + F(33) + F(34) + F(35) + F(36) + F(37) + F(38) + F(39) + F(40) + F(41) + F(42) + F(43) + F(44) + F(45) + F(46) + F(47) + F(48) + F(49) + F(50) + F(51) + F(52) + F(53) + F(54) + F(55) + F(56) + F(57) + F(58) + F(59) + F(60) + F(61) + F(62) + F(63) + return (1 & ((differentbits - 1) >> 8)) - 1; +} diff --git a/src/libsodium/crypto_verify/64/verify_64_api.c b/src/libsodium/crypto_verify/64/verify_64_api.c new file mode 100644 index 00000000..ec3e4d49 --- /dev/null +++ b/src/libsodium/crypto_verify/64/verify_64_api.c @@ -0,0 +1,6 @@ +#include "crypto_verify_64.h" + +size_t +crypto_verify_64_bytes(void) { + return crypto_verify_64_BYTES; +} diff --git a/src/libsodium/include/Makefile.am b/src/libsodium/include/Makefile.am index c014141c..23fbe4d9 100644 --- a/src/libsodium/include/Makefile.am +++ b/src/libsodium/include/Makefile.am @@ -46,6 +46,7 @@ SODIUM_EXPORT = \ sodium/crypto_uint8.h \ sodium/crypto_verify_16.h \ sodium/crypto_verify_32.h \ + sodium/crypto_verify_64.h \ sodium/export.h \ sodium/randombytes.h \ sodium/randombytes_salsa20_random.h \ diff --git a/src/libsodium/include/sodium/crypto_verify_64.h b/src/libsodium/include/sodium/crypto_verify_64.h new file mode 100644 index 00000000..fcb44e68 --- /dev/null +++ b/src/libsodium/include/sodium/crypto_verify_64.h @@ -0,0 +1,59 @@ +#ifndef crypto_verify_64_H +#define crypto_verify_64_H + +#include +#include "export.h" + +/** \addtogroup strcmp + * + * @{ + */ + +#define crypto_verify_64_BYTES 64U + +#ifdef __cplusplus +extern "C" { +#endif + + /// @TODO +SODIUM_EXPORT +size_t crypto_verify_64_bytes(void); + +/** + * Compares the first crypto_verify_64_BYTES of the given strings. + * + * @param[in] string1 a string + * @param[in] string2 another string + * + * @return 0 if string1 and string2 are equal, otherwise -1. + * + * @pre string1 must be minimum of crypto_verify_64_BYTES long. + * @pre string2 must be minimum of crypto_verify_64_BYTES long. + * + * @note The time taken by the function is independent of the contents + * of string1 and string2. In contrast, the standard C comparison + * function memcmp(string1,string2,64) takes time that is dependent on + * the longest matching prefix of string1 and string2. This often + * allows for easy timing attacks. + * + * Example invocation: + * + *~~~~~{.c} + * const unsigned char x[64]; + * const unsigned char y[64]; + * + * crypto_verify_64(x,y); + *~~~~~ + */ +SODIUM_EXPORT +int crypto_verify_64(const unsigned char *x, const unsigned char *y); + +#define crypto_verify_64_ref crypto_verify_64 ///< @TODO + + + /// @} +#ifdef __cplusplus +} +#endif + +#endif