From a1d040dc1949a84f839321510d73aeb385a348fb Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 26 Oct 2022 16:11:55 +0800 Subject: [PATCH 01/22] Update const return types --- include/abstract_encoder.hpp | 2 +- include/abstract_hash_encoder.hpp | 11 +++++++++ include/hash_encoder.hpp | 14 +++--------- include/hmac_encoder.hpp | 12 +--------- include/sequential_data.hpp | 23 ++++++++++--------- src/hash_encoder.cpp | 25 ++++++++++++--------- src/hmac_encoder.cpp | 10 ++++----- src/sequential_data.cpp | 37 ++++++++++++++++++++++--------- test/hash_encoder_test.hpp | 1 - test/hmactest.hpp | 6 ++--- 10 files changed, 77 insertions(+), 64 deletions(-) diff --git a/include/abstract_encoder.hpp b/include/abstract_encoder.hpp index 2084fa2..3ed552c 100644 --- a/include/abstract_encoder.hpp +++ b/include/abstract_encoder.hpp @@ -39,7 +39,7 @@ class AbstractEncoder update(sd.to_pgfe_seq(sz), sz); } - virtual SequentialData *get_digest() { + virtual const SequentialData *get_digest() { return nullptr; } }; // namespace AbstractEncoder diff --git a/include/abstract_hash_encoder.hpp b/include/abstract_hash_encoder.hpp index 6728a0b..4d9f29b 100644 --- a/include/abstract_hash_encoder.hpp +++ b/include/abstract_hash_encoder.hpp @@ -24,6 +24,17 @@ namespace PGFE { class AbstractHashEncoder : public AbstractEncoder, public AlgorithmSelectable { +protected: + size_t digsz, blocksz; + +public: + size_t digest_size() const { + return digsz; + } + + size_t block_size() const { + return blocksz; + } }; } // namespace PGFE diff --git a/include/hash_encoder.hpp b/include/hash_encoder.hpp index 7029fee..3dd5f42 100644 --- a/include/hash_encoder.hpp +++ b/include/hash_encoder.hpp @@ -25,12 +25,12 @@ class HashEncoder : public AbstractHashEncoder private: void *ctx = nullptr; - size_t digsz, blocksz; - pgfe_encode_t *seq = nullptr; + SequentialData *out = nullptr; void load_algorithm(); void destroy_context(); + void destroy_output(); void init(); @@ -49,15 +49,7 @@ class HashEncoder : public AbstractHashEncoder void update(std::string &cpp_s); void update(SequentialData &sd); - SequentialData *get_digest(uint64_t bitlength = 0); - - size_t digest_size() { - return digsz; - } - - size_t block_size() { - return blocksz; - } + const SequentialData *get_digest(uint64_t bitlength = 0); }; } // namespace PGFE diff --git a/include/hmac_encoder.hpp b/include/hmac_encoder.hpp index c8d4c44..521ad71 100644 --- a/include/hmac_encoder.hpp +++ b/include/hmac_encoder.hpp @@ -40,8 +40,6 @@ class HMACEncoder : public AbstractHashEncoder pgfe_hmac_sha3_512_ctx sha3_512; } ctx; - size_t digsz, blocksz; - SequentialData *output; void destroy_output(); @@ -66,15 +64,7 @@ class HMACEncoder : public AbstractHashEncoder void update(std::string &cpp_s); void update(SequentialData &sd); - SequentialData *get_digest(); - - size_t block_size() { - return blocksz; - } - - size_t digest_size() { - return digsz; - } + const SequentialData *get_digest(); }; } // namespace PGFE diff --git a/include/sequential_data.hpp b/include/sequential_data.hpp index a81484d..90829f5 100644 --- a/include/sequential_data.hpp +++ b/include/sequential_data.hpp @@ -40,27 +40,30 @@ class SequentialData SequentialData(const pgfe_encode_t *, size_t); SequentialData(const char *); SequentialData(std::string &); + SequentialData(const SequentialData *); + SequentialData(SequentialData *, bool delete_current); ~SequentialData(); - const char *to_cs(); - std::string to_str(); + const char *to_cs() const; + std::string to_str() const; const char *to_hex_cs(); - std::string to_hex_str(); + std::string to_hex_str() const; - const pgfe_encode_t *to_pgfe_seq(); - const pgfe_encode_t *to_pgfe_seq(size_t &); + const pgfe_encode_t *to_pgfe_seq() const; + const pgfe_encode_t *to_pgfe_seq(size_t &) const; - size_t length(); + size_t length() const; - bool is_str(); + bool is_str() const; void set_is_str(bool); - bool is_apparent_str(); + bool is_apparent_str() const; - SequentialData *truncate(size_t start, size_t length, bool inplace = false); + SequentialData *truncate(size_t start, size_t length, bool inplace); + SequentialData *truncate(size_t start, size_t length) const; - SequentialData *copy(); + SequentialData *copy() const; friend std::ostream &operator<<(std::ostream &os, const SequentialData &sd) { if (sd._is_str) { diff --git a/src/hash_encoder.cpp b/src/hash_encoder.cpp index ad20f06..8271a33 100644 --- a/src/hash_encoder.cpp +++ b/src/hash_encoder.cpp @@ -55,6 +55,13 @@ void HashEncoder::destroy_context() { __PGFE_BATCH_CASES(CTX_DELETE) } +void HashEncoder::destroy_output() { + if (!out) return; + + delete out; + out = nullptr; +} + void HashEncoder::before_change_alg() { destroy_context(); } @@ -67,11 +74,6 @@ void HashEncoder::load_algorithm() { __PGFE_BATCH_CASES(CTX_CREATE) __PGFE_BATCH_CASES(INIT_FUNC_CALL) __PGFE_BATCH_CASES(INIT_SIZE) - - if (seq) { - delete[] seq; - } - seq = new pgfe_encode_t[digsz + 1]; } void HashEncoder::reset() { @@ -90,9 +92,7 @@ HashEncoder::HashEncoder(pgfe_algorithm_choice choice) { HashEncoder::~HashEncoder() { destroy_context(); - if (seq) { - delete[] seq; - } + destroy_output(); } void HashEncoder::update(const pgfe_encode_t sequence[], size_t length) { @@ -111,7 +111,7 @@ inline void HashEncoder::update(SequentialData &sd) { return this->AbstractHashEncoder::update(sd); } -SequentialData *HashEncoder::get_digest(uint64_t bitlength) { +const SequentialData *HashEncoder::get_digest(uint64_t bitlength) { bool shake_flag = this->cur_alg == SHAKE128 || this->cur_alg == RawSHAKE128 || this->cur_alg == SHAKE256 || this->cur_alg == RawSHAKE256; uint64_t in_len = to_byte(bitlength) + bit_rem(bitlength); @@ -125,6 +125,9 @@ SequentialData *HashEncoder::get_digest(uint64_t bitlength) { } } + size_t length = shake_flag ? in_len : in_len < digsz && bitlength ? in_len : digsz; + pgfe_encode_t seq[length]; + if (shake_flag) { __PGFE_BATCH_SHAKE_CASES(DIGEST_FUNC_CALL_LIMIT) } @@ -132,5 +135,7 @@ SequentialData *HashEncoder::get_digest(uint64_t bitlength) { __PGFE_BATCH_CASES_SP(DIGEST_FUNC_CALL) } - return new SequentialData(seq, shake_flag ? in_len : in_len < digsz && bitlength ? in_len : digsz); + destroy_output(); + out = new SequentialData(seq, length); + return out; } \ No newline at end of file diff --git a/src/hmac_encoder.cpp b/src/hmac_encoder.cpp index 5e69d9e..6fec1c8 100644 --- a/src/hmac_encoder.cpp +++ b/src/hmac_encoder.cpp @@ -101,10 +101,8 @@ inline void HMACEncoder::update(SequentialData &sd) { this->AbstractHashEncoder::update(sd); } -SequentialData *HMACEncoder::get_digest() { - if (!output) { - __PGFE_BATCH_CASES_SP(HMAC_DIGEST) - } - - return output->copy(); +const SequentialData *HMACEncoder::get_digest() { + destroy_output(); + __PGFE_BATCH_CASES_SP(HMAC_DIGEST) + return output; } \ No newline at end of file diff --git a/src/sequential_data.cpp b/src/sequential_data.cpp index a1b95fc..b500a52 100644 --- a/src/sequential_data.cpp +++ b/src/sequential_data.cpp @@ -34,15 +34,24 @@ SequentialData::SequentialData(const char *cs) : SequentialData((const pgfe_enco SequentialData::SequentialData(std::string &cpp_s) : SequentialData((const pgfe_encode_t *)cpp_s.c_str(), cpp_s.length()) {} -size_t SequentialData::length() { +SequentialData::SequentialData(const SequentialData *sd) : SequentialData((const pgfe_encode_t *)sd->seq, sd->sz) {} + +SequentialData::SequentialData(SequentialData *sd, bool delete_current) + : SequentialData((const pgfe_encode_t *)sd->seq, sd->sz) { + if (delete_current) { + delete sd; + } +} + +size_t SequentialData::length() const { return sz; } -const char *SequentialData::to_cs() { +const char *SequentialData::to_cs() const { return (const char *)seq; } -std::string SequentialData::to_str() { +std::string SequentialData::to_str() const { std::string s((char *)seq); return s; } @@ -57,21 +66,23 @@ const char *SequentialData::to_hex_cs() { return hex_str; } -std::string SequentialData::to_hex_str() { - std::string s(to_hex_cs()); +std::string SequentialData::to_hex_str() const { + char hex_str[sz * 2 + 1]; + pgfe_hash_to_hex_string(seq, sz, hex_str); + std::string s(hex_str); return s; } -const pgfe_encode_t *SequentialData::to_pgfe_seq() { +const pgfe_encode_t *SequentialData::to_pgfe_seq() const { return seq; } -const pgfe_encode_t *SequentialData::to_pgfe_seq(size_t &length_out) { +const pgfe_encode_t *SequentialData::to_pgfe_seq(size_t &length_out) const { length_out = sz; return to_pgfe_seq(); } -bool SequentialData::is_str() { +bool SequentialData::is_str() const { return _is_str; } @@ -79,7 +90,7 @@ void SequentialData::set_is_str(bool str) { _is_str = str; } -bool SequentialData::is_apparent_str() { +bool SequentialData::is_apparent_str() const { return _apstr; } @@ -93,6 +104,10 @@ bool SequentialData::determine_ascii_str() { return true; } +SequentialData *SequentialData::truncate(size_t start, size_t length) const { + return new SequentialData(&seq[start], length); +} + SequentialData *SequentialData::truncate(size_t start, size_t length, bool inplace) { if (inplace) { if (start) { @@ -104,9 +119,9 @@ SequentialData *SequentialData::truncate(size_t start, size_t length, bool inpla return nullptr; } - return new SequentialData(&seq[start], length); + return truncate(start, length); } -SequentialData *SequentialData::copy() { +SequentialData *SequentialData::copy() const { return new SequentialData((const pgfe_encode_t *)seq, sz); } \ No newline at end of file diff --git a/test/hash_encoder_test.hpp b/test/hash_encoder_test.hpp index 48c9aad..fdf6b1f 100644 --- a/test/hash_encoder_test.hpp +++ b/test/hash_encoder_test.hpp @@ -32,5 +32,4 @@ void hash_encoder_test(ARGS) { // puts(sd.to_hex_cs()); cout << *sd << endl; - delete sd; } \ No newline at end of file diff --git a/test/hmactest.hpp b/test/hmactest.hpp index e7ca2c3..418f276 100644 --- a/test/hmactest.hpp +++ b/test/hmactest.hpp @@ -28,8 +28,8 @@ void hmac_encoder_test(ARGS) { encoder->update(argv[4]); - auto sd = encoder->get_digest(); - puts(sd->to_hex_cs()); - delete sd; + SequentialData sd{encoder->get_digest()}; + puts(sd.to_hex_cs()); + delete encoder; } From 9b18c2a739ce3e673c3815d25eaf15e89aab6fa9 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 26 Oct 2022 16:12:42 +0800 Subject: [PATCH 02/22] Update version number --- CMakeLists.txt | 2 +- include/meta.h | 4 ++-- meta.mak | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 656c329..23f6d91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16.0) set(CMAKE_C_COMPILER clang) set(CMAKE_CXX_COMPILER clang++) -project(libpgfe VERSION 0.4.0 LANGUAGES C CXX) +project(libpgfe VERSION 0.5.0 LANGUAGES C CXX) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 14) diff --git a/include/meta.h b/include/meta.h index 9304ec4..e5aa612 100644 --- a/include/meta.h +++ b/include/meta.h @@ -11,8 +11,8 @@ #define LIBPGFE_NAME "libpgfe" #define LIBPGFE_MAJOR_VERSION 0 -#define LIBPGFE_MINOR_VERSION 4 +#define LIBPGFE_MINOR_VERSION 5 #define LIBPGFE_REVISION 0 -#define LIBPGFE_VERSION "0.4.0" +#define LIBPGFE_VERSION "0.5.0" #endif diff --git a/meta.mak b/meta.mak index 802b863..0aa05e0 100644 --- a/meta.mak +++ b/meta.mak @@ -1,5 +1,5 @@ PROJECT := libpgfe -VERSION := 0.4.0 +VERSION := 0.5.0 BUILD_DIR := build From 8bd1d399da293541ecc997122887c5db8e81b42a Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 26 Oct 2022 16:31:09 +0800 Subject: [PATCH 03/22] Update const methods --- include/abstract_base_encoding.hpp | 8 ++++---- include/abstract_otp.hpp | 4 ++-- include/algorithm_selectable.hpp | 2 +- include/base32.hpp | 2 +- include/base64.hpp | 2 +- include/generic.hpp | 6 +++--- include/hotp.hpp | 4 ++-- include/totp.hpp | 8 ++++---- src/abstract_base_encoding.cpp | 8 ++++---- src/abstract_otp.cpp | 2 +- src/algorithm_selectable.cpp | 2 +- src/hotp.cpp | 4 ++-- src/totp.cpp | 8 ++++---- src/utils.cpp | 2 +- 14 files changed, 31 insertions(+), 31 deletions(-) diff --git a/include/abstract_base_encoding.hpp b/include/abstract_base_encoding.hpp index 42e705b..4a9790e 100644 --- a/include/abstract_base_encoding.hpp +++ b/include/abstract_base_encoding.hpp @@ -63,10 +63,10 @@ class AbstractBaseEncoding SequentialData decode(const char *); SequentialData decode(std::string &); - base_short_size_t unit_size(); - base_short_size_t chunk_size(); - base_short_size_t bit_size(); - base_short_size_t alphabet_size(); + base_short_size_t unit_size() const; + base_short_size_t chunk_size() const; + base_short_size_t bit_size() const; + base_short_size_t alphabet_size() const; }; } // namespace PGFE diff --git a/include/abstract_otp.hpp b/include/abstract_otp.hpp index 05b6152..79c51ac 100644 --- a/include/abstract_otp.hpp +++ b/include/abstract_otp.hpp @@ -31,11 +31,11 @@ class AbstractOTP : public AlgorithmSelectable virtual void set_counter(pgfe_otp_counter_t){}; - virtual pgfe_otp_t generate(uint8_t digit_count = 6) { + virtual pgfe_otp_t generate(uint8_t digit_count = 6) const { return 0; } - virtual std::string generate_str(uint8_t digit_count = 6); + virtual std::string generate_str(uint8_t digit_count = 6) const; }; } // namespace PGFE diff --git a/include/algorithm_selectable.hpp b/include/algorithm_selectable.hpp index 98f1396..a7240e0 100644 --- a/include/algorithm_selectable.hpp +++ b/include/algorithm_selectable.hpp @@ -28,7 +28,7 @@ class AlgorithmSelectable void select_algorithm(pgfe_algorithm_choice choice); public: - pgfe_algorithm_choice algorithm(); + pgfe_algorithm_choice algorithm() const; }; } // namespace PGFE } // namespace chardon55 diff --git a/include/base32.hpp b/include/base32.hpp index f8e06d8..01a7eeb 100644 --- a/include/base32.hpp +++ b/include/base32.hpp @@ -28,7 +28,7 @@ class Base32 : public AbstractBaseEncoding public: Base32(bool hex_mode = false); - bool is_hex_mode() { + bool is_hex_mode() const { return hexm; } }; diff --git a/include/base64.hpp b/include/base64.hpp index dbf7ae6..dc01fb6 100644 --- a/include/base64.hpp +++ b/include/base64.hpp @@ -28,7 +28,7 @@ class Base64 : public AbstractBaseEncoding public: Base64(bool url_safe_mode = false); - bool is_url_safe_mode() { + bool is_url_safe_mode() const { return _url_safe_mode; } }; diff --git a/include/generic.hpp b/include/generic.hpp index 09fbaa4..ff0d83a 100644 --- a/include/generic.hpp +++ b/include/generic.hpp @@ -102,7 +102,7 @@ namespace chardon55 { namespace PGFE { -static std::unordered_map pgfe_option_map = { +static const std::unordered_map pgfe_option_map = { {"sha1", SHA1 }, {"SHA1", SHA1 }, {"sha224", SHA224 }, @@ -137,7 +137,7 @@ static std::unordered_map pgfe_option_map = {"MD5", MD5 }, }; -static std::unordered_map pgfe_digest_length = { +static const std::unordered_map pgfe_digest_length = { {SHA1, PGFE_SHA1_DIGEST_SIZE }, {SHA224, PGFE_SHA224_DIGEST_SIZE }, {SHA256, PGFE_SHA256_DIGEST_SIZE }, @@ -156,7 +156,7 @@ static std::unordered_map pgfe_digest_length = { {RawSHAKE256, PGFE_RawSHAKE256_DIGEST_SIZE}, }; -static std::unordered_map pgfe_block_length = { +static const std::unordered_map pgfe_block_length = { {SHA1, PGFE_SHA1_BLOCK_SIZE }, {SHA224, PGFE_SHA224_BLOCK_SIZE }, {SHA256, PGFE_SHA256_BLOCK_SIZE }, diff --git a/include/hotp.hpp b/include/hotp.hpp index 37ee89b..fb594ff 100644 --- a/include/hotp.hpp +++ b/include/hotp.hpp @@ -50,8 +50,8 @@ class HOTP : public AbstractOTP void set_counter(pgfe_otp_counter_t); - pgfe_otp_t generate(uint8_t digit_count = 6); - std::string generate_str(uint8_t digit_count = 6); + pgfe_otp_t generate(uint8_t digit_count = 6) const; + std::string generate_str(uint8_t digit_count = 6) const; }; } // namespace PGFE diff --git a/include/totp.hpp b/include/totp.hpp index f958dc5..949d7a4 100644 --- a/include/totp.hpp +++ b/include/totp.hpp @@ -35,15 +35,15 @@ class TOTP : public HOTP void update_counter(); - pgfe_totp_interval_t get_interval(); + pgfe_totp_interval_t get_interval() const; void set_interval(pgfe_totp_interval_t); - pgfe_time_t get_initial_time(); + pgfe_time_t get_initial_time() const; void set_initial_time(pgfe_time_t); - pgfe_time_t get_update_time(); + pgfe_time_t get_update_time() const; - pgfe_time_t get_remain_time(); + pgfe_time_t get_remain_time() const; }; } // namespace PGFE diff --git a/src/abstract_base_encoding.cpp b/src/abstract_base_encoding.cpp index 0d6f007..c2f13b9 100644 --- a/src/abstract_base_encoding.cpp +++ b/src/abstract_base_encoding.cpp @@ -94,18 +94,18 @@ SequentialData AbstractBaseEncoding::decode(std::string &cpp_s) { return decode(cpp_s.c_str()); } -base_short_size_t AbstractBaseEncoding::unit_size() { +base_short_size_t AbstractBaseEncoding::unit_size() const { return unitsz; } -base_short_size_t AbstractBaseEncoding::chunk_size() { +base_short_size_t AbstractBaseEncoding::chunk_size() const { return chunksz; } -base_short_size_t AbstractBaseEncoding::bit_size() { +base_short_size_t AbstractBaseEncoding::bit_size() const { return bitsz; } -base_short_size_t AbstractBaseEncoding::alphabet_size() { +base_short_size_t AbstractBaseEncoding::alphabet_size() const { return alphabetsz; } \ No newline at end of file diff --git a/src/abstract_otp.cpp b/src/abstract_otp.cpp index ec7e832..c088524 100644 --- a/src/abstract_otp.cpp +++ b/src/abstract_otp.cpp @@ -26,7 +26,7 @@ void AbstractOTP::set_secret(SequentialData &sd) { set_secret(sd.to_pgfe_seq(sz), sz); } -std::string AbstractOTP::generate_str(uint8_t digit_count) { +std::string AbstractOTP::generate_str(uint8_t digit_count) const { std::string str = std::to_string(generate(digit_count)); while (str.length() < digit_count) { str.insert(0, "0"); diff --git a/src/algorithm_selectable.cpp b/src/algorithm_selectable.cpp index c2ca56a..7f6e1b9 100644 --- a/src/algorithm_selectable.cpp +++ b/src/algorithm_selectable.cpp @@ -10,6 +10,6 @@ void AlgorithmSelectable::select_algorithm(pgfe_algorithm_choice choice) { after_change_alg(); } -pgfe_algorithm_choice AlgorithmSelectable::algorithm() { +pgfe_algorithm_choice AlgorithmSelectable::algorithm() const { return cur_alg; } \ No newline at end of file diff --git a/src/hotp.cpp b/src/hotp.cpp index ea844d7..222237a 100644 --- a/src/hotp.cpp +++ b/src/hotp.cpp @@ -81,7 +81,7 @@ void HOTP::set_counter(pgfe_otp_counter_t c) { this->co = c; } -pgfe_otp_t HOTP::generate(uint8_t digit_count) { +pgfe_otp_t HOTP::generate(uint8_t digit_count) const { if (!secret) { throw NotInitializedException(); } @@ -89,7 +89,7 @@ pgfe_otp_t HOTP::generate(uint8_t digit_count) { return pgfe_hotp_generic(cur_alg, secret->to_pgfe_seq(), secret->length(), co, digit_count); } -std::string HOTP::generate_str(uint8_t digit_count) { +std::string HOTP::generate_str(uint8_t digit_count) const { return this->AbstractOTP::generate_str(digit_count); } diff --git a/src/totp.cpp b/src/totp.cpp index 05fa8bf..f791cc5 100644 --- a/src/totp.cpp +++ b/src/totp.cpp @@ -15,11 +15,11 @@ void TOTP::set_interval(pgfe_totp_interval_t interval) { this->interval = interval; } -pgfe_totp_interval_t TOTP::get_interval() { +pgfe_totp_interval_t TOTP::get_interval() const { return interval; } -pgfe_time_t TOTP::get_initial_time() { +pgfe_time_t TOTP::get_initial_time() const { return initial_time; } @@ -27,7 +27,7 @@ void TOTP::set_initial_time(pgfe_time_t initial_time) { this->initial_time = initial_time; } -pgfe_time_t TOTP::get_update_time() { +pgfe_time_t TOTP::get_update_time() const { return update_time; } @@ -36,7 +36,7 @@ void TOTP::update_counter() { set_counter(__pgfe_calc_periodic_counter(update_time, interval, initial_time, &delta)); } -pgfe_time_t TOTP::get_remain_time() { +pgfe_time_t TOTP::get_remain_time() const { return delta - (pgfe_curtime() - update_time); } diff --git a/src/utils.cpp b/src/utils.cpp index 667fb66..10ab468 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -47,7 +47,7 @@ pgfe_algorithm_choice string_to_algorithm_choice(const char *cs) { } pgfe_algorithm_choice string_to_algorithm_choice(std::string cpp_s) { - return pgfe_option_map[cpp_s]; + return pgfe_option_map.at(cpp_s); } } // namespace utils From e789dc9f1793d5364306bd2b1e2742d44d392005 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 26 Oct 2022 16:33:10 +0800 Subject: [PATCH 04/22] Update dispose function --- src/hmac_encoder.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hmac_encoder.cpp b/src/hmac_encoder.cpp index 6fec1c8..31467d9 100644 --- a/src/hmac_encoder.cpp +++ b/src/hmac_encoder.cpp @@ -36,6 +36,7 @@ using namespace chardon55::PGFE; void HMACEncoder::destroy_output() { if (output) { delete output; + output = nullptr; } } From df4b252966e388c1370b679f326ec3a5d3542f7c Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 26 Oct 2022 16:47:14 +0800 Subject: [PATCH 05/22] Update Q&A --- .github/qna.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/qna.md b/.github/qna.md index c32e861..dab3a96 100644 --- a/.github/qna.md +++ b/.github/qna.md @@ -17,7 +17,7 @@ and I currently don't have enough time or effort to tackle it. Also, I do not ha Firstly, this library prioritizes POSIX compatibility, instead of Windows compatibility. -Secondly, *libpgfe* need some necessary features that are not included in *MSVC*. For instance, like the C code below: +Secondly, *libpgfe* needs some necessary features that are not included in *MSVC*. For instance, like the C code below: ```c int main() { @@ -28,4 +28,4 @@ int main() { } ``` -*MSVC* will refuse to compile that code, because of a variable is used as the array's size, while *Clang* and *GCC* are OK with it. +*MSVC* will refuse to compile that code, because a variable is used as the array's size, while *Clang* and *GCC* are OK with it. From 8ec382718067de602078cc2cdef342caeb11b99e Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 10:51:34 +0800 Subject: [PATCH 06/22] Refactoring --- src/sequential_data.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/sequential_data.cpp b/src/sequential_data.cpp index b500a52..4dd426b 100644 --- a/src/sequential_data.cpp +++ b/src/sequential_data.cpp @@ -52,7 +52,7 @@ const char *SequentialData::to_cs() const { } std::string SequentialData::to_str() const { - std::string s((char *)seq); + std::string s{(char *)seq}; return s; } From 821a565c5c547c80ce61d86873238b3ba97942d6 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 11:21:13 +0800 Subject: [PATCH 07/22] Add source entry --- CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23f6d91..0fb32bf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ add_library(pgfe SHARED ${src_dir}/hotp.c ${src_dir}/totp.c ${src_dir}/base-encoding-internal.c ${src_dir}/base64.c ${src_dir}/base32.c ${src_dir}/base16.c + ${src_dir}/generic.cpp ${src_dir}/sequential_data.cpp ${src_dir}/utils.cpp ${src_dir}/algorithm_selectable.cpp From 0c9ab0d52b345792d3c416f970d0f2db6aa9bc4c Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 11:21:53 +0800 Subject: [PATCH 08/22] Move string2ac to generic --- include/generic.hpp | 5 +++++ include/utils.hpp | 3 --- src/generic.cpp | 23 +++++++++++++++++++++++ src/sequential_data.cpp | 4 +--- src/utils.cpp | 9 --------- test/hmactest.hpp | 1 - 6 files changed, 29 insertions(+), 16 deletions(-) create mode 100644 src/generic.cpp diff --git a/include/generic.hpp b/include/generic.hpp index ff0d83a..c3d5a5f 100644 --- a/include/generic.hpp +++ b/include/generic.hpp @@ -175,6 +175,11 @@ static const std::unordered_map pgfe_block_length {RawSHAKE256, PGFE_RawSHAKE256_BLOCK_SIZE}, }; +// String to algorithm choice type + +pgfe_algorithm_choice string_to_algorithm_choice(const char *cs); +pgfe_algorithm_choice string_to_algorithm_choice(std::string cpp_s); + } // namespace PGFE } // namespace chardon55 diff --git a/include/utils.hpp b/include/utils.hpp index aa54e55..5019061 100644 --- a/include/utils.hpp +++ b/include/utils.hpp @@ -28,9 +28,6 @@ SequentialData *to_sequential_data(const pgfe_encode_t *pgfe_c_seq, size_t); SequentialData *to_sequential_data(const char *cs); SequentialData *to_sequential_data(std::string &); -pgfe_algorithm_choice string_to_algorithm_choice(const char *cs); -pgfe_algorithm_choice string_to_algorithm_choice(std::string cpp_s); - namespace sequential_data { SequentialData *from_hex_string(const char *hex_cs); diff --git a/src/generic.cpp b/src/generic.cpp new file mode 100644 index 0000000..97821d6 --- /dev/null +++ b/src/generic.cpp @@ -0,0 +1,23 @@ +#ifndef LIBPGFE_GENERIC_CPP +#define LIBPGFE_GENERIC_CPP + +#include "generic.hpp" + +#include "generic.h" + +namespace chardon55 { +namespace PGFE { + +pgfe_algorithm_choice string_to_algorithm_choice(const char *cs) { + std::string s{cs}; + return string_to_algorithm_choice(s); +} + +pgfe_algorithm_choice string_to_algorithm_choice(std::string cpp_s) { + return pgfe_option_map.at(cpp_s); +} + +} // namespace PGFE +} // namespace chardon55 + +#endif \ No newline at end of file diff --git a/src/sequential_data.cpp b/src/sequential_data.cpp index 4dd426b..b030668 100644 --- a/src/sequential_data.cpp +++ b/src/sequential_data.cpp @@ -12,9 +12,7 @@ using namespace chardon55::PGFE; SequentialData::~SequentialData() { - if (seq) { - delete[] seq; - } + delete[] seq; if (hex_str) { delete[] hex_str; diff --git a/src/utils.cpp b/src/utils.cpp index 10ab468..c03e377 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -41,15 +41,6 @@ SequentialData *sequential_data::from_hex_string(std::string &hex_cpps) { return from_hex_string(hex_cpps.c_str()); } -pgfe_algorithm_choice string_to_algorithm_choice(const char *cs) { - std::string s{cs}; - return string_to_algorithm_choice(s); -} - -pgfe_algorithm_choice string_to_algorithm_choice(std::string cpp_s) { - return pgfe_option_map.at(cpp_s); -} - } // namespace utils } // namespace PGFE } // namespace chardon55 \ No newline at end of file diff --git a/test/hmactest.hpp b/test/hmactest.hpp index 418f276..4c57329 100644 --- a/test/hmactest.hpp +++ b/test/hmactest.hpp @@ -13,7 +13,6 @@ void hmac_encoder_test(ARGS) { USE_PGFE_CPP - USE_PGFE_CPP_UTILS HMACEncoder *encoder; From 2c192d9c846dfdde2984c9688467ee7c5ff6ed64 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 11:22:03 +0800 Subject: [PATCH 09/22] Add disposal code --- src/sha2-backend.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/sha2-backend.c b/src/sha2-backend.c index 59e4179..8f97a79 100644 --- a/src/sha2-backend.c +++ b/src/sha2-backend.c @@ -70,6 +70,10 @@ void __pgfe_sha256_process_block(struct pgfe_sha256_ctx *ctx) { ctx->state[7] += H; ctx->index = 0; + + // Wipe data from RAM + tmp1 = tmp2 = A = B = C = D = E = F = G = H = 0; + memset(ws, 0, PGFE_SHA256_BLOCK_SIZE); } void __pgfe_sha224n256_padding(struct pgfe_sha256_ctx *ctx) { From b53159459bd96f5e974db541b8cf5972ac66eaf2 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 11:22:08 +0800 Subject: [PATCH 10/22] Refactoring --- src/sha224.c | 4 ++-- src/sha256.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sha224.c b/src/sha224.c index 028ab85..d8af317 100644 --- a/src/sha224.c +++ b/src/sha224.c @@ -13,8 +13,8 @@ const pgfe_word_t __pgfe_sha224_H0[] = {0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4}; -__PGFE_FRONTEND_GEN2(sha224); -__PGFE_FRONTEND_DEFAULT_GEN2(sha224, SHA224); +__PGFE_FRONTEND_GEN2(sha224) +__PGFE_FRONTEND_DEFAULT_GEN2(sha224, SHA224) __PGFE_SHA_INIT(sha224) __PGFE_SHA_UPDATE(sha224, SHA224) diff --git a/src/sha256.c b/src/sha256.c index 3bfa704..b4bf57a 100644 --- a/src/sha256.c +++ b/src/sha256.c @@ -12,8 +12,8 @@ const pgfe_word_t __pgfe_sha256_H0[] = {0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19}; -__PGFE_FRONTEND_GEN2(sha256); -__PGFE_FRONTEND_DEFAULT_GEN2(sha256, SHA256); +__PGFE_FRONTEND_GEN2(sha256) +__PGFE_FRONTEND_DEFAULT_GEN2(sha256, SHA256) __PGFE_SHA_INIT(sha256) __PGFE_SHA_UPDATE(sha256, SHA256) From 8cb821f2ad23b59f6d8b0d74f364bb0226801467 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 12:18:09 +0800 Subject: [PATCH 11/22] Update file structure --- CMakeLists.txt | 57 +++++++++---------- .../{ => backend}/base-encoding-internal.h | 2 +- include/{ => backend}/generic-internal.h | 2 +- include/{ => backend}/keccak-backend.h | 0 include/{ => backend}/md5-backend.h | 0 include/{ => backend}/otp-generic.h | 4 +- include/{ => backend}/sha-internal.h | 0 include/{ => backend}/sha2-backend.h | 3 +- .../backend/templates.h | 6 +- .../abstract_base_encoding.hpp | 4 +- .../{ => backend_cpp}/abstract_encoder.hpp | 6 +- .../abstract_hash_encoder.hpp | 9 +-- include/{ => backend_cpp}/abstract_otp.hpp | 8 +-- include/base16.hpp | 2 +- include/base32.hpp | 2 +- include/base64.hpp | 2 +- include/hash_encoder.hpp | 2 +- include/hmac.h | 2 +- include/hmac_encoder.hpp | 2 +- include/hotp.h | 4 +- include/hotp.hpp | 2 +- include/md5.h | 2 +- include/sha1.h | 2 +- include/sha2.h | 2 +- include/sha3.h | 2 +- include/totp.h | 2 +- include/utils.h | 2 +- .../base_encoding}/base-encoding-internal.c | 4 +- src/{ => c/base_encoding}/base16.c | 2 +- src/{ => c/base_encoding}/base32.c | 4 +- src/{ => c/base_encoding}/base64.c | 2 +- src/{ => c}/generic-internal.c | 2 +- src/{ => c}/generic.c | 0 src/{ => c/hash}/keccak-backend.c | 2 +- src/{ => c/hash}/md5-backend.c | 2 +- src/{ => c/hash}/md5.c | 4 +- src/{ => c/hash}/sha-internal.c | 2 +- src/{ => c/hash}/sha1.c | 6 +- src/{ => c/hash}/sha2-backend.c | 5 +- src/{ => c/hash}/sha224.c | 4 +- src/{ => c/hash}/sha256.c | 5 +- src/{ => c/hash}/sha3-224.c | 3 +- src/{ => c/hash}/sha3-256.c | 3 +- src/{ => c/hash}/sha3-384.c | 3 +- src/{ => c/hash}/sha3-512.c | 3 +- src/{ => c/hash}/sha384.c | 4 +- src/{ => c/hash}/sha512.c | 4 +- src/{ => c/hash}/shake.c | 2 +- src/{ => c/hmac}/hmac.c | 2 +- src/{ => c/otp}/hotp.c | 2 +- src/{ => c/otp}/otp-generic.c | 2 +- src/{ => c/otp}/totp.c | 2 +- src/{ => c}/utils.c | 2 +- src/{ => cpp}/algorithm_selectable.cpp | 0 .../base_encoding}/abstract_base_encoding.cpp | 2 +- src/{ => cpp/base_encoding}/base16.cpp | 0 src/{ => cpp/base_encoding}/base32.cpp | 0 src/{ => cpp/base_encoding}/base64.cpp | 0 src/{ => cpp}/generic.cpp | 0 src/{ => cpp/hash}/hash_encoder.cpp | 0 src/{ => cpp/hmac}/hmac_encoder.cpp | 0 src/{ => cpp/otp}/abstract_otp.cpp | 2 +- src/{ => cpp/otp}/hotp.cpp | 0 src/{ => cpp/otp}/totp.cpp | 0 src/{ => cpp}/sequential_data.cpp | 0 src/{ => cpp}/utils.cpp | 0 66 files changed, 109 insertions(+), 102 deletions(-) rename include/{ => backend}/base-encoding-internal.h (98%) rename include/{ => backend}/generic-internal.h (99%) rename include/{ => backend}/keccak-backend.h (100%) rename include/{ => backend}/md5-backend.h (100%) rename include/{ => backend}/otp-generic.h (92%) rename include/{ => backend}/sha-internal.h (100%) rename include/{ => backend}/sha2-backend.h (98%) rename src/templates.c => include/backend/templates.h (99%) rename include/{ => backend_cpp}/abstract_base_encoding.hpp (96%) rename include/{ => backend_cpp}/abstract_encoder.hpp (92%) rename include/{ => backend_cpp}/abstract_hash_encoder.hpp (84%) rename include/{ => backend_cpp}/abstract_otp.hpp (85%) rename src/{ => c/base_encoding}/base-encoding-internal.c (98%) rename src/{ => c/base_encoding}/base16.c (95%) rename src/{ => c/base_encoding}/base32.c (96%) rename src/{ => c/base_encoding}/base64.c (97%) rename src/{ => c}/generic-internal.c (96%) rename src/{ => c}/generic.c (100%) rename src/{ => c/hash}/keccak-backend.c (99%) rename src/{ => c/hash}/md5-backend.c (99%) rename src/{ => c/hash}/md5.c (96%) rename src/{ => c/hash}/sha-internal.c (66%) rename src/{ => c/hash}/sha1.c (96%) rename src/{ => c/hash}/sha2-backend.c (99%) rename src/{ => c/hash}/sha224.c (89%) rename src/{ => c/hash}/sha256.c (89%) rename src/{ => c/hash}/sha3-224.c (95%) rename src/{ => c/hash}/sha3-256.c (95%) rename src/{ => c/hash}/sha3-384.c (95%) rename src/{ => c/hash}/sha3-512.c (95%) rename src/{ => c/hash}/sha384.c (93%) rename src/{ => c/hash}/sha512.c (97%) rename src/{ => c/hash}/shake.c (98%) rename src/{ => c/hmac}/hmac.c (99%) rename src/{ => c/otp}/hotp.c (98%) rename src/{ => c/otp}/otp-generic.c (92%) rename src/{ => c/otp}/totp.c (98%) rename src/{ => c}/utils.c (98%) rename src/{ => cpp}/algorithm_selectable.cpp (100%) rename src/{ => cpp/base_encoding}/abstract_base_encoding.cpp (98%) rename src/{ => cpp/base_encoding}/base16.cpp (100%) rename src/{ => cpp/base_encoding}/base32.cpp (100%) rename src/{ => cpp/base_encoding}/base64.cpp (100%) rename src/{ => cpp}/generic.cpp (100%) rename src/{ => cpp/hash}/hash_encoder.cpp (100%) rename src/{ => cpp/hmac}/hmac_encoder.cpp (100%) rename src/{ => cpp/otp}/abstract_otp.cpp (94%) rename src/{ => cpp/otp}/hotp.cpp (100%) rename src/{ => cpp/otp}/totp.cpp (100%) rename src/{ => cpp}/sequential_data.cpp (100%) rename src/{ => cpp}/utils.cpp (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0fb32bf..d82f6cc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,35 +16,34 @@ set(include_dir "include") set(test_dir "test") add_library(pgfe SHARED - ${src_dir}/generic.c - ${src_dir}/generic-internal.c - ${src_dir}/templates.c - ${src_dir}/utils.c - ${src_dir}/sha-internal.c - ${src_dir}/sha2-backend.c - ${src_dir}/keccak-backend.c - ${src_dir}/md5-backend.c - ${src_dir}/sha1.c ${src_dir}/sha224.c ${src_dir}/sha256.c ${src_dir}/sha384.c ${src_dir}/sha512.c - ${src_dir}/sha3-224.c ${src_dir}/sha3-256.c ${src_dir}/sha3-384.c ${src_dir}/sha3-512.c - ${src_dir}/md5.c - ${src_dir}/shake.c - ${src_dir}/hmac.c - ${src_dir}/otp-generic.c - ${src_dir}/hotp.c ${src_dir}/totp.c - ${src_dir}/base-encoding-internal.c - ${src_dir}/base64.c ${src_dir}/base32.c ${src_dir}/base16.c - ${src_dir}/generic.cpp - ${src_dir}/sequential_data.cpp - ${src_dir}/utils.cpp - ${src_dir}/algorithm_selectable.cpp - ${src_dir}/hash_encoder.cpp - ${src_dir}/hmac_encoder.cpp - ${src_dir}/abstract_base_encoding.cpp - ${src_dir}/base16.cpp - ${src_dir}/base32.cpp - ${src_dir}/base64.cpp - ${src_dir}/abstract_otp.cpp - ${src_dir}/hotp.cpp ${src_dir}/totp.cpp) + ${src_dir}/c/generic.c + ${src_dir}/c/generic-internal.c + ${src_dir}/c/utils.c + ${src_dir}/c/hash/sha-internal.c + ${src_dir}/c/hash/sha2-backend.c + ${src_dir}/c/hash/keccak-backend.c + ${src_dir}/c/hash/md5-backend.c + ${src_dir}/c/hash/sha1.c ${src_dir}/c/hash/sha224.c ${src_dir}/c/hash/sha256.c ${src_dir}/c/hash/sha384.c ${src_dir}/c/hash/sha512.c + ${src_dir}/c/hash/sha3-224.c ${src_dir}/c/hash/sha3-256.c ${src_dir}/c/hash/sha3-384.c ${src_dir}/c/hash/sha3-512.c + ${src_dir}/c/hash/md5.c + ${src_dir}/c/hash/shake.c + ${src_dir}/c/hmac/hmac.c + ${src_dir}/c/otp/otp-generic.c + ${src_dir}/c/otp/hotp.c ${src_dir}/c/otp/totp.c + ${src_dir}/c/base_encoding/base-encoding-internal.c + ${src_dir}/c/base_encoding/base64.c ${src_dir}/c/base_encoding/base32.c ${src_dir}/c/base_encoding/base16.c + ${src_dir}/cpp/generic.cpp + ${src_dir}/cpp/sequential_data.cpp + ${src_dir}/cpp/utils.cpp + ${src_dir}/cpp/algorithm_selectable.cpp + ${src_dir}/cpp/hash/hash_encoder.cpp + ${src_dir}/cpp/hmac/hmac_encoder.cpp + ${src_dir}/cpp/base_encoding/abstract_base_encoding.cpp + ${src_dir}/cpp/base_encoding/base16.cpp + ${src_dir}/cpp/base_encoding/base32.cpp + ${src_dir}/cpp/base_encoding/base64.cpp + ${src_dir}/cpp/otp/abstract_otp.cpp + ${src_dir}/cpp/otp/hotp.cpp ${src_dir}/cpp/otp/totp.cpp) add_executable(pgfetest ${test_dir}/test.c) # add_executable(totptest ${test_dir}/totptest.c) # add_executable(totptestcpp ${test_dir}/totptest.cpp) diff --git a/include/base-encoding-internal.h b/include/backend/base-encoding-internal.h similarity index 98% rename from include/base-encoding-internal.h rename to include/backend/base-encoding-internal.h index 6a7852c..ccee40d 100644 --- a/include/base-encoding-internal.h +++ b/include/backend/base-encoding-internal.h @@ -10,7 +10,7 @@ #include -#include "generic.h" +#include "../generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/generic-internal.h b/include/backend/generic-internal.h similarity index 99% rename from include/generic-internal.h rename to include/backend/generic-internal.h index f852841..018460a 100644 --- a/include/generic-internal.h +++ b/include/backend/generic-internal.h @@ -8,7 +8,7 @@ #ifndef LIBPGFE_GENERIC_INTERNAL_H #define LIBPGFE_GENERIC_INTERNAL_H -#include "generic.h" +#include "../generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/keccak-backend.h b/include/backend/keccak-backend.h similarity index 100% rename from include/keccak-backend.h rename to include/backend/keccak-backend.h diff --git a/include/md5-backend.h b/include/backend/md5-backend.h similarity index 100% rename from include/md5-backend.h rename to include/backend/md5-backend.h diff --git a/include/otp-generic.h b/include/backend/otp-generic.h similarity index 92% rename from include/otp-generic.h rename to include/backend/otp-generic.h index 75109c3..172deaf 100644 --- a/include/otp-generic.h +++ b/include/backend/otp-generic.h @@ -10,8 +10,8 @@ #include -#include "generic.h" -#include "hmac.h" +#include "../generic.h" +#include "../hmac.h" #ifdef __cplusplus extern "C" { diff --git a/include/sha-internal.h b/include/backend/sha-internal.h similarity index 100% rename from include/sha-internal.h rename to include/backend/sha-internal.h diff --git a/include/sha2-backend.h b/include/backend/sha2-backend.h similarity index 98% rename from include/sha2-backend.h rename to include/backend/sha2-backend.h index 453dc38..426ef63 100644 --- a/include/sha2-backend.h +++ b/include/backend/sha2-backend.h @@ -9,7 +9,8 @@ #define LIBPGFE_SHA2_INTERNAL_H #include "sha-internal.h" -#include "sha2.h" + +#include "../sha2.h" #ifdef __cpluslpus extern "C" { diff --git a/src/templates.c b/include/backend/templates.h similarity index 99% rename from src/templates.c rename to include/backend/templates.h index e5068d2..a440108 100644 --- a/src/templates.c +++ b/include/backend/templates.h @@ -1,12 +1,12 @@ /* libpgfe - templates.c + templates.h Copyright (c) 2022 Charles Dong */ -#ifndef LIBPGFE_TEMPLATES_C -#define LIBPGFE_TEMPLATES_C +#ifndef LIBPGFE_TEMPLATES_H +#define LIBPGFE_TEMPLATES_H #ifdef __cplusplus extern "C" { diff --git a/include/abstract_base_encoding.hpp b/include/backend_cpp/abstract_base_encoding.hpp similarity index 96% rename from include/abstract_base_encoding.hpp rename to include/backend_cpp/abstract_base_encoding.hpp index 4a9790e..9f36b3d 100644 --- a/include/abstract_base_encoding.hpp +++ b/include/backend_cpp/abstract_base_encoding.hpp @@ -14,8 +14,8 @@ #include #include -#include "generic.h" -#include "sequential_data.hpp" +#include "../generic.h" +#include "../sequential_data.hpp" namespace chardon55 { namespace PGFE { diff --git a/include/abstract_encoder.hpp b/include/backend_cpp/abstract_encoder.hpp similarity index 92% rename from include/abstract_encoder.hpp rename to include/backend_cpp/abstract_encoder.hpp index 3ed552c..80b1334 100644 --- a/include/abstract_encoder.hpp +++ b/include/backend_cpp/abstract_encoder.hpp @@ -14,9 +14,9 @@ #include #include -#include "generic.h" -#include "sequential_data.hpp" -#include "utils.hpp" +#include "../generic.h" +#include "../sequential_data.hpp" +#include "../utils.hpp" namespace chardon55 { namespace PGFE { diff --git a/include/abstract_hash_encoder.hpp b/include/backend_cpp/abstract_hash_encoder.hpp similarity index 84% rename from include/abstract_hash_encoder.hpp rename to include/backend_cpp/abstract_hash_encoder.hpp index 4d9f29b..83bcfbf 100644 --- a/include/abstract_hash_encoder.hpp +++ b/include/backend_cpp/abstract_hash_encoder.hpp @@ -14,10 +14,11 @@ #include #include "abstract_encoder.hpp" -#include "algorithm-choice.h" -#include "algorithm_selectable.hpp" -#include "generic.h" -#include "generic.hpp" + +#include "../algorithm-choice.h" +#include "../algorithm_selectable.hpp" +#include "../generic.h" +#include "../generic.hpp" namespace chardon55 { namespace PGFE { diff --git a/include/abstract_otp.hpp b/include/backend_cpp/abstract_otp.hpp similarity index 85% rename from include/abstract_otp.hpp rename to include/backend_cpp/abstract_otp.hpp index 79c51ac..1720b87 100644 --- a/include/abstract_otp.hpp +++ b/include/backend_cpp/abstract_otp.hpp @@ -13,10 +13,10 @@ #include -#include "algorithm_selectable.hpp" -#include "generic.h" -#include "otp-generic.h" -#include "sequential_data.hpp" +#include "../algorithm_selectable.hpp" +#include "../backend/otp-generic.h" +#include "../generic.h" +#include "../sequential_data.hpp" namespace chardon55 { namespace PGFE { diff --git a/include/base16.hpp b/include/base16.hpp index 915bbca..4038085 100644 --- a/include/base16.hpp +++ b/include/base16.hpp @@ -11,7 +11,7 @@ #error libpgfe error: C++ headers are not compatible with C source #endif -#include "abstract_base_encoding.hpp" +#include "backend_cpp/abstract_base_encoding.hpp" namespace chardon55 { namespace PGFE { diff --git a/include/base32.hpp b/include/base32.hpp index 01a7eeb..c55ce70 100644 --- a/include/base32.hpp +++ b/include/base32.hpp @@ -11,7 +11,7 @@ #error libpgfe error: C++ headers are not compatible with C source #endif -#include "abstract_base_encoding.hpp" +#include "backend_cpp/abstract_base_encoding.hpp" namespace chardon55 { namespace PGFE { diff --git a/include/base64.hpp b/include/base64.hpp index dc01fb6..6f4b2cd 100644 --- a/include/base64.hpp +++ b/include/base64.hpp @@ -11,7 +11,7 @@ #error libpgfe error: C++ headers are not compatible with C source #endif -#include "abstract_base_encoding.hpp" +#include "backend_cpp/abstract_base_encoding.hpp" namespace chardon55 { namespace PGFE { diff --git a/include/hash_encoder.hpp b/include/hash_encoder.hpp index 3dd5f42..04b657e 100644 --- a/include/hash_encoder.hpp +++ b/include/hash_encoder.hpp @@ -11,7 +11,7 @@ #error libpgfe error: C++ headers are not compatible with C source #endif -#include "abstract_hash_encoder.hpp" +#include "backend_cpp/abstract_hash_encoder.hpp" #include "generic.hpp" diff --git a/include/hmac.h b/include/hmac.h index ce5cd4f..e5e9f17 100644 --- a/include/hmac.h +++ b/include/hmac.h @@ -8,7 +8,7 @@ #ifndef LIBPGFE_HMAC_H #define LIBPGFE_HMAC_H -#include "generic-internal.h" +#include "backend/generic-internal.h" #include "generic.h" #include "md5.h" #include "sha1.h" diff --git a/include/hmac_encoder.hpp b/include/hmac_encoder.hpp index 521ad71..128023c 100644 --- a/include/hmac_encoder.hpp +++ b/include/hmac_encoder.hpp @@ -13,7 +13,7 @@ #include -#include "abstract_hash_encoder.hpp" +#include "backend_cpp/abstract_hash_encoder.hpp" #include "generic.h" #include "generic.hpp" #include "hmac.h" diff --git a/include/hotp.h b/include/hotp.h index 8546ac1..717dcc4 100644 --- a/include/hotp.h +++ b/include/hotp.h @@ -8,8 +8,8 @@ #ifndef LIBPGFE_HOTP_H #define LIBPGFE_HOTP_H -#include "generic-internal.h" -#include "otp-generic.h" +#include "backend/generic-internal.h" +#include "backend/otp-generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/hotp.hpp b/include/hotp.hpp index fb594ff..85eb81b 100644 --- a/include/hotp.hpp +++ b/include/hotp.hpp @@ -11,7 +11,7 @@ #error libpgfe error: C++ headers are not compatible with C source #endif -#include "abstract_otp.hpp" +#include "backend_cpp/abstract_otp.hpp" #include "base32.hpp" namespace chardon55 { diff --git a/include/md5.h b/include/md5.h index a69cafa..68ac42f 100644 --- a/include/md5.h +++ b/include/md5.h @@ -10,7 +10,7 @@ #include -#include "generic-internal.h" +#include "backend/generic-internal.h" #include "generic.h" #ifdef __cplusplus diff --git a/include/sha1.h b/include/sha1.h index 7a7a640..1e93ce8 100644 --- a/include/sha1.h +++ b/include/sha1.h @@ -10,7 +10,7 @@ #include -#include "generic-internal.h" +#include "backend/generic-internal.h" #ifdef __cplusplus extern "C" { diff --git a/include/sha2.h b/include/sha2.h index bcf245f..cc5a242 100644 --- a/include/sha2.h +++ b/include/sha2.h @@ -10,7 +10,7 @@ #include -#include "generic-internal.h" +#include "backend/generic-internal.h" #ifdef __cplusplus extern "C" { diff --git a/include/sha3.h b/include/sha3.h index 7c97271..23d24c7 100644 --- a/include/sha3.h +++ b/include/sha3.h @@ -10,8 +10,8 @@ #include +#include "backend/keccak-backend.h" #include "generic.h" -#include "keccak-backend.h" #ifdef __cplusplus extern "C" { diff --git a/include/totp.h b/include/totp.h index ab88a03..ae469dd 100644 --- a/include/totp.h +++ b/include/totp.h @@ -9,7 +9,7 @@ #ifndef LIBPGFE_TOTP_H #define LIBPGFE_TOTP_H -#include "otp-generic.h" +#include "backend/otp-generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/utils.h b/include/utils.h index d461696..65dadf1 100644 --- a/include/utils.h +++ b/include/utils.h @@ -8,8 +8,8 @@ #ifndef LIBPGFE_UTILS_H #define LIBPGFE_UTILS_H +#include "backend/otp-generic.h" #include "generic.h" -#include "otp-generic.h" #include diff --git a/src/base-encoding-internal.c b/src/c/base_encoding/base-encoding-internal.c similarity index 98% rename from src/base-encoding-internal.c rename to src/c/base_encoding/base-encoding-internal.c index c5e8bb9..12880ea 100644 --- a/src/base-encoding-internal.c +++ b/src/c/base_encoding/base-encoding-internal.c @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "base-encoding-internal.h" +#include "backend/base-encoding-internal.h" #include -#include "generic-internal.h" +#include "backend/generic-internal.h" uint8_t __pgfe_build_mask(uint8_t digit_c); diff --git a/src/base16.c b/src/c/base_encoding/base16.c similarity index 95% rename from src/base16.c rename to src/c/base_encoding/base16.c index c3460f5..46fba76 100644 --- a/src/base16.c +++ b/src/c/base_encoding/base16.c @@ -7,7 +7,7 @@ #include "base-encoding.h" -#include "base-encoding-internal.h" +#include "backend/base-encoding-internal.h" // Base 16 alphabet const char BASE16_ALPHABET[] = "0123456789ABCDEF" diff --git a/src/base32.c b/src/c/base_encoding/base32.c similarity index 96% rename from src/base32.c rename to src/c/base_encoding/base32.c index 25c7a18..197f8f3 100644 --- a/src/base32.c +++ b/src/c/base_encoding/base32.c @@ -9,8 +9,8 @@ #include -#include "base-encoding-internal.h" -#include "generic-internal.h" +#include "backend/base-encoding-internal.h" +#include "backend/generic-internal.h" // Base 32 alphabet // 0123456789ABCDEF diff --git a/src/base64.c b/src/c/base_encoding/base64.c similarity index 97% rename from src/base64.c rename to src/c/base_encoding/base64.c index 992b224..086332a 100644 --- a/src/base64.c +++ b/src/c/base_encoding/base64.c @@ -9,7 +9,7 @@ #include -#include "base-encoding-internal.h" +#include "backend/base-encoding-internal.h" // Base 64 alphabet // 0123456789ABCDEF diff --git a/src/generic-internal.c b/src/c/generic-internal.c similarity index 96% rename from src/generic-internal.c rename to src/c/generic-internal.c index aa5b261..c78cdab 100644 --- a/src/generic-internal.c +++ b/src/c/generic-internal.c @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "generic-internal.h" +#include "backend/generic-internal.h" inline void __pgfe_arrinit(pgfe_encode_t arr[], size_t size) { for (int i = 0; i < size; i++) { diff --git a/src/generic.c b/src/c/generic.c similarity index 100% rename from src/generic.c rename to src/c/generic.c diff --git a/src/keccak-backend.c b/src/c/hash/keccak-backend.c similarity index 99% rename from src/keccak-backend.c rename to src/c/hash/keccak-backend.c index 3c643cc..4134b3c 100644 --- a/src/keccak-backend.c +++ b/src/c/hash/keccak-backend.c @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "keccak-backend.h" +#include "backend/keccak-backend.h" #include #include diff --git a/src/md5-backend.c b/src/c/hash/md5-backend.c similarity index 99% rename from src/md5-backend.c rename to src/c/hash/md5-backend.c index f982a52..2e32304 100644 --- a/src/md5-backend.c +++ b/src/c/hash/md5-backend.c @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "md5-backend.h" +#include "backend/md5-backend.h" #include diff --git a/src/md5.c b/src/c/hash/md5.c similarity index 96% rename from src/md5.c rename to src/c/hash/md5.c index ba58c95..86c397a 100644 --- a/src/md5.c +++ b/src/c/hash/md5.c @@ -9,8 +9,8 @@ #include -#include "md5-backend.h" -#include "templates.c" +#include "backend/md5-backend.h" +#include "backend/templates.h" __PGFE_FRONTEND_GEN2(md5); __PGFE_FRONTEND_DEFAULT_GEN2(md5, MD5); diff --git a/src/sha-internal.c b/src/c/hash/sha-internal.c similarity index 66% rename from src/sha-internal.c rename to src/c/hash/sha-internal.c index e53ff61..f45f646 100644 --- a/src/sha-internal.c +++ b/src/c/hash/sha-internal.c @@ -5,4 +5,4 @@ Copyright (c) 2022 Charles Dong */ -#include "sha-internal.h" +#include "backend/sha-internal.h" diff --git a/src/sha1.c b/src/c/hash/sha1.c similarity index 96% rename from src/sha1.c rename to src/c/hash/sha1.c index f5617ce..fe13d7c 100644 --- a/src/sha1.c +++ b/src/c/hash/sha1.c @@ -7,9 +7,9 @@ #include "sha1.h" -#include "generic-internal.h" -#include "sha-internal.h" -#include "templates.c" +#include "backend/generic-internal.h" +#include "backend/sha-internal.h" +#include "backend/templates.h" const pgfe_word_t __pgfe_sha1_H0[] = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0}; diff --git a/src/sha2-backend.c b/src/c/hash/sha2-backend.c similarity index 99% rename from src/sha2-backend.c rename to src/c/hash/sha2-backend.c index 8f97a79..8c8d42f 100644 --- a/src/sha2-backend.c +++ b/src/c/hash/sha2-backend.c @@ -5,9 +5,10 @@ Copyright (c) 2022 Charles Dong */ -#include "sha2-backend.h" +#include "backend/sha2-backend.h" + +#include "backend/templates.h" #include "sha2.h" -#include "templates.c" #include diff --git a/src/sha224.c b/src/c/hash/sha224.c similarity index 89% rename from src/sha224.c rename to src/c/hash/sha224.c index d8af317..e1d4cde 100644 --- a/src/sha224.c +++ b/src/c/hash/sha224.c @@ -7,8 +7,8 @@ #include "sha2.h" -#include "sha2-backend.h" -#include "templates.c" +#include "backend/sha2-backend.h" +#include "backend/templates.h" const pgfe_word_t __pgfe_sha224_H0[] = {0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4}; diff --git a/src/sha256.c b/src/c/hash/sha256.c similarity index 89% rename from src/sha256.c rename to src/c/hash/sha256.c index b4bf57a..27f35af 100644 --- a/src/sha256.c +++ b/src/c/hash/sha256.c @@ -5,9 +5,10 @@ Copyright (c) 2022 Charles Dong */ -#include "sha2-backend.h" #include "sha2.h" -#include "templates.c" + +#include "backend/sha2-backend.h" +#include "backend/templates.h" const pgfe_word_t __pgfe_sha256_H0[] = {0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19}; diff --git a/src/sha3-224.c b/src/c/hash/sha3-224.c similarity index 95% rename from src/sha3-224.c rename to src/c/hash/sha3-224.c index 8ce2d81..8e8ec44 100644 --- a/src/sha3-224.c +++ b/src/c/hash/sha3-224.c @@ -6,7 +6,8 @@ */ #include "sha3.h" -#include "templates.c" + +#include "backend/templates.h" __PGFE_FRONTEND_GEN2(sha3_224); __PGFE_FRONTEND_DEFAULT_GEN2(sha3_224, SHA3_224); diff --git a/src/sha3-256.c b/src/c/hash/sha3-256.c similarity index 95% rename from src/sha3-256.c rename to src/c/hash/sha3-256.c index 707449a..f34a1da 100644 --- a/src/sha3-256.c +++ b/src/c/hash/sha3-256.c @@ -6,7 +6,8 @@ */ #include "sha3.h" -#include "templates.c" + +#include "backend/templates.h" __PGFE_FRONTEND_GEN2(sha3_256); __PGFE_FRONTEND_DEFAULT_GEN2(sha3_256, SHA3_256); diff --git a/src/sha3-384.c b/src/c/hash/sha3-384.c similarity index 95% rename from src/sha3-384.c rename to src/c/hash/sha3-384.c index 2db7dea..9bb2358 100644 --- a/src/sha3-384.c +++ b/src/c/hash/sha3-384.c @@ -6,7 +6,8 @@ */ #include "sha3.h" -#include "templates.c" + +#include "backend/templates.h" __PGFE_FRONTEND_GEN2(sha3_384); __PGFE_FRONTEND_DEFAULT_GEN2(sha3_384, SHA3_384); diff --git a/src/sha3-512.c b/src/c/hash/sha3-512.c similarity index 95% rename from src/sha3-512.c rename to src/c/hash/sha3-512.c index d92aaac..77be6b3 100644 --- a/src/sha3-512.c +++ b/src/c/hash/sha3-512.c @@ -6,7 +6,8 @@ */ #include "sha3.h" -#include "templates.c" + +#include "backend/templates.h" __PGFE_FRONTEND_GEN2(sha3_512); __PGFE_FRONTEND_DEFAULT_GEN2(sha3_512, SHA3_512); diff --git a/src/sha384.c b/src/c/hash/sha384.c similarity index 93% rename from src/sha384.c rename to src/c/hash/sha384.c index 15328a3..41db829 100644 --- a/src/sha384.c +++ b/src/c/hash/sha384.c @@ -7,8 +7,8 @@ #include "sha2.h" -#include "sha2-backend.h" -#include "templates.c" +#include "backend/sha2-backend.h" +#include "backend/templates.h" const pgfe_word_t __pgfe_sha384_H0[] = { 0xC1059ED8, 0xCBBB9D5D, 0x367CD507, 0x629A292A, 0x3070DD17, 0x9159015A, 0xF70E5939, 0x152FECD8, diff --git a/src/sha512.c b/src/c/hash/sha512.c similarity index 97% rename from src/sha512.c rename to src/c/hash/sha512.c index 9cd0b60..2e80ddf 100644 --- a/src/sha512.c +++ b/src/c/hash/sha512.c @@ -7,8 +7,8 @@ #include "sha2.h" -#include "sha2-backend.h" -#include "templates.c" +#include "backend/sha2-backend.h" +#include "backend/templates.h" const pgfe_word_t __pgfe_sha512_H0[] = { 0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85, 0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A, diff --git a/src/shake.c b/src/c/hash/shake.c similarity index 98% rename from src/shake.c rename to src/c/hash/shake.c index 7e0ab8f..94147e0 100644 --- a/src/shake.c +++ b/src/c/hash/shake.c @@ -7,7 +7,7 @@ #include "sha3.h" -#include "templates.c" +#include "backend/templates.h" // RawSHAKE128 diff --git a/src/hmac.c b/src/c/hmac/hmac.c similarity index 99% rename from src/hmac.c rename to src/c/hmac/hmac.c index 1e3f5af..29fe917 100644 --- a/src/hmac.c +++ b/src/c/hmac/hmac.c @@ -7,7 +7,7 @@ #include "hmac.h" -#include "generic-internal.h" +#include "backend/generic-internal.h" #define __pgfe_hmac_tmpl(name, upper) \ void pgfe_hmac_##name##_init(struct pgfe_hmac_##name##_ctx *ctx) { \ diff --git a/src/hotp.c b/src/c/otp/hotp.c similarity index 98% rename from src/hotp.c rename to src/c/otp/hotp.c index 2babd04..55cb125 100644 --- a/src/hotp.c +++ b/src/c/otp/hotp.c @@ -9,7 +9,7 @@ #include -#include "generic-internal.h" +#include "backend/generic-internal.h" #include "sha1.h" #define __PGFE_SET_SIZE_CASE_C(upper, lower) \ diff --git a/src/otp-generic.c b/src/c/otp/otp-generic.c similarity index 92% rename from src/otp-generic.c rename to src/c/otp/otp-generic.c index c415e47..e7cc515 100644 --- a/src/otp-generic.c +++ b/src/c/otp/otp-generic.c @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "otp-generic.h" +#include "backend/otp-generic.h" pgfe_otp_t pgfe_dynamically_truncate(const pgfe_encode_t hash[], size_t length) { uint8_t offset = hash[length - 1] & 0xF; diff --git a/src/totp.c b/src/c/otp/totp.c similarity index 98% rename from src/totp.c rename to src/c/otp/totp.c index 9a31f09..31450f8 100644 --- a/src/totp.c +++ b/src/c/otp/totp.c @@ -7,7 +7,7 @@ #include "totp.h" -#include "generic-internal.h" +#include "backend/generic-internal.h" #include "hotp.h" #include "sha1.h" #include "utils.h" diff --git a/src/utils.c b/src/c/utils.c similarity index 98% rename from src/utils.c rename to src/c/utils.c index 74f648e..598a863 100644 --- a/src/utils.c +++ b/src/c/utils.c @@ -7,7 +7,7 @@ #include "utils.h" -#include "generic-internal.h" +#include "backend/generic-internal.h" size_t pgfe_hash_to_hex_string(const pgfe_encode_t hash[], size_t hash_length, char out[]) { char *op = out, dual_hex[3]; diff --git a/src/algorithm_selectable.cpp b/src/cpp/algorithm_selectable.cpp similarity index 100% rename from src/algorithm_selectable.cpp rename to src/cpp/algorithm_selectable.cpp diff --git a/src/abstract_base_encoding.cpp b/src/cpp/base_encoding/abstract_base_encoding.cpp similarity index 98% rename from src/abstract_base_encoding.cpp rename to src/cpp/base_encoding/abstract_base_encoding.cpp index c2f13b9..016d152 100644 --- a/src/abstract_base_encoding.cpp +++ b/src/cpp/base_encoding/abstract_base_encoding.cpp @@ -8,7 +8,7 @@ #include #include -#include "abstract_base_encoding.hpp" +#include "backend_cpp/abstract_base_encoding.hpp" #define PGFE_SPACE_MULTIPLE 1.2 diff --git a/src/base16.cpp b/src/cpp/base_encoding/base16.cpp similarity index 100% rename from src/base16.cpp rename to src/cpp/base_encoding/base16.cpp diff --git a/src/base32.cpp b/src/cpp/base_encoding/base32.cpp similarity index 100% rename from src/base32.cpp rename to src/cpp/base_encoding/base32.cpp diff --git a/src/base64.cpp b/src/cpp/base_encoding/base64.cpp similarity index 100% rename from src/base64.cpp rename to src/cpp/base_encoding/base64.cpp diff --git a/src/generic.cpp b/src/cpp/generic.cpp similarity index 100% rename from src/generic.cpp rename to src/cpp/generic.cpp diff --git a/src/hash_encoder.cpp b/src/cpp/hash/hash_encoder.cpp similarity index 100% rename from src/hash_encoder.cpp rename to src/cpp/hash/hash_encoder.cpp diff --git a/src/hmac_encoder.cpp b/src/cpp/hmac/hmac_encoder.cpp similarity index 100% rename from src/hmac_encoder.cpp rename to src/cpp/hmac/hmac_encoder.cpp diff --git a/src/abstract_otp.cpp b/src/cpp/otp/abstract_otp.cpp similarity index 94% rename from src/abstract_otp.cpp rename to src/cpp/otp/abstract_otp.cpp index c088524..55c02ec 100644 --- a/src/abstract_otp.cpp +++ b/src/cpp/otp/abstract_otp.cpp @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "abstract_otp.hpp" +#include "backend_cpp/abstract_otp.hpp" #include diff --git a/src/hotp.cpp b/src/cpp/otp/hotp.cpp similarity index 100% rename from src/hotp.cpp rename to src/cpp/otp/hotp.cpp diff --git a/src/totp.cpp b/src/cpp/otp/totp.cpp similarity index 100% rename from src/totp.cpp rename to src/cpp/otp/totp.cpp diff --git a/src/sequential_data.cpp b/src/cpp/sequential_data.cpp similarity index 100% rename from src/sequential_data.cpp rename to src/cpp/sequential_data.cpp diff --git a/src/utils.cpp b/src/cpp/utils.cpp similarity index 100% rename from src/utils.cpp rename to src/cpp/utils.cpp From ccd390984445389ee5dd4d3629a14257825fc435 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 12:28:10 +0800 Subject: [PATCH 12/22] Update CMakeLists.txt --- CMakeLists.txt | 60 +++++++++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d82f6cc..ff43c2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,38 +16,38 @@ set(include_dir "include") set(test_dir "test") add_library(pgfe SHARED - ${src_dir}/c/generic.c - ${src_dir}/c/generic-internal.c - ${src_dir}/c/utils.c - ${src_dir}/c/hash/sha-internal.c - ${src_dir}/c/hash/sha2-backend.c - ${src_dir}/c/hash/keccak-backend.c - ${src_dir}/c/hash/md5-backend.c - ${src_dir}/c/hash/sha1.c ${src_dir}/c/hash/sha224.c ${src_dir}/c/hash/sha256.c ${src_dir}/c/hash/sha384.c ${src_dir}/c/hash/sha512.c - ${src_dir}/c/hash/sha3-224.c ${src_dir}/c/hash/sha3-256.c ${src_dir}/c/hash/sha3-384.c ${src_dir}/c/hash/sha3-512.c - ${src_dir}/c/hash/md5.c - ${src_dir}/c/hash/shake.c - ${src_dir}/c/hmac/hmac.c - ${src_dir}/c/otp/otp-generic.c - ${src_dir}/c/otp/hotp.c ${src_dir}/c/otp/totp.c - ${src_dir}/c/base_encoding/base-encoding-internal.c - ${src_dir}/c/base_encoding/base64.c ${src_dir}/c/base_encoding/base32.c ${src_dir}/c/base_encoding/base16.c - ${src_dir}/cpp/generic.cpp - ${src_dir}/cpp/sequential_data.cpp - ${src_dir}/cpp/utils.cpp - ${src_dir}/cpp/algorithm_selectable.cpp - ${src_dir}/cpp/hash/hash_encoder.cpp - ${src_dir}/cpp/hmac/hmac_encoder.cpp - ${src_dir}/cpp/base_encoding/abstract_base_encoding.cpp - ${src_dir}/cpp/base_encoding/base16.cpp - ${src_dir}/cpp/base_encoding/base32.cpp - ${src_dir}/cpp/base_encoding/base64.cpp - ${src_dir}/cpp/otp/abstract_otp.cpp - ${src_dir}/cpp/otp/hotp.cpp ${src_dir}/cpp/otp/totp.cpp) + ${src_dir}/c/generic.c + ${src_dir}/c/generic-internal.c + ${src_dir}/c/utils.c + ${src_dir}/c/hash/sha-internal.c + ${src_dir}/c/hash/sha2-backend.c + ${src_dir}/c/hash/keccak-backend.c + ${src_dir}/c/hash/md5-backend.c + ${src_dir}/c/hash/sha1.c ${src_dir}/c/hash/sha224.c ${src_dir}/c/hash/sha256.c ${src_dir}/c/hash/sha384.c ${src_dir}/c/hash/sha512.c + ${src_dir}/c/hash/sha3-224.c ${src_dir}/c/hash/sha3-256.c ${src_dir}/c/hash/sha3-384.c ${src_dir}/c/hash/sha3-512.c + ${src_dir}/c/hash/md5.c + ${src_dir}/c/hash/shake.c + ${src_dir}/c/hmac/hmac.c + ${src_dir}/c/otp/otp-generic.c + ${src_dir}/c/otp/hotp.c ${src_dir}/c/otp/totp.c + ${src_dir}/c/base_encoding/base-encoding-internal.c + ${src_dir}/c/base_encoding/base64.c ${src_dir}/c/base_encoding/base32.c ${src_dir}/c/base_encoding/base16.c + ${src_dir}/cpp/generic.cpp + ${src_dir}/cpp/sequential_data.cpp + ${src_dir}/cpp/utils.cpp + ${src_dir}/cpp/algorithm_selectable.cpp + ${src_dir}/cpp/hash/hash_encoder.cpp + ${src_dir}/cpp/hmac/hmac_encoder.cpp + ${src_dir}/cpp/base_encoding/abstract_base_encoding.cpp + ${src_dir}/cpp/base_encoding/base16.cpp + ${src_dir}/cpp/base_encoding/base32.cpp + ${src_dir}/cpp/base_encoding/base64.cpp + ${src_dir}/cpp/otp/abstract_otp.cpp + ${src_dir}/cpp/otp/hotp.cpp ${src_dir}/cpp/otp/totp.cpp) add_executable(pgfetest ${test_dir}/test.c) +add_executable(pgfetestcpp ${test_dir}/test.cpp) # add_executable(totptest ${test_dir}/totptest.c) # add_executable(totptestcpp ${test_dir}/totptest.cpp) -add_executable(pgfetestcpp ${test_dir}/test.cpp) target_include_directories(pgfe PRIVATE ${src_dir} @@ -55,8 +55,8 @@ target_include_directories(pgfe PRIVATE ) target_link_libraries(pgfetest pgfe) -# target_link_libraries(totptest pgfe) target_link_libraries(pgfetestcpp pgfe) +# target_link_libraries(totptest pgfe) # target_link_libraries(totptestcpp pgfe) include(${test_dir}/cmake/test_meta.cmake) From df20d81d98a09cc3e59a409673b1bd7aabc3732c Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 12:31:47 +0800 Subject: [PATCH 13/22] Update CMakeLists.txt --- CMakeLists.txt | 58 ++++++++++++++++++++++++++------------------------ 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index ff43c2a..d02373d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -12,38 +12,40 @@ include(CTest) enable_testing() set(src_dir "src") +set(src_c_dir "${src_dir}/c") +set(src_cpp_dir "${src_dir}/cpp") set(include_dir "include") set(test_dir "test") add_library(pgfe SHARED - ${src_dir}/c/generic.c - ${src_dir}/c/generic-internal.c - ${src_dir}/c/utils.c - ${src_dir}/c/hash/sha-internal.c - ${src_dir}/c/hash/sha2-backend.c - ${src_dir}/c/hash/keccak-backend.c - ${src_dir}/c/hash/md5-backend.c - ${src_dir}/c/hash/sha1.c ${src_dir}/c/hash/sha224.c ${src_dir}/c/hash/sha256.c ${src_dir}/c/hash/sha384.c ${src_dir}/c/hash/sha512.c - ${src_dir}/c/hash/sha3-224.c ${src_dir}/c/hash/sha3-256.c ${src_dir}/c/hash/sha3-384.c ${src_dir}/c/hash/sha3-512.c - ${src_dir}/c/hash/md5.c - ${src_dir}/c/hash/shake.c - ${src_dir}/c/hmac/hmac.c - ${src_dir}/c/otp/otp-generic.c - ${src_dir}/c/otp/hotp.c ${src_dir}/c/otp/totp.c - ${src_dir}/c/base_encoding/base-encoding-internal.c - ${src_dir}/c/base_encoding/base64.c ${src_dir}/c/base_encoding/base32.c ${src_dir}/c/base_encoding/base16.c - ${src_dir}/cpp/generic.cpp - ${src_dir}/cpp/sequential_data.cpp - ${src_dir}/cpp/utils.cpp - ${src_dir}/cpp/algorithm_selectable.cpp - ${src_dir}/cpp/hash/hash_encoder.cpp - ${src_dir}/cpp/hmac/hmac_encoder.cpp - ${src_dir}/cpp/base_encoding/abstract_base_encoding.cpp - ${src_dir}/cpp/base_encoding/base16.cpp - ${src_dir}/cpp/base_encoding/base32.cpp - ${src_dir}/cpp/base_encoding/base64.cpp - ${src_dir}/cpp/otp/abstract_otp.cpp - ${src_dir}/cpp/otp/hotp.cpp ${src_dir}/cpp/otp/totp.cpp) + ${src_c_dir}/generic.c + ${src_c_dir}/generic-internal.c + ${src_c_dir}/utils.c + ${src_c_dir}/hash/sha-internal.c + ${src_c_dir}/hash/sha2-backend.c + ${src_c_dir}/hash/keccak-backend.c + ${src_c_dir}/hash/md5-backend.c + ${src_c_dir}/hash/sha1.c ${src_c_dir}/hash/sha224.c ${src_c_dir}/hash/sha256.c ${src_c_dir}/hash/sha384.c ${src_c_dir}/hash/sha512.c + ${src_c_dir}/hash/sha3-224.c ${src_c_dir}/hash/sha3-256.c ${src_c_dir}/hash/sha3-384.c ${src_c_dir}/hash/sha3-512.c + ${src_c_dir}/hash/md5.c + ${src_c_dir}/hash/shake.c + ${src_c_dir}/hmac/hmac.c + ${src_c_dir}/otp/otp-generic.c + ${src_c_dir}/otp/hotp.c ${src_c_dir}/otp/totp.c + ${src_c_dir}/base_encoding/base-encoding-internal.c + ${src_c_dir}/base_encoding/base64.c ${src_c_dir}/base_encoding/base32.c ${src_c_dir}/base_encoding/base16.c + ${src_cpp_dir}/generic.cpp + ${src_cpp_dir}/sequential_data.cpp + ${src_cpp_dir}/utils.cpp + ${src_cpp_dir}/algorithm_selectable.cpp + ${src_cpp_dir}/hash/hash_encoder.cpp + ${src_cpp_dir}/hmac/hmac_encoder.cpp + ${src_cpp_dir}/base_encoding/abstract_base_encoding.cpp + ${src_cpp_dir}/base_encoding/base16.cpp + ${src_cpp_dir}/base_encoding/base32.cpp + ${src_cpp_dir}/base_encoding/base64.cpp + ${src_cpp_dir}/otp/abstract_otp.cpp + ${src_cpp_dir}/otp/hotp.cpp ${src_cpp_dir}/otp/totp.cpp) add_executable(pgfetest ${test_dir}/test.c) add_executable(pgfetestcpp ${test_dir}/test.cpp) # add_executable(totptest ${test_dir}/totptest.c) From 2edc341f1cd8def9d8dc9eebe2958dbfae2048d5 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 12:38:01 +0800 Subject: [PATCH 14/22] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 964c324..e9aff11 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,9 @@ *libpgfe* currently supports hash encoding (e.g. SHA256, MD5), HMAC encoding, HOTP/TOTP and Base 16/32/64. -| Item | Content | +*libpgfe* is currently under heavy development, more features and optimization will be added in the future. + +| Entry | Info | | :----------- | :------------------ | | C Standard | [C11 (ISO/IEC 9899:2011)](https://en.wikipedia.org/wiki/C11_(C_standard_revision)) | | C++ Standard | [C++14 (ISO/IEC 14882:2014)](https://en.wikipedia.org/wiki/C++14) | From 2e3e2f57813821be0a821ef71402f83498f4bcb7 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 13:12:42 +0800 Subject: [PATCH 15/22] Update info --- .github/qna.md | 14 +++++++++++--- README.md | 4 +--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.github/qna.md b/.github/qna.md index dab3a96..5584076 100644 --- a/.github/qna.md +++ b/.github/qna.md @@ -11,13 +11,21 @@ Since v0.2.0, *libpgfe* has been "self-sufficient" and does not depend on any th I will think about it eventually, but not now! Because byte order compatibility will dramatically increase complexity of the code, and I currently don't have enough time or effort to tackle it. Also, I do not have Big Endian machines or virtual machines, so the additional code would be left untested, which is what I don't want to happen. -## Q3: Why not MSVC? +## Q3: Why not [Assembly Language](https://en.wikipedia.org/wiki/Assembly_language)? + +1. I'm not familiar with Assembly. + +2. Assembly is machine-dependent. + +3. C is fast enough for *libpgfe*. It's no need to use Assembly to do those optimizations. + +## Q4: Why not MSVC? > ***PS:** MSVC = Microsoft Visual C++* -Firstly, this library prioritizes POSIX compatibility, instead of Windows compatibility. +1. This library prioritizes POSIX compatibility, instead of Windows compatibility. -Secondly, *libpgfe* needs some necessary features that are not included in *MSVC*. For instance, like the C code below: +2. *libpgfe* needs some necessary features that are not included in *MSVC*. For instance, like the C code below: ```c int main() { diff --git a/README.md b/README.md index e9aff11..8cc6d5c 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,7 @@ [*Any questions?*](.github/qna.md) -## Endianness (Byte order) - -> [*What is it anyway??*](https://en.wikipedia.org/wiki/Endianness) +## [Endianness (Byte order)](https://en.wikipedia.org/wiki/Endianness) The implementation philosophy of *libpgfe* assumes that the systems running this library are **Little Endian**, since it is widely used by architectures and OS. Therefore, this library should not run properly on Big Endian systems. From 877e1d05442e818863437c9bfae35ecd953e6d41 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 13:14:35 +0800 Subject: [PATCH 16/22] Update qna.md --- .github/qna.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.github/qna.md b/.github/qna.md index 5584076..6a062f0 100644 --- a/.github/qna.md +++ b/.github/qna.md @@ -25,7 +25,7 @@ and I currently don't have enough time or effort to tackle it. Also, I do not ha 1. This library prioritizes POSIX compatibility, instead of Windows compatibility. -2. *libpgfe* needs some necessary features that are not included in *MSVC*. For instance, like the C code below: +2. *libpgfe* needs some necessary features that are not included in *MSVC*. For instance, like the C code below. *MSVC* will refuse to compile that code, because a variable is used as the array's size, while *Clang* and *GCC* are OK with it. ```c int main() { @@ -35,5 +35,3 @@ int main() { return 0; } ``` - -*MSVC* will refuse to compile that code, because a variable is used as the array's size, while *Clang* and *GCC* are OK with it. From 5d1dd2e3c01c2fead6e51e11fe7e62b8bb0e5f0b Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 13:16:53 +0800 Subject: [PATCH 17/22] Update qna.md --- .github/qna.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/qna.md b/.github/qna.md index 6a062f0..89c4435 100644 --- a/.github/qna.md +++ b/.github/qna.md @@ -9,7 +9,7 @@ Since v0.2.0, *libpgfe* has been "self-sufficient" and does not depend on any th ## Q2: Interested in supporting Big Endian? I will think about it eventually, but not now! Because byte order compatibility will dramatically increase complexity of the code, -and I currently don't have enough time or effort to tackle it. Also, I do not have Big Endian machines or virtual machines, so the additional code would be left untested, which is what I don't want to happen. +and I currently don't have enough time or effort to tackle it. Also, I do not have Big Endian machines or virtual machines, so the additional code would be left untested, which is what I don't expect. ## Q3: Why not [Assembly Language](https://en.wikipedia.org/wiki/Assembly_language)? From a3f2f465e2568d7b5ca60285f3b22ccdeecdf470 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 13:17:53 +0800 Subject: [PATCH 18/22] Update info content --- .github/qna.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/qna.md b/.github/qna.md index 89c4435..cec4f98 100644 --- a/.github/qna.md +++ b/.github/qna.md @@ -9,7 +9,7 @@ Since v0.2.0, *libpgfe* has been "self-sufficient" and does not depend on any th ## Q2: Interested in supporting Big Endian? I will think about it eventually, but not now! Because byte order compatibility will dramatically increase complexity of the code, -and I currently don't have enough time or effort to tackle it. Also, I do not have Big Endian machines or virtual machines, so the additional code would be left untested, which is what I don't expect. +and I currently don't have enough time or effort to tackle it. Also, I do not have Big Endian machines or virtual machines, so the additional code would be left untested, which is not what I expect. ## Q3: Why not [Assembly Language](https://en.wikipedia.org/wiki/Assembly_language)? From 3372e374d785466f15a9dd6643b1c37e2caa560d Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 14:07:32 +0800 Subject: [PATCH 19/22] Add comment header --- src/cpp/algorithm_selectable.cpp | 7 +++++++ src/cpp/generic.cpp | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/src/cpp/algorithm_selectable.cpp b/src/cpp/algorithm_selectable.cpp index 7f6e1b9..2993c0f 100644 --- a/src/cpp/algorithm_selectable.cpp +++ b/src/cpp/algorithm_selectable.cpp @@ -1,3 +1,10 @@ +/* + libpgfe + algorithm_selectable.cpp + + Copyright (c) 2022 Charles Dong +*/ + #include "algorithm_selectable.hpp" using namespace chardon55::PGFE; diff --git a/src/cpp/generic.cpp b/src/cpp/generic.cpp index 97821d6..5df02ba 100644 --- a/src/cpp/generic.cpp +++ b/src/cpp/generic.cpp @@ -1,3 +1,10 @@ +/* + libpgfe + generic.cpp + + Copyright (c) 2022 Charles Dong +*/ + #ifndef LIBPGFE_GENERIC_CPP #define LIBPGFE_GENERIC_CPP From ff85b51f390fda4e35c91d41ed9a778c5a677418 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 14:07:40 +0800 Subject: [PATCH 20/22] Update metadata --- Makefile | 2 +- include/{meta.h => version.h} | 10 ++--- meta.mak => metadata.mak | 0 project.json | 4 ++ scripts/{comment_header.py => comment_header} | 13 +++--- scripts/{deploy.py => deploy} | 26 ++++++----- scripts/metadata.mak.in | 15 +++++++ scripts/update_meta | 37 ++++++++++++++++ scripts/update_meta.py | 43 ------------------- scripts/version.h.template | 11 +++++ 10 files changed, 97 insertions(+), 64 deletions(-) rename include/{meta.h => version.h} (67%) rename meta.mak => metadata.mak (100%) create mode 100644 project.json rename scripts/{comment_header.py => comment_header} (77%) mode change 100644 => 100755 rename scripts/{deploy.py => deploy} (79%) mode change 100644 => 100755 create mode 100644 scripts/metadata.mak.in create mode 100755 scripts/update_meta delete mode 100644 scripts/update_meta.py create mode 100644 scripts/version.h.template diff --git a/Makefile b/Makefile index b9d3b3b..d93e37b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -include meta.mak +include metadata.mak .PHONY: all rebuild clean test install uninstall diff --git a/include/meta.h b/include/version.h similarity index 67% rename from include/meta.h rename to include/version.h index e5aa612..dbbbc2d 100644 --- a/include/meta.h +++ b/include/version.h @@ -1,18 +1,18 @@ /* libpgfe - meta.h + version.h Copyright (c) 2022 Charles Dong */ -#ifndef LIBPGFE_META_H -#define LIBPGFE_META_H - -#define LIBPGFE_NAME "libpgfe" +#ifndef LIBPGFE_VERSION_H +#define LIBPGFE_VERSION_H #define LIBPGFE_MAJOR_VERSION 0 #define LIBPGFE_MINOR_VERSION 5 #define LIBPGFE_REVISION 0 +#define LIBPGFE_VARIANT #define LIBPGFE_VERSION "0.5.0" + #endif diff --git a/meta.mak b/metadata.mak similarity index 100% rename from meta.mak rename to metadata.mak diff --git a/project.json b/project.json new file mode 100644 index 0000000..fca74ae --- /dev/null +++ b/project.json @@ -0,0 +1,4 @@ +{ + "name": "libpgfe", + "version": "0.5.0" +} \ No newline at end of file diff --git a/scripts/comment_header.py b/scripts/comment_header old mode 100644 new mode 100755 similarity index 77% rename from scripts/comment_header.py rename to scripts/comment_header index 19e658d..c0340d4 --- a/scripts/comment_header.py +++ b/scripts/comment_header @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + from pathlib import Path import sys @@ -24,7 +26,7 @@ def add_comment_header(file: Path): print(f"Updated {file}") -def iter_dir(path_item: Path): +def iter_dir(path_item: Path, inside_subdir=False): if not path_item.exists(): return @@ -32,10 +34,10 @@ def iter_dir(path_item: Path): add_comment_header(path_item) else: for item in path_item.iterdir(): - if item.is_dir() and item.name in INCLUDE_SUBDIR: - iter_dir(item) + if item.is_dir() and (item.name in INCLUDE_SUBDIR or inside_subdir): + iter_dir(item, inside_subdir=True) continue - + if item.name.split('.')[-1] in EXTS: add_comment_header(item) @@ -44,5 +46,6 @@ def main(args): if len(args) > 0: iter_dir(Path(args[0])) + if __name__ == "__main__": - main(sys.argv[1:]) \ No newline at end of file + main(sys.argv[1:]) diff --git a/scripts/deploy.py b/scripts/deploy old mode 100644 new mode 100755 similarity index 79% rename from scripts/deploy.py rename to scripts/deploy index 0dba1ac..60f1097 --- a/scripts/deploy.py +++ b/scripts/deploy @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + from argparse import ArgumentParser import os from glob import glob @@ -8,20 +10,21 @@ SHARED_LIB = "libpgfe.so" LIB_DIR = "./build" + def main(args): if args.uninstall: for ds in args.header_dir: _dir = Path(ds) / HEADER_ROOT if not _dir.exists(): continue - + shutil.rmtree(_dir) - + for ss in args.lib_dir: _dir = Path(ss) if not _dir.exists(): continue - + os.remove(_dir / SHARED_LIB) else: @@ -29,23 +32,26 @@ def main(args): _dir = Path(ds) / HEADER_ROOT if not _dir.exists(): _dir.mkdir(parents=True) - + for f in glob(r'./*.h'): shutil.copy(f, _dir) - + for f in glob(r'./*.hpp'): shutil.copy(f, _dir) - + for ss in args.lib_dir: _dir = Path(ss) if not _dir.exists(): _dir.mkdir(parents=True) - + shutil.copy(str(Path(LIB_DIR, SHARED_LIB)), _dir) + if __name__ == '__main__': ap = ArgumentParser() - ap.add_argument("-h", "--header-dir", required=True, nargs='*', action='extend', default=[]) - ap.add_argument("-l", "--lib-dir", required=True, nargs='*', action='extend', default=[]) + ap.add_argument("-h", "--header-dir", required=True, + nargs='*', action='extend', default=[]) + ap.add_argument("-l", "--lib-dir", required=True, + nargs='*', action='extend', default=[]) ap.add_argument("-u", "--uninstall", action='store_true') - main(ap.parse_args()) \ No newline at end of file + main(ap.parse_args()) diff --git a/scripts/metadata.mak.in b/scripts/metadata.mak.in new file mode 100644 index 0000000..8a9c71c --- /dev/null +++ b/scripts/metadata.mak.in @@ -0,0 +1,15 @@ +PROJECT := {name} +VERSION := {version} + +BUILD_DIR := build + +INCLUDE_DIR := include +SRC_DIR := src + +HEADER_DIR := /usr/local/include/libpgfe +LIB_DIR := /usr/lib +TARGET_DIR := $(BUILD_DIR) +TARGET_FILE := $(PROJECT).so + +TARGET := $(TARGET_DIR)/$(TARGET_FILE) +TEST_TARGET := $(TARGET_DIR)/$(TEST_BIN) \ No newline at end of file diff --git a/scripts/update_meta b/scripts/update_meta new file mode 100755 index 0000000..48c92d1 --- /dev/null +++ b/scripts/update_meta @@ -0,0 +1,37 @@ +#!/usr/bin/env python3 + +import json + + +FILES = { + "scripts/metadata.mak.in": "metadata.mak", + "scripts/version.h.template": "include/version.h", +} + + +def main(): + p = {} + with open("project.json") as fp: + p = json.load(fp) + + name = p['name'] + version = p['version'] + version_list = [int(i) for i in version.split('-')[0].split('.')] + + info = { + "name": name, + "version": version, + "major_version": version_list[0], + "minor_version": version_list[1], + "revision": version_list[2], + "variant": '-'.join(version.split('-')[1:]), + } + + for src, dest in FILES.items(): + with open(src, 'r') as s_fp: + with open(dest, 'w') as d_fp: + d_fp.write(s_fp.read().format(**info)) + + +if __name__ == '__main__': + main() diff --git a/scripts/update_meta.py b/scripts/update_meta.py deleted file mode 100644 index 68fff5f..0000000 --- a/scripts/update_meta.py +++ /dev/null @@ -1,43 +0,0 @@ -import sys - -import json - - -def main(args): - p = {} - with open(args[0]) as fp: - p = json.load(fp) - - name = p['name'] - version = p['version'] - version_list = [int(i) for i in version.split('.')] - - with open('meta.mak', 'w') as f: - f.write(f'''\ -PROJECT := {name} -VERSION := {version} - -BUILD_DIR := build -TARGET_DIR := $(BUILD_DIR)/bin -''') - - nameuc = name.upper() - - with open('meta.h', 'w') as f: - f.write(f'''\ -#ifndef {nameuc}_META_H -#define {nameuc}_META_H - -#define {nameuc}_NAME "{name}" - -#define {nameuc}_MAJOR_VERSION {version_list[0]} -#define {nameuc}_MINOR_VERSION {version_list[1]} -#define {nameuc}_REVISION {version_list[2]} - -#define {nameuc}_VERSION "{version}" -#endif - ''') - - -if __name__ == '__main__': - main(sys.argv[1:]) diff --git a/scripts/version.h.template b/scripts/version.h.template new file mode 100644 index 0000000..f921ca9 --- /dev/null +++ b/scripts/version.h.template @@ -0,0 +1,11 @@ +#ifndef LIBPGFE_VERSION_H +#define LIBPGFE_VERSION_H + +#define LIBPGFE_MAJOR_VERSION {major_version} +#define LIBPGFE_MINOR_VERSION {minor_version} +#define LIBPGFE_REVISION {revision} +#define LIBPGFE_VARIANT {variant} + +#define LIBPGFE_VERSION "{version}" + +#endif From 1e76e4e2bcc302d5344f04f8e2df04a6aa9d5ca1 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 14:09:34 +0800 Subject: [PATCH 21/22] Bug fix --- include/version.h | 2 +- scripts/version.h.template | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/include/version.h b/include/version.h index dbbbc2d..1d99022 100644 --- a/include/version.h +++ b/include/version.h @@ -11,7 +11,7 @@ #define LIBPGFE_MAJOR_VERSION 0 #define LIBPGFE_MINOR_VERSION 5 #define LIBPGFE_REVISION 0 -#define LIBPGFE_VARIANT +#define LIBPGFE_VARIANT "" #define LIBPGFE_VERSION "0.5.0" diff --git a/scripts/version.h.template b/scripts/version.h.template index f921ca9..f53ec14 100644 --- a/scripts/version.h.template +++ b/scripts/version.h.template @@ -4,7 +4,7 @@ #define LIBPGFE_MAJOR_VERSION {major_version} #define LIBPGFE_MINOR_VERSION {minor_version} #define LIBPGFE_REVISION {revision} -#define LIBPGFE_VARIANT {variant} +#define LIBPGFE_VARIANT "{variant}" #define LIBPGFE_VERSION "{version}" From 83aa7192c8b4490267e3eb177ca922d255dfa284 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 30 Oct 2022 14:13:33 +0800 Subject: [PATCH 22/22] Update Makefile --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index d93e37b..1d493f7 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ include metadata.mak -.PHONY: all rebuild clean test install uninstall +.PHONY: all rebuild clean test install uninstall init-scripts all: @echo 'Building...' @@ -37,3 +37,6 @@ uninstall: @echo 'Removing shared library...' @rm -vrf $(LIB_DIR)/$(TARGET_FILE) @echo done + +init-scripts: + @chmod u+x ./scripts/{comment_header,update_meta,deploy}