OSDN Git Service

Use "fast" stdint types, where appropriate.
authorLoRd_MuldeR <mulder2@gmx.de>
Sat, 12 Aug 2017 14:51:43 +0000 (16:51 +0200)
committerLoRd_MuldeR <mulder2@gmx.de>
Sat, 12 Aug 2017 14:51:43 +0000 (16:51 +0200)
include/mhash_384.h
src/main.c
src/self_test.h
src/utilities.h

index 5a9accc..d0fb78b 100644 (file)
@@ -63,13 +63,13 @@ namespace internals {
 /* ======================================================================== */
 
 /*Version*/
-static const uint16_t MHASH_384_VERSION_MAJOR = UINT32_C(1);
-static const uint16_t MHASH_384_VERSION_MINOR = UINT32_C(1);
-static const uint16_t MHASH_384_VERSION_PATCH = UINT32_C(0);
+static const uint_fast16_t MHASH_384_VERSION_MAJOR = UINT32_C(1);
+static const uint_fast16_t MHASH_384_VERSION_MINOR = UINT32_C(1);
+static const uint_fast16_t MHASH_384_VERSION_PATCH = UINT32_C(0);
 
 /*Hash length definition*/
 #ifdef __cplusplus
-static const uint16_t MHASH_384_LEN = UINT16_C(48);
+static const uint_fast16_t MHASH_384_LEN = UINT16_C(48);
 #else
 #define MHASH_384_LEN UINT16_C(48)
 #endif
@@ -1365,9 +1365,9 @@ static MHASH_384_INLINE void mhash_384_initialize(mhash_384_t *const ctx)
 }
 
 /*Update Function*/
-static MHASH_384_INLINE void mhash_384_update(mhash_384_t *const ctx, const uint8_t *const input, const size_t len)
+static MHASH_384_INLINE void mhash_384_update(mhash_384_t *const ctx, const uint8_t *const input, const uint_fast32_t len)
 {
-       size_t k, i;
+       uint_fast32_t k, i;
        for (k = 0U; k < len; ++k)
        {
                uint8_t *const ptr_src = ctx->digest[ctx->idx ? 1U : 0U];
@@ -1388,7 +1388,7 @@ static MHASH_384_INLINE void mhash_384_finalize(const mhash_384_t *const ctx, ui
 {
        const uint8_t *const ptr_src = ctx->digest[ctx->idx];
        const uint8_t *const ptr_xor = MHASH_384_TABLE_XOR[MHASH_384_TSIZE_XOR-1U];
-       size_t i;
+       uint_fast32_t i;
        for (i = 0; i < MHASH_384_LEN; ++i)
        {
                output[i] = ptr_src[i] ^ ptr_xor[i];
@@ -1419,19 +1419,19 @@ public:
                internals::mhash_384_initialize(&m_context);
        }
 
-       inline void update(const uint8_t *const input, const size_t len)
+       inline void update(const uint8_t *const input, const uint_fast32_t len)
        {
                internals::mhash_384_update(&m_context, input, len);
        }
 
 #ifndef MHASH_DISABLE_STL
-       inline void update(const std::vector<uint8_t> &input, const size_t offset = 0, const size_t len = 0)
+       inline void update(const std::vector<uint8_t> &input, const uint_fast32_t offset = 0, const uint_fast32_t len = 0)
        {
                assert(len + offset <= input.size());
                internals::mhash_384_update(&m_context, input.data() + offset, (len > 0) ? len : (input.size() - offset));
        }
 
-       inline void update(const std::string &input, const size_t offset = 0, const size_t len = 0)
+       inline void update(const std::string &input, const uint_fast32_t offset = 0, const uint_fast32_t len = 0)
        {
                assert(len + offset <= input.length());
                internals::mhash_384_update(&m_context, reinterpret_cast<const uint8_t*>(input.c_str() + offset), (len > 0) ? len : (input.length() - offset));
@@ -1450,7 +1450,7 @@ public:
                internals::mhash_384_finalize(&m_context, output);
        }
 
-       inline static void version(uint16_t &major, uint16_t &minor, uint16_t &patch)
+       inline static void version(uint_fast16_t &major, uint_fast16_t &minor, uint_fast16_t &patch)
        {
                major = internals::MHASH_384_VERSION_MAJOR;
                minor = internals::MHASH_384_VERSION_MINOR;
index 291f166..d131c34 100644 (file)
@@ -52,9 +52,9 @@ int MAIN(int argc, CHAR *argv[])
        param_t param;
        FILE *source;
        uint8_t buffer[BUFF_SIZE], result[MHASH_384_LEN];
-       size_t count;
+       uint_fast32_t count;
        uint64_t size_total, size_processed;
-       uint16_t update_iter;
+       uint_fast16_t update_iter;
        clock_t ts_start, ts_finish;
        mhash_384_t context;
 
@@ -105,7 +105,7 @@ int MAIN(int argc, CHAR *argv[])
        /*process file contents*/
        while(!(ferror(source) || feof(source)))
        {
-               count = fread(buffer, sizeof(uint8_t), BUFF_SIZE, source);
+               count = (uint_fast32_t) fread(buffer, sizeof(uint8_t), BUFF_SIZE, source);
                if (count > 0)
                {
                        mhash_384_update(&context, buffer, count);
index eb062d8..9f03c1e 100644 (file)
@@ -55,8 +55,8 @@ while(0)
 /*Test vectors and reference outputs (short)*/
 static const struct
 {
-       uint32_t itrations;
-       uint32_t len;
+       uint_fast32_t itrations;
+       uint_fast32_t len;
        const char *const str;
 }
 TEST_VECTOR[] =
@@ -119,7 +119,7 @@ static MHASH_384_INLINE uint32_t test_distance_mix(const uint8_t *const a, const
 
 static int self_test(void)
 {
-       uint32_t i, j;
+       uint_fast32_t i, j;
        uint8_t result[MHASH_384_LEN];
        mhash_384_t context;
 
@@ -163,7 +163,7 @@ static int self_test(void)
                mhash_384_initialize(&context);
                for (j = 0; j < TEST_VECTOR[i].itrations; ++j)
                {
-                       mhash_384_update(&context, (const uint8_t*)TEST_VECTOR[i].str, TEST_VECTOR[i].len ? TEST_VECTOR[i].len : strlen(TEST_VECTOR[i].str));
+                       mhash_384_update(&context, (const uint8_t*)TEST_VECTOR[i].str, TEST_VECTOR[i].len ? TEST_VECTOR[i].len : (uint_fast32_t)strlen(TEST_VECTOR[i].str));
                }
                mhash_384_finalize(&context, result);
                printf("\b\b\b");
index 44f8a2b..8fa195d 100644 (file)
@@ -54,9 +54,9 @@ param_t;
 /*Version*/
 typedef struct version_t
 {
-       uint16_t major;
-       uint16_t minor;
-       uint16_t patch;
+       uint_fast16_t major;
+       uint_fast16_t minor;
+       uint_fast16_t patch;
 }
 version_t;