MHash-384 development repository
Revision | 80bd8fe4135ecb4b4fc32abc17c2f018a16bac87 (tree) |
---|---|
Time | 2020-02-22 06:23:22 |
Author | LoRd_MuldeR <mulder2@gmx....> |
Commiter | LoRd_MuldeR |
Some build fixes for pure C compilers in core library.
@@ -217,8 +217,7 @@ static bool append_string(UnorderedHashSet &hash_set, std::vector<std::array<uin | ||
217 | 217 | */ |
218 | 218 | bool self_test(const options_t &options) |
219 | 219 | { |
220 | - bool success = mhash384_selftest(); | |
221 | - | |
220 | + bool success = (mhash384_selftest() != 0); | |
222 | 221 | if(success) |
223 | 222 | { |
224 | 223 | for(size_t i = 0U; SELFTEST_INPUT[i].count > 0U; ++i) |
@@ -62,13 +62,17 @@ mhash384_t; | ||
62 | 62 | /* |
63 | 63 | * MHash-384 public functions |
64 | 64 | */ |
65 | -MHASH384_API void mhash384_init (mhash384_t *const ctx); | |
66 | -MHASH384_API void mhash384_update (mhash384_t *const ctx, const uint8_t *const data_in, const size_t len); | |
67 | -MHASH384_API void mhash384_final (mhash384_t *const ctx, uint8_t *const digest_out); | |
68 | -MHASH384_API void mhash384_compute (uint8_t *const digest_out, const uint8_t *const data_in, const size_t len); | |
69 | -MHASH384_API void mhash384_version (uint16_t *const major, uint16_t *const minor, uint16_t *const patch); | |
65 | +MHASH384_API void mhash384_init (mhash384_t *const ctx); | |
66 | +MHASH384_API void mhash384_update (mhash384_t *const ctx, const uint8_t *const data_in, const size_t len); | |
67 | +MHASH384_API void mhash384_final (mhash384_t *const ctx, uint8_t *const digest_out); | |
68 | +MHASH384_API void mhash384_compute(uint8_t *const digest_out, const uint8_t *const data_in, const size_t len); | |
69 | +MHASH384_API void mhash384_version(uint16_t *const major, uint16_t *const minor, uint16_t *const patch); | |
70 | + | |
71 | +/* | |
72 | + * MHash-384 self-test function | |
73 | + */ | |
70 | 74 | #ifndef MHASH384_NOSELFTEST |
71 | -MHASH384_API bool mhash384_selftest(void); | |
75 | +MHASH384_API int mhash384_selftest(void); | |
72 | 76 | #endif //MHASH384_NOSELFTEST |
73 | 77 | |
74 | 78 | /* |
@@ -31,12 +31,14 @@ | ||
31 | 31 | /* |
32 | 32 | * C/C++ compiler support |
33 | 33 | */ |
34 | -#if defined(__GNUC__) || defined(__clang__) | |
35 | -# define ALWAYS_INLINE __attribute__((always_inline)) inline | |
36 | -#elif defined(_MSC_VER) | |
34 | +#if defined(_MSC_VER) | |
37 | 35 | # define ALWAYS_INLINE __forceinline |
38 | -#else | |
36 | +#elif defined(__GNUC__) | |
37 | +# define ALWAYS_INLINE __attribute__((always_inline)) inline | |
38 | +#elif defined(__cplusplus) | |
39 | 39 | # define ALWAYS_INLINE inline |
40 | +#else | |
41 | +# define ALWAYS_INLINE | |
40 | 42 | #endif |
41 | 43 | |
42 | 44 | /* |
@@ -999,12 +1001,13 @@ static ALWAYS_INLINE ui32_t popcnt64(ui64_t u) | ||
999 | 1001 | /* |
1000 | 1002 | * Hamming distance of 384-Bit table row |
1001 | 1003 | */ |
1002 | -static ALWAYS_INLINE ui32_t hamming_distance(const ui64_t *const x, const ui64_t *const y) | |
1004 | +static ALWAYS_INLINE ui32_t hamming_distance(const ui64_t *const row_x, const ui64_t *const row_y) | |
1003 | 1005 | { |
1004 | 1006 | ui32_t distance = 0U; |
1005 | - for(size_t i = 0; i < MHASH384_WORDS; ++i) | |
1007 | + size_t i; | |
1008 | + for(i = 0; i < MHASH384_WORDS; ++i) | |
1006 | 1009 | { |
1007 | - distance += popcnt64(x[i] ^ y[i]); | |
1010 | + distance += popcnt64(row_x[i] ^ row_y[i]); | |
1008 | 1011 | } |
1009 | 1012 | return distance; |
1010 | 1013 | } |
@@ -1012,12 +1015,13 @@ static ALWAYS_INLINE ui32_t hamming_distance(const ui64_t *const x, const ui64_t | ||
1012 | 1015 | /* |
1013 | 1016 | * MHash384 self-test |
1014 | 1017 | */ |
1015 | -bool mhash384_selftest(void) | |
1018 | +int mhash384_selftest(void) | |
1016 | 1019 | { |
1017 | - for(size_t i = 0; i <= 256U; ++i) | |
1020 | + size_t i, j; | |
1021 | + for(i = 0; i <= 256U; ++i) | |
1018 | 1022 | { |
1019 | 1023 | ui32_t min_distance = UINT32_MAX; |
1020 | - for(size_t j = 0; j <= 256U; ++j) | |
1024 | + for(j = 0; j <= 256U; ++j) | |
1021 | 1025 | { |
1022 | 1026 | if(i != j) |
1023 | 1027 | { |
@@ -1028,10 +1032,10 @@ bool mhash384_selftest(void) | ||
1028 | 1032 | } |
1029 | 1033 | if(min_distance < 182U) |
1030 | 1034 | { |
1031 | - return false; //self-test has failed! | |
1035 | + return 0; //self-test has failed! | |
1032 | 1036 | } |
1033 | 1037 | } |
1034 | - return true; | |
1038 | + return 1; | |
1035 | 1039 | } |
1036 | 1040 | |
1037 | 1041 | #endif //MHASH384_NOSELFTEST |