1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-25 04:55:07 -07:00

+crypto_verify64

This commit is contained in:
Frank Denis 2014-04-08 14:11:30 -07:00 committed by evoskuil
parent 0f9aec94b6
commit 80aff278d0
8 changed files with 156 additions and 1 deletions

View File

@ -359,6 +359,7 @@
<ClInclude Include="src\libsodium\include\sodium\crypto_uint8.h" /> <ClInclude Include="src\libsodium\include\sodium\crypto_uint8.h" />
<ClInclude Include="src\libsodium\include\sodium\crypto_verify_16.h" /> <ClInclude Include="src\libsodium\include\sodium\crypto_verify_16.h" />
<ClInclude Include="src\libsodium\include\sodium\crypto_verify_32.h" /> <ClInclude Include="src\libsodium\include\sodium\crypto_verify_32.h" />
<ClInclude Include="src\libsodium\include\sodium\crypto_verify_64.h" />
<ClInclude Include="src\libsodium\include\sodium\export.h" /> <ClInclude Include="src\libsodium\include\sodium\export.h" />
<ClInclude Include="src\libsodium\include\sodium\randombytes.h" /> <ClInclude Include="src\libsodium\include\sodium\randombytes.h" />
<ClInclude Include="src\libsodium\include\sodium\randombytes_salsa20_random.h" /> <ClInclude Include="src\libsodium\include\sodium\randombytes_salsa20_random.h" />
@ -494,6 +495,8 @@
<ClCompile Include="src\libsodium\crypto_verify\16\verify_16_api.c" /> <ClCompile Include="src\libsodium\crypto_verify\16\verify_16_api.c" />
<ClCompile Include="src\libsodium\crypto_verify\32\ref\verify_32.c" /> <ClCompile Include="src\libsodium\crypto_verify\32\ref\verify_32.c" />
<ClCompile Include="src\libsodium\crypto_verify\32\verify_32_api.c" /> <ClCompile Include="src\libsodium\crypto_verify\32\verify_32_api.c" />
<ClCompile Include="src\libsodium\crypto_verify\64\ref\verify_64.c" />
<ClCompile Include="src\libsodium\crypto_verify\64\verify_64_api.c" />
<ClCompile Include="src\libsodium\randombytes\randombytes.c" /> <ClCompile Include="src\libsodium\randombytes\randombytes.c" />
<ClCompile Include="src\libsodium\randombytes\salsa20\randombytes_salsa20_random.c" /> <ClCompile Include="src\libsodium\randombytes\salsa20\randombytes_salsa20_random.c" />
<ClCompile Include="src\libsodium\randombytes\sysrandom\randombytes_sysrandom.c" /> <ClCompile Include="src\libsodium\randombytes\sysrandom\randombytes_sysrandom.c" />

View File

@ -147,6 +147,9 @@
<ClInclude Include="src\libsodium\include\sodium\crypto_verify_32.h"> <ClInclude Include="src\libsodium\include\sodium\crypto_verify_32.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="src\libsodium\include\sodium\crypto_verify_64.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="src\libsodium\include\sodium\export.h"> <ClInclude Include="src\libsodium\include\sodium\export.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
@ -544,6 +547,12 @@
<ClCompile Include="src\libsodium\crypto_verify\32\verify_32_api.c"> <ClCompile Include="src\libsodium\crypto_verify\32\verify_32_api.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="src\libsodium\crypto_verify\64\ref\verify_64.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\libsodium\crypto_verify\64\verify_64_api.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="src\libsodium\sodium\compat.c"> <ClCompile Include="src\libsodium\sodium\compat.c">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>

View File

@ -180,6 +180,9 @@ libsodium_la_SOURCES = \
crypto_verify/32/verify_32_api.c \ crypto_verify/32/verify_32_api.c \
crypto_verify/32/ref/api.h \ crypto_verify/32/ref/api.h \
crypto_verify/32/ref/verify_32.c \ 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/randombytes.c \
randombytes/salsa20/randombytes_salsa20_random.c \ randombytes/salsa20/randombytes_salsa20_random.c \
randombytes/sysrandom/randombytes_sysrandom.c \ randombytes/sysrandom/randombytes_sysrandom.c \

View File

@ -0,0 +1,2 @@
#include "crypto_verify_64.h"

View File

@ -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;
}

View File

@ -0,0 +1,6 @@
#include "crypto_verify_64.h"
size_t
crypto_verify_64_bytes(void) {
return crypto_verify_64_BYTES;
}

View File

@ -46,6 +46,7 @@ SODIUM_EXPORT = \
sodium/crypto_uint8.h \ sodium/crypto_uint8.h \
sodium/crypto_verify_16.h \ sodium/crypto_verify_16.h \
sodium/crypto_verify_32.h \ sodium/crypto_verify_32.h \
sodium/crypto_verify_64.h \
sodium/export.h \ sodium/export.h \
sodium/randombytes.h \ sodium/randombytes.h \
sodium/randombytes_salsa20_random.h \ sodium/randombytes_salsa20_random.h \

View File

@ -0,0 +1,59 @@
#ifndef crypto_verify_64_H
#define crypto_verify_64_H
#include <stddef.h>
#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