• R/O
  • HTTP
  • SSH
  • HTTPS

mhash384: Commit

MHash-384 development repository


Commit MetaInfo

Revision80bd8fe4135ecb4b4fc32abc17c2f018a16bac87 (tree)
Zeit2020-02-22 06:23:22
AutorLoRd_MuldeR <mulder2@gmx....>
CommiterLoRd_MuldeR

Log Message

Some build fixes for pure C compilers in core library.

Ändern Zusammenfassung

Diff

--- a/frontend/src/self_test.cpp
+++ b/frontend/src/self_test.cpp
@@ -217,8 +217,7 @@ static bool append_string(UnorderedHashSet &hash_set, std::vector<std::array<uin
217217 */
218218 bool self_test(const options_t &options)
219219 {
220- bool success = mhash384_selftest();
221-
220+ bool success = (mhash384_selftest() != 0);
222221 if(success)
223222 {
224223 for(size_t i = 0U; SELFTEST_INPUT[i].count > 0U; ++i)
--- a/libmhash384/include/mhash384.h
+++ b/libmhash384/include/mhash384.h
@@ -62,13 +62,17 @@ mhash384_t;
6262 /*
6363 * MHash-384 public functions
6464 */
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+ */
7074 #ifndef MHASH384_NOSELFTEST
71-MHASH384_API bool mhash384_selftest(void);
75+MHASH384_API int mhash384_selftest(void);
7276 #endif //MHASH384_NOSELFTEST
7377
7478 /*
--- a/libmhash384/src/mhash384.cpp
+++ b/libmhash384/src/mhash384.cpp
@@ -31,12 +31,14 @@
3131 /*
3232 * C/C++ compiler support
3333 */
34-#if defined(__GNUC__) || defined(__clang__)
35-# define ALWAYS_INLINE __attribute__((always_inline)) inline
36-#elif defined(_MSC_VER)
34+#if defined(_MSC_VER)
3735 # define ALWAYS_INLINE __forceinline
38-#else
36+#elif defined(__GNUC__)
37+# define ALWAYS_INLINE __attribute__((always_inline)) inline
38+#elif defined(__cplusplus)
3939 # define ALWAYS_INLINE inline
40+#else
41+# define ALWAYS_INLINE
4042 #endif
4143
4244 /*
@@ -999,12 +1001,13 @@ static ALWAYS_INLINE ui32_t popcnt64(ui64_t u)
9991001 /*
10001002 * Hamming distance of 384-Bit table row
10011003 */
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)
10031005 {
10041006 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)
10061009 {
1007- distance += popcnt64(x[i] ^ y[i]);
1010+ distance += popcnt64(row_x[i] ^ row_y[i]);
10081011 }
10091012 return distance;
10101013 }
@@ -1012,12 +1015,13 @@ static ALWAYS_INLINE ui32_t hamming_distance(const ui64_t *const x, const ui64_t
10121015 /*
10131016 * MHash384 self-test
10141017 */
1015-bool mhash384_selftest(void)
1018+int mhash384_selftest(void)
10161019 {
1017- for(size_t i = 0; i <= 256U; ++i)
1020+ size_t i, j;
1021+ for(i = 0; i <= 256U; ++i)
10181022 {
10191023 ui32_t min_distance = UINT32_MAX;
1020- for(size_t j = 0; j <= 256U; ++j)
1024+ for(j = 0; j <= 256U; ++j)
10211025 {
10221026 if(i != j)
10231027 {
@@ -1028,10 +1032,10 @@ bool mhash384_selftest(void)
10281032 }
10291033 if(min_distance < 182U)
10301034 {
1031- return false; //self-test has failed!
1035+ return 0; //self-test has failed!
10321036 }
10331037 }
1034- return true;
1038+ return 1;
10351039 }
10361040
10371041 #endif //MHASH384_NOSELFTEST
Show on old repository browser