From ee79480faec65a06509cb6b1ee3d25b7ba1e660b Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sat, 27 May 2023 23:34:27 +0800 Subject: [PATCH 1/8] Move headers --- include/libpgfe/advanced.h | 0 include/libpgfe/advanced.hpp | 0 .../libpgfe/{ => advanced}/abstract_symmetric_crypter.hpp | 0 include/libpgfe/{ => advanced}/blowfish.h | 0 include/libpgfe/{ => advanced}/blowfish.hpp | 0 include/libpgfe/all.h | 8 ++++++++ include/libpgfe/all.hpp | 0 include/libpgfe/core.h | 0 include/libpgfe/core.hpp | 0 include/libpgfe/{ => core}/abstract_encoder.hpp | 0 include/libpgfe/{ => core}/algorithm-choice.h | 0 include/libpgfe/{ => core}/algorithm_selectable.hpp | 0 .../libpgfe/{ => core/bases}/abstract_base_encoding.hpp | 0 include/libpgfe/{ => core/bases}/base-encoding.h | 0 include/libpgfe/{ => core/bases}/base16.hpp | 0 include/libpgfe/{ => core/bases}/base32.hpp | 0 include/libpgfe/{ => core/bases}/base64.hpp | 0 include/libpgfe/{ => core}/exceptions.hpp | 0 include/libpgfe/{ => core}/generic.h | 0 include/libpgfe/{ => core}/generic.hpp | 0 .../libpgfe/{ => core/hashes}/abstract_hash_encoder.hpp | 0 include/libpgfe/{ => core/hashes}/hash_encoder.hpp | 0 include/libpgfe/{ => core/hashes}/md5.h | 0 include/libpgfe/{ => core/hashes}/sha1.h | 0 include/libpgfe/{ => core/hashes}/sha2.h | 0 include/libpgfe/{ => core/hashes}/sha3.h | 0 include/libpgfe/{ => core/hmac}/hmac.h | 0 include/libpgfe/{ => core/hmac}/hmac_encoder.hpp | 0 include/libpgfe/{ => core}/sequential_data.hpp | 0 include/libpgfe/{ => core}/utils.h | 0 include/libpgfe/{ => core}/utils.hpp | 0 include/libpgfe/{ => otp}/abstract_otp.hpp | 0 include/libpgfe/{ => otp}/hotp.h | 0 include/libpgfe/{ => otp}/hotp.hpp | 0 include/libpgfe/otp/otp.h | 0 include/libpgfe/otp/otp.hpp | 0 include/libpgfe/{ => otp}/otp_types.h | 0 include/libpgfe/{ => otp}/totp.h | 0 include/libpgfe/{ => otp}/totp.hpp | 0 39 files changed, 8 insertions(+) create mode 100644 include/libpgfe/advanced.h create mode 100644 include/libpgfe/advanced.hpp rename include/libpgfe/{ => advanced}/abstract_symmetric_crypter.hpp (100%) rename include/libpgfe/{ => advanced}/blowfish.h (100%) rename include/libpgfe/{ => advanced}/blowfish.hpp (100%) create mode 100644 include/libpgfe/all.h create mode 100644 include/libpgfe/all.hpp create mode 100644 include/libpgfe/core.h create mode 100644 include/libpgfe/core.hpp rename include/libpgfe/{ => core}/abstract_encoder.hpp (100%) rename include/libpgfe/{ => core}/algorithm-choice.h (100%) rename include/libpgfe/{ => core}/algorithm_selectable.hpp (100%) rename include/libpgfe/{ => core/bases}/abstract_base_encoding.hpp (100%) rename include/libpgfe/{ => core/bases}/base-encoding.h (100%) rename include/libpgfe/{ => core/bases}/base16.hpp (100%) rename include/libpgfe/{ => core/bases}/base32.hpp (100%) rename include/libpgfe/{ => core/bases}/base64.hpp (100%) rename include/libpgfe/{ => core}/exceptions.hpp (100%) rename include/libpgfe/{ => core}/generic.h (100%) rename include/libpgfe/{ => core}/generic.hpp (100%) rename include/libpgfe/{ => core/hashes}/abstract_hash_encoder.hpp (100%) rename include/libpgfe/{ => core/hashes}/hash_encoder.hpp (100%) rename include/libpgfe/{ => core/hashes}/md5.h (100%) rename include/libpgfe/{ => core/hashes}/sha1.h (100%) rename include/libpgfe/{ => core/hashes}/sha2.h (100%) rename include/libpgfe/{ => core/hashes}/sha3.h (100%) rename include/libpgfe/{ => core/hmac}/hmac.h (100%) rename include/libpgfe/{ => core/hmac}/hmac_encoder.hpp (100%) rename include/libpgfe/{ => core}/sequential_data.hpp (100%) rename include/libpgfe/{ => core}/utils.h (100%) rename include/libpgfe/{ => core}/utils.hpp (100%) rename include/libpgfe/{ => otp}/abstract_otp.hpp (100%) rename include/libpgfe/{ => otp}/hotp.h (100%) rename include/libpgfe/{ => otp}/hotp.hpp (100%) create mode 100644 include/libpgfe/otp/otp.h create mode 100644 include/libpgfe/otp/otp.hpp rename include/libpgfe/{ => otp}/otp_types.h (100%) rename include/libpgfe/{ => otp}/totp.h (100%) rename include/libpgfe/{ => otp}/totp.hpp (100%) diff --git a/include/libpgfe/advanced.h b/include/libpgfe/advanced.h new file mode 100644 index 0000000..e69de29 diff --git a/include/libpgfe/advanced.hpp b/include/libpgfe/advanced.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/libpgfe/abstract_symmetric_crypter.hpp b/include/libpgfe/advanced/abstract_symmetric_crypter.hpp similarity index 100% rename from include/libpgfe/abstract_symmetric_crypter.hpp rename to include/libpgfe/advanced/abstract_symmetric_crypter.hpp diff --git a/include/libpgfe/blowfish.h b/include/libpgfe/advanced/blowfish.h similarity index 100% rename from include/libpgfe/blowfish.h rename to include/libpgfe/advanced/blowfish.h diff --git a/include/libpgfe/blowfish.hpp b/include/libpgfe/advanced/blowfish.hpp similarity index 100% rename from include/libpgfe/blowfish.hpp rename to include/libpgfe/advanced/blowfish.hpp diff --git a/include/libpgfe/all.h b/include/libpgfe/all.h new file mode 100644 index 0000000..37c6bc4 --- /dev/null +++ b/include/libpgfe/all.h @@ -0,0 +1,8 @@ +// Core feature +#include "libpgfe/core.h" + +// OTP feature +#include "libpgfe/otp.h" + +// Advanced feature +#include "libpgfe/advanced.h" \ No newline at end of file diff --git a/include/libpgfe/all.hpp b/include/libpgfe/all.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/libpgfe/core.h b/include/libpgfe/core.h new file mode 100644 index 0000000..e69de29 diff --git a/include/libpgfe/core.hpp b/include/libpgfe/core.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/libpgfe/abstract_encoder.hpp b/include/libpgfe/core/abstract_encoder.hpp similarity index 100% rename from include/libpgfe/abstract_encoder.hpp rename to include/libpgfe/core/abstract_encoder.hpp diff --git a/include/libpgfe/algorithm-choice.h b/include/libpgfe/core/algorithm-choice.h similarity index 100% rename from include/libpgfe/algorithm-choice.h rename to include/libpgfe/core/algorithm-choice.h diff --git a/include/libpgfe/algorithm_selectable.hpp b/include/libpgfe/core/algorithm_selectable.hpp similarity index 100% rename from include/libpgfe/algorithm_selectable.hpp rename to include/libpgfe/core/algorithm_selectable.hpp diff --git a/include/libpgfe/abstract_base_encoding.hpp b/include/libpgfe/core/bases/abstract_base_encoding.hpp similarity index 100% rename from include/libpgfe/abstract_base_encoding.hpp rename to include/libpgfe/core/bases/abstract_base_encoding.hpp diff --git a/include/libpgfe/base-encoding.h b/include/libpgfe/core/bases/base-encoding.h similarity index 100% rename from include/libpgfe/base-encoding.h rename to include/libpgfe/core/bases/base-encoding.h diff --git a/include/libpgfe/base16.hpp b/include/libpgfe/core/bases/base16.hpp similarity index 100% rename from include/libpgfe/base16.hpp rename to include/libpgfe/core/bases/base16.hpp diff --git a/include/libpgfe/base32.hpp b/include/libpgfe/core/bases/base32.hpp similarity index 100% rename from include/libpgfe/base32.hpp rename to include/libpgfe/core/bases/base32.hpp diff --git a/include/libpgfe/base64.hpp b/include/libpgfe/core/bases/base64.hpp similarity index 100% rename from include/libpgfe/base64.hpp rename to include/libpgfe/core/bases/base64.hpp diff --git a/include/libpgfe/exceptions.hpp b/include/libpgfe/core/exceptions.hpp similarity index 100% rename from include/libpgfe/exceptions.hpp rename to include/libpgfe/core/exceptions.hpp diff --git a/include/libpgfe/generic.h b/include/libpgfe/core/generic.h similarity index 100% rename from include/libpgfe/generic.h rename to include/libpgfe/core/generic.h diff --git a/include/libpgfe/generic.hpp b/include/libpgfe/core/generic.hpp similarity index 100% rename from include/libpgfe/generic.hpp rename to include/libpgfe/core/generic.hpp diff --git a/include/libpgfe/abstract_hash_encoder.hpp b/include/libpgfe/core/hashes/abstract_hash_encoder.hpp similarity index 100% rename from include/libpgfe/abstract_hash_encoder.hpp rename to include/libpgfe/core/hashes/abstract_hash_encoder.hpp diff --git a/include/libpgfe/hash_encoder.hpp b/include/libpgfe/core/hashes/hash_encoder.hpp similarity index 100% rename from include/libpgfe/hash_encoder.hpp rename to include/libpgfe/core/hashes/hash_encoder.hpp diff --git a/include/libpgfe/md5.h b/include/libpgfe/core/hashes/md5.h similarity index 100% rename from include/libpgfe/md5.h rename to include/libpgfe/core/hashes/md5.h diff --git a/include/libpgfe/sha1.h b/include/libpgfe/core/hashes/sha1.h similarity index 100% rename from include/libpgfe/sha1.h rename to include/libpgfe/core/hashes/sha1.h diff --git a/include/libpgfe/sha2.h b/include/libpgfe/core/hashes/sha2.h similarity index 100% rename from include/libpgfe/sha2.h rename to include/libpgfe/core/hashes/sha2.h diff --git a/include/libpgfe/sha3.h b/include/libpgfe/core/hashes/sha3.h similarity index 100% rename from include/libpgfe/sha3.h rename to include/libpgfe/core/hashes/sha3.h diff --git a/include/libpgfe/hmac.h b/include/libpgfe/core/hmac/hmac.h similarity index 100% rename from include/libpgfe/hmac.h rename to include/libpgfe/core/hmac/hmac.h diff --git a/include/libpgfe/hmac_encoder.hpp b/include/libpgfe/core/hmac/hmac_encoder.hpp similarity index 100% rename from include/libpgfe/hmac_encoder.hpp rename to include/libpgfe/core/hmac/hmac_encoder.hpp diff --git a/include/libpgfe/sequential_data.hpp b/include/libpgfe/core/sequential_data.hpp similarity index 100% rename from include/libpgfe/sequential_data.hpp rename to include/libpgfe/core/sequential_data.hpp diff --git a/include/libpgfe/utils.h b/include/libpgfe/core/utils.h similarity index 100% rename from include/libpgfe/utils.h rename to include/libpgfe/core/utils.h diff --git a/include/libpgfe/utils.hpp b/include/libpgfe/core/utils.hpp similarity index 100% rename from include/libpgfe/utils.hpp rename to include/libpgfe/core/utils.hpp diff --git a/include/libpgfe/abstract_otp.hpp b/include/libpgfe/otp/abstract_otp.hpp similarity index 100% rename from include/libpgfe/abstract_otp.hpp rename to include/libpgfe/otp/abstract_otp.hpp diff --git a/include/libpgfe/hotp.h b/include/libpgfe/otp/hotp.h similarity index 100% rename from include/libpgfe/hotp.h rename to include/libpgfe/otp/hotp.h diff --git a/include/libpgfe/hotp.hpp b/include/libpgfe/otp/hotp.hpp similarity index 100% rename from include/libpgfe/hotp.hpp rename to include/libpgfe/otp/hotp.hpp diff --git a/include/libpgfe/otp/otp.h b/include/libpgfe/otp/otp.h new file mode 100644 index 0000000..e69de29 diff --git a/include/libpgfe/otp/otp.hpp b/include/libpgfe/otp/otp.hpp new file mode 100644 index 0000000..e69de29 diff --git a/include/libpgfe/otp_types.h b/include/libpgfe/otp/otp_types.h similarity index 100% rename from include/libpgfe/otp_types.h rename to include/libpgfe/otp/otp_types.h diff --git a/include/libpgfe/totp.h b/include/libpgfe/otp/totp.h similarity index 100% rename from include/libpgfe/totp.h rename to include/libpgfe/otp/totp.h diff --git a/include/libpgfe/totp.hpp b/include/libpgfe/otp/totp.hpp similarity index 100% rename from include/libpgfe/totp.hpp rename to include/libpgfe/otp/totp.hpp From 93881352ea5e71ca1a5de9b7fdaa20cd0d9c2946 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sun, 28 May 2023 11:26:49 +0800 Subject: [PATCH 2/8] Update structure --- CMakeLists.txt | 121 +++++++++--------- LICENSE | 2 +- cmake/advanced.cmake | 14 ++ cmake/core.cmake | 46 +++++++ cmake/otp.cmake | 17 +++ include/libpgfe/advanced.h | 0 include/libpgfe/advanced.hpp | 0 .../advanced/abstract_symmetric_crypter.hpp | 8 +- .../libpgfe/advanced/{ => fishes}/blowfish.h | 8 +- .../advanced/{ => fishes}/blowfish.hpp | 10 +- include/libpgfe/all.h | 8 -- include/libpgfe/all.hpp | 0 include/libpgfe/core.h | 0 include/libpgfe/core.hpp | 0 include/libpgfe/core/abstract_encoder.hpp | 12 +- include/libpgfe/core/algorithm-choice.h | 6 +- include/libpgfe/core/algorithm_selectable.hpp | 8 +- .../core/bases/abstract_base_encoding.hpp | 10 +- include/libpgfe/core/bases/base-encoding.h | 67 ---------- include/libpgfe/core/bases/base16.h | 25 ++++ include/libpgfe/core/bases/base16.hpp | 8 +- include/libpgfe/core/bases/base32.h | 33 +++++ include/libpgfe/core/bases/base32.hpp | 8 +- include/libpgfe/core/bases/base64.h | 30 +++++ include/libpgfe/core/bases/base64.hpp | 8 +- include/libpgfe/core/exceptions.hpp | 6 +- include/libpgfe/core/generic.h | 16 +-- include/libpgfe/core/generic.hpp | 51 +------- include/libpgfe/core/hashes.h | 9 ++ .../core/hashes/abstract_hash_encoder.hpp | 16 +-- include/libpgfe/core/hashes/hash_encoder.hpp | 8 +- include/libpgfe/core/hashes/md5.h | 8 +- include/libpgfe/core/hashes/sha1.h | 8 +- include/libpgfe/core/hashes/sha2.h | 8 +- include/libpgfe/core/hashes/sha3.h | 8 +- include/libpgfe/core/hmac/hmac.h | 13 +- include/libpgfe/core/hmac/hmac_encoder.hpp | 14 +- include/libpgfe/core/sequential_data.hpp | 10 +- include/libpgfe/core/utils.h | 8 +- include/libpgfe/core/utils.hpp | 10 +- include/libpgfe/hash.h | 4 - include/libpgfe/otp/abstract_otp.hpp | 14 +- include/libpgfe/otp/hotp.h | 10 +- include/libpgfe/otp/hotp.hpp | 10 +- include/libpgfe/otp/otp.h | 0 include/libpgfe/otp/otp.hpp | 0 include/libpgfe/otp/totp.h | 10 +- include/libpgfe/otp/totp.hpp | 10 +- include/libpgfe/otp/{otp_types.h => types.h} | 0 include/libpgfe/version.h | 2 +- scripts/{comment_header => comment_header.py} | 2 +- scripts/{deploy => deploy.py} | 0 scripts/{update_meta => update_meta.py} | 0 .../blowfish => advanced/c/fishes}/blowfish.c | 4 +- .../cpp}/abstract_symmetric_crypter.cpp | 4 +- .../cpp/fishes}/blowfish.cpp | 4 +- src/c/generic.c | 8 -- src/c/hash/keccak-backend.h | 35 ----- src/c/hash/md5-backend.h | 29 ----- src/c/hash/sha224.c | 27 ---- src/c/hash/sha256.c | 27 ---- .../c/bases}/base-encoding-internal.c | 25 ++-- .../c/bases}/base-encoding-internal.h | 28 ++-- .../base_encoding => core/c/bases}/base16.c | 12 +- .../base_encoding => core/c/bases}/base32.c | 24 ++-- .../base_encoding => core/c/bases}/base64.c | 16 +-- src/{ => core}/c/generic-internal.c | 12 +- src/{ => core}/c/generic-internal.h | 59 +++++++-- src/core/c/generic.c | 8 ++ .../hash => core/c/hashes}/keccak-backend.c | 26 ++-- src/core/c/hashes/keccak-backend.h | 35 +++++ src/{c/hash => core/c/hashes}/md5-backend.c | 22 ++-- src/core/c/hashes/md5-backend.h | 29 +++++ src/{c/hash => core/c/hashes}/md5.c | 16 +-- src/{c/hash => core/c/hashes}/sha-internal.c | 2 +- src/{c/hash => core/c/hashes}/sha-internal.h | 4 +- src/{c/hash => core/c/hashes}/sha1.c | 26 ++-- src/{c/hash => core/c/hashes}/sha2-backend.c | 34 ++--- src/{c/hash => core/c/hashes}/sha2-backend.h | 22 ++-- src/core/c/hashes/sha224.c | 27 ++++ src/core/c/hashes/sha256.c | 27 ++++ src/{c/hash => core/c/hashes}/sha3-224.c | 15 ++- src/{c/hash => core/c/hashes}/sha3-256.c | 15 ++- src/{c/hash => core/c/hashes}/sha3-384.c | 15 ++- src/{c/hash => core/c/hashes}/sha3-512.c | 15 ++- src/{c/hash => core/c/hashes}/sha384.c | 16 +-- src/{c/hash => core/c/hashes}/sha512.c | 40 +++--- src/{c/hash => core/c/hashes}/shake.c | 29 +++-- src/{c/hash => core/c/hashes}/templates.h | 16 +-- src/{ => core}/c/hmac/hmac.c | 34 ++--- src/{ => core}/c/utils.c | 8 +- src/{ => core}/cpp/algorithm_selectable.cpp | 4 +- .../cpp/bases}/abstract_base_encoding.cpp | 4 +- .../cpp/bases}/base16.cpp | 6 +- .../cpp/bases}/base32.cpp | 6 +- .../cpp/bases}/base64.cpp | 6 +- src/{ => core}/cpp/generic.cpp | 6 +- .../hash => core/cpp/hashes}/hash_encoder.cpp | 8 +- src/{ => core}/cpp/hmac/hmac_encoder.cpp | 4 +- src/{ => core}/cpp/sequential_data.cpp | 4 +- src/{ => core}/cpp/utils.cpp | 6 +- src/{c/otp => otp/c}/hotp.c | 12 +- src/{c/otp => otp/c}/otp-generic.c | 16 +-- src/{c/otp => otp/c}/otp-generic.h | 14 +- src/{c/otp => otp/c}/totp.c | 10 +- src/{cpp/otp => otp/cpp}/abstract_otp.cpp | 6 +- src/{cpp/otp => otp/cpp}/hotp.cpp | 10 +- src/{cpp/otp => otp/cpp}/totp.cpp | 13 +- tests/CMakeLists.txt | 17 +++ {test => tests}/base_multithread.hpp | 2 +- {test => tests}/base_test.hpp | 4 +- {test => tests}/baseencodetest.h | 2 +- {test => tests}/blowfish_test.h | 6 +- {test => tests}/blowfish_test.hpp | 6 +- {test => tests}/cmake/base_tests.cmake | 0 {test => tests}/cmake/blowfish_tests.cmake | 0 {test => tests}/cmake/hash_tests.cmake | 0 {test => tests}/cmake/hmac_tests.cmake | 0 {test => tests}/cmake/otp_tests.cmake | 0 {test => tests}/cmake/shake_tests.cmake | 0 {test => tests}/cmake/test_meta.cmake | 0 {test => tests}/cmake/util_tests.cmake | 0 {test => tests}/hash_encoder_test.hpp | 6 +- {test => tests}/hmactest.h | 8 +- {test => tests}/hmactest.hpp | 6 +- {test => tests}/mdtest.h | 6 +- {test => tests}/otptest.h | 6 +- {test => tests}/otptest.hpp | 6 +- {test => tests}/shake_test.h | 6 +- {test => tests}/shatest.h | 10 +- {test => tests}/test.c | 2 +- {test => tests}/test.cpp | 2 +- {test => tests}/test.h | 2 +- {test => tests}/test.txt | 0 {test => tests}/utilstest.h | 4 +- 135 files changed, 928 insertions(+), 807 deletions(-) create mode 100644 cmake/advanced.cmake create mode 100644 cmake/core.cmake create mode 100644 cmake/otp.cmake delete mode 100644 include/libpgfe/advanced.h delete mode 100644 include/libpgfe/advanced.hpp rename include/libpgfe/advanced/{ => fishes}/blowfish.h (86%) rename include/libpgfe/advanced/{ => fishes}/blowfish.hpp (80%) delete mode 100644 include/libpgfe/all.h delete mode 100644 include/libpgfe/all.hpp delete mode 100644 include/libpgfe/core.h delete mode 100644 include/libpgfe/core.hpp delete mode 100644 include/libpgfe/core/bases/base-encoding.h create mode 100644 include/libpgfe/core/bases/base16.h create mode 100644 include/libpgfe/core/bases/base32.h create mode 100644 include/libpgfe/core/bases/base64.h create mode 100644 include/libpgfe/core/hashes.h delete mode 100644 include/libpgfe/hash.h delete mode 100644 include/libpgfe/otp/otp.h delete mode 100644 include/libpgfe/otp/otp.hpp rename include/libpgfe/otp/{otp_types.h => types.h} (100%) rename scripts/{comment_header => comment_header.py} (96%) rename scripts/{deploy => deploy.py} (100%) rename scripts/{update_meta => update_meta.py} (100%) rename src/{c/blowfish => advanced/c/fishes}/blowfish.c (99%) rename src/{cpp/misc => advanced/cpp}/abstract_symmetric_crypter.cpp (90%) rename src/{cpp/blowfish => advanced/cpp/fishes}/blowfish.cpp (95%) delete mode 100644 src/c/generic.c delete mode 100644 src/c/hash/keccak-backend.h delete mode 100644 src/c/hash/md5-backend.h delete mode 100644 src/c/hash/sha224.c delete mode 100644 src/c/hash/sha256.c rename src/{c/base_encoding => core/c/bases}/base-encoding-internal.c (82%) rename src/{c/base_encoding => core/c/bases}/base-encoding-internal.h (52%) rename src/{c/base_encoding => core/c/bases}/base16.c (64%) rename src/{c/base_encoding => core/c/bases}/base32.c (68%) rename src/{c/base_encoding => core/c/bases}/base64.c (75%) rename src/{ => core}/c/generic-internal.c (63%) rename src/{ => core}/c/generic-internal.h (62%) create mode 100644 src/core/c/generic.c rename src/{c/hash => core/c/hashes}/keccak-backend.c (90%) create mode 100644 src/core/c/hashes/keccak-backend.h rename src/{c/hash => core/c/hashes}/md5-backend.c (87%) create mode 100644 src/core/c/hashes/md5-backend.h rename src/{c/hash => core/c/hashes}/md5.c (82%) rename src/{c/hash => core/c/hashes}/sha-internal.c (61%) rename src/{c/hash => core/c/hashes}/sha-internal.h (85%) rename src/{c/hash => core/c/hashes}/sha1.c (81%) rename src/{c/hash => core/c/hashes}/sha2-backend.c (89%) rename src/{c/hash => core/c/hashes}/sha2-backend.h (56%) create mode 100644 src/core/c/hashes/sha224.c create mode 100644 src/core/c/hashes/sha256.c rename src/{c/hash => core/c/hashes}/sha3-224.c (59%) rename src/{c/hash => core/c/hashes}/sha3-256.c (59%) rename src/{c/hash => core/c/hashes}/sha3-384.c (59%) rename src/{c/hash => core/c/hashes}/sha3-512.c (59%) rename src/{c/hash => core/c/hashes}/sha384.c (64%) rename src/{c/hash => core/c/hashes}/sha512.c (63%) rename src/{c/hash => core/c/hashes}/shake.c (77%) rename src/{c/hash => core/c/hashes}/templates.h (96%) rename src/{ => core}/c/hmac/hmac.c (87%) rename src/{ => core}/c/utils.c (94%) rename src/{ => core}/cpp/algorithm_selectable.cpp (79%) rename src/{cpp/base_encoding => core/cpp/bases}/abstract_base_encoding.cpp (95%) rename src/{cpp/base_encoding => core/cpp/bases}/base16.cpp (82%) rename src/{cpp/base_encoding => core/cpp/bases}/base32.cpp (86%) rename src/{cpp/base_encoding => core/cpp/bases}/base64.cpp (85%) rename src/{ => core}/cpp/generic.cpp (75%) rename src/{cpp/hash => core/cpp/hashes}/hash_encoder.cpp (96%) rename src/{ => core}/cpp/hmac/hmac_encoder.cpp (97%) rename src/{ => core}/cpp/sequential_data.cpp (95%) rename src/{ => core}/cpp/utils.cpp (88%) rename src/{c/otp => otp/c}/hotp.c (88%) rename src/{c/otp => otp/c}/otp-generic.c (54%) rename src/{c/otp => otp/c}/otp-generic.h (56%) rename src/{c/otp => otp/c}/totp.c (87%) rename src/{cpp/otp => otp/cpp}/abstract_otp.cpp (85%) rename src/{cpp/otp => otp/cpp}/hotp.cpp (91%) rename src/{cpp/otp => otp/cpp}/totp.cpp (89%) create mode 100644 tests/CMakeLists.txt rename {test => tests}/base_multithread.hpp (98%) rename {test => tests}/base_test.hpp (93%) rename {test => tests}/baseencodetest.h (97%) rename {test => tests}/blowfish_test.h (91%) rename {test => tests}/blowfish_test.hpp (81%) rename {test => tests}/cmake/base_tests.cmake (100%) rename {test => tests}/cmake/blowfish_tests.cmake (100%) rename {test => tests}/cmake/hash_tests.cmake (100%) rename {test => tests}/cmake/hmac_tests.cmake (100%) rename {test => tests}/cmake/otp_tests.cmake (100%) rename {test => tests}/cmake/shake_tests.cmake (100%) rename {test => tests}/cmake/test_meta.cmake (100%) rename {test => tests}/cmake/util_tests.cmake (100%) rename {test => tests}/hash_encoder_test.hpp (80%) rename {test => tests}/hmactest.h (90%) rename {test => tests}/hmactest.hpp (84%) rename {test => tests}/mdtest.h (64%) rename {test => tests}/otptest.h (86%) rename {test => tests}/otptest.hpp (76%) rename {test => tests}/shake_test.h (94%) rename {test => tests}/shatest.h (94%) rename {test => tests}/test.c (98%) rename {test => tests}/test.cpp (97%) rename {test => tests}/test.h (96%) rename {test => tests}/test.txt (100%) rename {test => tests}/utilstest.h (86%) diff --git a/CMakeLists.txt b/CMakeLists.txt index f0f0360..c6a3003 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16.0) +cmake_minimum_required(VERSION 3.26.0) set(CMAKE_C_COMPILER clang) set(CMAKE_CXX_COMPILER clang++) @@ -11,75 +11,82 @@ project(libpgfe ) set(CMAKE_C_STANDARD 11) -set(CMAKE_CXX_STANDARD 14) +set(CMAKE_C_STANDARD_REQUIRED ON) -include(CTest) -enable_testing() +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_STANDARD_REQUIRED ON) 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") +set(cmake_module_dir "cmake") +set(test_dir "tests") + +list(APPEND cmake_modules "core.cmake" "otp.cmake" "advanced.cmake") + +foreach(mod IN LISTS cmake_modules) + include(${cmake_module_dir}/${mod}) +endforeach(i) -add_library(pgfe SHARED - ${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_c_dir}/blowfish/blowfish.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 - ${src_cpp_dir}/misc/abstract_symmetric_crypter.cpp - ${src_cpp_dir}/blowfish/blowfish.cpp) -add_executable(pgfetest ${test_dir}/test.c) -add_executable(pgfetestcpp ${test_dir}/test.cpp) +add_subdirectory(${test_dir}) + +# add_library(pgfe SHARED +# ${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_c_dir}/blowfish/blowfish.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 +# ${src_cpp_dir}/misc/abstract_symmetric_crypter.cpp +# ${src_cpp_dir}/blowfish/blowfish.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) -target_include_directories(pgfe PUBLIC - ${include_dir} -) +# target_include_directories(pgfe PUBLIC +# ${include_dir} +# ) -target_include_directories(pgfe PRIVATE - ${src_dir} -) +# target_include_directories(pgfe PRIVATE +# ${src_dir} +# ) -target_link_libraries(pgfetest pgfe) -target_link_libraries(pgfetestcpp pgfe) +# target_link_libraries(pgfetest pgfe) +# target_link_libraries(pgfetestcpp pgfe) # target_link_libraries(totptest pgfe) # target_link_libraries(totptestcpp pgfe) -include(${test_dir}/cmake/test_meta.cmake) -include(${test_dir}/cmake/hash_tests.cmake) -include(${test_dir}/cmake/hmac_tests.cmake) -include(${test_dir}/cmake/util_tests.cmake) -include(${test_dir}/cmake/base_tests.cmake) -include(${test_dir}/cmake/otp_tests.cmake) -include(${test_dir}/cmake/shake_tests.cmake) -include(${test_dir}/cmake/blowfish_tests.cmake) +# include(${test_dir}/cmake/test_meta.cmake) +# include(${test_dir}/cmake/hash_tests.cmake) +# include(${test_dir}/cmake/hmac_tests.cmake) +# include(${test_dir}/cmake/util_tests.cmake) +# include(${test_dir}/cmake/base_tests.cmake) +# include(${test_dir}/cmake/otp_tests.cmake) +# include(${test_dir}/cmake/shake_tests.cmake) +# include(${test_dir}/cmake/blowfish_tests.cmake) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) diff --git a/LICENSE b/LICENSE index efd54ad..6780c64 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ BSD 3-Clause License -Copyright (c) 2023 Charles Dong +Copyright (c) 2022-2023 Charles Dong Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: diff --git a/cmake/advanced.cmake b/cmake/advanced.cmake new file mode 100644 index 0000000..66f4a1e --- /dev/null +++ b/cmake/advanced.cmake @@ -0,0 +1,14 @@ +set(advanced_src "${src_dir}/advanced") + +add_library(pgfe_advanced SHARED + ${advanced_src}/c/fishes/blowfish.c + ${advanced_src}/cpp/abstract_symmetric_crypter.cpp + ${advanced_src}/cpp/fishes/blowfish.cpp +) + +target_include_directories(pgfe_advanced + PUBLIC ${include_dir} + PRIVATE ${src_dir} +) + +target_link_libraries(pgfe_advanced pgfe_core) \ No newline at end of file diff --git a/cmake/core.cmake b/cmake/core.cmake new file mode 100644 index 0000000..cb8d8ae --- /dev/null +++ b/cmake/core.cmake @@ -0,0 +1,46 @@ +set(core_src "${src_dir}/core") + +add_library(pgfe_core SHARED + # General + ${core_src}/c/generic.c + ${core_src}/c/generic-internal.c + ${core_src}/c/utils.c + ${core_src}/cpp/generic.cpp + ${core_src}/cpp/algorithm_selectable.cpp + ${core_src}/cpp/sequential_data.cpp + ${core_src}/cpp/utils.cpp + # Bases + ${core_src}/c/bases/base-encoding-internal.c + ${core_src}/c/bases/base16.c + ${core_src}/c/bases/base32.c + ${core_src}/c/bases/base64.c + ${core_src}/cpp/bases/abstract_base_encoding.cpp + ${core_src}/cpp/bases/base16.cpp + ${core_src}/cpp/bases/base32.cpp + ${core_src}/cpp/bases/base64.cpp + # Hashes + ${core_src}/c/hashes/keccak-backend.c + ${core_src}/c/hashes/md5-backend.c + ${core_src}/c/hashes/md5.c + ${core_src}/c/hashes/sha-internal.c + ${core_src}/c/hashes/sha1.c + ${core_src}/c/hashes/sha2-backend.c + ${core_src}/c/hashes/sha3-224.c + ${core_src}/c/hashes/sha3-256.c + ${core_src}/c/hashes/sha3-384.c + ${core_src}/c/hashes/sha3-512.c + ${core_src}/c/hashes/sha224.c + ${core_src}/c/hashes/sha256.c + ${core_src}/c/hashes/sha384.c + ${core_src}/c/hashes/sha512.c + ${core_src}/c/hashes/shake.c + ${core_src}/cpp/hashes/hash_encoder.cpp + # HMAC + ${core_src}/c/hmac/hmac.c + ${core_src}/cpp/hmac/hmac_encoder.cpp +) + +target_include_directories(pgfe_core + PUBLIC ${include_dir} + PRIVATE ${src_dir} +) \ No newline at end of file diff --git a/cmake/otp.cmake b/cmake/otp.cmake new file mode 100644 index 0000000..c1627da --- /dev/null +++ b/cmake/otp.cmake @@ -0,0 +1,17 @@ +set(otp_src "${src_dir}/otp") + +add_library(pgfe_otp SHARED + ${otp_src}/c/otp-generic.c + ${otp_src}/c/hotp.c + ${otp_src}/c/totp.c + ${otp_src}/cpp/abstract_otp.cpp + ${otp_src}/cpp/hotp.cpp + ${otp_src}/cpp/totp.cpp +) + +target_include_directories(pgfe_otp + PUBLIC ${include_dir} + PRIVATE ${src_dir} +) + +target_link_libraries(pgfe_otp pgfe_core) \ No newline at end of file diff --git a/include/libpgfe/advanced.h b/include/libpgfe/advanced.h deleted file mode 100644 index e69de29..0000000 diff --git a/include/libpgfe/advanced.hpp b/include/libpgfe/advanced.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/include/libpgfe/advanced/abstract_symmetric_crypter.hpp b/include/libpgfe/advanced/abstract_symmetric_crypter.hpp index ba9cb0e..cdfa73a 100644 --- a/include/libpgfe/advanced/abstract_symmetric_crypter.hpp +++ b/include/libpgfe/advanced/abstract_symmetric_crypter.hpp @@ -2,18 +2,18 @@ libpgfe abstract_symmetric_crypter.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_ABSTRACT_SYMMETRIC_CRYPTER_HPP -#define LIBPGFE_ABSTRACT_SYMMETRIC_CRYPTER_HPP +#ifndef LIBPGFE_ADVANCED_ABSTRACT_SYMMETRIC_CRYPTER_HPP +#define LIBPGFE_ADVANCED_ABSTRACT_SYMMETRIC_CRYPTER_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif #include -#include "libpgfe/sequential_data.hpp" +#include "libpgfe/core/sequential_data.hpp" namespace libpgfe { diff --git a/include/libpgfe/advanced/blowfish.h b/include/libpgfe/advanced/fishes/blowfish.h similarity index 86% rename from include/libpgfe/advanced/blowfish.h rename to include/libpgfe/advanced/fishes/blowfish.h index 3aaf488..c99b415 100644 --- a/include/libpgfe/advanced/blowfish.h +++ b/include/libpgfe/advanced/fishes/blowfish.h @@ -4,16 +4,16 @@ Blowfish - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_BLOWFISH_H -#define LIBPGFE_BLOWFISH_H +#ifndef LIBPGFE_ADVANCED_BLOWFISH_H +#define LIBPGFE_ADVANCED_BLOWFISH_H #ifdef __cplusplus extern "C" { #endif -#include "libpgfe/generic.h" +#include "libpgfe/core/generic.h" #define __PGFE_BF_N 16 #define __PGFE_BF_Np2 18 diff --git a/include/libpgfe/advanced/blowfish.hpp b/include/libpgfe/advanced/fishes/blowfish.hpp similarity index 80% rename from include/libpgfe/advanced/blowfish.hpp rename to include/libpgfe/advanced/fishes/blowfish.hpp index a89410c..296d814 100644 --- a/include/libpgfe/advanced/blowfish.hpp +++ b/include/libpgfe/advanced/fishes/blowfish.hpp @@ -2,19 +2,19 @@ libpgfe blowfish.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_BLOWFISH_HPP -#define LIBPGFE_BLOWFISH_HPP +#ifndef LIBPGFE_ADVANCED_BLOWFISH_HPP +#define LIBPGFE_ADVANCED_BLOWFISH_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif #include -#include "libpgfe/abstract_symmetric_crypter.hpp" -#include "libpgfe/blowfish.h" +#include "libpgfe/advanced/abstract_symmetric_crypter.hpp" +#include "libpgfe/advanced/fishes/blowfish.h" namespace libpgfe { diff --git a/include/libpgfe/all.h b/include/libpgfe/all.h deleted file mode 100644 index 37c6bc4..0000000 --- a/include/libpgfe/all.h +++ /dev/null @@ -1,8 +0,0 @@ -// Core feature -#include "libpgfe/core.h" - -// OTP feature -#include "libpgfe/otp.h" - -// Advanced feature -#include "libpgfe/advanced.h" \ No newline at end of file diff --git a/include/libpgfe/all.hpp b/include/libpgfe/all.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/include/libpgfe/core.h b/include/libpgfe/core.h deleted file mode 100644 index e69de29..0000000 diff --git a/include/libpgfe/core.hpp b/include/libpgfe/core.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/include/libpgfe/core/abstract_encoder.hpp b/include/libpgfe/core/abstract_encoder.hpp index 640be80..435b30c 100644 --- a/include/libpgfe/core/abstract_encoder.hpp +++ b/include/libpgfe/core/abstract_encoder.hpp @@ -2,11 +2,11 @@ libpgfe abstract_encoder.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_GENERIC_ENCODER_HPP -#define LIBPGFE_GENERIC_ENCODER_HPP +#ifndef LIBPGFE_CORE_GENERIC_ENCODER_HPP +#define LIBPGFE_CORE_GENERIC_ENCODER_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif @@ -14,9 +14,9 @@ #include #include -#include "libpgfe/generic.h" -#include "libpgfe/sequential_data.hpp" -#include "libpgfe/utils.hpp" +#include "libpgfe/core/generic.h" +#include "libpgfe/core/sequential_data.hpp" +#include "libpgfe/core/utils.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/algorithm-choice.h b/include/libpgfe/core/algorithm-choice.h index ae6d2a1..c9e93e3 100644 --- a/include/libpgfe/core/algorithm-choice.h +++ b/include/libpgfe/core/algorithm-choice.h @@ -2,11 +2,11 @@ libpgfe algorithm-choice.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_ALGORITHM_CHOICE_H -#define LIBPGFE_ALGORITHM_CHOICE_H +#ifndef LIBPGFE_CORE_ALGORITHM_CHOICE_H +#define LIBPGFE_CORE_ALGORITHM_CHOICE_H #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/algorithm_selectable.hpp b/include/libpgfe/core/algorithm_selectable.hpp index c1e9f0b..4d5afb8 100644 --- a/include/libpgfe/core/algorithm_selectable.hpp +++ b/include/libpgfe/core/algorithm_selectable.hpp @@ -2,17 +2,17 @@ libpgfe algorithm_selectable.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_ALGORITHM_SELECTABLE_HPP -#define LIBPGFE_ALGORITHM_SELECTABLE_HPP +#ifndef LIBPGFE_CORE_ALGORITHM_SELECTABLE_HPP +#define LIBPGFE_CORE_ALGORITHM_SELECTABLE_HPP #ifdef __cplusplus #include #include -#include "libpgfe/algorithm-choice.h" +#include "libpgfe/core/algorithm-choice.h" namespace libpgfe { diff --git a/include/libpgfe/core/bases/abstract_base_encoding.hpp b/include/libpgfe/core/bases/abstract_base_encoding.hpp index 99d6a4b..922111e 100644 --- a/include/libpgfe/core/bases/abstract_base_encoding.hpp +++ b/include/libpgfe/core/bases/abstract_base_encoding.hpp @@ -2,11 +2,11 @@ libpgfe abstract_base_encoding.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_ABSTRACT_BASE_ENCODING -#define LIBPGFE_ABSTRACT_BASE_ENCODING +#ifndef LIBPGFE_CORE_ABSTRACT_BASE_ENCODING +#define LIBPGFE_CORE_ABSTRACT_BASE_ENCODING #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif @@ -15,8 +15,8 @@ #include #include -#include "libpgfe/generic.h" -#include "libpgfe/sequential_data.hpp" +#include "libpgfe/core/generic.h" +#include "libpgfe/core/sequential_data.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/bases/base-encoding.h b/include/libpgfe/core/bases/base-encoding.h deleted file mode 100644 index 0f36db7..0000000 --- a/include/libpgfe/core/bases/base-encoding.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - libpgfe - base-encoding.h - - Copyright (c) 2022 Charles Dong -*/ - -#ifndef LIBPGFE_BASE_ENCODING_H -#define LIBPGFE_BASE_ENCODING_H - -#include "libpgfe/generic.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define PGFE_BASE64_UNIT_SIZE 3 -#define PGFE_BASE64_CHUNK_COUNT 4 -#define PGFE_BASE64_BIT_SIZE 6 -#define PGFE_BASE64_ALPHABET_SIZE 64 - -#define PGFE_BASE32_UNIT_SIZE 5 -#define PGFE_BASE32_CHUNK_COUNT 8 -#define PGFE_BASE32_BIT_SIZE 5 -#define PGFE_BASE32_ALPHABET_SIZE 32 - -#define PGFE_BASE16_UNIT_SIZE 1 -#define PGFE_BASE16_CHUNK_COUNT 2 -#define PGFE_BASE16_BIT_SIZE 4 -#define PGFE_BASE16_ALPHABET_SIZE 16 - -// Base 64 - -// Encode input to standard Base 64 -size_t pgfe_encode_base64(const pgfe_encode_t input[], size_t input_length, char cs_out[]); - -// Encode input to the URL and Filename safe variant of Base 64 -size_t pgfe_encode_base64_url(const pgfe_encode_t input[], size_t input_length, char cs_out[]); - -// Decode Base 64 (for both standard and name-safe) -size_t pgfe_decode_base64(const char base64_cs[], pgfe_encode_t output[]); - -// Base 32 - -// Encode input to standard Base 32 -size_t pgfe_encode_base32(const pgfe_encode_t input[], size_t input_length, char cs_out[]); - -// Encode input to Base 32-Hex -size_t pgfe_encode_base32hex(const pgfe_encode_t input[], size_t input_length, char cs_out[]); - -// Decode standard Base 32 -size_t pgfe_decode_base32(const char base32_cs[], pgfe_encode_t output[]); - -// Decode Base 32-Hex -size_t pgfe_decode_base32hex(const char base32_cs[], pgfe_encode_t output[]); - -// Base 16 - -size_t pgfe_encode_base16(const pgfe_encode_t input[], size_t input_length, char cs_out[]); - -size_t pgfe_decode_base16(const char base16_cs[], pgfe_encode_t output[]); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/include/libpgfe/core/bases/base16.h b/include/libpgfe/core/bases/base16.h new file mode 100644 index 0000000..0ca7ac4 --- /dev/null +++ b/include/libpgfe/core/bases/base16.h @@ -0,0 +1,25 @@ +#ifndef LIBPGFE_CORE_BASE16_H +#define LIBPGFE_CORE_BASE16_H + +#include "libpgfe/core/generic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PGFE_BASE16_UNIT_SIZE 1 +#define PGFE_BASE16_CHUNK_COUNT 2 +#define PGFE_BASE16_BIT_SIZE 4 +#define PGFE_BASE16_ALPHABET_SIZE 16 + +// Base 16 + +size_t pgfe_encode_base16(const pgfe_encode_t input[], size_t input_length, char cs_out[]); + +size_t pgfe_decode_base16(const char base16_cs[], pgfe_encode_t output[]); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/include/libpgfe/core/bases/base16.hpp b/include/libpgfe/core/bases/base16.hpp index ba2ae2d..a19a9ae 100644 --- a/include/libpgfe/core/bases/base16.hpp +++ b/include/libpgfe/core/bases/base16.hpp @@ -2,16 +2,16 @@ libpgfe base16.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_BASE16_HPP -#define LIBPGFE_BASE16_HPP +#ifndef LIBPGFE_CORE_BASE16_HPP +#define LIBPGFE_CORE_BASE16_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif -#include "libpgfe/abstract_base_encoding.hpp" +#include "libpgfe/core/abstract_base_encoding.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/bases/base32.h b/include/libpgfe/core/bases/base32.h new file mode 100644 index 0000000..8d281c0 --- /dev/null +++ b/include/libpgfe/core/bases/base32.h @@ -0,0 +1,33 @@ +#ifndef LIBPGFE_CORE_BASE32_H +#define LIBPGFE_CORE_BASE32_H + +#include "libpgfe/core/generic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PGFE_BASE32_UNIT_SIZE 5 +#define PGFE_BASE32_CHUNK_COUNT 8 +#define PGFE_BASE32_BIT_SIZE 5 +#define PGFE_BASE32_ALPHABET_SIZE 32 + +// Base 32 + +// Encode input to standard Base 32 +size_t pgfe_encode_base32(const pgfe_encode_t input[], size_t input_length, char cs_out[]); + +// Encode input to Base 32-Hex +size_t pgfe_encode_base32hex(const pgfe_encode_t input[], size_t input_length, char cs_out[]); + +// Decode standard Base 32 +size_t pgfe_decode_base32(const char base32_cs[], pgfe_encode_t output[]); + +// Decode Base 32-Hex +size_t pgfe_decode_base32hex(const char base32_cs[], pgfe_encode_t output[]); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/include/libpgfe/core/bases/base32.hpp b/include/libpgfe/core/bases/base32.hpp index 4eb7dd6..b757e6d 100644 --- a/include/libpgfe/core/bases/base32.hpp +++ b/include/libpgfe/core/bases/base32.hpp @@ -2,16 +2,16 @@ libpgfe base32.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_BASE32_HPP -#define LIBPGFE_BASE32_HPP +#ifndef LIBPGFE_CORE_BASE32_HPP +#define LIBPGFE_CORE_BASE32_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif -#include "libpgfe/abstract_base_encoding.hpp" +#include "libpgfe/core/abstract_base_encoding.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/bases/base64.h b/include/libpgfe/core/bases/base64.h new file mode 100644 index 0000000..a5b8034 --- /dev/null +++ b/include/libpgfe/core/bases/base64.h @@ -0,0 +1,30 @@ +#ifndef LIBPGFE_CORE_BASE64_H +#define LIBPGFE_CORE_BASE64_H + +#include "libpgfe/core/generic.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define PGFE_BASE64_UNIT_SIZE 3 +#define PGFE_BASE64_CHUNK_COUNT 4 +#define PGFE_BASE64_BIT_SIZE 6 +#define PGFE_BASE64_ALPHABET_SIZE 64 + +// Base 64 + +// Encode input to standard Base 64 +size_t pgfe_encode_base64(const pgfe_encode_t input[], size_t input_length, char cs_out[]); + +// Encode input to the URL and Filename safe variant of Base 64 +size_t pgfe_encode_base64_url(const pgfe_encode_t input[], size_t input_length, char cs_out[]); + +// Decode Base 64 (for both standard and name-safe) +size_t pgfe_decode_base64(const char base64_cs[], pgfe_encode_t output[]); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/include/libpgfe/core/bases/base64.hpp b/include/libpgfe/core/bases/base64.hpp index c87b884..52cfa00 100644 --- a/include/libpgfe/core/bases/base64.hpp +++ b/include/libpgfe/core/bases/base64.hpp @@ -2,16 +2,16 @@ libpgfe base64.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_BASE64_HPP -#define LIBPGFE_BASE64_HPP +#ifndef LIBPGFE_CORE_BASE64_HPP +#define LIBPGFE_CORE_BASE64_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif -#include "libpgfe/abstract_base_encoding.hpp" +#include "libpgfe/core/abstract_base_encoding.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/exceptions.hpp b/include/libpgfe/core/exceptions.hpp index da1557d..c528bdf 100644 --- a/include/libpgfe/core/exceptions.hpp +++ b/include/libpgfe/core/exceptions.hpp @@ -2,12 +2,12 @@ libpgfe exceptions.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_EXCEPTIONS_HPP -#define LIBPGFE_EXCEPTIONS_HPP +#ifndef LIBPGFE_CORE_EXCEPTIONS_HPP +#define LIBPGFE_CORE_EXCEPTIONS_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif diff --git a/include/libpgfe/core/generic.h b/include/libpgfe/core/generic.h index 0c11a9b..eceba5d 100644 --- a/include/libpgfe/core/generic.h +++ b/include/libpgfe/core/generic.h @@ -2,30 +2,30 @@ libpgfe generic.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_GENERIC_H -#define LIBPGFE_GENERIC_H +#ifndef LIBPGFE_CORE_GENERIC_H +#define LIBPGFE_CORE_GENERIC_H #include #include -#include "libpgfe/algorithm-choice.h" +#include "libpgfe/core/algorithm-choice.h" #ifdef __cplusplus extern "C" { #endif // Default reading buffer size -#define PGFE_BUFFER_SIZE 1024 +#define PGFE_BUFFER_SIZE (1024) // byte -> bit (e.g. to_bit(4) = 32) -#define to_bit(value) ((value)*8) +#define pgfe_to_bit(value) ((value)*8) // bit -> byte (e.g. to_byte(32) = 4) -#define to_byte(value) ((value) / 8) +#define pgfe_to_byte(value) ((value) / 8) // Remainder of bit -#define bit_rem(value) ((value) % 8) +#define pgfe_bit_rem(value) ((value) % 8) typedef char pgfe_ascii_t; diff --git a/include/libpgfe/core/generic.hpp b/include/libpgfe/core/generic.hpp index b62d641..4458523 100644 --- a/include/libpgfe/core/generic.hpp +++ b/include/libpgfe/core/generic.hpp @@ -2,11 +2,11 @@ libpgfe generic.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_GENERIC_HPP -#define LIBPGFE_GENERIC_HPP +#ifndef LIBPGFE_CORE_GENERIC_HPP +#define LIBPGFE_CORE_GENERIC_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif @@ -14,48 +14,9 @@ #include #include -#include "libpgfe/algorithm-choice.h" -#include "libpgfe/exceptions.hpp" -#include "libpgfe/md5.h" -#include "libpgfe/sha1.h" -#include "libpgfe/sha2.h" -#include "libpgfe/sha3.h" - -#define __PGFE_BATCH_SHAKE_CASES(name) \ - switch (cur_alg) { \ - __PGFE_##name##_CASE(RawSHAKE128, rawshake128); \ - __PGFE_##name##_CASE(SHAKE128, shake128); \ - __PGFE_##name##_CASE(RawSHAKE256, rawshake256); \ - __PGFE_##name##_CASE(SHAKE256, shake256); \ - default: \ - break; \ - } - -#define __PGFE_INIT_SIZE_CASE(alg, name) \ - case alg: \ - digsz = PGFE_##alg##_DIGEST_SIZE; \ - blocksz = PGFE_##alg##_BLOCK_SIZE; \ - break - -#define __PGFE_INIT_CTXP_CASE(alg, name) \ - case alg: \ - pgfe_##name##_init((pgfe_##name##_ctx *)ctx); \ - break - -#define __PGFE_INIT_CTX_CASE(alg, name) \ - case alg: \ - pgfe_##name##_init(&ctx); \ - break - -#define __PGFE_SET_CTXP_CASE(alg, name) \ - case alg: \ - ctx = new pgfe_##name##_ctx; \ - break - -#define __PGFE_FREE_CTXP_CASE(alg, name) \ - case alg: \ - delete (pgfe_##name##_ctx *)ctx; \ - break +#include "libpgfe/core/algorithm-choice.h" +#include "libpgfe/core/exceptions.hpp" +#include "libpgfe/core/hashes.h" namespace libpgfe { diff --git a/include/libpgfe/core/hashes.h b/include/libpgfe/core/hashes.h new file mode 100644 index 0000000..71f9cef --- /dev/null +++ b/include/libpgfe/core/hashes.h @@ -0,0 +1,9 @@ +#ifndef LIBPGFE_CORE_HASHES_H +#define LIBPGFE_CORE_HASHES_H + +#include "libpgfe/core/hashes/md5.h" +#include "libpgfe/core/hashes/sha1.h" +#include "libpgfe/core/hashes/sha2.h" +#include "libpgfe/core/hashes/sha3.h" + +#endif \ No newline at end of file diff --git a/include/libpgfe/core/hashes/abstract_hash_encoder.hpp b/include/libpgfe/core/hashes/abstract_hash_encoder.hpp index 060abaa..3dd7926 100644 --- a/include/libpgfe/core/hashes/abstract_hash_encoder.hpp +++ b/include/libpgfe/core/hashes/abstract_hash_encoder.hpp @@ -2,23 +2,23 @@ libpgfe abstract_hash_encoder.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_GENERIC_HASH_ENCODER_HPP -#define LIBPGFE_GENERIC_HASH_ENCODER_HPP +#ifndef LIBPGFE_CORE_GENERIC_HASH_ENCODER_HPP +#define LIBPGFE_CORE_GENERIC_HASH_ENCODER_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif #include -#include "libpgfe/abstract_encoder.hpp" +#include "libpgfe/core/abstract_encoder.hpp" -#include "libpgfe/algorithm-choice.h" -#include "libpgfe/algorithm_selectable.hpp" -#include "libpgfe/generic.h" -#include "libpgfe/generic.hpp" +#include "libpgfe/core/algorithm-choice.h" +#include "libpgfe/core/algorithm_selectable.hpp" +#include "libpgfe/core/generic.h" +#include "libpgfe/core/generic.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/hashes/hash_encoder.hpp b/include/libpgfe/core/hashes/hash_encoder.hpp index 821f886..7c21dca 100644 --- a/include/libpgfe/core/hashes/hash_encoder.hpp +++ b/include/libpgfe/core/hashes/hash_encoder.hpp @@ -4,16 +4,16 @@ Hash encoder - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_HASH_ENCODER_HPP -#define LIBPGFE_HASH_ENCODER_HPP +#ifndef LIBPGFE_CORE_HASH_ENCODER_HPP +#define LIBPGFE_CORE_HASH_ENCODER_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif -#include "libpgfe/abstract_hash_encoder.hpp" +#include "libpgfe/core/abstract_hash_encoder.hpp" #include diff --git a/include/libpgfe/core/hashes/md5.h b/include/libpgfe/core/hashes/md5.h index 9b43ecc..4cc68a8 100644 --- a/include/libpgfe/core/hashes/md5.h +++ b/include/libpgfe/core/hashes/md5.h @@ -2,15 +2,15 @@ libpgfe md5.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_MD5_H -#define LIBPGFE_MD5_H +#ifndef LIBPGFE_CORE_MD5_H +#define LIBPGFE_CORE_MD5_H #include -#include "libpgfe/generic.h" +#include "libpgfe/core/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/hashes/sha1.h b/include/libpgfe/core/hashes/sha1.h index 3a4ebb9..1032afb 100644 --- a/include/libpgfe/core/hashes/sha1.h +++ b/include/libpgfe/core/hashes/sha1.h @@ -2,15 +2,15 @@ libpgfe sha1.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_SHA1_H -#define LIBPGFE_SHA1_H +#ifndef LIBPGFE_CORE_SHA1_H +#define LIBPGFE_CORE_SHA1_H #include -#include "libpgfe/generic.h" +#include "libpgfe/core/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/hashes/sha2.h b/include/libpgfe/core/hashes/sha2.h index a184844..bb3167b 100644 --- a/include/libpgfe/core/hashes/sha2.h +++ b/include/libpgfe/core/hashes/sha2.h @@ -2,15 +2,15 @@ libpgfe sha2.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_SHA2_H -#define LIBPGFE_SHA2_H +#ifndef LIBPGFE_CORE_SHA2_H +#define LIBPGFE_CORE_SHA2_H #include -#include "libpgfe/generic.h" +#include "libpgfe/core/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/hashes/sha3.h b/include/libpgfe/core/hashes/sha3.h index 879a5d2..d83030c 100644 --- a/include/libpgfe/core/hashes/sha3.h +++ b/include/libpgfe/core/hashes/sha3.h @@ -2,15 +2,15 @@ libpgfe sha3.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_SHA3_H -#define LIBPGFE_SHA3_H +#ifndef LIBPGFE_CORE_SHA3_H +#define LIBPGFE_CORE_SHA3_H #include -#include "libpgfe/generic.h" +#include "libpgfe/core/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/hmac/hmac.h b/include/libpgfe/core/hmac/hmac.h index 7de3a03..524b970 100644 --- a/include/libpgfe/core/hmac/hmac.h +++ b/include/libpgfe/core/hmac/hmac.h @@ -2,17 +2,14 @@ libpgfe hmac.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_HMAC_H -#define LIBPGFE_HMAC_H +#ifndef LIBPGFE_CORE_HMAC_H +#define LIBPGFE_CORE_HMAC_H -#include "libpgfe/generic.h" -#include "libpgfe/md5.h" -#include "libpgfe/sha1.h" -#include "libpgfe/sha2.h" -#include "libpgfe/sha3.h" +#include "libpgfe/core/generic.h" +#include "libpgfe/core/hashes.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/hmac/hmac_encoder.hpp b/include/libpgfe/core/hmac/hmac_encoder.hpp index 6915d88..9cd0f18 100644 --- a/include/libpgfe/core/hmac/hmac_encoder.hpp +++ b/include/libpgfe/core/hmac/hmac_encoder.hpp @@ -2,11 +2,11 @@ libpgfe hmac_encoder.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_HMAC_ENCODER_HPP -#define LIBPGFE_HMAC_ENCODER_HPP +#ifndef LIBPGFE_CORE_HMAC_ENCODER_HPP +#define LIBPGFE_CORE_HMAC_ENCODER_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif @@ -14,10 +14,10 @@ #include #include -#include "libpgfe/abstract_hash_encoder.hpp" -#include "libpgfe/generic.h" -#include "libpgfe/generic.hpp" -#include "libpgfe/hmac.h" +#include "libpgfe/core/abstract_hash_encoder.hpp" +#include "libpgfe/core/generic.h" +#include "libpgfe/core/generic.hpp" +#include "libpgfe/core/hmac/hmac.h" namespace libpgfe { diff --git a/include/libpgfe/core/sequential_data.hpp b/include/libpgfe/core/sequential_data.hpp index 7eee5a1..4603b4b 100644 --- a/include/libpgfe/core/sequential_data.hpp +++ b/include/libpgfe/core/sequential_data.hpp @@ -4,11 +4,11 @@ Header of Sequential Data class - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_SEQUENTIAL_DATA_HPP -#define LIBPGFE_SEQUENTIAL_DATA_HPP +#ifndef LIBPGFE_CORE_SEQUENTIAL_DATA_HPP +#define LIBPGFE_CORE_SEQUENTIAL_DATA_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif @@ -16,8 +16,8 @@ #include #include -#include "libpgfe/generic.h" -#include "libpgfe/utils.h" +#include "libpgfe/core/generic.h" +#include "libpgfe/core/utils.h" namespace libpgfe { diff --git a/include/libpgfe/core/utils.h b/include/libpgfe/core/utils.h index de089de..0801cd9 100644 --- a/include/libpgfe/core/utils.h +++ b/include/libpgfe/core/utils.h @@ -2,13 +2,13 @@ libpgfe utils.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_UTILS_H -#define LIBPGFE_UTILS_H +#ifndef LIBPGFE_CORE_UTILS_H +#define LIBPGFE_CORE_UTILS_H -#include "libpgfe/generic.h" +#include "libpgfe/core/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/utils.hpp b/include/libpgfe/core/utils.hpp index 53ac8b9..94c8406 100644 --- a/include/libpgfe/core/utils.hpp +++ b/include/libpgfe/core/utils.hpp @@ -2,19 +2,19 @@ libpgfe utils.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_UTILS_HPP -#define LIBPGFE_UTILS_HPP +#ifndef LIBPGFE_CORE_UTILS_HPP +#define LIBPGFE_CORE_UTILS_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif #include -#include "libpgfe/generic.hpp" -#include "libpgfe/sequential_data.hpp" +#include "libpgfe/core/generic.hpp" +#include "libpgfe/core/sequential_data.hpp" namespace libpgfe { namespace utils { diff --git a/include/libpgfe/hash.h b/include/libpgfe/hash.h deleted file mode 100644 index aaa6338..0000000 --- a/include/libpgfe/hash.h +++ /dev/null @@ -1,4 +0,0 @@ -#include "libpgfe/md5.h" -#include "libpgfe/sha1.h" -#include "libpgfe/sha2.h" -#include "libpgfe/sha3.h" \ No newline at end of file diff --git a/include/libpgfe/otp/abstract_otp.hpp b/include/libpgfe/otp/abstract_otp.hpp index 38ba3a8..e8d3223 100644 --- a/include/libpgfe/otp/abstract_otp.hpp +++ b/include/libpgfe/otp/abstract_otp.hpp @@ -2,21 +2,21 @@ libpgfe abstract_otp.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_GENERIC_OTP_HPP -#define LIBPGFE_GENERIC_OTP_HPP +#ifndef LIBPGFE_OTP_GENERIC_OTP_HPP +#define LIBPGFE_OTP_GENERIC_OTP_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif #include -#include "libpgfe/algorithm_selectable.hpp" -#include "libpgfe/generic.h" -#include "libpgfe/otp_types.h" -#include "libpgfe/sequential_data.hpp" +#include "libpgfe/core/algorithm_selectable.hpp" +#include "libpgfe/core/generic.h" +#include "libpgfe/core/sequential_data.hpp" +#include "libpgfe/otp/types.h" namespace libpgfe { diff --git a/include/libpgfe/otp/hotp.h b/include/libpgfe/otp/hotp.h index 2a5a4e8..9bb516a 100644 --- a/include/libpgfe/otp/hotp.h +++ b/include/libpgfe/otp/hotp.h @@ -2,14 +2,14 @@ libpgfe hotp.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_HOTP_H -#define LIBPGFE_HOTP_H +#ifndef LIBPGFE_OTP_HOTP_H +#define LIBPGFE_OTP_HOTP_H -#include "libpgfe/generic.h" -#include "libpgfe/otp_types.h" +#include "libpgfe/core/generic.h" +#include "libpgfe/otp/types.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/otp/hotp.hpp b/include/libpgfe/otp/hotp.hpp index c31781a..3480a6e 100644 --- a/include/libpgfe/otp/hotp.hpp +++ b/include/libpgfe/otp/hotp.hpp @@ -2,19 +2,19 @@ libpgfe hotp.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_HOTP_HPP -#define LIBPGFE_HOTP_HPP +#ifndef LIBPGFE_OTP_HOTP_HPP +#define LIBPGFE_OTP_HOTP_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif #include -#include "libpgfe/abstract_otp.hpp" -#include "libpgfe/base32.hpp" +#include "libpgfe/core/hashes/base32.hpp" +#include "libpgfe/otp/abstract_otp.hpp" namespace libpgfe { diff --git a/include/libpgfe/otp/otp.h b/include/libpgfe/otp/otp.h deleted file mode 100644 index e69de29..0000000 diff --git a/include/libpgfe/otp/otp.hpp b/include/libpgfe/otp/otp.hpp deleted file mode 100644 index e69de29..0000000 diff --git a/include/libpgfe/otp/totp.h b/include/libpgfe/otp/totp.h index 20cbc80..34c57a6 100644 --- a/include/libpgfe/otp/totp.h +++ b/include/libpgfe/otp/totp.h @@ -2,17 +2,17 @@ libpgfe totp.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_TOTP_H -#define LIBPGFE_TOTP_H +#ifndef LIBPGFE_OTP_TOTP_H +#define LIBPGFE_OTP_TOTP_H #include -#include "libpgfe/generic.h" -#include "libpgfe/otp_types.h" +#include "libpgfe/core/generic.h" +#include "libpgfe/otp/types.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/otp/totp.hpp b/include/libpgfe/otp/totp.hpp index dddce05..44c4889 100644 --- a/include/libpgfe/otp/totp.hpp +++ b/include/libpgfe/otp/totp.hpp @@ -2,17 +2,17 @@ libpgfe totp.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_TOTP_HPP -#define LIBPGFE_TOTP_HPP +#ifndef LIBPGFE_OTP_TOTP_HPP +#define LIBPGFE_OTP_TOTP_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif -#include "libpgfe/hotp.hpp" -#include "libpgfe/totp.h" +#include "libpgfe/otp/hotp.hpp" +#include "libpgfe/otp/totp.h" namespace libpgfe { diff --git a/include/libpgfe/otp/otp_types.h b/include/libpgfe/otp/types.h similarity index 100% rename from include/libpgfe/otp/otp_types.h rename to include/libpgfe/otp/types.h diff --git a/include/libpgfe/version.h b/include/libpgfe/version.h index 7f7bb24..c23f355 100644 --- a/include/libpgfe/version.h +++ b/include/libpgfe/version.h @@ -2,7 +2,7 @@ libpgfe version.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #ifndef LIBPGFE_VERSION_H diff --git a/scripts/comment_header b/scripts/comment_header.py similarity index 96% rename from scripts/comment_header rename to scripts/comment_header.py index c0340d4..898f3f5 100755 --- a/scripts/comment_header +++ b/scripts/comment_header.py @@ -9,7 +9,7 @@ libpgfe {0} - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ ''' diff --git a/scripts/deploy b/scripts/deploy.py similarity index 100% rename from scripts/deploy rename to scripts/deploy.py diff --git a/scripts/update_meta b/scripts/update_meta.py similarity index 100% rename from scripts/update_meta rename to scripts/update_meta.py diff --git a/src/c/blowfish/blowfish.c b/src/advanced/c/fishes/blowfish.c similarity index 99% rename from src/c/blowfish/blowfish.c rename to src/advanced/c/fishes/blowfish.c index 5f22b98..6f57603 100644 --- a/src/c/blowfish/blowfish.c +++ b/src/advanced/c/fishes/blowfish.c @@ -2,10 +2,10 @@ libpgfe blowfish.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/blowfish.h" +#include "libpgfe/advanced/fishes/blowfish.h" #include diff --git a/src/cpp/misc/abstract_symmetric_crypter.cpp b/src/advanced/cpp/abstract_symmetric_crypter.cpp similarity index 90% rename from src/cpp/misc/abstract_symmetric_crypter.cpp rename to src/advanced/cpp/abstract_symmetric_crypter.cpp index 6acc2df..32aba43 100644 --- a/src/cpp/misc/abstract_symmetric_crypter.cpp +++ b/src/advanced/cpp/abstract_symmetric_crypter.cpp @@ -2,10 +2,10 @@ libpgfe abstract_symmetric_crypter.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/abstract_symmetric_crypter.hpp" +#include "libpgfe/advanced/abstract_symmetric_crypter.hpp" #include diff --git a/src/cpp/blowfish/blowfish.cpp b/src/advanced/cpp/fishes/blowfish.cpp similarity index 95% rename from src/cpp/blowfish/blowfish.cpp rename to src/advanced/cpp/fishes/blowfish.cpp index 6a03c4c..a082db9 100644 --- a/src/cpp/blowfish/blowfish.cpp +++ b/src/advanced/cpp/fishes/blowfish.cpp @@ -2,10 +2,10 @@ libpgfe blowfish.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/blowfish.hpp" +#include "libpgfe/advanced/fishes/blowfish.hpp" #include #include diff --git a/src/c/generic.c b/src/c/generic.c deleted file mode 100644 index 2852ac0..0000000 --- a/src/c/generic.c +++ /dev/null @@ -1,8 +0,0 @@ -/* - libpgfe - generic.c - - Copyright (c) 2022 Charles Dong -*/ - -#include "libpgfe/generic.h" diff --git a/src/c/hash/keccak-backend.h b/src/c/hash/keccak-backend.h deleted file mode 100644 index acae1bb..0000000 --- a/src/c/hash/keccak-backend.h +++ /dev/null @@ -1,35 +0,0 @@ -/* - libpgfe - keccak-backend.h - - Backend implementation of SHA3/Keccak algorithm - - Copyright (c) 2022 Charles Dong -*/ - -#ifndef LIBPGFE_KECCAK_BACKEND_H -#define LIBPGFE_KECCAK_BACKEND_H - -#include - -#include "libpgfe/sha3.h" - -#include "../generic-internal.h" - -#define __PGFE_KECCAK_b 1600 - -#ifdef __cplusplus -extern "C" { -#endif - -int __pgfe_keccak_init(struct pgfe_keccak_sponge_ctx *ctx, uint32_t capacity); - -int __pgfe_keccak_absorb_b1600(struct pgfe_keccak_sponge_ctx *ctx, const pgfe_encode_t input[], uint64_t bit_len); - -int __pgfe_keccak_squeeze_b1600(struct pgfe_keccak_sponge_ctx *ctx, pgfe_encode_t output[]); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/src/c/hash/md5-backend.h b/src/c/hash/md5-backend.h deleted file mode 100644 index ab7eb1d..0000000 --- a/src/c/hash/md5-backend.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - libpgfe - md5-backend.h - - Backend implementation of MD5 algorithm - - Copyright (c) 2022 Charles Dong -*/ - -#ifndef LIBPGFE_MD5_BACKEND_H -#define LIBPGFE_MD5_BACKEND_H - -#include "../generic-internal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -void __pgfe_md5_transform(pgfe_word_t state[4], const pgfe_encode_t block[64]); - -void __pgfe_md5_encode(pgfe_word_t input[], size_t length, pgfe_encode_t output[]); - -void __pgfe_md5_decode(const pgfe_encode_t input[], size_t length, pgfe_word_t output[]); - -#ifdef __cplusplus -} -#endif - -#endif \ No newline at end of file diff --git a/src/c/hash/sha224.c b/src/c/hash/sha224.c deleted file mode 100644 index 2713fe3..0000000 --- a/src/c/hash/sha224.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - libpgfe - sha224.c - - Copyright (c) 2022 Charles Dong -*/ - -#include "libpgfe/sha2.h" - -#include - -#include "./sha2-backend.h" -#include "./templates.h" - -static 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_SHA_INIT(sha224) -__PGFE_SHA_UPDATE(sha224, SHA224) - -inline void pgfe_sha224_digest(struct pgfe_sha224_ctx *ctx, pgfe_encode_t output[]) { - __pgfe_sha224n256_digest(ctx, output, PGFE_SHA224_DIGEST_SIZE); -} diff --git a/src/c/hash/sha256.c b/src/c/hash/sha256.c deleted file mode 100644 index 2f616ba..0000000 --- a/src/c/hash/sha256.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - libpgfe - sha256.c - - Copyright (c) 2022 Charles Dong -*/ - -#include "libpgfe/sha2.h" - -#include - -#include "./sha2-backend.h" -#include "./templates.h" - -static 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_SHA_INIT(sha256) -__PGFE_SHA_UPDATE(sha256, SHA256) - -inline void pgfe_sha256_digest(struct pgfe_sha256_ctx *ctx, pgfe_encode_t output[]) { - __pgfe_sha224n256_digest(ctx, output, PGFE_SHA256_DIGEST_SIZE); -} \ No newline at end of file diff --git a/src/c/base_encoding/base-encoding-internal.c b/src/core/c/bases/base-encoding-internal.c similarity index 82% rename from src/c/base_encoding/base-encoding-internal.c rename to src/core/c/bases/base-encoding-internal.c index 1160a9d..bc24753 100644 --- a/src/c/base_encoding/base-encoding-internal.c +++ b/src/core/c/bases/base-encoding-internal.c @@ -2,7 +2,7 @@ libpgfe base-encoding-internal.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "./base-encoding-internal.h" @@ -12,11 +12,11 @@ #include "../generic-internal.h" -#define __bitsz 8 +#define __bitsz (8) #define __mkmask(digit) (UINT8_MAX >> (__bitsz - (digit))) -size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_t chunk_size, pgfe_encode_t out[]) { +size_t transform(const pgfe_encode_t input[], size_t length, uint8_t chunk_size, pgfe_encode_t out[]) { const pgfe_encode_t *inp = input; pgfe_encode_t *op = out; size_t low, high, mv_sz, sz_diff; @@ -47,7 +47,7 @@ size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_ return op - out; } -size_t __pgfe_unittostr( +size_t unittostr( size_t chunk_count, size_t unit_size, size_t bit_size, size_t alphabet_size, const char alphabet[], const pgfe_encode_t unit[], char out[], bool padding ) { @@ -55,7 +55,7 @@ size_t __pgfe_unittostr( pgfe_encode_t unit_split[chunk_count]; int i; - __pgfe_transform_codes(unit, unit_size, bit_size, unit_split); + transform(unit, unit_size, bit_size, unit_split); for (i = 0; i < chunk_count; i++) { unit_s[i] = alphabet[unit_split[i]]; } @@ -74,7 +74,7 @@ size_t __pgfe_unittostr( return chunk_count; } -size_t __pgfe_encode_base_generic( +size_t encode_base_generic( PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t input[], size_t input_length, char cs_out[] ) { pgfe_encode_t input_unit[unit_size]; @@ -85,7 +85,7 @@ size_t __pgfe_encode_base_generic( for (i = 0; i < input_length; i += unit_size) { remain = input_length - i; if (remain < unit_size) { - __pgfe_arrinit(input_unit, unit_size); + arrinit(input_unit, unit_size); memcpy(input_unit, inp, remain); } else { @@ -93,9 +93,7 @@ size_t __pgfe_encode_base_generic( remain = unit_size; } - sp += __pgfe_unittostr( - chunk_count, unit_size, bit_size, alphabet_size, alphabet, input_unit, sp, unit_size - remain - ); + sp += unittostr(chunk_count, unit_size, bit_size, alphabet_size, alphabet, input_unit, sp, unit_size - remain); inp += unit_size; } @@ -103,9 +101,8 @@ size_t __pgfe_encode_base_generic( return sp - cs_out; } -size_t __pgfe_decode_base_generic( - PGFE_BASE_PARAMS_DEF, pgfe_encode_t (*func)(char), const char basexx_cs[], pgfe_encode_t output[] -) { +size_t +decode_base_generic(PGFE_BASE_PARAMS_DEF, pgfe_encode_t (*func)(char), const char basexx_cs[], pgfe_encode_t output[]) { pgfe_encode_t *op, ch, sig, o_unit[unit_size]; const char *sp = basexx_cs; size_t i, j; @@ -119,7 +116,7 @@ size_t __pgfe_decode_base_generic( ch = func(*sp); sig = ch & 0xC0; - if (sig == PGFE_BASE_UNKNOWN_CODE) { + if (sig == UNKNOWN_CODE) { continue; } diff --git a/src/c/base_encoding/base-encoding-internal.h b/src/core/c/bases/base-encoding-internal.h similarity index 52% rename from src/c/base_encoding/base-encoding-internal.h rename to src/core/c/bases/base-encoding-internal.h index e7b4b79..cac0b84 100644 --- a/src/c/base_encoding/base-encoding-internal.h +++ b/src/core/c/bases/base-encoding-internal.h @@ -4,7 +4,7 @@ Base encoding backend - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #ifndef LIBPGFE_BASE_ENCODING_INTERNAL_H @@ -12,40 +12,38 @@ #include -#include "libpgfe/generic.h" +#include "libpgfe/core/generic.h" #ifdef __cplusplus extern "C" { #endif -#define PGFE_BASE_PADDING_CODE 0x00 -#define PGFE_BASE_UNKNOWN_CODE 0xC0 +#define PADDING_CODE (0x00) +#define UNKNOWN_CODE (0xC0) #define PGFE_BASE_PARAMS(upper) \ PGFE_##upper##_CHUNK_COUNT, PGFE_##upper##_UNIT_SIZE, PGFE_##upper##_BIT_SIZE, PGFE_##upper##_ALPHABET_SIZE #define PGFE_BASE_PARAMS_DEF size_t chunk_count, size_t unit_size, size_t bit_size, size_t alphabet_size -pgfe_encode_t pgfe_decode_base64_char(char base64_c); +pgfe_encode_t decode_base64_char(char base64_c); -pgfe_encode_t pgfe_decode_base32_char(char base32_c); +pgfe_encode_t decode_base32_char(char base32_c); -pgfe_encode_t pgfe_decode_base32hex_char(char base32_c); +pgfe_encode_t decode_base32hex_char(char base32_c); -pgfe_encode_t pgfe_decode_base16_char(char base16_c); +pgfe_encode_t decode_base16_char(char base16_c); -size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_t chunk_size, pgfe_encode_t out[]); +size_t transform(const pgfe_encode_t input[], size_t length, uint8_t chunk_size, pgfe_encode_t out[]); -size_t -__pgfe_unittostr(PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t unit[], char out[], bool padding); +size_t unittostr(PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t unit[], char out[], bool padding); -size_t __pgfe_encode_base_generic( +size_t encode_base_generic( PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t input[], size_t input_length, char cs_out[] ); -size_t __pgfe_decode_base_generic( - PGFE_BASE_PARAMS_DEF, pgfe_encode_t (*func)(char), const char basexx_cs[], pgfe_encode_t output[] -); +size_t +decode_base_generic(PGFE_BASE_PARAMS_DEF, pgfe_encode_t (*func)(char), const char basexx_cs[], pgfe_encode_t output[]); #ifdef __cplusplus } diff --git a/src/c/base_encoding/base16.c b/src/core/c/bases/base16.c similarity index 64% rename from src/c/base_encoding/base16.c rename to src/core/c/bases/base16.c index 528366e..714efd6 100644 --- a/src/c/base_encoding/base16.c +++ b/src/core/c/bases/base16.c @@ -2,10 +2,10 @@ libpgfe base16.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/base-encoding.h" +#include "libpgfe/core/bases/base16.h" #include "./base-encoding-internal.h" @@ -13,7 +13,7 @@ const char BASE16_ALPHABET[] = "0123456789ABCDEF" "0"; // Compatibility addition -inline pgfe_encode_t pgfe_decode_base16_char(char base16_c) { +inline pgfe_encode_t decode_base16_char(char base16_c) { pgfe_encode_t o; if (base16_c >= '0' && base16_c <= '9') { @@ -26,16 +26,16 @@ inline pgfe_encode_t pgfe_decode_base16_char(char base16_c) { o = base16_c - 'a' + 10; } else { - o = PGFE_BASE_UNKNOWN_CODE; + o = UNKNOWN_CODE; } return o; } inline size_t pgfe_encode_base16(const pgfe_encode_t input[], size_t input_length, char cs_out[]) { - return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE16), BASE16_ALPHABET, input, input_length, cs_out); + return encode_base_generic(PGFE_BASE_PARAMS(BASE16), BASE16_ALPHABET, input, input_length, cs_out); } size_t pgfe_decode_base16(const char base16_cs[], pgfe_encode_t output[]) { - return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE16), pgfe_decode_base16_char, base16_cs, output); + return decode_base_generic(PGFE_BASE_PARAMS(BASE16), decode_base16_char, base16_cs, output); } \ No newline at end of file diff --git a/src/c/base_encoding/base32.c b/src/core/c/bases/base32.c similarity index 68% rename from src/c/base_encoding/base32.c rename to src/core/c/bases/base32.c index f31c3fe..e074e9d 100644 --- a/src/c/base_encoding/base32.c +++ b/src/core/c/bases/base32.c @@ -2,10 +2,10 @@ libpgfe base32.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/base-encoding.h" +#include "libpgfe/core/bases/base32.h" #include @@ -24,7 +24,7 @@ const char BASE32_ALPHABET_EXTHEX[] = "0123456789ABCDEF" // 0X "GHIJKLMNOPQRSTUV" // 1X "="; // Padding -inline pgfe_encode_t pgfe_decode_base32_char(char base32_c) { +inline pgfe_encode_t decode_base32_char(char base32_c) { pgfe_encode_t o; if (base32_c >= '2' && base32_c <= '7') { @@ -37,16 +37,16 @@ inline pgfe_encode_t pgfe_decode_base32_char(char base32_c) { o = base32_c - 'a'; } else if (base32_c == '=') { - o = PGFE_BASE_PADDING_CODE; + o = PADDING_CODE; } else { - o = PGFE_BASE_UNKNOWN_CODE; + o = UNKNOWN_CODE; } return o; } -inline pgfe_encode_t pgfe_decode_base32hex_char(char base32_c) { +inline pgfe_encode_t decode_base32hex_char(char base32_c) { pgfe_encode_t o; if (base32_c >= '0' && base32_c <= '9') { @@ -59,27 +59,27 @@ inline pgfe_encode_t pgfe_decode_base32hex_char(char base32_c) { o = base32_c - 'a' + 10; } else if (base32_c == '=') { - o = PGFE_BASE_PADDING_CODE; + o = PADDING_CODE; } else { - o = PGFE_BASE_UNKNOWN_CODE; + o = UNKNOWN_CODE; } return o; } inline size_t pgfe_encode_base32(const pgfe_encode_t input[], size_t input_length, char cs_out[]) { - return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET, input, input_length, cs_out); + return encode_base_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET, input, input_length, cs_out); } inline size_t pgfe_encode_base32hex(const pgfe_encode_t input[], size_t input_length, char cs_out[]) { - return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET_EXTHEX, input, input_length, cs_out); + return encode_base_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET_EXTHEX, input, input_length, cs_out); } inline size_t pgfe_decode_base32(const char base32_cs[], pgfe_encode_t output[]) { - return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32_char, base32_cs, output); + return decode_base_generic(PGFE_BASE_PARAMS(BASE32), decode_base32_char, base32_cs, output); } inline size_t pgfe_decode_base32hex(const char base32_cs[], pgfe_encode_t output[]) { - return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32hex_char, base32_cs, output); + return decode_base_generic(PGFE_BASE_PARAMS(BASE32), decode_base32hex_char, base32_cs, output); } \ No newline at end of file diff --git a/src/c/base_encoding/base64.c b/src/core/c/bases/base64.c similarity index 75% rename from src/c/base_encoding/base64.c rename to src/core/c/bases/base64.c index d67a68d..03a8b3e 100644 --- a/src/c/base_encoding/base64.c +++ b/src/core/c/bases/base64.c @@ -2,10 +2,10 @@ libpgfe base64.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/base-encoding.h" +#include "libpgfe/core/bases/base64.h" #include @@ -27,7 +27,7 @@ const char BASE64_ALPHABET_FS[] = "ABCDEFGHIJKLMNOP" // 0X "wxyz0123456789-_" // 3X "="; // Padding -inline pgfe_encode_t pgfe_decode_base64_char(char base64_c) { +inline pgfe_encode_t decode_base64_char(char base64_c) { pgfe_encode_t o; if (base64_c >= 'a' && base64_c <= 'z') { @@ -46,23 +46,23 @@ inline pgfe_encode_t pgfe_decode_base64_char(char base64_c) { o = 63; } else if (base64_c == '=') { - o = PGFE_BASE_PADDING_CODE; + o = PADDING_CODE; } else { - o = PGFE_BASE_UNKNOWN_CODE; + o = UNKNOWN_CODE; } return o; } inline size_t pgfe_encode_base64(const pgfe_encode_t input[], size_t input_length, char cs_out[]) { - return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET, input, input_length, cs_out); + return encode_base_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET, input, input_length, cs_out); } inline size_t pgfe_encode_base64_url(const pgfe_encode_t input[], size_t input_length, char cs_out[]) { - return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET_FS, input, input_length, cs_out); + return encode_base_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET_FS, input, input_length, cs_out); } inline size_t pgfe_decode_base64(const char base64_cs[], pgfe_encode_t output[]) { - return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE64), pgfe_decode_base64_char, base64_cs, output); + return decode_base_generic(PGFE_BASE_PARAMS(BASE64), decode_base64_char, base64_cs, output); } \ No newline at end of file diff --git a/src/c/generic-internal.c b/src/core/c/generic-internal.c similarity index 63% rename from src/c/generic-internal.c rename to src/core/c/generic-internal.c index bf01583..bf24317 100644 --- a/src/c/generic-internal.c +++ b/src/core/c/generic-internal.c @@ -2,24 +2,24 @@ libpgfe generic-internal.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "./generic-internal.h" #include -inline void __pgfe_arrinit(pgfe_encode_t arr[], size_t size) { +inline void arrinit(pgfe_encode_t arr[], size_t size) { memset(arr, 0, size); } -inline void __pgfe_arrcpy(pgfe_encode_t dest[], size_t dest_s, const pgfe_encode_t src[], size_t src_s) { +inline void arrcpy(pgfe_encode_t dest[], size_t dest_s, const pgfe_encode_t src[], size_t src_s) { size_t cpy_s = dest_s > src_s ? src_s : dest_s; memcpy(dest, src, cpy_s); - __pgfe_arrinit(dest + cpy_s, dest_s - cpy_s); + arrinit(dest + cpy_s, dest_s - cpy_s); } -inline void __pgfe_ch2hex(char ch, pgfe_encode_t *hex) { +inline void ch2hex(char ch, pgfe_encode_t *hex) { pgfe_encode_t tmp_o = 0; if (ch >= '0' && ch <= '9') { tmp_o = ch - '0'; @@ -37,7 +37,7 @@ inline void __pgfe_ch2hex(char ch, pgfe_encode_t *hex) { *hex = tmp_o; } -void __pgfe_reverse_elements(pgfe_encode_t *low, pgfe_encode_t *high) { +void reverse(pgfe_encode_t *low, pgfe_encode_t *high) { pgfe_encode_t tmp; for (; low < high; low++, high--) { diff --git a/src/c/generic-internal.h b/src/core/c/generic-internal.h similarity index 62% rename from src/c/generic-internal.h rename to src/core/c/generic-internal.h index 706a7ec..acbfac2 100644 --- a/src/c/generic-internal.h +++ b/src/core/c/generic-internal.h @@ -4,13 +4,13 @@ Generic configuration backend - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #ifndef LIBPGFE_GENERIC_INTERNAL_H #define LIBPGFE_GENERIC_INTERNAL_H -#include "libpgfe/generic.h" +#include "libpgfe/core/generic.h" #ifdef __cplusplus extern "C" { @@ -21,20 +21,25 @@ extern "C" { #define PGFE_ENCODER_DEF_SIG pgfe_encode_multi_func *func, size_t block_size, size_t digest_size #define PGFE_ENCODER_CALL_SIG func, block_size, digest_size +// Conversion mapping (to bit) +#define to_bit(value) pgfe_to_bit(value) +// Conversion mapping (to byte) +#define to_byte(value) pgfe_to_byte(value) +// Conversion mapping (bit remainder) +#define bit_rem(value) pgfe_bit_rem(value) + // Circular left shift #define clshift(n, c) (((n) << (c)) | ((n) >> (to_bit(sizeof(n)) - (c)))) // Circular right shift #define crshift(n, c) (((n) >> (c)) | ((n) << (to_bit(sizeof(n)) - (c)))) -#define __pgfe_loop for (;;) - -void __pgfe_arrinit(pgfe_encode_t arr[], size_t size); +void arrinit(pgfe_encode_t arr[], size_t size); -void __pgfe_arrcpy(pgfe_encode_t dest[], size_t dest_s, const pgfe_encode_t src[], size_t src_s); +void arrcpy(pgfe_encode_t dest[], size_t dest_s, const pgfe_encode_t src[], size_t src_s); -void __pgfe_ch2hex(char ch, pgfe_encode_t *hex); +void ch2hex(char ch, pgfe_encode_t *hex); -void __pgfe_reverse_elements(pgfe_encode_t *low, pgfe_encode_t *high); +void reverse(pgfe_encode_t *low, pgfe_encode_t *high); #define __PGFE_BATCH_CASES(target, name) \ switch (target) { \ @@ -86,6 +91,44 @@ void __pgfe_reverse_elements(pgfe_encode_t *low, pgfe_encode_t *high); break; \ } +// CXX compatibility + +#define __PGFE_BATCH_SHAKE_CASES(name) \ + switch (cur_alg) { \ + __PGFE_##name##_CASE(RawSHAKE128, rawshake128); \ + __PGFE_##name##_CASE(SHAKE128, shake128); \ + __PGFE_##name##_CASE(RawSHAKE256, rawshake256); \ + __PGFE_##name##_CASE(SHAKE256, shake256); \ + default: \ + break; \ + } + +#define __PGFE_INIT_SIZE_CASE(alg, name) \ + case alg: \ + digsz = PGFE_##alg##_DIGEST_SIZE; \ + blocksz = PGFE_##alg##_BLOCK_SIZE; \ + break + +#define __PGFE_INIT_CTXP_CASE(alg, name) \ + case alg: \ + pgfe_##name##_init((pgfe_##name##_ctx *)ctx); \ + break + +#define __PGFE_INIT_CTX_CASE(alg, name) \ + case alg: \ + pgfe_##name##_init(&ctx); \ + break + +#define __PGFE_SET_CTXP_CASE(alg, name) \ + case alg: \ + ctx = new pgfe_##name##_ctx; \ + break + +#define __PGFE_FREE_CTXP_CASE(alg, name) \ + case alg: \ + delete (pgfe_##name##_ctx *)ctx; \ + break + #ifdef __cplusplus } #endif diff --git a/src/core/c/generic.c b/src/core/c/generic.c new file mode 100644 index 0000000..dde866f --- /dev/null +++ b/src/core/c/generic.c @@ -0,0 +1,8 @@ +/* + libpgfe + generic.c + + Copyright (c) 2022-2023 Charles Dong +*/ + +#include "libpgfe/core/generic.h" diff --git a/src/c/hash/keccak-backend.c b/src/core/c/hashes/keccak-backend.c similarity index 90% rename from src/c/hash/keccak-backend.c rename to src/core/c/hashes/keccak-backend.c index 04b3222..577a6d0 100644 --- a/src/c/hash/keccak-backend.c +++ b/src/core/c/hashes/keccak-backend.c @@ -2,7 +2,7 @@ libpgfe keccak-backend.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "./keccak-backend.h" @@ -10,11 +10,11 @@ #include #include -static const uint16_t _r[24] = { +static const uint16_t r[24] = { 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44, }; -static const uint64_t _RC[24] = { +static const uint64_t RC[24] = { 0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 0x8000000080008000, 0x000000000000808b, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 0x0000000000000088, 0x0000000080008009, 0x000000008000000a, 0x000000008000808b, 0x800000000000008b, 0x8000000000008089, @@ -22,7 +22,7 @@ static const uint64_t _RC[24] = { 0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008, }; -static const uint16_t _piln[24] = { +static const uint16_t piln[24] = { 10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1, }; @@ -47,9 +47,9 @@ static void transform(pgfe_keccak_bitcube_t A, uint64_t RC) { // Rho & Pi t = A[1][0]; for (x = 0; x < 24; x++) { - j = _piln[x]; + j = piln[x]; C[0] = A[j % 5][j / 5]; - A[j % 5][j / 5] = clshift(t, _r[x]); + A[j % 5][j / 5] = clshift(t, r[x]); t = C[0]; } @@ -70,10 +70,10 @@ static void transform(pgfe_keccak_bitcube_t A, uint64_t RC) { A[0][0] ^= RC; } -int __pgfe_keccak_init(struct pgfe_keccak_sponge_ctx *ctx, uint32_t capacity) { - uint32_t r = __PGFE_KECCAK_b - capacity; +int keccak_init(struct pgfe_keccak_sponge_ctx *ctx, uint32_t capacity) { + uint32_t r = KECCAK_b - capacity; - if (r >= __PGFE_KECCAK_b || r % 64) { + if (r >= KECCAK_b || r % 64) { return EXIT_FAILURE; } @@ -109,7 +109,7 @@ seq_to_state_jump_end:; static void permutation(pgfe_keccak_bitcube_t A, uint16_t nr) { for (uint16_t i = 0; i < nr; i++) { - transform(A, _RC[i]); + transform(A, RC[i]); } } @@ -164,7 +164,7 @@ static void padding(struct pgfe_keccak_sponge_ctx *ctx) { ctx->squeezing = 1; } -int __pgfe_keccak_absorb_b1600(struct pgfe_keccak_sponge_ctx *ctx, const pgfe_encode_t input[], uint64_t bit_len) { +int keccak_absorb_b1600(struct pgfe_keccak_sponge_ctx *ctx, const pgfe_encode_t input[], uint64_t bit_len) { uint64_t i, j, whole_blocks; uint32_t partial_block, partial_byte; uint8_t mask; @@ -211,12 +211,12 @@ int __pgfe_keccak_absorb_b1600(struct pgfe_keccak_sponge_ctx *ctx, const pgfe_en return EXIT_SUCCESS; } -int __pgfe_keccak_squeeze_b1600(struct pgfe_keccak_sponge_ctx *ctx, pgfe_encode_t output[]) { +int keccak_squeeze_b1600(struct pgfe_keccak_sponge_ctx *ctx, pgfe_encode_t output[]) { uint64_t i, bit_len = ctx->out_length; uint32_t partial_block; if (ctx->ap_len && !ctx->ap_added) { - __pgfe_keccak_absorb_b1600(ctx, &ctx->ap, ctx->ap_len); + keccak_absorb_b1600(ctx, &ctx->ap, ctx->ap_len); ctx->ap_added = 1; } diff --git a/src/core/c/hashes/keccak-backend.h b/src/core/c/hashes/keccak-backend.h new file mode 100644 index 0000000..1412f82 --- /dev/null +++ b/src/core/c/hashes/keccak-backend.h @@ -0,0 +1,35 @@ +/* + libpgfe + keccak-backend.h + + Backend implementation of SHA3/Keccak algorithm + + Copyright (c) 2022-2023 Charles Dong +*/ + +#ifndef LIBPGFE_CORE_KECCAK_BACKEND_H +#define LIBPGFE_CORE_KECCAK_BACKEND_H + +#include + +#include "libpgfe/core/hashes/sha3.h" + +#include "../generic-internal.h" + +#define KECCAK_b 1600 + +#ifdef __cplusplus +extern "C" { +#endif + +int keccak_init(struct pgfe_keccak_sponge_ctx *ctx, uint32_t capacity); + +int keccak_absorb_b1600(struct pgfe_keccak_sponge_ctx *ctx, const pgfe_encode_t input[], uint64_t bit_len); + +int keccak_squeeze_b1600(struct pgfe_keccak_sponge_ctx *ctx, pgfe_encode_t output[]); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/c/hash/md5-backend.c b/src/core/c/hashes/md5-backend.c similarity index 87% rename from src/c/hash/md5-backend.c rename to src/core/c/hashes/md5-backend.c index 954e350..444743c 100644 --- a/src/c/hash/md5-backend.c +++ b/src/core/c/hashes/md5-backend.c @@ -2,7 +2,7 @@ libpgfe md5-backend.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "./md5-backend.h" @@ -18,21 +18,21 @@ #define _O(i, offset, limit) (((i) + (offset)) % (limit)) -static const uint8_t __S[4][4] = { +static const uint8_t S[4][4] = { {7, 12, 17, 22}, {5, 9, 14, 20}, {4, 11, 16, 23}, {6, 10, 15, 21}, }; -static const uint8_t __idx[4][16] = { +static const uint8_t idx[4][16] = { {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, {1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12}, {5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2 }, {0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 }, }; -static const uint32_t __ac[4][16] = { +static const uint32_t ac[4][16] = { {0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 0x698098d8, 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821}, {0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, 0x21e1cde6, @@ -43,7 +43,7 @@ static const uint32_t __ac[4][16] = { 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391}, }; -#define __F(r, a, b, c, d, x, s, ac) \ +#define _F(r, a, b, c, d, x, s, ac) \ switch (r) { \ case 0: \ _ROUND_TRAN((a), F((b), (c), (d)), (b), (x), (s), (ac)); \ @@ -61,7 +61,7 @@ static const uint32_t __ac[4][16] = { break; \ } -void __pgfe_md5_decode(const pgfe_encode_t input[], size_t length, pgfe_word_t output[]) { +void md5_decode(const pgfe_encode_t input[], size_t length, pgfe_word_t output[]) { size_t i, ix4; for (i = ix4 = 0; ix4 < length; i++, ix4 += 4) { @@ -72,7 +72,7 @@ void __pgfe_md5_decode(const pgfe_encode_t input[], size_t length, pgfe_word_t o } } -void __pgfe_md5_encode(pgfe_word_t input[], size_t length, pgfe_encode_t output[]) { +void md5_encode(pgfe_word_t input[], size_t length, pgfe_encode_t output[]) { size_t i, ix4; for (i = ix4 = 0; ix4 < length; i++, ix4 += 4) { @@ -83,7 +83,7 @@ void __pgfe_md5_encode(pgfe_word_t input[], size_t length, pgfe_encode_t output[ } } -void __pgfe_md5_transform(pgfe_word_t state[4], const pgfe_encode_t block[64]) { +void md5_transform(pgfe_word_t state[4], const pgfe_encode_t block[64]) { pgfe_word_t x[16], buf[4]; uint16_t r, i; @@ -93,13 +93,13 @@ void __pgfe_md5_transform(pgfe_word_t state[4], const pgfe_encode_t block[64]) { buf[1] = state[2]; // c buf[0] = state[3]; // d - __pgfe_md5_decode(block, 64, x); + md5_decode(block, 64, x); // Round 1 - 4 for (r = 0; r < 4; r++) { for (i = 0; i < 16; i++) { - __F(r, buf[_O(i, 3, 4)], buf[_O(i, 2, 4)], buf[_O(i, 1, 4)], buf[_O(i, 0, 4)], x[__idx[r][i]], - __S[r][i % 4], __ac[r][i]); + _F(r, buf[_O(i, 3, 4)], buf[_O(i, 2, 4)], buf[_O(i, 1, 4)], buf[_O(i, 0, 4)], x[idx[r][i]], S[r][i % 4], + ac[r][i]); } } diff --git a/src/core/c/hashes/md5-backend.h b/src/core/c/hashes/md5-backend.h new file mode 100644 index 0000000..52a5bde --- /dev/null +++ b/src/core/c/hashes/md5-backend.h @@ -0,0 +1,29 @@ +/* + libpgfe + md5-backend.h + + Backend implementation of MD5 algorithm + + Copyright (c) 2022-2023 Charles Dong +*/ + +#ifndef LIBPGFE_MD5_BACKEND_H +#define LIBPGFE_MD5_BACKEND_H + +#include "../generic-internal.h" + +#ifdef __cplusplus +extern "C" { +#endif + +void md5_transform(pgfe_word_t state[4], const pgfe_encode_t block[64]); + +void md5_encode(pgfe_word_t input[], size_t length, pgfe_encode_t output[]); + +void md5_decode(const pgfe_encode_t input[], size_t length, pgfe_word_t output[]); + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/c/hash/md5.c b/src/core/c/hashes/md5.c similarity index 82% rename from src/c/hash/md5.c rename to src/core/c/hashes/md5.c index 04373fa..f950248 100644 --- a/src/c/hash/md5.c +++ b/src/core/c/hashes/md5.c @@ -2,18 +2,18 @@ libpgfe md5.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/md5.h" +#include "libpgfe/core/hashes/md5.h" #include #include "./md5-backend.h" #include "./templates.h" -__PGFE_FRONTEND_GEN2(md5); -__PGFE_FRONTEND_DEFAULT_GEN2(md5, MD5); +FRONTEND_GEN2(md5); +FRONTEND_GEN2_DEFAULT(md5, MD5); static const pgfe_word_t H0[] = {0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476}; @@ -42,10 +42,10 @@ void pgfe_md5_update(struct pgfe_md5_ctx *ctx, const pgfe_encode_t input[], size if (length >= part_len) { memcpy(ctx->block + index, input, part_len); - __pgfe_md5_transform(ctx->state, ctx->block); + md5_transform(ctx->state, ctx->block); for (i = part_len; i + 63 < length; i += 64) { - __pgfe_md5_transform(ctx->state, input + i); + md5_transform(ctx->state, input + i); } index = 0; @@ -61,7 +61,7 @@ void pgfe_md5_digest(struct pgfe_md5_ctx *ctx, pgfe_encode_t output[]) { pgfe_encode_t chunk[8]; size_t i, padding_len; - __pgfe_md5_encode(ctx->count, 8, chunk); + md5_encode(ctx->count, 8, chunk); i = (size_t)((ctx->count[0] >> 3) & 0x3F); padding_len = (i < 56) ? (56 - i) : (120 - i); @@ -73,5 +73,5 @@ void pgfe_md5_digest(struct pgfe_md5_ctx *ctx, pgfe_encode_t output[]) { memset(ctx->block, 0, sizeof(ctx->block)); ctx->count[0] = ctx->count[1] = 0; - __pgfe_md5_encode(ctx->state, PGFE_MD5_DIGEST_SIZE, output); + md5_encode(ctx->state, PGFE_MD5_DIGEST_SIZE, output); } \ No newline at end of file diff --git a/src/c/hash/sha-internal.c b/src/core/c/hashes/sha-internal.c similarity index 61% rename from src/c/hash/sha-internal.c rename to src/core/c/hashes/sha-internal.c index afd4fab..62773f7 100644 --- a/src/c/hash/sha-internal.c +++ b/src/core/c/hashes/sha-internal.c @@ -2,7 +2,7 @@ libpgfe sha-internal.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "./sha-internal.h" diff --git a/src/c/hash/sha-internal.h b/src/core/c/hashes/sha-internal.h similarity index 85% rename from src/c/hash/sha-internal.h rename to src/core/c/hashes/sha-internal.h index 7ea750e..d80d291 100644 --- a/src/c/hash/sha-internal.h +++ b/src/core/c/hashes/sha-internal.h @@ -4,7 +4,7 @@ Generic implementation of SHA family - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #ifndef LIBPGFE_SHA_INTERNAL_H @@ -21,7 +21,7 @@ extern "C" { #define sha_parity(x, y, z) ((x) ^ (y) ^ (z)) -#define __PGFE_PADDING_HEADER 0x80 +#define PADDING_HEADER 0x80 #ifdef __cplusplus } diff --git a/src/c/hash/sha1.c b/src/core/c/hashes/sha1.c similarity index 81% rename from src/c/hash/sha1.c rename to src/core/c/hashes/sha1.c index 0a5a1c4..782ac1a 100644 --- a/src/c/hash/sha1.c +++ b/src/core/c/hashes/sha1.c @@ -2,10 +2,10 @@ libpgfe sha1.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/sha1.h" +#include "libpgfe/core/hashes/sha1.h" #include @@ -13,12 +13,12 @@ #include "./sha-internal.h" #include "./templates.h" -static const pgfe_word_t __pgfe_sha1_H0[] = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0}; +static const pgfe_word_t H0[] = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0}; -__PGFE_FRONTEND_GEN2(sha1) -__PGFE_FRONTEND_DEFAULT_GEN2(sha1, SHA1) +FRONTEND_GEN2(sha1) +FRONTEND_GEN2_DEFAULT(sha1, SHA1) -static void __pgfe_sha1_process_block(struct pgfe_sha1_ctx *ctx) { +static void process_block(struct pgfe_sha1_ctx *ctx) { // Constants in SHA1 static const pgfe_word_t K[] = {0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6}; @@ -91,14 +91,14 @@ static void __pgfe_sha1_process_block(struct pgfe_sha1_ctx *ctx) { memset(ws, 0, sizeof(ws)); } -static void __pgfe_sha1_padding(struct pgfe_sha1_ctx *ctx) { - ctx->block[ctx->index++] = __PGFE_PADDING_HEADER; +static void padding(struct pgfe_sha1_ctx *ctx) { + ctx->block[ctx->index++] = PADDING_HEADER; // 56 = PGFE_SHA1_BLOCK_SIZE - 8 if (ctx->index > 56) { memset(ctx->block + ctx->index, 0, PGFE_SHA1_BLOCK_SIZE - ctx->index); ctx->index = PGFE_SHA1_BLOCK_SIZE; - __pgfe_sha1_process_block(ctx); + process_block(ctx); } else if (ctx->index < 56) { memset(ctx->block + ctx->index, 0, 56 - ctx->index); @@ -115,9 +115,9 @@ static void __pgfe_sha1_padding(struct pgfe_sha1_ctx *ctx) { ctx->block[62] = (uint8_t)(ctx->len_low >> 8); ctx->block[63] = (uint8_t)ctx->len_low; - __pgfe_sha1_process_block(ctx); + process_block(ctx); } -__PGFE_SHA_INIT(sha1) -__PGFE_SHA_UPDATE(sha1, SHA1) -__PGFE_SHA_DIGEST(sha1, SHA1) +SHA_INIT(sha1) +SHA_UPDATE(sha1, SHA1) +SHA_DIGEST(sha1, SHA1) diff --git a/src/c/hash/sha2-backend.c b/src/core/c/hashes/sha2-backend.c similarity index 89% rename from src/c/hash/sha2-backend.c rename to src/core/c/hashes/sha2-backend.c index 9a55cdf..228b00f 100644 --- a/src/c/hash/sha2-backend.c +++ b/src/core/c/hashes/sha2-backend.c @@ -2,19 +2,19 @@ libpgfe sha2-backend.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "./sha2-backend.h" #include "./templates.h" -#include "libpgfe/sha2.h" +#include "libpgfe/core/hashes/sha2.h" #include // SHA-224/256 -void __pgfe_sha256_process_block(struct pgfe_sha256_ctx *ctx) { +void sha256_process_block(struct pgfe_sha256_ctx *ctx) { static const pgfe_word_t K[] = { 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5, 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174, @@ -78,14 +78,14 @@ void __pgfe_sha256_process_block(struct pgfe_sha256_ctx *ctx) { memset(ws, 0, PGFE_SHA256_BLOCK_SIZE); } -void __pgfe_sha224n256_padding(struct pgfe_sha256_ctx *ctx) { - ctx->block[ctx->index++] = __PGFE_PADDING_HEADER; +void sha224n256_padding(struct pgfe_sha256_ctx *ctx) { + ctx->block[ctx->index++] = PADDING_HEADER; // 56 = PGFE_SHA256_BLOCK_SIZE - 8 if (ctx->index > 56) { memset(ctx->block + ctx->index, 0, PGFE_SHA256_BLOCK_SIZE - ctx->index); ctx->index = PGFE_SHA256_BLOCK_SIZE; - __pgfe_sha256_process_block(ctx); + sha256_process_block(ctx); } else if (ctx->index < 56) { memset(ctx->block + ctx->index, 0, 56 - ctx->index); @@ -102,15 +102,15 @@ void __pgfe_sha224n256_padding(struct pgfe_sha256_ctx *ctx) { ctx->block[62] = (uint8_t)(ctx->len_low >> 8); ctx->block[63] = (uint8_t)(ctx->len_low); - __pgfe_sha256_process_block(ctx); + sha256_process_block(ctx); } -void __pgfe_sha224n256_digest(struct pgfe_sha256_ctx *ctx, pgfe_encode_t output[], uint8_t digest_size) { +void sha224n256_digest(struct pgfe_sha256_ctx *ctx, pgfe_encode_t output[], uint8_t digest_size) { if (!ctx || !output) return; size_t i; - __pgfe_sha224n256_padding(ctx); + sha224n256_padding(ctx); // Wipe sensitive data from the RAM memset(ctx->block, 0, sizeof(ctx->block)); @@ -124,7 +124,7 @@ void __pgfe_sha224n256_digest(struct pgfe_sha256_ctx *ctx, pgfe_encode_t output[ // SHA-384/512 -void __pgfe_sha384n512_process_block(struct pgfe_sha512_ctx *ctx) { +void sha384n512_process_block(struct pgfe_sha512_ctx *ctx) { static const pgfe_word_t K[] = { 0xD728AE22, 0x428A2F98, 0x23EF65CD, 0x71374491, 0xEC4D3B2F, 0xB5C0FBCF, 0x8189DBBC, 0xE9B5DBA5, 0xF348B538, 0x3956C25B, 0xB605D019, 0x59F111F1, 0xAF194F9B, 0x923F82A4, 0xDA6D8118, 0xAB1C5ED5, 0xA3030242, 0xD807AA98, @@ -201,7 +201,7 @@ void __pgfe_sha384n512_process_block(struct pgfe_sha512_ctx *ctx) { memset(ws, 0, 80); } -void __pgfe_sha384n512_update(struct pgfe_sha512_ctx *ctx, const pgfe_encode_t input[], size_t length) { +void sha384n512_update(struct pgfe_sha512_ctx *ctx, const pgfe_encode_t input[], size_t length) { if (!ctx || !input) return; const pgfe_encode_t *inp = input; @@ -219,21 +219,21 @@ void __pgfe_sha384n512_update(struct pgfe_sha512_ctx *ctx, const pgfe_encode_t i } if (!corrupt_flag && ctx->index == PGFE_SHA512_BLOCK_SIZE) { - __pgfe_sha384n512_process_block(ctx); + sha384n512_process_block(ctx); } inp++; } } -void __pgfe_sha384n512_padding(struct pgfe_sha512_ctx *ctx, pgfe_encode_t padding_byte) { +void sha384n512_padding(struct pgfe_sha512_ctx *ctx, pgfe_encode_t padding_byte) { ctx->block[ctx->index++] = padding_byte; // 112 = PGFE_SHA512_BLOCK_SIZE - 16 if (ctx->index > 112) { memset(&ctx->block[ctx->index], 0, PGFE_SHA512_BLOCK_SIZE - ctx->index); ctx->index = PGFE_SHA512_BLOCK_SIZE; - __pgfe_sha384n512_process_block(ctx); + sha384n512_process_block(ctx); } else if (ctx->index < 112) { memset(&ctx->block[ctx->index], 0, 112 - ctx->index); @@ -257,15 +257,15 @@ void __pgfe_sha384n512_padding(struct pgfe_sha512_ctx *ctx, pgfe_encode_t paddin ctx->block[126] = (uint8_t)(ctx->len_low >> 8); ctx->block[127] = (uint8_t)ctx->len_low; - __pgfe_sha384n512_process_block(ctx); + sha384n512_process_block(ctx); } -void __pgfe_sha384n512_digest(struct pgfe_sha512_ctx *ctx, pgfe_encode_t output[], uint8_t digest_size) { +void sha384n512_digest(struct pgfe_sha512_ctx *ctx, pgfe_encode_t output[], uint8_t digest_size) { if (!ctx || !output) return; size_t i; - __pgfe_sha384n512_padding(ctx, __PGFE_PADDING_HEADER); + sha384n512_padding(ctx, PADDING_HEADER); // Wipe data from RAM memset(ctx->block, 0, sizeof(ctx->block)); diff --git a/src/c/hash/sha2-backend.h b/src/core/c/hashes/sha2-backend.h similarity index 56% rename from src/c/hash/sha2-backend.h rename to src/core/c/hashes/sha2-backend.h index 7610316..10d7ed3 100644 --- a/src/c/hash/sha2-backend.h +++ b/src/core/c/hashes/sha2-backend.h @@ -4,7 +4,7 @@ Generic implementation of SHA2 family - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #ifndef LIBPGFE_SHA2_INTERNAL_H @@ -12,7 +12,7 @@ #include "./sha-internal.h" -#include "libpgfe/sha2.h" +#include "libpgfe/core/hashes/sha2.h" #ifdef __cpluslpus extern "C" { @@ -28,25 +28,25 @@ extern "C" { #define sha512_sigma0(word) (crshift((word), 1) ^ crshift((word), 8) ^ ((word) >> 7)) #define sha512_sigma1(word) (crshift((word), 19) ^ crshift((word), 61) ^ ((word) >> 6)) -void __pgfe_sha224n256_init(struct pgfe_sha256_ctx *ctx, const pgfe_word_t H0[]); +void sha224n256_init(struct pgfe_sha256_ctx *ctx, const pgfe_word_t H0[]); -void __pgfe_sha256_process_block(struct pgfe_sha256_ctx *ctx); +void sha256_process_block(struct pgfe_sha256_ctx *ctx); #define __pgfe_sha224_process_block __pgfe_sha256_process_block -void __pgfe_sha224n256_padding(struct pgfe_sha256_ctx *ctx); +void sha224n256_padding(struct pgfe_sha256_ctx *ctx); -void __pgfe_sha224n256_digest(struct pgfe_sha256_ctx *ctx, pgfe_encode_t output[], uint8_t digest_size); +void sha224n256_digest(struct pgfe_sha256_ctx *ctx, pgfe_encode_t output[], uint8_t digest_size); -void __pgfe_sha384n512_init(struct pgfe_sha512_ctx *ctx, const pgfe_word_t H0[]); +void sha384n512_init(struct pgfe_sha512_ctx *ctx, const pgfe_word_t H0[]); -void __pgfe_sha384n512_update(struct pgfe_sha512_ctx *ctx, const pgfe_encode_t input[], size_t length); +void sha384n512_update(struct pgfe_sha512_ctx *ctx, const pgfe_encode_t input[], size_t length); -void __pgfe_sha384n512_process_block(struct pgfe_sha512_ctx *ctx); +void sha384n512_process_block(struct pgfe_sha512_ctx *ctx); -void __pgfe_sha384n512_padding(struct pgfe_sha512_ctx *ctx, pgfe_encode_t padding_byte); +void sha384n512_padding(struct pgfe_sha512_ctx *ctx, pgfe_encode_t padding_byte); -void __pgfe_sha384n512_digest(struct pgfe_sha512_ctx *ctx, pgfe_encode_t output[], uint8_t digest_size); +void sha384n512_digest(struct pgfe_sha512_ctx *ctx, pgfe_encode_t output[], uint8_t digest_size); #ifdef __cplusplus } diff --git a/src/core/c/hashes/sha224.c b/src/core/c/hashes/sha224.c new file mode 100644 index 0000000..f290c9a --- /dev/null +++ b/src/core/c/hashes/sha224.c @@ -0,0 +1,27 @@ +/* + libpgfe + sha224.c + + Copyright (c) 2022-2023 Charles Dong +*/ + +#include "libpgfe/core/hashes/sha2.h" + +#include + +#include "./sha2-backend.h" +#include "./templates.h" + +static const pgfe_word_t H0[] = { + 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4, +}; + +FRONTEND_GEN2(sha224) +FRONTEND_GEN2_DEFAULT(sha224, SHA224) + +SHA_INIT(sha224) +SHA_UPDATE(sha224, SHA224) + +inline void pgfe_sha224_digest(struct pgfe_sha224_ctx *ctx, pgfe_encode_t output[]) { + sha224n256_digest(ctx, output, PGFE_SHA224_DIGEST_SIZE); +} diff --git a/src/core/c/hashes/sha256.c b/src/core/c/hashes/sha256.c new file mode 100644 index 0000000..16d19fd --- /dev/null +++ b/src/core/c/hashes/sha256.c @@ -0,0 +1,27 @@ +/* + libpgfe + sha256.c + + Copyright (c) 2022-2023 Charles Dong +*/ + +#include "libpgfe/core/hashes/sha2.h" + +#include + +#include "./sha2-backend.h" +#include "./templates.h" + +static const pgfe_word_t H0[] = { + 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19, +}; + +FRONTEND_GEN2(sha256) +FRONTEND_GEN2_DEFAULT(sha256, SHA256) + +SHA_INIT(sha256) +SHA_UPDATE(sha256, SHA256) + +inline void pgfe_sha256_digest(struct pgfe_sha256_ctx *ctx, pgfe_encode_t output[]) { + sha224n256_digest(ctx, output, PGFE_SHA256_DIGEST_SIZE); +} \ No newline at end of file diff --git a/src/c/hash/sha3-224.c b/src/core/c/hashes/sha3-224.c similarity index 59% rename from src/c/hash/sha3-224.c rename to src/core/c/hashes/sha3-224.c index b900c3c..aa01f51 100644 --- a/src/c/hash/sha3-224.c +++ b/src/core/c/hashes/sha3-224.c @@ -2,29 +2,30 @@ libpgfe sha3-224.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/sha3.h" +#include "libpgfe/core/hashes/sha3.h" #include +#include "./keccak-backend.h" #include "./templates.h" -__PGFE_FRONTEND_GEN2(sha3_224); -__PGFE_FRONTEND_DEFAULT_GEN2(sha3_224, SHA3_224); +FRONTEND_GEN2(sha3_224); +FRONTEND_GEN2_DEFAULT(sha3_224, SHA3_224); inline void pgfe_sha3_224_init(struct pgfe_sha3_224_ctx *ctx) { - __pgfe_keccak_init(ctx, 448); + keccak_init(ctx, 448); ctx->out_length = 224; ctx->ap = PGFE_SHA3_APPENDIX; ctx->ap_len = PGFE_SHA3_APPENDIX_SIZE; } inline void pgfe_sha3_224_update(struct pgfe_sha3_224_ctx *ctx, const pgfe_encode_t input[], size_t length) { - __pgfe_keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); + keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); } inline void pgfe_sha3_224_digest(struct pgfe_sha3_224_ctx *ctx, pgfe_encode_t output[]) { - __pgfe_keccak_squeeze_b1600(ctx, output); + keccak_squeeze_b1600(ctx, output); } \ No newline at end of file diff --git a/src/c/hash/sha3-256.c b/src/core/c/hashes/sha3-256.c similarity index 59% rename from src/c/hash/sha3-256.c rename to src/core/c/hashes/sha3-256.c index 9155dee..f107964 100644 --- a/src/c/hash/sha3-256.c +++ b/src/core/c/hashes/sha3-256.c @@ -2,29 +2,30 @@ libpgfe sha3-256.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/sha3.h" +#include "libpgfe/core/hashes/sha3.h" #include +#include "./keccak-backend.h" #include "./templates.h" -__PGFE_FRONTEND_GEN2(sha3_256); -__PGFE_FRONTEND_DEFAULT_GEN2(sha3_256, SHA3_256); +FRONTEND_GEN2(sha3_256); +FRONTEND_GEN2_DEFAULT(sha3_256, SHA3_256); inline void pgfe_sha3_256_init(struct pgfe_sha3_256_ctx *ctx) { - __pgfe_keccak_init(ctx, 512); + keccak_init(ctx, 512); ctx->out_length = 256; ctx->ap = PGFE_SHA3_APPENDIX; ctx->ap_len = PGFE_SHA3_APPENDIX_SIZE; } inline void pgfe_sha3_256_update(struct pgfe_sha3_256_ctx *ctx, const pgfe_encode_t input[], size_t length) { - __pgfe_keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); + keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); } inline void pgfe_sha3_256_digest(struct pgfe_sha3_256_ctx *ctx, pgfe_encode_t output[]) { - __pgfe_keccak_squeeze_b1600(ctx, output); + keccak_squeeze_b1600(ctx, output); } \ No newline at end of file diff --git a/src/c/hash/sha3-384.c b/src/core/c/hashes/sha3-384.c similarity index 59% rename from src/c/hash/sha3-384.c rename to src/core/c/hashes/sha3-384.c index 6bbfe3b..fe666bb 100644 --- a/src/c/hash/sha3-384.c +++ b/src/core/c/hashes/sha3-384.c @@ -2,29 +2,30 @@ libpgfe sha3-384.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/sha3.h" +#include "libpgfe/core/hashes/sha3.h" #include +#include "./keccak-backend.h" #include "./templates.h" -__PGFE_FRONTEND_GEN2(sha3_384); -__PGFE_FRONTEND_DEFAULT_GEN2(sha3_384, SHA3_384); +FRONTEND_GEN2(sha3_384); +FRONTEND_GEN2_DEFAULT(sha3_384, SHA3_384); inline void pgfe_sha3_384_init(struct pgfe_sha3_384_ctx *ctx) { - __pgfe_keccak_init(ctx, 768); + keccak_init(ctx, 768); ctx->out_length = 384; ctx->ap = PGFE_SHA3_APPENDIX; ctx->ap_len = PGFE_SHA3_APPENDIX_SIZE; } inline void pgfe_sha3_384_update(struct pgfe_sha3_384_ctx *ctx, const pgfe_encode_t input[], size_t length) { - __pgfe_keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); + keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); } inline void pgfe_sha3_384_digest(struct pgfe_sha3_384_ctx *ctx, pgfe_encode_t output[]) { - __pgfe_keccak_squeeze_b1600(ctx, output); + keccak_squeeze_b1600(ctx, output); } \ No newline at end of file diff --git a/src/c/hash/sha3-512.c b/src/core/c/hashes/sha3-512.c similarity index 59% rename from src/c/hash/sha3-512.c rename to src/core/c/hashes/sha3-512.c index 9d63e8d..b61f240 100644 --- a/src/c/hash/sha3-512.c +++ b/src/core/c/hashes/sha3-512.c @@ -2,29 +2,30 @@ libpgfe sha3-512.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/sha3.h" +#include "libpgfe/core/hashes/sha3.h" #include +#include "./keccak-backend.h" #include "./templates.h" -__PGFE_FRONTEND_GEN2(sha3_512); -__PGFE_FRONTEND_DEFAULT_GEN2(sha3_512, SHA3_512); +FRONTEND_GEN2(sha3_512); +FRONTEND_GEN2_DEFAULT(sha3_512, SHA3_512); inline void pgfe_sha3_512_init(struct pgfe_sha3_512_ctx *ctx) { - __pgfe_keccak_init(ctx, 1024); + keccak_init(ctx, 1024); ctx->out_length = 512; ctx->ap = PGFE_SHA3_APPENDIX; ctx->ap_len = PGFE_SHA3_APPENDIX_SIZE; } inline void pgfe_sha3_512_update(struct pgfe_sha3_512_ctx *ctx, const pgfe_encode_t input[], size_t length) { - __pgfe_keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); + keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); } inline void pgfe_sha3_512_digest(struct pgfe_sha3_512_ctx *ctx, pgfe_encode_t output[]) { - __pgfe_keccak_squeeze_b1600(ctx, output); + keccak_squeeze_b1600(ctx, output); } \ No newline at end of file diff --git a/src/c/hash/sha384.c b/src/core/c/hashes/sha384.c similarity index 64% rename from src/c/hash/sha384.c rename to src/core/c/hashes/sha384.c index 675bd00..e1381f4 100644 --- a/src/c/hash/sha384.c +++ b/src/core/c/hashes/sha384.c @@ -2,23 +2,23 @@ libpgfe sha384.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/sha2.h" +#include "libpgfe/core/hashes/sha2.h" #include #include "./sha2-backend.h" #include "./templates.h" -static const pgfe_word_t __pgfe_sha384_H0[] = { +static const pgfe_word_t H0[] = { 0xC1059ED8, 0xCBBB9D5D, 0x367CD507, 0x629A292A, 0x3070DD17, 0x9159015A, 0xF70E5939, 0x152FECD8, 0xFFC00B31, 0x67332667, 0x68581511, 0x8EB44A87, 0x64F98FA7, 0xDB0C2E0D, 0xBEFA4FA4, 0x47B5481D, }; -__PGFE_FRONTEND_GEN2(sha384) -__PGFE_FRONTEND_DEFAULT_GEN2(sha384, SHA384) +FRONTEND_GEN2(sha384) +FRONTEND_GEN2_DEFAULT(sha384, SHA384) void pgfe_sha384_init(struct pgfe_sha384_ctx *ctx) { if (!ctx) return; @@ -26,13 +26,13 @@ void pgfe_sha384_init(struct pgfe_sha384_ctx *ctx) { ctx->len_low = ctx->len_high = 0; ctx->index = 0; - memcpy(ctx->state, __pgfe_sha384_H0, sizeof(ctx->state)); + memcpy(ctx->state, H0, sizeof(ctx->state)); } inline void pgfe_sha384_update(struct pgfe_sha384_ctx *ctx, const pgfe_encode_t input[], size_t length) { - __pgfe_sha384n512_update(ctx, input, length); + sha384n512_update(ctx, input, length); } inline void pgfe_sha384_digest(struct pgfe_sha384_ctx *ctx, pgfe_encode_t output[]) { - __pgfe_sha384n512_digest(ctx, output, PGFE_SHA384_DIGEST_SIZE); + sha384n512_digest(ctx, output, PGFE_SHA384_DIGEST_SIZE); } \ No newline at end of file diff --git a/src/c/hash/sha512.c b/src/core/c/hashes/sha512.c similarity index 63% rename from src/c/hash/sha512.c rename to src/core/c/hashes/sha512.c index bb83a17..4fe1add 100644 --- a/src/c/hash/sha512.c +++ b/src/core/c/hashes/sha512.c @@ -2,27 +2,27 @@ libpgfe sha512.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/sha2.h" +#include "libpgfe/core/hashes/sha2.h" #include #include "./sha2-backend.h" #include "./templates.h" -static const pgfe_word_t __pgfe_sha512_H0[] = { +static const pgfe_word_t H0[] = { 0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85, 0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A, 0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C, 0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19, }; -static const pgfe_word_t __pgfe_sha512_224_H0[] = { +static const pgfe_word_t H0_224[] = { 0x19544DA2, 0x8C3D37C8, 0x89DCD4D6, 0x73E19966, 0x32FF9C82, 0x1DFAB7AE, 0x582F9FCF, 0x679DD514, 0x7BD44DA8, 0x0F6D2B69, 0x04C48942, 0x77E36F73, 0x6A1D36C8, 0x3F9D85A8, 0x91D692A1, 0x1112E6AD, }; -static const pgfe_word_t __pgfe_sha512_256_H0[] = { +static const pgfe_word_t H0_256[] = { 0xFC2BF72C, 0x22312194, 0xC84C64C2, 0x9F555FA3, 0x6F53B151, 0x2393B86B, 0x5940EABD, 0x96387719, 0xA88EFFE3, 0x96283EE2, 0x53863992, 0xBE5E1E25, 0x2C85B8AA, 0x2B0199FC, 0x81C52CA2, 0x0EB72DDC, }; @@ -36,47 +36,47 @@ static void pgfe_sha512_generic_init(struct pgfe_sha512_ctx *ctx, const pgfe_wor memcpy(ctx->state, H0, sizeof(ctx->state)); } -__PGFE_FRONTEND_GEN2(sha512) -__PGFE_FRONTEND_DEFAULT_GEN2(sha512, SHA512); +FRONTEND_GEN2(sha512) +FRONTEND_GEN2_DEFAULT(sha512, SHA512); inline void pgfe_sha512_init(struct pgfe_sha512_ctx *ctx) { - pgfe_sha512_generic_init(ctx, __pgfe_sha512_H0); + pgfe_sha512_generic_init(ctx, H0); } inline void pgfe_sha512_update(struct pgfe_sha512_ctx *ctx, const pgfe_encode_t input[], size_t length) { - __pgfe_sha384n512_update(ctx, input, length); + sha384n512_update(ctx, input, length); } inline void pgfe_sha512_digest(struct pgfe_sha512_ctx *ctx, pgfe_encode_t output[]) { - __pgfe_sha384n512_digest(ctx, output, PGFE_SHA512_DIGEST_SIZE); + sha384n512_digest(ctx, output, PGFE_SHA512_DIGEST_SIZE); } -__PGFE_FRONTEND_GEN2(sha512_224); -__PGFE_FRONTEND_DEFAULT_GEN2(sha512_224, SHA512_224); +FRONTEND_GEN2(sha512_224); +FRONTEND_GEN2_DEFAULT(sha512_224, SHA512_224); inline void pgfe_sha512_224_init(struct pgfe_sha512_ctx *ctx) { - pgfe_sha512_generic_init(ctx, __pgfe_sha512_224_H0); + pgfe_sha512_generic_init(ctx, H0_224); } inline void pgfe_sha512_224_update(struct pgfe_sha512_ctx *ctx, const pgfe_encode_t input[], size_t length) { - __pgfe_sha384n512_update(ctx, input, length); + sha384n512_update(ctx, input, length); } inline void pgfe_sha512_224_digest(struct pgfe_sha512_ctx *ctx, pgfe_encode_t output[]) { - __pgfe_sha384n512_digest(ctx, output, PGFE_SHA512_224_DIGEST_SIZE); + sha384n512_digest(ctx, output, PGFE_SHA512_224_DIGEST_SIZE); } -__PGFE_FRONTEND_GEN2(sha512_256); -__PGFE_FRONTEND_DEFAULT_GEN2(sha512_256, SHA512_256); +FRONTEND_GEN2(sha512_256); +FRONTEND_GEN2_DEFAULT(sha512_256, SHA512_256); inline void pgfe_sha512_256_init(struct pgfe_sha512_ctx *ctx) { - pgfe_sha512_generic_init(ctx, __pgfe_sha512_256_H0); + pgfe_sha512_generic_init(ctx, H0_256); } inline void pgfe_sha512_256_update(struct pgfe_sha512_ctx *ctx, const pgfe_encode_t input[], size_t length) { - __pgfe_sha384n512_update(ctx, input, length); + sha384n512_update(ctx, input, length); } inline void pgfe_sha512_256_digest(struct pgfe_sha512_ctx *ctx, pgfe_encode_t output[]) { - __pgfe_sha384n512_digest(ctx, output, PGFE_SHA512_256_DIGEST_SIZE); + sha384n512_digest(ctx, output, PGFE_SHA512_256_DIGEST_SIZE); } diff --git a/src/c/hash/shake.c b/src/core/c/hashes/shake.c similarity index 77% rename from src/c/hash/shake.c rename to src/core/c/hashes/shake.c index 6347ac3..869e3d6 100644 --- a/src/c/hash/shake.c +++ b/src/core/c/hashes/shake.c @@ -2,44 +2,45 @@ libpgfe shake.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/sha3.h" +#include "libpgfe/core/hashes/sha3.h" #include +#include "./keccak-backend.h" #include "./templates.h" // RawSHAKE128 -__PGFE_FRONTEND_GEN3(rawshake128, RAWSHAKE128) +FRONTEND_GEN3(rawshake128, RAWSHAKE128) // -- Context-based functions void pgfe_rawshake128_init(struct pgfe_shake128_ctx *ctx) { - __pgfe_keccak_init(ctx, 256); + keccak_init(ctx, 256); ctx->ap = PGFE_RAWSHAKE_APPENDIX; ctx->ap_len = PGFE_RAWSHAKE_APPENDIX_SIZE; } void pgfe_rawshake128_update(struct pgfe_shake128_ctx *ctx, const pgfe_encode_t input[], size_t length) { - __pgfe_keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); + keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); } void pgfe_rawshake128_digest(struct pgfe_shake128_ctx *ctx, pgfe_encode_t output[], size_t output_bitlength) { ctx->out_length = output_bitlength; - __pgfe_keccak_squeeze_b1600(ctx, output); + keccak_squeeze_b1600(ctx, output); } // SHAKE128 -__PGFE_FRONTEND_GEN3(shake128, SHAKE128) +FRONTEND_GEN3(shake128, SHAKE128) // -- Context-based functions void pgfe_shake128_init(struct pgfe_shake128_ctx *ctx) { - __pgfe_keccak_init(ctx, 256); + keccak_init(ctx, 256); ctx->ap = PGFE_SHAKE_APPENDIX; ctx->ap_len = PGFE_SHAKE_APPENDIX_SIZE; } @@ -54,33 +55,33 @@ inline void pgfe_shake128_digest(struct pgfe_shake128_ctx *ctx, pgfe_encode_t ou // RawSHAKE256 -__PGFE_FRONTEND_GEN3(rawshake256, RAWSHAKE256) +FRONTEND_GEN3(rawshake256, RAWSHAKE256) // -- Context-based functions void pgfe_rawshake256_init(struct pgfe_shake256_ctx *ctx) { - __pgfe_keccak_init(ctx, 512); + keccak_init(ctx, 512); ctx->ap = PGFE_RAWSHAKE_APPENDIX; ctx->ap_len = PGFE_RAWSHAKE_APPENDIX_SIZE; } void pgfe_rawshake256_update(struct pgfe_shake256_ctx *ctx, const pgfe_encode_t input[], size_t length) { - __pgfe_keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); + keccak_absorb_b1600(ctx, input, to_bit((uint64_t)length)); } void pgfe_rawshake256_digest(struct pgfe_shake256_ctx *ctx, pgfe_encode_t output[], size_t output_bitlength) { ctx->out_length = output_bitlength; - __pgfe_keccak_squeeze_b1600(ctx, output); + keccak_squeeze_b1600(ctx, output); } // SHAKE256 -__PGFE_FRONTEND_GEN3(shake256, SHAKE256) +FRONTEND_GEN3(shake256, SHAKE256) // -- Context-based functions void pgfe_shake256_init(struct pgfe_shake256_ctx *ctx) { - __pgfe_keccak_init(ctx, 512); + keccak_init(ctx, 512); ctx->ap = PGFE_SHAKE_APPENDIX; ctx->ap_len = PGFE_SHAKE_APPENDIX_SIZE; } diff --git a/src/c/hash/templates.h b/src/core/c/hashes/templates.h similarity index 96% rename from src/c/hash/templates.h rename to src/core/c/hashes/templates.h index 9aa1de2..afa4611 100644 --- a/src/c/hash/templates.h +++ b/src/core/c/hashes/templates.h @@ -4,7 +4,7 @@ Template macros - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #ifndef LIBPGFE_TEMPLATES_H @@ -16,7 +16,7 @@ extern "C" { // NATIVE HASH BACKEND -#define __PGFE_FRONTEND_GEN2(name) \ +#define FRONTEND_GEN2(name) \ void pgfe_##name##_encode(const pgfe_encode_t data[], size_t length, pgfe_encode_t output[]) { \ struct pgfe_##name##_ctx ctx; \ \ @@ -63,12 +63,12 @@ extern "C" { pgfe_##name##_digest(&ctx, output); \ } -#define __PGFE_FRONTEND_DEFAULT_GEN2(name, upper) \ +#define FRONTEND_GEN2_DEFAULT(name, upper) \ inline void pgfe_##name##_encode_default(const pgfe_encode_t data_str[], pgfe_encode_t output[]) { \ pgfe_##name##_encode(data_str, strlen((char *)data_str), output); \ } -#define __PGFE_FRONTEND_GEN3(name, upper) \ +#define FRONTEND_GEN3(name, upper) \ void pgfe_##name##_encode( \ const pgfe_encode_t data[], size_t length, pgfe_encode_t output[], size_t out_bitlength \ ) { \ @@ -122,17 +122,17 @@ extern "C" { pgfe_##name##_encode(data_str, strlen((char *)data_str), output, out_bitlength); \ } -#define __PGFE_SHA_INIT(name) \ +#define SHA_INIT(name) \ void pgfe_##name##_init(struct pgfe_##name##_ctx *ctx) { \ if (!ctx) return; \ \ ctx->len_low = ctx->len_high = 0; \ ctx->index = 0; \ \ - memcpy(ctx->state, __pgfe_##name##_H0, sizeof(__pgfe_##name##_H0)); \ + memcpy(ctx->state, H0, sizeof(H0)); \ } -#define __PGFE_SHA_UPDATE(name, upper) \ +#define SHA_UPDATE(name, upper) \ void pgfe_##name##_update(struct pgfe_##name##_ctx *ctx, const pgfe_encode_t input[], size_t length) { \ if (!ctx || !input) return; \ \ @@ -154,7 +154,7 @@ extern "C" { } \ } -#define __PGFE_SHA_DIGEST(name, upper) \ +#define SHA_DIGEST(name, upper) \ void pgfe_##name##_digest(struct pgfe_##name##_ctx *ctx, pgfe_encode_t output[]) { \ if (!ctx || !output) return; \ \ diff --git a/src/c/hmac/hmac.c b/src/core/c/hmac/hmac.c similarity index 87% rename from src/c/hmac/hmac.c rename to src/core/c/hmac/hmac.c index 46a5ee3..35f3b1d 100644 --- a/src/c/hmac/hmac.c +++ b/src/core/c/hmac/hmac.c @@ -2,16 +2,16 @@ libpgfe hmac.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/hmac.h" +#include "libpgfe/core/hmac/hmac.h" #include #include "../generic-internal.h" -#define __pgfe_hmac_tmpl(name, upper) \ +#define hmac_gen(name, upper) \ void pgfe_hmac_##name##_init(struct pgfe_hmac_##name##_ctx *ctx) { \ pgfe_##name##_init(&ctx->hash_ctx); \ memset(ctx->k_i_pad, I_UNIT, PGFE_##upper##_BLOCK_SIZE); \ @@ -21,8 +21,8 @@ void pgfe_hmac_##name##_set_key( \ struct pgfe_hmac_##name##_ctx *ctx, const pgfe_encode_t key[], size_t key_length \ ) { \ - __pgfe_arrcpy(ctx->k_i_pad, PGFE_##upper##_BLOCK_SIZE, key, key_length); \ - __pgfe_arrcpy(ctx->k_o_pad, PGFE_##upper##_BLOCK_SIZE, key, key_length); \ + arrcpy(ctx->k_i_pad, PGFE_##upper##_BLOCK_SIZE, key, key_length); \ + arrcpy(ctx->k_o_pad, PGFE_##upper##_BLOCK_SIZE, key, key_length); \ for (size_t i = 0; i < PGFE_##upper##_BLOCK_SIZE; i++) { \ ctx->k_i_pad[i] ^= I_UNIT; \ ctx->k_o_pad[i] ^= O_UNIT; \ @@ -58,18 +58,18 @@ pgfe_hmac_##name##_digest(&ctx, output); \ } -__pgfe_hmac_tmpl(md5, MD5); -__pgfe_hmac_tmpl(sha1, SHA1); -__pgfe_hmac_tmpl(sha224, SHA224); -__pgfe_hmac_tmpl(sha256, SHA256); -__pgfe_hmac_tmpl(sha384, SHA384); -__pgfe_hmac_tmpl(sha512, SHA512); -__pgfe_hmac_tmpl(sha512_224, SHA512_224); -__pgfe_hmac_tmpl(sha512_256, SHA512_256); -__pgfe_hmac_tmpl(sha3_224, SHA3_224); -__pgfe_hmac_tmpl(sha3_256, SHA3_256); -__pgfe_hmac_tmpl(sha3_384, SHA3_384); -__pgfe_hmac_tmpl(sha3_512, SHA3_512); +hmac_gen(md5, MD5); +hmac_gen(sha1, SHA1); +hmac_gen(sha224, SHA224); +hmac_gen(sha256, SHA256); +hmac_gen(sha384, SHA384); +hmac_gen(sha512, SHA512); +hmac_gen(sha512_224, SHA512_224); +hmac_gen(sha512_256, SHA512_256); +hmac_gen(sha3_224, SHA3_224); +hmac_gen(sha3_256, SHA3_256); +hmac_gen(sha3_384, SHA3_384); +hmac_gen(sha3_512, SHA3_512); #define __PGFE_ALG_SELECT_CASE(upper, lower) \ case upper: \ diff --git a/src/c/utils.c b/src/core/c/utils.c similarity index 94% rename from src/c/utils.c rename to src/core/c/utils.c index f87d86d..b9ffdcc 100644 --- a/src/c/utils.c +++ b/src/core/c/utils.c @@ -2,10 +2,10 @@ libpgfe utils.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/utils.h" +#include "libpgfe/core/utils.h" #include @@ -43,7 +43,7 @@ size_t pgfe_hex_string_to_hash(const char hash_s[], pgfe_encode_t hash_out[]) { } for (op = hash_out, pos = hash_str_len % 2; *sp; sp++) { - __pgfe_ch2hex(*sp, &tmp_o); + ch2hex(*sp, &tmp_o); if (tmp_o == PGFE_HEX_UNKNOWN_CHAR) { continue; @@ -83,7 +83,7 @@ size_t pgfe_hash_string_clean(const char hash_s[], char output[]) { } } - __pgfe_ch2hex(*sp, &h); + ch2hex(*sp, &h); if (h == PGFE_HEX_UNKNOWN_CHAR) { continue; } diff --git a/src/cpp/algorithm_selectable.cpp b/src/core/cpp/algorithm_selectable.cpp similarity index 79% rename from src/cpp/algorithm_selectable.cpp rename to src/core/cpp/algorithm_selectable.cpp index e9a16b9..2de7ae5 100644 --- a/src/cpp/algorithm_selectable.cpp +++ b/src/core/cpp/algorithm_selectable.cpp @@ -2,10 +2,10 @@ libpgfe algorithm_selectable.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/algorithm_selectable.hpp" +#include "libpgfe/core/algorithm_selectable.hpp" using namespace libpgfe; diff --git a/src/cpp/base_encoding/abstract_base_encoding.cpp b/src/core/cpp/bases/abstract_base_encoding.cpp similarity index 95% rename from src/cpp/base_encoding/abstract_base_encoding.cpp rename to src/core/cpp/bases/abstract_base_encoding.cpp index 4803743..cfd54f1 100644 --- a/src/cpp/base_encoding/abstract_base_encoding.cpp +++ b/src/core/cpp/bases/abstract_base_encoding.cpp @@ -2,13 +2,13 @@ libpgfe abstract_base_encoding.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include #include -#include "libpgfe/abstract_base_encoding.hpp" +#include "libpgfe/core/abstract_base_encoding.hpp" #define PGFE_SPACE_MULTIPLE 1.2 diff --git a/src/cpp/base_encoding/base16.cpp b/src/core/cpp/bases/base16.cpp similarity index 82% rename from src/cpp/base_encoding/base16.cpp rename to src/core/cpp/bases/base16.cpp index 4b77fec..72e90f5 100644 --- a/src/cpp/base_encoding/base16.cpp +++ b/src/core/cpp/bases/base16.cpp @@ -2,12 +2,12 @@ libpgfe base16.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/base16.hpp" +#include "libpgfe/core/bases/base16.hpp" -#include "libpgfe/base-encoding.h" +#include "libpgfe/core/bases/base16.h" using namespace libpgfe; diff --git a/src/cpp/base_encoding/base32.cpp b/src/core/cpp/bases/base32.cpp similarity index 86% rename from src/cpp/base_encoding/base32.cpp rename to src/core/cpp/bases/base32.cpp index 91fd027..e9da75d 100644 --- a/src/cpp/base_encoding/base32.cpp +++ b/src/core/cpp/bases/base32.cpp @@ -2,12 +2,12 @@ libpgfe base32.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/base32.hpp" +#include "libpgfe/core/bases/base32.hpp" -#include "libpgfe/base-encoding.h" +#include "libpgfe/core/bases/base32.h" using namespace libpgfe; diff --git a/src/cpp/base_encoding/base64.cpp b/src/core/cpp/bases/base64.cpp similarity index 85% rename from src/cpp/base_encoding/base64.cpp rename to src/core/cpp/bases/base64.cpp index a3b8dc2..8912e68 100644 --- a/src/cpp/base_encoding/base64.cpp +++ b/src/core/cpp/bases/base64.cpp @@ -2,12 +2,12 @@ libpgfe base64.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/base64.hpp" +#include "libpgfe/core/bases/base64.hpp" -#include "libpgfe/base-encoding.h" +#include "libpgfe/core/bases/base64.h" using namespace libpgfe; diff --git a/src/cpp/generic.cpp b/src/core/cpp/generic.cpp similarity index 75% rename from src/cpp/generic.cpp rename to src/core/cpp/generic.cpp index 308a565..7977ea2 100644 --- a/src/cpp/generic.cpp +++ b/src/core/cpp/generic.cpp @@ -2,15 +2,15 @@ libpgfe generic.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #ifndef LIBPGFE_GENERIC_CPP #define LIBPGFE_GENERIC_CPP -#include "libpgfe/generic.hpp" +#include "libpgfe/core/generic.hpp" -#include "libpgfe/generic.h" +#include "libpgfe/core/generic.h" namespace libpgfe { diff --git a/src/cpp/hash/hash_encoder.cpp b/src/core/cpp/hashes/hash_encoder.cpp similarity index 96% rename from src/cpp/hash/hash_encoder.cpp rename to src/core/cpp/hashes/hash_encoder.cpp index 1cd812b..e0dfa33 100644 --- a/src/cpp/hash/hash_encoder.cpp +++ b/src/core/cpp/hashes/hash_encoder.cpp @@ -2,16 +2,16 @@ libpgfe hash_encoder.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/hash_encoder.hpp" +#include "libpgfe/core/hashes/hash_encoder.hpp" #include #include -#include "libpgfe/hash.h" -#include "libpgfe/utils.h" +#include "libpgfe/core/hashes.h" +#include "libpgfe/core/utils.h" #include "../../c/generic-internal.h" diff --git a/src/cpp/hmac/hmac_encoder.cpp b/src/core/cpp/hmac/hmac_encoder.cpp similarity index 97% rename from src/cpp/hmac/hmac_encoder.cpp rename to src/core/cpp/hmac/hmac_encoder.cpp index 9a02509..9f8e847 100644 --- a/src/cpp/hmac/hmac_encoder.cpp +++ b/src/core/cpp/hmac/hmac_encoder.cpp @@ -2,10 +2,10 @@ libpgfe hmac_encoder.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/hmac_encoder.hpp" +#include "libpgfe/core/hmac/hmac_encoder.hpp" #include "../../c/generic-internal.h" diff --git a/src/cpp/sequential_data.cpp b/src/core/cpp/sequential_data.cpp similarity index 95% rename from src/cpp/sequential_data.cpp rename to src/core/cpp/sequential_data.cpp index 881a2fb..33f9d76 100644 --- a/src/cpp/sequential_data.cpp +++ b/src/core/cpp/sequential_data.cpp @@ -2,10 +2,10 @@ libpgfe sequential_data.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/sequential_data.hpp" +#include "libpgfe/core/sequential_data.hpp" #include #include diff --git a/src/cpp/utils.cpp b/src/core/cpp/utils.cpp similarity index 88% rename from src/cpp/utils.cpp rename to src/core/cpp/utils.cpp index ae04aef..c131122 100644 --- a/src/cpp/utils.cpp +++ b/src/core/cpp/utils.cpp @@ -2,14 +2,14 @@ libpgfe utils.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/utils.hpp" +#include "libpgfe/core/utils.hpp" #include -#include "libpgfe/utils.h" +#include "libpgfe/core/utils.h" namespace libpgfe { namespace utils { diff --git a/src/c/otp/hotp.c b/src/otp/c/hotp.c similarity index 88% rename from src/c/otp/hotp.c rename to src/otp/c/hotp.c index 0c115f8..d761ad8 100644 --- a/src/c/otp/hotp.c +++ b/src/otp/c/hotp.c @@ -2,7 +2,7 @@ libpgfe hotp.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "libpgfe/hotp.h" @@ -22,9 +22,9 @@ // 10 ^ 0 1 2 3 4 5 6 7 8 9 static const pgfe_otp_t DIGITS_POW[] = {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000}; -pgfe_otp_t __pgfe_10pow(uint8_t p); +pgfe_otp_t _10pow(uint8_t p); -inline pgfe_otp_t __pgfe_10pow(uint8_t p) { +inline pgfe_otp_t _10pow(uint8_t p) { return DIGITS_POW[p]; } @@ -40,13 +40,13 @@ pgfe_otp_t pgfe_hotp_generic( pgfe_otp_t result; memcpy(counter_h, &counter, counter_len); - __pgfe_reverse_elements(counter_h, counter_h + counter_len - 1); + reverse(counter_h, counter_h + counter_len - 1); pgfe_hmac(alg, secret, secret_length, counter_h, counter_len, out_hash); - result = pgfe_dynamically_truncate(out_hash, digest_size); + result = dynamically_truncate(out_hash, digest_size); if (digit_c < PGFE_OTP_DIGIT_MAX_LIMIT) { - result %= __pgfe_10pow(digit_c); + result %= _10pow(digit_c); } return result; diff --git a/src/c/otp/otp-generic.c b/src/otp/c/otp-generic.c similarity index 54% rename from src/c/otp/otp-generic.c rename to src/otp/c/otp-generic.c index 7b7c6fe..a04813a 100644 --- a/src/c/otp/otp-generic.c +++ b/src/otp/c/otp-generic.c @@ -2,31 +2,31 @@ libpgfe otp-generic.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "./otp-generic.h" -#define __ENS_BIT 8 -#define __SIZE 4 +#define ENS_BIT 8 +#define SIZE 4 -pgfe_otp_t pgfe_dynamically_truncate(const pgfe_encode_t hash[], size_t length) { +pgfe_otp_t dynamically_truncate(const pgfe_encode_t hash[], size_t length) { uint8_t offset = hash[length - 1] & 0xF; pgfe_otp_t code = 0; - for (size_t i = 0; i < __SIZE; i++) { - code <<= __ENS_BIT; + for (size_t i = 0; i < SIZE; i++) { + code <<= ENS_BIT; code |= hash[offset + i]; } return code << 1 >> 1; } -inline time_t pgfe_curtime() { +inline time_t curtime() { return time(NULL); } -void pgfe_otp_to_string(pgfe_otp_t otp, char *cs_out, size_t digit_c) { +void otp_to_string(pgfe_otp_t otp, char *cs_out, size_t digit_c) { char *sp; for (sp = cs_out + digit_c - 1; sp >= cs_out; sp--) { diff --git a/src/c/otp/otp-generic.h b/src/otp/c/otp-generic.h similarity index 56% rename from src/c/otp/otp-generic.h rename to src/otp/c/otp-generic.h index fc2904f..d82e8d4 100644 --- a/src/c/otp/otp-generic.h +++ b/src/otp/c/otp-generic.h @@ -4,7 +4,7 @@ Generic implementation of HOTP/TOTP - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #ifndef LIBPGFE_OTP_GENERIC_H @@ -13,9 +13,9 @@ #include #include -#include "libpgfe/generic.h" -#include "libpgfe/hmac.h" -#include "libpgfe/otp_types.h" +#include "libpgfe/core/generic.h" +#include "libpgfe/core/hmac/hmac.h" +#include "libpgfe/otp/types.h" #ifdef __cplusplus extern "C" { @@ -26,12 +26,12 @@ extern "C" { #define PGFE_OTP_DIGIT_MAX_LIMIT 10 // Performing dynamic truncation -pgfe_otp_t pgfe_dynamically_truncate(const pgfe_encode_t hash[], size_t length); +pgfe_otp_t dynamically_truncate(const pgfe_encode_t hash[], size_t length); // Get current UNIX time -time_t pgfe_curtime(); +time_t curtime(); -void pgfe_otp_to_string(pgfe_otp_t otp, char *cs_out, size_t digit_c); +void otp_to_string(pgfe_otp_t otp, char *cs_out, size_t digit_c); #ifdef __cplusplus } diff --git a/src/c/otp/totp.c b/src/otp/c/totp.c similarity index 87% rename from src/c/otp/totp.c rename to src/otp/c/totp.c index efa6113..6d3094e 100644 --- a/src/c/otp/totp.c +++ b/src/otp/c/totp.c @@ -2,14 +2,16 @@ libpgfe totp.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/totp.h" +#include "libpgfe/otp/totp.h" #include "../generic-internal.h" +#include "./otp-generic.h" + +#include "libpgfe/core/hashes/sha1.h" #include "libpgfe/hotp.h" -#include "libpgfe/sha1.h" pgfe_otp_counter_t __pgfe_calc_periodic_counter( time_t realtime, pgfe_totp_interval_t interval, time_t initial_time, pgfe_totp_delta_t *delta_out @@ -25,7 +27,7 @@ pgfe_otp_t pgfe_totp_generic( enum pgfe_algorithm_choice alg, const pgfe_encode_t secret[], size_t secret_length, uint8_t digit_c, pgfe_totp_interval_t interval, time_t initial_time, pgfe_totp_delta_t *delta_out ) { - pgfe_otp_counter_t counter = __pgfe_calc_periodic_counter(pgfe_curtime(), interval, initial_time, delta_out); + pgfe_otp_counter_t counter = __pgfe_calc_periodic_counter(curtime(), interval, initial_time, delta_out); return pgfe_hotp_generic(alg, secret, secret_length, counter, digit_c); } diff --git a/src/cpp/otp/abstract_otp.cpp b/src/otp/cpp/abstract_otp.cpp similarity index 85% rename from src/cpp/otp/abstract_otp.cpp rename to src/otp/cpp/abstract_otp.cpp index 5c71229..036d298 100644 --- a/src/cpp/otp/abstract_otp.cpp +++ b/src/otp/cpp/abstract_otp.cpp @@ -2,15 +2,13 @@ libpgfe abstract_otp.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/abstract_otp.hpp" +#include "libpgfe/otp/abstract_otp.hpp" #include -#include "libpgfe/base-encoding.h" - using namespace libpgfe; void AbstractOTP::set_secret(const char *cs) { diff --git a/src/cpp/otp/hotp.cpp b/src/otp/cpp/hotp.cpp similarity index 91% rename from src/cpp/otp/hotp.cpp rename to src/otp/cpp/hotp.cpp index 44a535d..ac9a3f5 100644 --- a/src/cpp/otp/hotp.cpp +++ b/src/otp/cpp/hotp.cpp @@ -2,17 +2,17 @@ libpgfe hotp.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/hotp.hpp" +#include "libpgfe/otp/hotp.hpp" #include -#include "libpgfe/generic.hpp" -#include "libpgfe/hotp.h" +#include "libpgfe/core/generic.hpp" +#include "libpgfe/otp/hotp.h" -#include "../../c/generic-internal.h" +#include "core/c/generic-internal.h" using namespace libpgfe; diff --git a/src/cpp/otp/totp.cpp b/src/otp/cpp/totp.cpp similarity index 89% rename from src/cpp/otp/totp.cpp rename to src/otp/cpp/totp.cpp index eb9e389..78f6fee 100644 --- a/src/cpp/otp/totp.cpp +++ b/src/otp/cpp/totp.cpp @@ -2,13 +2,14 @@ libpgfe totp.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/totp.hpp" -#include "libpgfe/utils.h" +#include "libpgfe/otp/totp.hpp" -#include "../../c/otp/otp-generic.h" +#include "libpgfe/core/utils.h" + +#include "../c/otp-generic.h" using namespace libpgfe; @@ -59,12 +60,12 @@ time_t TOTP::update_time() const { } void TOTP::update_counter() { - _update_time = pgfe_curtime(); + _update_time = curtime(); set_counter(__pgfe_calc_periodic_counter(_update_time, _interval, _initial_time, &delta)); } time_t TOTP::remaining_time() const { - return delta - (pgfe_curtime() - _update_time); + return delta - (curtime() - _update_time); } pgfe_otp_t TOTP::generate(uint8_t digit_count) { diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt new file mode 100644 index 0000000..b1165f8 --- /dev/null +++ b/tests/CMakeLists.txt @@ -0,0 +1,17 @@ +cmake_minimum_required(VERSION 3.26.0) + +include(CTest) +enable_testing() + +include(FetchContent) + +# Fetch GoogleTest +FetchContent_Declare( + googletest + URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip +) +# For Windows: Prevent overriding the parent project's compiler/linker settings +set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) + +# Apply GoogleTest +FetchContent_MakeAvailable(googletest) \ No newline at end of file diff --git a/test/base_multithread.hpp b/tests/base_multithread.hpp similarity index 98% rename from test/base_multithread.hpp rename to tests/base_multithread.hpp index 72bb713..2f2f46b 100644 --- a/test/base_multithread.hpp +++ b/tests/base_multithread.hpp @@ -2,7 +2,7 @@ libpgfe base_multithread.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" diff --git a/test/base_test.hpp b/tests/base_test.hpp similarity index 93% rename from test/base_test.hpp rename to tests/base_test.hpp index 206df57..7db4f3d 100644 --- a/test/base_test.hpp +++ b/tests/base_test.hpp @@ -2,13 +2,13 @@ libpgfe base_test.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" #include "../include/libpgfe/base16.hpp" -#include "../include/libpgfe/base32.hpp" +#include "../include/libpgfe/core/hashes/base32.hpp" #include "../include/libpgfe/base64.hpp" using namespace std; diff --git a/test/baseencodetest.h b/tests/baseencodetest.h similarity index 97% rename from test/baseencodetest.h rename to tests/baseencodetest.h index c1621e3..03c63f1 100644 --- a/test/baseencodetest.h +++ b/tests/baseencodetest.h @@ -2,7 +2,7 @@ libpgfe baseencodetest.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" diff --git a/test/blowfish_test.h b/tests/blowfish_test.h similarity index 91% rename from test/blowfish_test.h rename to tests/blowfish_test.h index c5fb17c..2402d1e 100644 --- a/test/blowfish_test.h +++ b/tests/blowfish_test.h @@ -2,13 +2,13 @@ libpgfe blowfish_test.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" -#include "../include/libpgfe/blowfish.h" -#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/advanced/blowfish.h" +#include "../include/libpgfe/core/utils.h" void blowfish_encrypt_unit_test(ARGS) { struct pgfe_blowfish_ctx ctx; diff --git a/test/blowfish_test.hpp b/tests/blowfish_test.hpp similarity index 81% rename from test/blowfish_test.hpp rename to tests/blowfish_test.hpp index 976ec7f..9c340c2 100644 --- a/test/blowfish_test.hpp +++ b/tests/blowfish_test.hpp @@ -2,7 +2,7 @@ libpgfe blowfish_test.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" @@ -11,8 +11,8 @@ #include #include -#include "../include/libpgfe/blowfish.hpp" -#include "../include/libpgfe/utils.hpp" +#include "../include/libpgfe/advanced/blowfish.hpp" +#include "../include/libpgfe/core/utils.hpp" void blowfish_encrypt_test(ARGS) { using namespace libpgfe; diff --git a/test/cmake/base_tests.cmake b/tests/cmake/base_tests.cmake similarity index 100% rename from test/cmake/base_tests.cmake rename to tests/cmake/base_tests.cmake diff --git a/test/cmake/blowfish_tests.cmake b/tests/cmake/blowfish_tests.cmake similarity index 100% rename from test/cmake/blowfish_tests.cmake rename to tests/cmake/blowfish_tests.cmake diff --git a/test/cmake/hash_tests.cmake b/tests/cmake/hash_tests.cmake similarity index 100% rename from test/cmake/hash_tests.cmake rename to tests/cmake/hash_tests.cmake diff --git a/test/cmake/hmac_tests.cmake b/tests/cmake/hmac_tests.cmake similarity index 100% rename from test/cmake/hmac_tests.cmake rename to tests/cmake/hmac_tests.cmake diff --git a/test/cmake/otp_tests.cmake b/tests/cmake/otp_tests.cmake similarity index 100% rename from test/cmake/otp_tests.cmake rename to tests/cmake/otp_tests.cmake diff --git a/test/cmake/shake_tests.cmake b/tests/cmake/shake_tests.cmake similarity index 100% rename from test/cmake/shake_tests.cmake rename to tests/cmake/shake_tests.cmake diff --git a/test/cmake/test_meta.cmake b/tests/cmake/test_meta.cmake similarity index 100% rename from test/cmake/test_meta.cmake rename to tests/cmake/test_meta.cmake diff --git a/test/cmake/util_tests.cmake b/tests/cmake/util_tests.cmake similarity index 100% rename from test/cmake/util_tests.cmake rename to tests/cmake/util_tests.cmake diff --git a/test/hash_encoder_test.hpp b/tests/hash_encoder_test.hpp similarity index 80% rename from test/hash_encoder_test.hpp rename to tests/hash_encoder_test.hpp index b33c062..d13936b 100644 --- a/test/hash_encoder_test.hpp +++ b/tests/hash_encoder_test.hpp @@ -2,7 +2,7 @@ libpgfe hash_encoder_test.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" @@ -11,8 +11,8 @@ #include #include "../include/libpgfe/hash_encoder.hpp" -#include "../include/libpgfe/utils.h" -#include "../include/libpgfe/utils.hpp" +#include "../include/libpgfe/core/utils.h" +#include "../include/libpgfe/core/utils.hpp" void hash_encoder_test(ARGS) { using namespace std; diff --git a/test/hmactest.h b/tests/hmactest.h similarity index 90% rename from test/hmactest.h rename to tests/hmactest.h index 8e715b2..c1d94ee 100644 --- a/test/hmactest.h +++ b/tests/hmactest.h @@ -2,14 +2,14 @@ libpgfe hmactest.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" -#include "../include/libpgfe/hmac.h" -#include "../include/libpgfe/md5.h" -#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/core/hmac/hmac.h" +#include "../include/libpgfe/core/hashes/md5.h" +#include "../include/libpgfe/core/utils.h" enum pgfe_algorithm_choice get_alg_choice(char option[]) { enum pgfe_algorithm_choice c; diff --git a/test/hmactest.hpp b/tests/hmactest.hpp similarity index 84% rename from test/hmactest.hpp rename to tests/hmactest.hpp index 98b8053..a37db93 100644 --- a/test/hmactest.hpp +++ b/tests/hmactest.hpp @@ -2,7 +2,7 @@ libpgfe hmactest.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" @@ -10,8 +10,8 @@ #include #include "../include/libpgfe/hmac_encoder.hpp" -#include "../include/libpgfe/utils.h" -#include "../include/libpgfe/utils.hpp" +#include "../include/libpgfe/core/utils.h" +#include "../include/libpgfe/core/utils.hpp" void hmac_encoder_test(ARGS) { using namespace libpgfe; diff --git a/test/mdtest.h b/tests/mdtest.h similarity index 64% rename from test/mdtest.h rename to tests/mdtest.h index 9ab8e72..31fe28f 100644 --- a/test/mdtest.h +++ b/tests/mdtest.h @@ -2,13 +2,13 @@ libpgfe mdtest.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" -#include "../include/libpgfe/md5.h" -#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/core/hashes/md5.h" +#include "../include/libpgfe/core/utils.h" void md5test(ARGS) { pgfe_encode_t output[PGFE_MD5_DIGEST_SIZE]; diff --git a/test/otptest.h b/tests/otptest.h similarity index 86% rename from test/otptest.h rename to tests/otptest.h index 7a9cc42..f55307f 100644 --- a/test/otptest.h +++ b/tests/otptest.h @@ -2,14 +2,14 @@ libpgfe otptest.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" #include "../include/libpgfe/hotp.h" -#include "../include/libpgfe/sha2.h" -#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/core/hashes/sha2.h" +#include "../include/libpgfe/core/utils.h" void hotp_hex(ARGS) { pgfe_encode_t key[100]; diff --git a/test/otptest.hpp b/tests/otptest.hpp similarity index 76% rename from test/otptest.hpp rename to tests/otptest.hpp index 32263c8..171357a 100644 --- a/test/otptest.hpp +++ b/tests/otptest.hpp @@ -2,7 +2,7 @@ libpgfe otptest.hpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" @@ -10,8 +10,8 @@ #include #include -#include "../include/libpgfe/hotp.hpp" -#include "../include/libpgfe/utils.hpp" +#include "../include/libpgfe/otp/hotp.hpp" +#include "../include/libpgfe/core/utils.hpp" void hotp_hex_test(ARGS) { HOTP hotp{_algstr(argv[2])}; diff --git a/test/shake_test.h b/tests/shake_test.h similarity index 94% rename from test/shake_test.h rename to tests/shake_test.h index 4a75b3c..247257b 100644 --- a/test/shake_test.h +++ b/tests/shake_test.h @@ -2,7 +2,7 @@ libpgfe shake_test.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" @@ -10,8 +10,8 @@ #include #include -#include "../include/libpgfe/sha3.h" -#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/core/hashes/sha3.h" +#include "../include/libpgfe/core/utils.h" void shake_test(ARGS) { size_t bitsize; diff --git a/test/shatest.h b/tests/shatest.h similarity index 94% rename from test/shatest.h rename to tests/shatest.h index af6317a..c8ebc39 100644 --- a/test/shatest.h +++ b/tests/shatest.h @@ -2,15 +2,15 @@ libpgfe shatest.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" -#include "../include/libpgfe/sha1.h" -#include "../include/libpgfe/sha2.h" -#include "../include/libpgfe/sha3.h" -#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/core/hashes/sha1.h" +#include "../include/libpgfe/core/hashes/sha2.h" +#include "../include/libpgfe/core/hashes/sha3.h" +#include "../include/libpgfe/core/utils.h" void sha1_test(ARGS) { pgfe_encode_t output[PGFE_SHA1_DIGEST_SIZE]; diff --git a/test/test.c b/tests/test.c similarity index 98% rename from test/test.c rename to tests/test.c index 7ce6b55..1aaeff4 100644 --- a/test/test.c +++ b/tests/test.c @@ -2,7 +2,7 @@ libpgfe test.c - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include diff --git a/test/test.cpp b/tests/test.cpp similarity index 97% rename from test/test.cpp rename to tests/test.cpp index fd9df00..b6c042d 100644 --- a/test/test.cpp +++ b/tests/test.cpp @@ -2,7 +2,7 @@ libpgfe test.cpp - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include diff --git a/test/test.h b/tests/test.h similarity index 96% rename from test/test.h rename to tests/test.h index 1e385a7..57f05eb 100644 --- a/test/test.h +++ b/tests/test.h @@ -2,7 +2,7 @@ libpgfe test.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #ifndef LIBPGFE_TEST_TEST_H diff --git a/test/test.txt b/tests/test.txt similarity index 100% rename from test/test.txt rename to tests/test.txt diff --git a/test/utilstest.h b/tests/utilstest.h similarity index 86% rename from test/utilstest.h rename to tests/utilstest.h index 993cc82..0a691e9 100644 --- a/test/utilstest.h +++ b/tests/utilstest.h @@ -2,12 +2,12 @@ libpgfe utilstest.h - Copyright (c) 2022 Charles Dong + Copyright (c) 2022-2023 Charles Dong */ #include "test.h" -#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/core/utils.h" #include void string2hash(ARGS) { From 1fb12588fe77a624ed37cd924fcc354510d6267c Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 31 May 2023 21:38:38 +0800 Subject: [PATCH 3/8] Structure overhaul 3 --- CMakeLists.txt | 65 +------------------ Makefile | 6 +- cmake/advanced.cmake | 14 ---- cmake/core.cmake | 46 ------------- cmake/otp.cmake | 17 ----- cmake/targets/libpgfe.cmake | 55 ++++++++++++++++ .../libpgfe/{core => }/abstract_encoder.hpp | 10 +-- .../abstract_symmetric_crypter.hpp | 6 +- include/libpgfe/{core => }/algorithm-choice.h | 4 +- .../{core => }/algorithm_selectable.hpp | 6 +- .../abstract_base_encoding.hpp | 8 +-- .../{core/bases => base_encoding}/base16.h | 6 +- .../{core/bases => base_encoding}/base16.hpp | 6 +- .../{core/bases => base_encoding}/base32.h | 6 +- .../{core/bases => base_encoding}/base32.hpp | 6 +- .../{core/bases => base_encoding}/base64.h | 6 +- .../{core/bases => base_encoding}/base64.hpp | 6 +- include/libpgfe/core/hashes.h | 9 --- include/libpgfe/{core => }/exceptions.hpp | 4 +- .../libpgfe/{advanced => }/fishes/blowfish.h | 6 +- .../{advanced => }/fishes/blowfish.hpp | 8 +-- include/libpgfe/{core => }/generic.h | 6 +- include/libpgfe/{core => }/generic.hpp | 10 +-- include/libpgfe/hashes.h | 9 +++ .../hashes/abstract_hash_encoder.hpp | 14 ++-- .../{core => }/hashes/hash_encoder.hpp | 8 +-- include/libpgfe/{core => }/hashes/md5.h | 6 +- include/libpgfe/{core => }/hashes/sha1.h | 6 +- include/libpgfe/{core => }/hashes/sha2.h | 6 +- include/libpgfe/{core => }/hashes/sha3.h | 24 +++---- include/libpgfe/{core => }/hmac/hmac.h | 8 +-- .../libpgfe/{core => }/hmac/hmac_encoder.hpp | 12 ++-- include/libpgfe/otp/abstract_otp.hpp | 6 +- include/libpgfe/otp/hotp.h | 2 +- include/libpgfe/otp/hotp.hpp | 2 +- include/libpgfe/otp/totp.h | 2 +- .../libpgfe/{core => }/sequential_data.hpp | 8 +-- include/libpgfe/{core => }/utils.h | 6 +- include/libpgfe/{core => }/utils.hpp | 8 +-- .../abstract_base_encoding.cpp | 3 +- .../base-encoding-internal.c | 2 +- .../base-encoding-internal.h | 2 +- src/{core/c/bases => base_encoding}/base16.c | 2 +- .../cpp/bases => base_encoding}/base16.cpp | 4 +- src/{core/c/bases => base_encoding}/base32.c | 4 +- .../cpp/bases => base_encoding}/base32.cpp | 4 +- src/{core/c/bases => base_encoding}/base64.c | 2 +- .../cpp/bases => base_encoding}/base64.cpp | 4 +- .../abstract_symmetric_crypter.cpp | 2 +- src/core/{cpp => }/algorithm_selectable.cpp | 2 +- src/core/{c => }/generic-internal.c | 0 src/core/{c => }/generic-internal.h | 2 +- src/core/{c => }/generic.c | 2 +- src/core/{cpp => }/generic.cpp | 4 +- src/core/{cpp => }/sequential_data.cpp | 2 +- src/core/{c => }/utils.c | 3 +- src/core/{cpp => }/utils.cpp | 4 +- src/{advanced/c => }/fishes/blowfish.c | 2 +- src/{advanced/cpp => }/fishes/blowfish.cpp | 2 +- src/{core/cpp => }/hashes/hash_encoder.cpp | 8 +-- src/{core/c => }/hashes/keccak-backend.c | 0 src/{core/c => }/hashes/keccak-backend.h | 8 +-- src/{core/c => }/hashes/md5-backend.c | 0 src/{core/c => }/hashes/md5-backend.h | 2 +- src/{core/c => }/hashes/md5.c | 2 +- src/{core/c => }/hashes/sha-internal.c | 0 src/{core/c => }/hashes/sha-internal.h | 2 +- src/{core/c => }/hashes/sha1.c | 12 ++-- src/{core/c => }/hashes/sha2-backend.c | 2 +- src/{core/c => }/hashes/sha2-backend.h | 4 +- src/{core/c => }/hashes/sha224.c | 2 +- src/{core/c => }/hashes/sha256.c | 2 +- src/{core/c => }/hashes/sha3-224.c | 2 +- src/{core/c => }/hashes/sha3-256.c | 2 +- src/{core/c => }/hashes/sha3-384.c | 2 +- src/{core/c => }/hashes/sha3-512.c | 2 +- src/{core/c => }/hashes/sha384.c | 2 +- src/{core/c => }/hashes/sha512.c | 2 +- src/{core/c => }/hashes/shake.c | 2 +- src/{core/c => }/hashes/templates.h | 4 +- src/{core/c => }/hmac/hmac.c | 4 +- src/{core/cpp => }/hmac/hmac_encoder.cpp | 4 +- src/otp/{cpp => }/abstract_otp.cpp | 0 src/otp/{c => }/hotp.c | 6 +- src/otp/{cpp => }/hotp.cpp | 4 +- src/otp/{c => }/otp-generic.c | 0 src/otp/{c => }/otp-generic.h | 4 +- src/otp/{c => }/totp.c | 6 +- src/otp/{cpp => }/totp.cpp | 4 +- tests/base_test.hpp | 2 +- tests/blowfish_test.h | 4 +- tests/blowfish_test.hpp | 4 +- tests/hash_encoder_test.hpp | 4 +- tests/hmactest.h | 6 +- tests/hmactest.hpp | 4 +- tests/mdtest.h | 4 +- tests/otptest.h | 4 +- tests/otptest.hpp | 2 +- tests/shake_test.h | 4 +- tests/shatest.h | 8 +-- tests/utilstest.h | 2 +- 101 files changed, 279 insertions(+), 358 deletions(-) delete mode 100644 cmake/advanced.cmake delete mode 100644 cmake/core.cmake delete mode 100644 cmake/otp.cmake create mode 100644 cmake/targets/libpgfe.cmake rename include/libpgfe/{core => }/abstract_encoder.hpp (81%) rename include/libpgfe/{advanced => }/abstract_symmetric_crypter.hpp (83%) rename include/libpgfe/{core => }/algorithm-choice.h (89%) rename include/libpgfe/{core => }/algorithm_selectable.hpp (77%) rename include/libpgfe/{core/bases => base_encoding}/abstract_base_encoding.hpp (90%) rename include/libpgfe/{core/bases => base_encoding}/base16.h (80%) rename include/libpgfe/{core/bases => base_encoding}/base16.hpp (80%) rename include/libpgfe/{core/bases => base_encoding}/base32.h (87%) rename include/libpgfe/{core/bases => base_encoding}/base32.hpp (83%) rename include/libpgfe/{core/bases => base_encoding}/base64.h (87%) rename include/libpgfe/{core/bases => base_encoding}/base64.hpp (84%) delete mode 100644 include/libpgfe/core/hashes.h rename include/libpgfe/{core => }/exceptions.hpp (83%) rename include/libpgfe/{advanced => }/fishes/blowfish.h (90%) rename include/libpgfe/{advanced => }/fishes/blowfish.hpp (83%) rename include/libpgfe/{core => }/generic.h (89%) rename include/libpgfe/{core => }/generic.hpp (94%) create mode 100644 include/libpgfe/hashes.h rename include/libpgfe/{core => }/hashes/abstract_hash_encoder.hpp (62%) rename include/libpgfe/{core => }/hashes/hash_encoder.hpp (84%) rename include/libpgfe/{core => }/hashes/md5.h (91%) rename include/libpgfe/{core => }/hashes/sha1.h (92%) rename include/libpgfe/{core => }/hashes/sha2.h (98%) rename include/libpgfe/{core => }/hashes/sha3.h (88%) rename include/libpgfe/{core => }/hmac/hmac.h (98%) rename include/libpgfe/{core => }/hmac/hmac_encoder.hpp (87%) rename include/libpgfe/{core => }/sequential_data.hpp (89%) rename include/libpgfe/{core => }/utils.h (89%) rename include/libpgfe/{core => }/utils.hpp (81%) rename src/{core/cpp/bases => base_encoding}/abstract_base_encoding.cpp (95%) rename src/{core/c/bases => base_encoding}/base-encoding-internal.c (99%) rename src/{core/c/bases => base_encoding}/base-encoding-internal.h (97%) rename src/{core/c/bases => base_encoding}/base16.c (96%) rename src/{core/cpp/bases => base_encoding}/base16.cpp (87%) rename src/{core/c/bases => base_encoding}/base32.c (96%) rename src/{core/cpp/bases => base_encoding}/base32.cpp (90%) rename src/{core/c/bases => base_encoding}/base64.c (98%) rename src/{core/cpp/bases => base_encoding}/base64.cpp (89%) rename src/{advanced/cpp => core}/abstract_symmetric_crypter.cpp (94%) rename src/core/{cpp => }/algorithm_selectable.cpp (88%) rename src/core/{c => }/generic-internal.c (100%) rename src/core/{c => }/generic-internal.h (99%) rename src/core/{c => }/generic.c (66%) rename src/core/{cpp => }/generic.cpp (84%) rename src/core/{cpp => }/sequential_data.cpp (97%) rename src/core/{c => }/utils.c (98%) rename src/core/{cpp => }/utils.cpp (93%) rename src/{advanced/c => }/fishes/blowfish.c (99%) rename src/{advanced/cpp => }/fishes/blowfish.cpp (97%) rename src/{core/cpp => }/hashes/hash_encoder.cpp (96%) rename src/{core/c => }/hashes/keccak-backend.c (100%) rename src/{core/c => }/hashes/keccak-backend.h (77%) rename src/{core/c => }/hashes/md5-backend.c (100%) rename src/{core/c => }/hashes/md5-backend.h (92%) rename src/{core/c => }/hashes/md5.c (98%) rename src/{core/c => }/hashes/sha-internal.c (100%) rename src/{core/c => }/hashes/sha-internal.h (92%) rename src/{core/c => }/hashes/sha1.c (91%) rename src/{core/c => }/hashes/sha2-backend.c (99%) rename src/{core/c => }/hashes/sha2-backend.h (94%) rename src/{core/c => }/hashes/sha224.c (93%) rename src/{core/c => }/hashes/sha256.c (93%) rename src/{core/c => }/hashes/sha3-224.c (94%) rename src/{core/c => }/hashes/sha3-256.c (94%) rename src/{core/c => }/hashes/sha3-384.c (94%) rename src/{core/c => }/hashes/sha3-512.c (95%) rename src/{core/c => }/hashes/sha384.c (96%) rename src/{core/c => }/hashes/sha512.c (98%) rename src/{core/c => }/hashes/shake.c (98%) rename src/{core/c => }/hashes/templates.h (99%) rename src/{core/c => }/hmac/hmac.c (98%) rename src/{core/cpp => }/hmac/hmac_encoder.cpp (97%) rename src/otp/{cpp => }/abstract_otp.cpp (100%) rename src/otp/{c => }/hotp.c (95%) rename src/otp/{cpp => }/hotp.cpp (96%) rename src/otp/{c => }/otp-generic.c (100%) rename src/otp/{c => }/otp-generic.h (89%) rename src/otp/{c => }/totp.c (94%) rename src/otp/{cpp => }/totp.cpp (96%) diff --git a/CMakeLists.txt b/CMakeLists.txt index c6a3003..fd3ead2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,73 +21,14 @@ set(include_dir "include") set(cmake_module_dir "cmake") set(test_dir "tests") -list(APPEND cmake_modules "core.cmake" "otp.cmake" "advanced.cmake") +list(APPEND cmake_modules "libpgfe") foreach(mod IN LISTS cmake_modules) - include(${cmake_module_dir}/${mod}) -endforeach(i) + include(${cmake_module_dir}/targets/${mod}.cmake) +endforeach() add_subdirectory(${test_dir}) -# add_library(pgfe SHARED -# ${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_c_dir}/blowfish/blowfish.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 -# ${src_cpp_dir}/misc/abstract_symmetric_crypter.cpp -# ${src_cpp_dir}/blowfish/blowfish.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) - -# target_include_directories(pgfe PUBLIC -# ${include_dir} -# ) - -# target_include_directories(pgfe PRIVATE -# ${src_dir} -# ) - -# target_link_libraries(pgfetest pgfe) -# target_link_libraries(pgfetestcpp pgfe) -# target_link_libraries(totptest pgfe) -# target_link_libraries(totptestcpp pgfe) - -# include(${test_dir}/cmake/test_meta.cmake) -# include(${test_dir}/cmake/hash_tests.cmake) -# include(${test_dir}/cmake/hmac_tests.cmake) -# include(${test_dir}/cmake/util_tests.cmake) -# include(${test_dir}/cmake/base_tests.cmake) -# include(${test_dir}/cmake/otp_tests.cmake) -# include(${test_dir}/cmake/shake_tests.cmake) -# include(${test_dir}/cmake/blowfish_tests.cmake) - set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) include(CPack) diff --git a/Makefile b/Makefile index 1d493f7..425ea02 100644 --- a/Makefile +++ b/Makefile @@ -4,8 +4,8 @@ include metadata.mak all: @echo 'Building...' - @cmake . -B $(BUILD_DIR) - @cmake --build $(BUILD_DIR) --config Release -j18 -- + @cmake . -B $(BUILD_DIR) -G Ninja + @cmake --build $(BUILD_DIR) --config Release -j20 --target pgfe -- @echo 'Building done' rebuild: clean all @@ -39,4 +39,4 @@ uninstall: @echo done init-scripts: - @chmod u+x ./scripts/{comment_header,update_meta,deploy} + @chmod u+x ./scripts/{comment_header.py,update_meta.py,deploy.py} diff --git a/cmake/advanced.cmake b/cmake/advanced.cmake deleted file mode 100644 index 66f4a1e..0000000 --- a/cmake/advanced.cmake +++ /dev/null @@ -1,14 +0,0 @@ -set(advanced_src "${src_dir}/advanced") - -add_library(pgfe_advanced SHARED - ${advanced_src}/c/fishes/blowfish.c - ${advanced_src}/cpp/abstract_symmetric_crypter.cpp - ${advanced_src}/cpp/fishes/blowfish.cpp -) - -target_include_directories(pgfe_advanced - PUBLIC ${include_dir} - PRIVATE ${src_dir} -) - -target_link_libraries(pgfe_advanced pgfe_core) \ No newline at end of file diff --git a/cmake/core.cmake b/cmake/core.cmake deleted file mode 100644 index cb8d8ae..0000000 --- a/cmake/core.cmake +++ /dev/null @@ -1,46 +0,0 @@ -set(core_src "${src_dir}/core") - -add_library(pgfe_core SHARED - # General - ${core_src}/c/generic.c - ${core_src}/c/generic-internal.c - ${core_src}/c/utils.c - ${core_src}/cpp/generic.cpp - ${core_src}/cpp/algorithm_selectable.cpp - ${core_src}/cpp/sequential_data.cpp - ${core_src}/cpp/utils.cpp - # Bases - ${core_src}/c/bases/base-encoding-internal.c - ${core_src}/c/bases/base16.c - ${core_src}/c/bases/base32.c - ${core_src}/c/bases/base64.c - ${core_src}/cpp/bases/abstract_base_encoding.cpp - ${core_src}/cpp/bases/base16.cpp - ${core_src}/cpp/bases/base32.cpp - ${core_src}/cpp/bases/base64.cpp - # Hashes - ${core_src}/c/hashes/keccak-backend.c - ${core_src}/c/hashes/md5-backend.c - ${core_src}/c/hashes/md5.c - ${core_src}/c/hashes/sha-internal.c - ${core_src}/c/hashes/sha1.c - ${core_src}/c/hashes/sha2-backend.c - ${core_src}/c/hashes/sha3-224.c - ${core_src}/c/hashes/sha3-256.c - ${core_src}/c/hashes/sha3-384.c - ${core_src}/c/hashes/sha3-512.c - ${core_src}/c/hashes/sha224.c - ${core_src}/c/hashes/sha256.c - ${core_src}/c/hashes/sha384.c - ${core_src}/c/hashes/sha512.c - ${core_src}/c/hashes/shake.c - ${core_src}/cpp/hashes/hash_encoder.cpp - # HMAC - ${core_src}/c/hmac/hmac.c - ${core_src}/cpp/hmac/hmac_encoder.cpp -) - -target_include_directories(pgfe_core - PUBLIC ${include_dir} - PRIVATE ${src_dir} -) \ No newline at end of file diff --git a/cmake/otp.cmake b/cmake/otp.cmake deleted file mode 100644 index c1627da..0000000 --- a/cmake/otp.cmake +++ /dev/null @@ -1,17 +0,0 @@ -set(otp_src "${src_dir}/otp") - -add_library(pgfe_otp SHARED - ${otp_src}/c/otp-generic.c - ${otp_src}/c/hotp.c - ${otp_src}/c/totp.c - ${otp_src}/cpp/abstract_otp.cpp - ${otp_src}/cpp/hotp.cpp - ${otp_src}/cpp/totp.cpp -) - -target_include_directories(pgfe_otp - PUBLIC ${include_dir} - PRIVATE ${src_dir} -) - -target_link_libraries(pgfe_otp pgfe_core) \ No newline at end of file diff --git a/cmake/targets/libpgfe.cmake b/cmake/targets/libpgfe.cmake new file mode 100644 index 0000000..b3c2c08 --- /dev/null +++ b/cmake/targets/libpgfe.cmake @@ -0,0 +1,55 @@ +add_library(pgfe SHARED + # Core + ${src_dir}/core/generic.c + ${src_dir}/core/generic-internal.c + ${src_dir}/core/utils.c + ${src_dir}/core/abstract_symmetric_crypter.cpp + ${src_dir}/core/algorithm_selectable.cpp + ${src_dir}/core/generic.cpp + ${src_dir}/core/sequential_data.cpp + ${src_dir}/core/utils.cpp + # Hashes + ${src_dir}/hashes/sha-internal.c + ${src_dir}/hashes/sha2-backend.c + ${src_dir}/hashes/keccak-backend.c + ${src_dir}/hashes/md5-backend.c + ${src_dir}/hashes/sha1.c + ${src_dir}/hashes/sha224.c + ${src_dir}/hashes/sha256.c + ${src_dir}/hashes/sha384.c + ${src_dir}/hashes/sha512.c + ${src_dir}/hashes/sha3-224.c + ${src_dir}/hashes/sha3-256.c + ${src_dir}/hashes/sha3-384.c + ${src_dir}/hashes/sha3-512.c + ${src_dir}/hashes/md5.c + ${src_dir}/hashes/shake.c + ${src_dir}/hashes/hash_encoder.cpp + # HMAC + ${src_dir}/hmac/hmac.c + ${src_dir}/hmac/hmac_encoder.cpp + # Base encoding + ${src_dir}/base_encoding/base-encoding-internal.c + ${src_dir}/base_encoding/base64.c + ${src_dir}/base_encoding/base32.c + ${src_dir}/base_encoding/base16.c + ${src_dir}/base_encoding/abstract_base_encoding.cpp + ${src_dir}/base_encoding/base16.cpp + ${src_dir}/base_encoding/base32.cpp + ${src_dir}/base_encoding/base64.cpp + # OTP + ${src_dir}/otp/otp-generic.c + ${src_dir}/otp/hotp.c + ${src_dir}/otp/totp.c + ${src_dir}/otp/abstract_otp.cpp + ${src_dir}/otp/hotp.cpp + ${src_dir}/otp/totp.cpp + # Fishes (Blowfish, Twofish, Threefish etc.) + ${src_dir}/fishes/blowfish.c + ${src_dir}/fishes/blowfish.cpp +) + +target_include_directories(pgfe + PUBLIC ${include_dir} + PRIVATE ${src_dir} +) diff --git a/include/libpgfe/core/abstract_encoder.hpp b/include/libpgfe/abstract_encoder.hpp similarity index 81% rename from include/libpgfe/core/abstract_encoder.hpp rename to include/libpgfe/abstract_encoder.hpp index 435b30c..766b137 100644 --- a/include/libpgfe/core/abstract_encoder.hpp +++ b/include/libpgfe/abstract_encoder.hpp @@ -5,8 +5,8 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_GENERIC_ENCODER_HPP -#define LIBPGFE_CORE_GENERIC_ENCODER_HPP +#ifndef LIBPGFE_GENERIC_ENCODER_HPP +#define LIBPGFE_GENERIC_ENCODER_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif @@ -14,9 +14,9 @@ #include #include -#include "libpgfe/core/generic.h" -#include "libpgfe/core/sequential_data.hpp" -#include "libpgfe/core/utils.hpp" +#include "libpgfe/generic.h" +#include "libpgfe/sequential_data.hpp" +#include "libpgfe/utils.hpp" namespace libpgfe { diff --git a/include/libpgfe/advanced/abstract_symmetric_crypter.hpp b/include/libpgfe/abstract_symmetric_crypter.hpp similarity index 83% rename from include/libpgfe/advanced/abstract_symmetric_crypter.hpp rename to include/libpgfe/abstract_symmetric_crypter.hpp index cdfa73a..7de5e7d 100644 --- a/include/libpgfe/advanced/abstract_symmetric_crypter.hpp +++ b/include/libpgfe/abstract_symmetric_crypter.hpp @@ -5,15 +5,15 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_ADVANCED_ABSTRACT_SYMMETRIC_CRYPTER_HPP -#define LIBPGFE_ADVANCED_ABSTRACT_SYMMETRIC_CRYPTER_HPP +#ifndef LIBPGFE_ABSTRACT_SYMMETRIC_CRYPTER_HPP +#define LIBPGFE_ABSTRACT_SYMMETRIC_CRYPTER_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif #include -#include "libpgfe/core/sequential_data.hpp" +#include "libpgfe/sequential_data.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/algorithm-choice.h b/include/libpgfe/algorithm-choice.h similarity index 89% rename from include/libpgfe/core/algorithm-choice.h rename to include/libpgfe/algorithm-choice.h index c9e93e3..9248f83 100644 --- a/include/libpgfe/core/algorithm-choice.h +++ b/include/libpgfe/algorithm-choice.h @@ -5,8 +5,8 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_ALGORITHM_CHOICE_H -#define LIBPGFE_CORE_ALGORITHM_CHOICE_H +#ifndef LIBPGFE_ALGORITHM_CHOICE_H +#define LIBPGFE_ALGORITHM_CHOICE_H #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/algorithm_selectable.hpp b/include/libpgfe/algorithm_selectable.hpp similarity index 77% rename from include/libpgfe/core/algorithm_selectable.hpp rename to include/libpgfe/algorithm_selectable.hpp index 4d5afb8..ad450c0 100644 --- a/include/libpgfe/core/algorithm_selectable.hpp +++ b/include/libpgfe/algorithm_selectable.hpp @@ -5,14 +5,14 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_ALGORITHM_SELECTABLE_HPP -#define LIBPGFE_CORE_ALGORITHM_SELECTABLE_HPP +#ifndef LIBPGFE_ALGORITHM_SELECTABLE_HPP +#define LIBPGFE_ALGORITHM_SELECTABLE_HPP #ifdef __cplusplus #include #include -#include "libpgfe/core/algorithm-choice.h" +#include "libpgfe/algorithm-choice.h" namespace libpgfe { diff --git a/include/libpgfe/core/bases/abstract_base_encoding.hpp b/include/libpgfe/base_encoding/abstract_base_encoding.hpp similarity index 90% rename from include/libpgfe/core/bases/abstract_base_encoding.hpp rename to include/libpgfe/base_encoding/abstract_base_encoding.hpp index 922111e..4aef6a6 100644 --- a/include/libpgfe/core/bases/abstract_base_encoding.hpp +++ b/include/libpgfe/base_encoding/abstract_base_encoding.hpp @@ -5,8 +5,8 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_ABSTRACT_BASE_ENCODING -#define LIBPGFE_CORE_ABSTRACT_BASE_ENCODING +#ifndef LIBPGFE_ABSTRACT_BASE_ENCODING +#define LIBPGFE_ABSTRACT_BASE_ENCODING #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif @@ -15,8 +15,8 @@ #include #include -#include "libpgfe/core/generic.h" -#include "libpgfe/core/sequential_data.hpp" +#include "libpgfe/generic.h" +#include "libpgfe/sequential_data.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/bases/base16.h b/include/libpgfe/base_encoding/base16.h similarity index 80% rename from include/libpgfe/core/bases/base16.h rename to include/libpgfe/base_encoding/base16.h index 0ca7ac4..52e1aca 100644 --- a/include/libpgfe/core/bases/base16.h +++ b/include/libpgfe/base_encoding/base16.h @@ -1,7 +1,7 @@ -#ifndef LIBPGFE_CORE_BASE16_H -#define LIBPGFE_CORE_BASE16_H +#ifndef LIBPGFE_BASE16_H +#define LIBPGFE_BASE16_H -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/bases/base16.hpp b/include/libpgfe/base_encoding/base16.hpp similarity index 80% rename from include/libpgfe/core/bases/base16.hpp rename to include/libpgfe/base_encoding/base16.hpp index a19a9ae..422888b 100644 --- a/include/libpgfe/core/bases/base16.hpp +++ b/include/libpgfe/base_encoding/base16.hpp @@ -5,13 +5,13 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_BASE16_HPP -#define LIBPGFE_CORE_BASE16_HPP +#ifndef LIBPGFE_BASE16_HPP +#define LIBPGFE_BASE16_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif -#include "libpgfe/core/abstract_base_encoding.hpp" +#include "libpgfe/base_encoding/abstract_base_encoding.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/bases/base32.h b/include/libpgfe/base_encoding/base32.h similarity index 87% rename from include/libpgfe/core/bases/base32.h rename to include/libpgfe/base_encoding/base32.h index 8d281c0..1d26b03 100644 --- a/include/libpgfe/core/bases/base32.h +++ b/include/libpgfe/base_encoding/base32.h @@ -1,7 +1,7 @@ -#ifndef LIBPGFE_CORE_BASE32_H -#define LIBPGFE_CORE_BASE32_H +#ifndef LIBPGFE_BASE32_H +#define LIBPGFE_BASE32_H -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/bases/base32.hpp b/include/libpgfe/base_encoding/base32.hpp similarity index 83% rename from include/libpgfe/core/bases/base32.hpp rename to include/libpgfe/base_encoding/base32.hpp index b757e6d..7e4420c 100644 --- a/include/libpgfe/core/bases/base32.hpp +++ b/include/libpgfe/base_encoding/base32.hpp @@ -5,13 +5,13 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_BASE32_HPP -#define LIBPGFE_CORE_BASE32_HPP +#ifndef LIBPGFE_BASE32_HPP +#define LIBPGFE_BASE32_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif -#include "libpgfe/core/abstract_base_encoding.hpp" +#include "libpgfe/base_encoding/abstract_base_encoding.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/bases/base64.h b/include/libpgfe/base_encoding/base64.h similarity index 87% rename from include/libpgfe/core/bases/base64.h rename to include/libpgfe/base_encoding/base64.h index a5b8034..61ebcce 100644 --- a/include/libpgfe/core/bases/base64.h +++ b/include/libpgfe/base_encoding/base64.h @@ -1,7 +1,7 @@ -#ifndef LIBPGFE_CORE_BASE64_H -#define LIBPGFE_CORE_BASE64_H +#ifndef LIBPGFE_BASE64_H +#define LIBPGFE_BASE64_H -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/bases/base64.hpp b/include/libpgfe/base_encoding/base64.hpp similarity index 84% rename from include/libpgfe/core/bases/base64.hpp rename to include/libpgfe/base_encoding/base64.hpp index 52cfa00..dab3fc1 100644 --- a/include/libpgfe/core/bases/base64.hpp +++ b/include/libpgfe/base_encoding/base64.hpp @@ -5,13 +5,13 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_BASE64_HPP -#define LIBPGFE_CORE_BASE64_HPP +#ifndef LIBPGFE_BASE64_HPP +#define LIBPGFE_BASE64_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif -#include "libpgfe/core/abstract_base_encoding.hpp" +#include "libpgfe/base_encoding/abstract_base_encoding.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/hashes.h b/include/libpgfe/core/hashes.h deleted file mode 100644 index 71f9cef..0000000 --- a/include/libpgfe/core/hashes.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef LIBPGFE_CORE_HASHES_H -#define LIBPGFE_CORE_HASHES_H - -#include "libpgfe/core/hashes/md5.h" -#include "libpgfe/core/hashes/sha1.h" -#include "libpgfe/core/hashes/sha2.h" -#include "libpgfe/core/hashes/sha3.h" - -#endif \ No newline at end of file diff --git a/include/libpgfe/core/exceptions.hpp b/include/libpgfe/exceptions.hpp similarity index 83% rename from include/libpgfe/core/exceptions.hpp rename to include/libpgfe/exceptions.hpp index c528bdf..9c06a09 100644 --- a/include/libpgfe/core/exceptions.hpp +++ b/include/libpgfe/exceptions.hpp @@ -6,8 +6,8 @@ */ -#ifndef LIBPGFE_CORE_EXCEPTIONS_HPP -#define LIBPGFE_CORE_EXCEPTIONS_HPP +#ifndef LIBPGFE_EXCEPTIONS_HPP +#define LIBPGFE_EXCEPTIONS_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif diff --git a/include/libpgfe/advanced/fishes/blowfish.h b/include/libpgfe/fishes/blowfish.h similarity index 90% rename from include/libpgfe/advanced/fishes/blowfish.h rename to include/libpgfe/fishes/blowfish.h index c99b415..dd4daaf 100644 --- a/include/libpgfe/advanced/fishes/blowfish.h +++ b/include/libpgfe/fishes/blowfish.h @@ -7,13 +7,13 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_ADVANCED_BLOWFISH_H -#define LIBPGFE_ADVANCED_BLOWFISH_H +#ifndef LIBPGFE_BLOWFISH_H +#define LIBPGFE_BLOWFISH_H #ifdef __cplusplus extern "C" { #endif -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #define __PGFE_BF_N 16 #define __PGFE_BF_Np2 18 diff --git a/include/libpgfe/advanced/fishes/blowfish.hpp b/include/libpgfe/fishes/blowfish.hpp similarity index 83% rename from include/libpgfe/advanced/fishes/blowfish.hpp rename to include/libpgfe/fishes/blowfish.hpp index 296d814..3477bd1 100644 --- a/include/libpgfe/advanced/fishes/blowfish.hpp +++ b/include/libpgfe/fishes/blowfish.hpp @@ -5,16 +5,16 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_ADVANCED_BLOWFISH_HPP -#define LIBPGFE_ADVANCED_BLOWFISH_HPP +#ifndef LIBPGFE_BLOWFISH_HPP +#define LIBPGFE_BLOWFISH_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif #include -#include "libpgfe/advanced/abstract_symmetric_crypter.hpp" -#include "libpgfe/advanced/fishes/blowfish.h" +#include "libpgfe/abstract_symmetric_crypter.hpp" +#include "libpgfe/fishes/blowfish.h" namespace libpgfe { diff --git a/include/libpgfe/core/generic.h b/include/libpgfe/generic.h similarity index 89% rename from include/libpgfe/core/generic.h rename to include/libpgfe/generic.h index eceba5d..acacfa0 100644 --- a/include/libpgfe/core/generic.h +++ b/include/libpgfe/generic.h @@ -5,13 +5,13 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_GENERIC_H -#define LIBPGFE_CORE_GENERIC_H +#ifndef LIBPGFE_GENERIC_H +#define LIBPGFE_GENERIC_H #include #include -#include "libpgfe/core/algorithm-choice.h" +#include "libpgfe/algorithm-choice.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/generic.hpp b/include/libpgfe/generic.hpp similarity index 94% rename from include/libpgfe/core/generic.hpp rename to include/libpgfe/generic.hpp index 4458523..a85ed74 100644 --- a/include/libpgfe/core/generic.hpp +++ b/include/libpgfe/generic.hpp @@ -5,8 +5,8 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_GENERIC_HPP -#define LIBPGFE_CORE_GENERIC_HPP +#ifndef LIBPGFE_GENERIC_HPP +#define LIBPGFE_GENERIC_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif @@ -14,9 +14,9 @@ #include #include -#include "libpgfe/core/algorithm-choice.h" -#include "libpgfe/core/exceptions.hpp" -#include "libpgfe/core/hashes.h" +#include "libpgfe/algorithm-choice.h" +#include "libpgfe/exceptions.hpp" +#include "libpgfe/hashes.h" namespace libpgfe { diff --git a/include/libpgfe/hashes.h b/include/libpgfe/hashes.h new file mode 100644 index 0000000..102bc22 --- /dev/null +++ b/include/libpgfe/hashes.h @@ -0,0 +1,9 @@ +#ifndef LIBPGFE_HASHES_H +#define LIBPGFE_HASHES_H + +#include "libpgfe/hashes/md5.h" +#include "libpgfe/hashes/sha1.h" +#include "libpgfe/hashes/sha2.h" +#include "libpgfe/hashes/sha3.h" + +#endif \ No newline at end of file diff --git a/include/libpgfe/core/hashes/abstract_hash_encoder.hpp b/include/libpgfe/hashes/abstract_hash_encoder.hpp similarity index 62% rename from include/libpgfe/core/hashes/abstract_hash_encoder.hpp rename to include/libpgfe/hashes/abstract_hash_encoder.hpp index 3dd7926..cc14795 100644 --- a/include/libpgfe/core/hashes/abstract_hash_encoder.hpp +++ b/include/libpgfe/hashes/abstract_hash_encoder.hpp @@ -5,20 +5,20 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_GENERIC_HASH_ENCODER_HPP -#define LIBPGFE_CORE_GENERIC_HASH_ENCODER_HPP +#ifndef LIBPGFE_GENERIC_HASH_ENCODER_HPP +#define LIBPGFE_GENERIC_HASH_ENCODER_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif #include -#include "libpgfe/core/abstract_encoder.hpp" +#include "libpgfe/abstract_encoder.hpp" -#include "libpgfe/core/algorithm-choice.h" -#include "libpgfe/core/algorithm_selectable.hpp" -#include "libpgfe/core/generic.h" -#include "libpgfe/core/generic.hpp" +#include "libpgfe/algorithm-choice.h" +#include "libpgfe/algorithm_selectable.hpp" +#include "libpgfe/generic.h" +#include "libpgfe/generic.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/hashes/hash_encoder.hpp b/include/libpgfe/hashes/hash_encoder.hpp similarity index 84% rename from include/libpgfe/core/hashes/hash_encoder.hpp rename to include/libpgfe/hashes/hash_encoder.hpp index 7c21dca..da9c6a4 100644 --- a/include/libpgfe/core/hashes/hash_encoder.hpp +++ b/include/libpgfe/hashes/hash_encoder.hpp @@ -7,17 +7,17 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_HASH_ENCODER_HPP -#define LIBPGFE_CORE_HASH_ENCODER_HPP +#ifndef LIBPGFE_HASH_ENCODER_HPP +#define LIBPGFE_HASH_ENCODER_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif -#include "libpgfe/core/abstract_hash_encoder.hpp" +#include "libpgfe/hashes/abstract_hash_encoder.hpp" #include -#include "generic.hpp" +#include "libpgfe/generic.hpp" namespace libpgfe { diff --git a/include/libpgfe/core/hashes/md5.h b/include/libpgfe/hashes/md5.h similarity index 91% rename from include/libpgfe/core/hashes/md5.h rename to include/libpgfe/hashes/md5.h index 4cc68a8..aef4db3 100644 --- a/include/libpgfe/core/hashes/md5.h +++ b/include/libpgfe/hashes/md5.h @@ -5,12 +5,12 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_MD5_H -#define LIBPGFE_CORE_MD5_H +#ifndef LIBPGFE_MD5_H +#define LIBPGFE_MD5_H #include -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/hashes/sha1.h b/include/libpgfe/hashes/sha1.h similarity index 92% rename from include/libpgfe/core/hashes/sha1.h rename to include/libpgfe/hashes/sha1.h index 1032afb..40870d6 100644 --- a/include/libpgfe/core/hashes/sha1.h +++ b/include/libpgfe/hashes/sha1.h @@ -5,12 +5,12 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_SHA1_H -#define LIBPGFE_CORE_SHA1_H +#ifndef LIBPGFE_SHA1_H +#define LIBPGFE_SHA1_H #include -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/hashes/sha2.h b/include/libpgfe/hashes/sha2.h similarity index 98% rename from include/libpgfe/core/hashes/sha2.h rename to include/libpgfe/hashes/sha2.h index bb3167b..e997f54 100644 --- a/include/libpgfe/core/hashes/sha2.h +++ b/include/libpgfe/hashes/sha2.h @@ -5,12 +5,12 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_SHA2_H -#define LIBPGFE_CORE_SHA2_H +#ifndef LIBPGFE_SHA2_H +#define LIBPGFE_SHA2_H #include -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/hashes/sha3.h b/include/libpgfe/hashes/sha3.h similarity index 88% rename from include/libpgfe/core/hashes/sha3.h rename to include/libpgfe/hashes/sha3.h index d83030c..d35468a 100644 --- a/include/libpgfe/core/hashes/sha3.h +++ b/include/libpgfe/hashes/sha3.h @@ -5,12 +5,12 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_SHA3_H -#define LIBPGFE_CORE_SHA3_H +#ifndef LIBPGFE_SHA3_H +#define LIBPGFE_SHA3_H #include -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { @@ -25,15 +25,15 @@ typedef pgfe_keccak_lane_t pgfe_keccak_bitcube_t[5][5]; // Generic Keccak Sponge Context struct pgfe_keccak_sponge_ctx { - pgfe_keccak_bitcube_t state; // Keccak sponge state array - pgfe_encode_t data_queue[to_byte(__PGFE_KECCAK_MAX_RATE)]; // Data queue - uint32_t rate, capacity, inqueue_bits, out_length; // Rate, capacity, bits in queue, output bit length - uint16_t nr; // Number of rounds (Usually 24) - int squeezing; // Is squeezing - unsigned int squeezable; // Size of squeezable bits - pgfe_encode_t ap; // Reserved appendix for adapting SHA-3 - uint8_t ap_len; // Bit length of appendix - int ap_added; // Is appendix added + pgfe_keccak_bitcube_t state; // Keccak sponge state array + pgfe_encode_t data_queue[pgfe_to_byte(__PGFE_KECCAK_MAX_RATE)]; // Data queue + uint32_t rate, capacity, inqueue_bits, out_length; // Rate, capacity, bits in queue, output bit length + uint16_t nr; // Number of rounds (Usually 24) + int squeezing; // Is squeezing + unsigned int squeezable; // Size of squeezable bits + pgfe_encode_t ap; // Reserved appendix for adapting SHA-3 + uint8_t ap_len; // Bit length of appendix + int ap_added; // Is appendix added }; #define PGFE_SHA3_224_DIGEST_SIZE 28 diff --git a/include/libpgfe/core/hmac/hmac.h b/include/libpgfe/hmac/hmac.h similarity index 98% rename from include/libpgfe/core/hmac/hmac.h rename to include/libpgfe/hmac/hmac.h index 524b970..3420605 100644 --- a/include/libpgfe/core/hmac/hmac.h +++ b/include/libpgfe/hmac/hmac.h @@ -5,11 +5,11 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_HMAC_H -#define LIBPGFE_CORE_HMAC_H +#ifndef LIBPGFE_HMAC_H +#define LIBPGFE_HMAC_H -#include "libpgfe/core/generic.h" -#include "libpgfe/core/hashes.h" +#include "libpgfe/generic.h" +#include "libpgfe/hashes.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/hmac/hmac_encoder.hpp b/include/libpgfe/hmac/hmac_encoder.hpp similarity index 87% rename from include/libpgfe/core/hmac/hmac_encoder.hpp rename to include/libpgfe/hmac/hmac_encoder.hpp index 9cd0f18..40ceaf1 100644 --- a/include/libpgfe/core/hmac/hmac_encoder.hpp +++ b/include/libpgfe/hmac/hmac_encoder.hpp @@ -5,8 +5,8 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_HMAC_ENCODER_HPP -#define LIBPGFE_CORE_HMAC_ENCODER_HPP +#ifndef LIBPGFE_HMAC_ENCODER_HPP +#define LIBPGFE_HMAC_ENCODER_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif @@ -14,10 +14,10 @@ #include #include -#include "libpgfe/core/abstract_hash_encoder.hpp" -#include "libpgfe/core/generic.h" -#include "libpgfe/core/generic.hpp" -#include "libpgfe/core/hmac/hmac.h" +#include "libpgfe/generic.h" +#include "libpgfe/generic.hpp" +#include "libpgfe/hashes/abstract_hash_encoder.hpp" +#include "libpgfe/hmac/hmac.h" namespace libpgfe { diff --git a/include/libpgfe/otp/abstract_otp.hpp b/include/libpgfe/otp/abstract_otp.hpp index e8d3223..ff8cfce 100644 --- a/include/libpgfe/otp/abstract_otp.hpp +++ b/include/libpgfe/otp/abstract_otp.hpp @@ -13,9 +13,9 @@ #include -#include "libpgfe/core/algorithm_selectable.hpp" -#include "libpgfe/core/generic.h" -#include "libpgfe/core/sequential_data.hpp" +#include "libpgfe/algorithm_selectable.hpp" +#include "libpgfe/generic.h" +#include "libpgfe/sequential_data.hpp" #include "libpgfe/otp/types.h" namespace libpgfe { diff --git a/include/libpgfe/otp/hotp.h b/include/libpgfe/otp/hotp.h index 9bb516a..41513f9 100644 --- a/include/libpgfe/otp/hotp.h +++ b/include/libpgfe/otp/hotp.h @@ -8,7 +8,7 @@ #ifndef LIBPGFE_OTP_HOTP_H #define LIBPGFE_OTP_HOTP_H -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #include "libpgfe/otp/types.h" #ifdef __cplusplus diff --git a/include/libpgfe/otp/hotp.hpp b/include/libpgfe/otp/hotp.hpp index 3480a6e..b27b1f1 100644 --- a/include/libpgfe/otp/hotp.hpp +++ b/include/libpgfe/otp/hotp.hpp @@ -13,7 +13,7 @@ #include -#include "libpgfe/core/hashes/base32.hpp" +#include "libpgfe/base_encoding/base32.hpp" #include "libpgfe/otp/abstract_otp.hpp" namespace libpgfe { diff --git a/include/libpgfe/otp/totp.h b/include/libpgfe/otp/totp.h index 34c57a6..826f0e0 100644 --- a/include/libpgfe/otp/totp.h +++ b/include/libpgfe/otp/totp.h @@ -11,7 +11,7 @@ #include -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #include "libpgfe/otp/types.h" #ifdef __cplusplus diff --git a/include/libpgfe/core/sequential_data.hpp b/include/libpgfe/sequential_data.hpp similarity index 89% rename from include/libpgfe/core/sequential_data.hpp rename to include/libpgfe/sequential_data.hpp index 4603b4b..4daa971 100644 --- a/include/libpgfe/core/sequential_data.hpp +++ b/include/libpgfe/sequential_data.hpp @@ -7,8 +7,8 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_SEQUENTIAL_DATA_HPP -#define LIBPGFE_CORE_SEQUENTIAL_DATA_HPP +#ifndef LIBPGFE_SEQUENTIAL_DATA_HPP +#define LIBPGFE_SEQUENTIAL_DATA_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif @@ -16,8 +16,8 @@ #include #include -#include "libpgfe/core/generic.h" -#include "libpgfe/core/utils.h" +#include "libpgfe/generic.h" +#include "libpgfe/utils.h" namespace libpgfe { diff --git a/include/libpgfe/core/utils.h b/include/libpgfe/utils.h similarity index 89% rename from include/libpgfe/core/utils.h rename to include/libpgfe/utils.h index 0801cd9..cb405c4 100644 --- a/include/libpgfe/core/utils.h +++ b/include/libpgfe/utils.h @@ -5,10 +5,10 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_UTILS_H -#define LIBPGFE_CORE_UTILS_H +#ifndef LIBPGFE_UTILS_H +#define LIBPGFE_UTILS_H -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/core/utils.hpp b/include/libpgfe/utils.hpp similarity index 81% rename from include/libpgfe/core/utils.hpp rename to include/libpgfe/utils.hpp index 94c8406..29ae848 100644 --- a/include/libpgfe/core/utils.hpp +++ b/include/libpgfe/utils.hpp @@ -5,16 +5,16 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_UTILS_HPP -#define LIBPGFE_CORE_UTILS_HPP +#ifndef LIBPGFE_UTILS_HPP +#define LIBPGFE_UTILS_HPP #ifndef __cplusplus #error libpgfe error: C++ headers are not compatible with C source #endif #include -#include "libpgfe/core/generic.hpp" -#include "libpgfe/core/sequential_data.hpp" +#include "libpgfe/generic.hpp" +#include "libpgfe/sequential_data.hpp" namespace libpgfe { namespace utils { diff --git a/src/core/cpp/bases/abstract_base_encoding.cpp b/src/base_encoding/abstract_base_encoding.cpp similarity index 95% rename from src/core/cpp/bases/abstract_base_encoding.cpp rename to src/base_encoding/abstract_base_encoding.cpp index cfd54f1..a03a2dc 100644 --- a/src/core/cpp/bases/abstract_base_encoding.cpp +++ b/src/base_encoding/abstract_base_encoding.cpp @@ -4,11 +4,12 @@ Copyright (c) 2022-2023 Charles Dong */ +#include "libpgfe/base_encoding/abstract_base_encoding.hpp" #include #include -#include "libpgfe/core/abstract_base_encoding.hpp" +#include "../core/generic-internal.h" #define PGFE_SPACE_MULTIPLE 1.2 diff --git a/src/core/c/bases/base-encoding-internal.c b/src/base_encoding/base-encoding-internal.c similarity index 99% rename from src/core/c/bases/base-encoding-internal.c rename to src/base_encoding/base-encoding-internal.c index bc24753..9d21d79 100644 --- a/src/core/c/bases/base-encoding-internal.c +++ b/src/base_encoding/base-encoding-internal.c @@ -10,7 +10,7 @@ #include #include -#include "../generic-internal.h" +#include "../core/generic-internal.h" #define __bitsz (8) diff --git a/src/core/c/bases/base-encoding-internal.h b/src/base_encoding/base-encoding-internal.h similarity index 97% rename from src/core/c/bases/base-encoding-internal.h rename to src/base_encoding/base-encoding-internal.h index cac0b84..2f9ff7d 100644 --- a/src/core/c/bases/base-encoding-internal.h +++ b/src/base_encoding/base-encoding-internal.h @@ -12,7 +12,7 @@ #include -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/src/core/c/bases/base16.c b/src/base_encoding/base16.c similarity index 96% rename from src/core/c/bases/base16.c rename to src/base_encoding/base16.c index 714efd6..6519621 100644 --- a/src/core/c/bases/base16.c +++ b/src/base_encoding/base16.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/bases/base16.h" +#include "libpgfe/base_encoding/base16.h" #include "./base-encoding-internal.h" diff --git a/src/core/cpp/bases/base16.cpp b/src/base_encoding/base16.cpp similarity index 87% rename from src/core/cpp/bases/base16.cpp rename to src/base_encoding/base16.cpp index 72e90f5..7fc4b6a 100644 --- a/src/core/cpp/bases/base16.cpp +++ b/src/base_encoding/base16.cpp @@ -5,9 +5,9 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/bases/base16.hpp" +#include "libpgfe/base_encoding/base16.hpp" -#include "libpgfe/core/bases/base16.h" +#include "libpgfe/base_encoding/base16.h" using namespace libpgfe; diff --git a/src/core/c/bases/base32.c b/src/base_encoding/base32.c similarity index 96% rename from src/core/c/bases/base32.c rename to src/base_encoding/base32.c index e074e9d..5d52b46 100644 --- a/src/core/c/bases/base32.c +++ b/src/base_encoding/base32.c @@ -5,11 +5,11 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/bases/base32.h" +#include "libpgfe/base_encoding/base32.h" #include -#include "../generic-internal.h" +#include "../core/generic-internal.h" #include "./base-encoding-internal.h" // Base 32 alphabet diff --git a/src/core/cpp/bases/base32.cpp b/src/base_encoding/base32.cpp similarity index 90% rename from src/core/cpp/bases/base32.cpp rename to src/base_encoding/base32.cpp index e9da75d..19644c5 100644 --- a/src/core/cpp/bases/base32.cpp +++ b/src/base_encoding/base32.cpp @@ -5,9 +5,9 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/bases/base32.hpp" +#include "libpgfe/base_encoding/base32.hpp" -#include "libpgfe/core/bases/base32.h" +#include "libpgfe/base_encoding/base32.h" using namespace libpgfe; diff --git a/src/core/c/bases/base64.c b/src/base_encoding/base64.c similarity index 98% rename from src/core/c/bases/base64.c rename to src/base_encoding/base64.c index 03a8b3e..cd83c32 100644 --- a/src/core/c/bases/base64.c +++ b/src/base_encoding/base64.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/bases/base64.h" +#include "libpgfe/base_encoding/base64.h" #include diff --git a/src/core/cpp/bases/base64.cpp b/src/base_encoding/base64.cpp similarity index 89% rename from src/core/cpp/bases/base64.cpp rename to src/base_encoding/base64.cpp index 8912e68..27a34d1 100644 --- a/src/core/cpp/bases/base64.cpp +++ b/src/base_encoding/base64.cpp @@ -5,9 +5,9 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/bases/base64.hpp" +#include "libpgfe/base_encoding/base64.hpp" -#include "libpgfe/core/bases/base64.h" +#include "libpgfe/base_encoding/base64.h" using namespace libpgfe; diff --git a/src/advanced/cpp/abstract_symmetric_crypter.cpp b/src/core/abstract_symmetric_crypter.cpp similarity index 94% rename from src/advanced/cpp/abstract_symmetric_crypter.cpp rename to src/core/abstract_symmetric_crypter.cpp index 32aba43..5ad2a43 100644 --- a/src/advanced/cpp/abstract_symmetric_crypter.cpp +++ b/src/core/abstract_symmetric_crypter.cpp @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/advanced/abstract_symmetric_crypter.hpp" +#include "libpgfe/abstract_symmetric_crypter.hpp" #include diff --git a/src/core/cpp/algorithm_selectable.cpp b/src/core/algorithm_selectable.cpp similarity index 88% rename from src/core/cpp/algorithm_selectable.cpp rename to src/core/algorithm_selectable.cpp index 2de7ae5..e0783d8 100644 --- a/src/core/cpp/algorithm_selectable.cpp +++ b/src/core/algorithm_selectable.cpp @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/algorithm_selectable.hpp" +#include "libpgfe/algorithm_selectable.hpp" using namespace libpgfe; diff --git a/src/core/c/generic-internal.c b/src/core/generic-internal.c similarity index 100% rename from src/core/c/generic-internal.c rename to src/core/generic-internal.c diff --git a/src/core/c/generic-internal.h b/src/core/generic-internal.h similarity index 99% rename from src/core/c/generic-internal.h rename to src/core/generic-internal.h index acbfac2..7d60f02 100644 --- a/src/core/c/generic-internal.h +++ b/src/core/generic-internal.h @@ -10,7 +10,7 @@ #ifndef LIBPGFE_GENERIC_INTERNAL_H #define LIBPGFE_GENERIC_INTERNAL_H -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/src/core/c/generic.c b/src/core/generic.c similarity index 66% rename from src/core/c/generic.c rename to src/core/generic.c index dde866f..f9e7801 100644 --- a/src/core/c/generic.c +++ b/src/core/generic.c @@ -5,4 +5,4 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" diff --git a/src/core/cpp/generic.cpp b/src/core/generic.cpp similarity index 84% rename from src/core/cpp/generic.cpp rename to src/core/generic.cpp index 7977ea2..5a252f9 100644 --- a/src/core/cpp/generic.cpp +++ b/src/core/generic.cpp @@ -8,9 +8,9 @@ #ifndef LIBPGFE_GENERIC_CPP #define LIBPGFE_GENERIC_CPP -#include "libpgfe/core/generic.hpp" +#include "libpgfe/generic.hpp" -#include "libpgfe/core/generic.h" +#include "libpgfe/generic.h" namespace libpgfe { diff --git a/src/core/cpp/sequential_data.cpp b/src/core/sequential_data.cpp similarity index 97% rename from src/core/cpp/sequential_data.cpp rename to src/core/sequential_data.cpp index 33f9d76..69d8c60 100644 --- a/src/core/cpp/sequential_data.cpp +++ b/src/core/sequential_data.cpp @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/sequential_data.hpp" +#include "libpgfe/sequential_data.hpp" #include #include diff --git a/src/core/c/utils.c b/src/core/utils.c similarity index 98% rename from src/core/c/utils.c rename to src/core/utils.c index b9ffdcc..7fa55f6 100644 --- a/src/core/c/utils.c +++ b/src/core/utils.c @@ -5,8 +5,9 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/utils.h" +#include "libpgfe/utils.h" +#include #include #include "./generic-internal.h" diff --git a/src/core/cpp/utils.cpp b/src/core/utils.cpp similarity index 93% rename from src/core/cpp/utils.cpp rename to src/core/utils.cpp index c131122..9d24d9e 100644 --- a/src/core/cpp/utils.cpp +++ b/src/core/utils.cpp @@ -5,11 +5,11 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/utils.hpp" +#include "libpgfe/utils.hpp" #include -#include "libpgfe/core/utils.h" +#include "libpgfe/utils.h" namespace libpgfe { namespace utils { diff --git a/src/advanced/c/fishes/blowfish.c b/src/fishes/blowfish.c similarity index 99% rename from src/advanced/c/fishes/blowfish.c rename to src/fishes/blowfish.c index 6f57603..c04eb2a 100644 --- a/src/advanced/c/fishes/blowfish.c +++ b/src/fishes/blowfish.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/advanced/fishes/blowfish.h" +#include "libpgfe/fishes/blowfish.h" #include diff --git a/src/advanced/cpp/fishes/blowfish.cpp b/src/fishes/blowfish.cpp similarity index 97% rename from src/advanced/cpp/fishes/blowfish.cpp rename to src/fishes/blowfish.cpp index a082db9..ee52a51 100644 --- a/src/advanced/cpp/fishes/blowfish.cpp +++ b/src/fishes/blowfish.cpp @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/advanced/fishes/blowfish.hpp" +#include "libpgfe/fishes/blowfish.hpp" #include #include diff --git a/src/core/cpp/hashes/hash_encoder.cpp b/src/hashes/hash_encoder.cpp similarity index 96% rename from src/core/cpp/hashes/hash_encoder.cpp rename to src/hashes/hash_encoder.cpp index e0dfa33..e4c64a4 100644 --- a/src/core/cpp/hashes/hash_encoder.cpp +++ b/src/hashes/hash_encoder.cpp @@ -5,15 +5,15 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/hash_encoder.hpp" +#include "libpgfe/hashes/hash_encoder.hpp" #include #include -#include "libpgfe/core/hashes.h" -#include "libpgfe/core/utils.h" +#include "libpgfe/hashes.h" +#include "libpgfe/utils.h" -#include "../../c/generic-internal.h" +#include "../core/generic-internal.h" #define __PGFE_CTX_CREATE_CASE(alg, name) \ case alg: \ diff --git a/src/core/c/hashes/keccak-backend.c b/src/hashes/keccak-backend.c similarity index 100% rename from src/core/c/hashes/keccak-backend.c rename to src/hashes/keccak-backend.c diff --git a/src/core/c/hashes/keccak-backend.h b/src/hashes/keccak-backend.h similarity index 77% rename from src/core/c/hashes/keccak-backend.h rename to src/hashes/keccak-backend.h index 1412f82..4bfbdbd 100644 --- a/src/core/c/hashes/keccak-backend.h +++ b/src/hashes/keccak-backend.h @@ -7,14 +7,14 @@ Copyright (c) 2022-2023 Charles Dong */ -#ifndef LIBPGFE_CORE_KECCAK_BACKEND_H -#define LIBPGFE_CORE_KECCAK_BACKEND_H +#ifndef LIBPGFE_KECCAK_BACKEND_H +#define LIBPGFE_KECCAK_BACKEND_H #include -#include "libpgfe/core/hashes/sha3.h" +#include "libpgfe/hashes/sha3.h" -#include "../generic-internal.h" +#include "../core/generic-internal.h" #define KECCAK_b 1600 diff --git a/src/core/c/hashes/md5-backend.c b/src/hashes/md5-backend.c similarity index 100% rename from src/core/c/hashes/md5-backend.c rename to src/hashes/md5-backend.c diff --git a/src/core/c/hashes/md5-backend.h b/src/hashes/md5-backend.h similarity index 92% rename from src/core/c/hashes/md5-backend.h rename to src/hashes/md5-backend.h index 52a5bde..a7c0440 100644 --- a/src/core/c/hashes/md5-backend.h +++ b/src/hashes/md5-backend.h @@ -10,7 +10,7 @@ #ifndef LIBPGFE_MD5_BACKEND_H #define LIBPGFE_MD5_BACKEND_H -#include "../generic-internal.h" +#include "../core/generic-internal.h" #ifdef __cplusplus extern "C" { diff --git a/src/core/c/hashes/md5.c b/src/hashes/md5.c similarity index 98% rename from src/core/c/hashes/md5.c rename to src/hashes/md5.c index f950248..551e9f0 100644 --- a/src/core/c/hashes/md5.c +++ b/src/hashes/md5.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/md5.h" +#include "libpgfe/hashes/md5.h" #include diff --git a/src/core/c/hashes/sha-internal.c b/src/hashes/sha-internal.c similarity index 100% rename from src/core/c/hashes/sha-internal.c rename to src/hashes/sha-internal.c diff --git a/src/core/c/hashes/sha-internal.h b/src/hashes/sha-internal.h similarity index 92% rename from src/core/c/hashes/sha-internal.h rename to src/hashes/sha-internal.h index d80d291..b2177c6 100644 --- a/src/core/c/hashes/sha-internal.h +++ b/src/hashes/sha-internal.h @@ -10,7 +10,7 @@ #ifndef LIBPGFE_SHA_INTERNAL_H #define LIBPGFE_SHA_INTERNAL_H -#include "../generic-internal.h" +#include "../core/generic-internal.h" #ifdef __cplusplus extern "C" { diff --git a/src/core/c/hashes/sha1.c b/src/hashes/sha1.c similarity index 91% rename from src/core/c/hashes/sha1.c rename to src/hashes/sha1.c index 782ac1a..f044eb9 100644 --- a/src/core/c/hashes/sha1.c +++ b/src/hashes/sha1.c @@ -5,11 +5,11 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/sha1.h" +#include "libpgfe/hashes/sha1.h" #include -#include "../generic-internal.h" +#include "../core/generic-internal.h" #include "./sha-internal.h" #include "./templates.h" @@ -18,7 +18,7 @@ static const pgfe_word_t H0[] = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, FRONTEND_GEN2(sha1) FRONTEND_GEN2_DEFAULT(sha1, SHA1) -static void process_block(struct pgfe_sha1_ctx *ctx) { +static void sha1_process_block(struct pgfe_sha1_ctx *ctx) { // Constants in SHA1 static const pgfe_word_t K[] = {0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6}; @@ -91,14 +91,14 @@ static void process_block(struct pgfe_sha1_ctx *ctx) { memset(ws, 0, sizeof(ws)); } -static void padding(struct pgfe_sha1_ctx *ctx) { +static void sha1_padding(struct pgfe_sha1_ctx *ctx) { ctx->block[ctx->index++] = PADDING_HEADER; // 56 = PGFE_SHA1_BLOCK_SIZE - 8 if (ctx->index > 56) { memset(ctx->block + ctx->index, 0, PGFE_SHA1_BLOCK_SIZE - ctx->index); ctx->index = PGFE_SHA1_BLOCK_SIZE; - process_block(ctx); + sha1_process_block(ctx); } else if (ctx->index < 56) { memset(ctx->block + ctx->index, 0, 56 - ctx->index); @@ -115,7 +115,7 @@ static void padding(struct pgfe_sha1_ctx *ctx) { ctx->block[62] = (uint8_t)(ctx->len_low >> 8); ctx->block[63] = (uint8_t)ctx->len_low; - process_block(ctx); + sha1_process_block(ctx); } SHA_INIT(sha1) diff --git a/src/core/c/hashes/sha2-backend.c b/src/hashes/sha2-backend.c similarity index 99% rename from src/core/c/hashes/sha2-backend.c rename to src/hashes/sha2-backend.c index 228b00f..b9bf17a 100644 --- a/src/core/c/hashes/sha2-backend.c +++ b/src/hashes/sha2-backend.c @@ -8,7 +8,7 @@ #include "./sha2-backend.h" #include "./templates.h" -#include "libpgfe/core/hashes/sha2.h" +#include "libpgfe/hashes/sha2.h" #include diff --git a/src/core/c/hashes/sha2-backend.h b/src/hashes/sha2-backend.h similarity index 94% rename from src/core/c/hashes/sha2-backend.h rename to src/hashes/sha2-backend.h index 10d7ed3..055733b 100644 --- a/src/core/c/hashes/sha2-backend.h +++ b/src/hashes/sha2-backend.h @@ -12,7 +12,7 @@ #include "./sha-internal.h" -#include "libpgfe/core/hashes/sha2.h" +#include "libpgfe/hashes/sha2.h" #ifdef __cpluslpus extern "C" { @@ -32,7 +32,7 @@ void sha224n256_init(struct pgfe_sha256_ctx *ctx, const pgfe_word_t H0[]); void sha256_process_block(struct pgfe_sha256_ctx *ctx); -#define __pgfe_sha224_process_block __pgfe_sha256_process_block +#define sha224_process_block sha256_process_block void sha224n256_padding(struct pgfe_sha256_ctx *ctx); diff --git a/src/core/c/hashes/sha224.c b/src/hashes/sha224.c similarity index 93% rename from src/core/c/hashes/sha224.c rename to src/hashes/sha224.c index f290c9a..0ec3a8f 100644 --- a/src/core/c/hashes/sha224.c +++ b/src/hashes/sha224.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/sha2.h" +#include "libpgfe/hashes/sha2.h" #include diff --git a/src/core/c/hashes/sha256.c b/src/hashes/sha256.c similarity index 93% rename from src/core/c/hashes/sha256.c rename to src/hashes/sha256.c index 16d19fd..b7b835a 100644 --- a/src/core/c/hashes/sha256.c +++ b/src/hashes/sha256.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/sha2.h" +#include "libpgfe/hashes/sha2.h" #include diff --git a/src/core/c/hashes/sha3-224.c b/src/hashes/sha3-224.c similarity index 94% rename from src/core/c/hashes/sha3-224.c rename to src/hashes/sha3-224.c index aa01f51..a0d7383 100644 --- a/src/core/c/hashes/sha3-224.c +++ b/src/hashes/sha3-224.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/sha3.h" +#include "libpgfe/hashes/sha3.h" #include diff --git a/src/core/c/hashes/sha3-256.c b/src/hashes/sha3-256.c similarity index 94% rename from src/core/c/hashes/sha3-256.c rename to src/hashes/sha3-256.c index f107964..57e6af2 100644 --- a/src/core/c/hashes/sha3-256.c +++ b/src/hashes/sha3-256.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/sha3.h" +#include "libpgfe/hashes/sha3.h" #include diff --git a/src/core/c/hashes/sha3-384.c b/src/hashes/sha3-384.c similarity index 94% rename from src/core/c/hashes/sha3-384.c rename to src/hashes/sha3-384.c index fe666bb..88b2e27 100644 --- a/src/core/c/hashes/sha3-384.c +++ b/src/hashes/sha3-384.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/sha3.h" +#include "libpgfe/hashes/sha3.h" #include diff --git a/src/core/c/hashes/sha3-512.c b/src/hashes/sha3-512.c similarity index 95% rename from src/core/c/hashes/sha3-512.c rename to src/hashes/sha3-512.c index b61f240..2eccb93 100644 --- a/src/core/c/hashes/sha3-512.c +++ b/src/hashes/sha3-512.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/sha3.h" +#include "libpgfe/hashes/sha3.h" #include diff --git a/src/core/c/hashes/sha384.c b/src/hashes/sha384.c similarity index 96% rename from src/core/c/hashes/sha384.c rename to src/hashes/sha384.c index e1381f4..ce5c1f6 100644 --- a/src/core/c/hashes/sha384.c +++ b/src/hashes/sha384.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/sha2.h" +#include "libpgfe/hashes/sha2.h" #include diff --git a/src/core/c/hashes/sha512.c b/src/hashes/sha512.c similarity index 98% rename from src/core/c/hashes/sha512.c rename to src/hashes/sha512.c index 4fe1add..70b6d92 100644 --- a/src/core/c/hashes/sha512.c +++ b/src/hashes/sha512.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/sha2.h" +#include "libpgfe/hashes/sha2.h" #include diff --git a/src/core/c/hashes/shake.c b/src/hashes/shake.c similarity index 98% rename from src/core/c/hashes/shake.c rename to src/hashes/shake.c index 869e3d6..3d1ab12 100644 --- a/src/core/c/hashes/shake.c +++ b/src/hashes/shake.c @@ -5,7 +5,7 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hashes/sha3.h" +#include "libpgfe/hashes/sha3.h" #include diff --git a/src/core/c/hashes/templates.h b/src/hashes/templates.h similarity index 99% rename from src/core/c/hashes/templates.h rename to src/hashes/templates.h index afa4611..88a9a2c 100644 --- a/src/core/c/hashes/templates.h +++ b/src/hashes/templates.h @@ -147,7 +147,7 @@ extern "C" { corrupt_flag = ctx->len_low < tmp_low && !(++ctx->len_high); \ \ if (!corrupt_flag && ctx->index == PGFE_##upper##_BLOCK_SIZE) { \ - __pgfe_##name##_process_block(ctx); \ + name##_process_block(ctx); \ } \ \ inp++; \ @@ -160,7 +160,7 @@ extern "C" { \ size_t i; \ \ - __pgfe_##name##_padding(ctx); \ + name##_padding(ctx); \ \ /* Wipe stored data */ \ memset(ctx->block, 0, sizeof(ctx->block)); \ diff --git a/src/core/c/hmac/hmac.c b/src/hmac/hmac.c similarity index 98% rename from src/core/c/hmac/hmac.c rename to src/hmac/hmac.c index 35f3b1d..4d14ab9 100644 --- a/src/core/c/hmac/hmac.c +++ b/src/hmac/hmac.c @@ -5,11 +5,11 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hmac/hmac.h" +#include "libpgfe/hmac/hmac.h" #include -#include "../generic-internal.h" +#include "../core/generic-internal.h" #define hmac_gen(name, upper) \ void pgfe_hmac_##name##_init(struct pgfe_hmac_##name##_ctx *ctx) { \ diff --git a/src/core/cpp/hmac/hmac_encoder.cpp b/src/hmac/hmac_encoder.cpp similarity index 97% rename from src/core/cpp/hmac/hmac_encoder.cpp rename to src/hmac/hmac_encoder.cpp index 9f8e847..5276ecd 100644 --- a/src/core/cpp/hmac/hmac_encoder.cpp +++ b/src/hmac/hmac_encoder.cpp @@ -5,9 +5,9 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/core/hmac/hmac_encoder.hpp" +#include "libpgfe/hmac/hmac_encoder.hpp" -#include "../../c/generic-internal.h" +#include "../core/generic-internal.h" #include diff --git a/src/otp/cpp/abstract_otp.cpp b/src/otp/abstract_otp.cpp similarity index 100% rename from src/otp/cpp/abstract_otp.cpp rename to src/otp/abstract_otp.cpp diff --git a/src/otp/c/hotp.c b/src/otp/hotp.c similarity index 95% rename from src/otp/c/hotp.c rename to src/otp/hotp.c index d761ad8..cc89fcd 100644 --- a/src/otp/c/hotp.c +++ b/src/otp/hotp.c @@ -5,14 +5,14 @@ Copyright (c) 2022-2023 Charles Dong */ -#include "libpgfe/hotp.h" +#include "libpgfe/otp/hotp.h" #include -#include "../generic-internal.h" +#include "../core/generic-internal.h" #include "./otp-generic.h" -#include "libpgfe/hash.h" +#include "libpgfe/hashes.h" #define __PGFE_SET_SIZE_CASE(upper, lower) \ case upper: \ diff --git a/src/otp/cpp/hotp.cpp b/src/otp/hotp.cpp similarity index 96% rename from src/otp/cpp/hotp.cpp rename to src/otp/hotp.cpp index ac9a3f5..e3c17f6 100644 --- a/src/otp/cpp/hotp.cpp +++ b/src/otp/hotp.cpp @@ -9,10 +9,10 @@ #include -#include "libpgfe/core/generic.hpp" +#include "libpgfe/generic.hpp" #include "libpgfe/otp/hotp.h" -#include "core/c/generic-internal.h" +#include "core/generic-internal.h" using namespace libpgfe; diff --git a/src/otp/c/otp-generic.c b/src/otp/otp-generic.c similarity index 100% rename from src/otp/c/otp-generic.c rename to src/otp/otp-generic.c diff --git a/src/otp/c/otp-generic.h b/src/otp/otp-generic.h similarity index 89% rename from src/otp/c/otp-generic.h rename to src/otp/otp-generic.h index d82e8d4..67a5cbf 100644 --- a/src/otp/c/otp-generic.h +++ b/src/otp/otp-generic.h @@ -13,8 +13,8 @@ #include #include -#include "libpgfe/core/generic.h" -#include "libpgfe/core/hmac/hmac.h" +#include "libpgfe/generic.h" +#include "libpgfe/hmac/hmac.h" #include "libpgfe/otp/types.h" #ifdef __cplusplus diff --git a/src/otp/c/totp.c b/src/otp/totp.c similarity index 94% rename from src/otp/c/totp.c rename to src/otp/totp.c index 6d3094e..7d0644e 100644 --- a/src/otp/c/totp.c +++ b/src/otp/totp.c @@ -7,11 +7,11 @@ #include "libpgfe/otp/totp.h" -#include "../generic-internal.h" +#include "../core/generic-internal.h" #include "./otp-generic.h" -#include "libpgfe/core/hashes/sha1.h" -#include "libpgfe/hotp.h" +#include "libpgfe/hashes/sha1.h" +#include "libpgfe/otp/hotp.h" pgfe_otp_counter_t __pgfe_calc_periodic_counter( time_t realtime, pgfe_totp_interval_t interval, time_t initial_time, pgfe_totp_delta_t *delta_out diff --git a/src/otp/cpp/totp.cpp b/src/otp/totp.cpp similarity index 96% rename from src/otp/cpp/totp.cpp rename to src/otp/totp.cpp index 78f6fee..a46c8a7 100644 --- a/src/otp/cpp/totp.cpp +++ b/src/otp/totp.cpp @@ -7,9 +7,9 @@ #include "libpgfe/otp/totp.hpp" -#include "libpgfe/core/utils.h" +#include "libpgfe/utils.h" -#include "../c/otp-generic.h" +#include "./otp-generic.h" using namespace libpgfe; diff --git a/tests/base_test.hpp b/tests/base_test.hpp index 7db4f3d..878c993 100644 --- a/tests/base_test.hpp +++ b/tests/base_test.hpp @@ -8,7 +8,7 @@ #include "test.h" #include "../include/libpgfe/base16.hpp" -#include "../include/libpgfe/core/hashes/base32.hpp" +#include "../include/libpgfe/hashes/base32.hpp" #include "../include/libpgfe/base64.hpp" using namespace std; diff --git a/tests/blowfish_test.h b/tests/blowfish_test.h index 2402d1e..f9ad968 100644 --- a/tests/blowfish_test.h +++ b/tests/blowfish_test.h @@ -7,8 +7,8 @@ #include "test.h" -#include "../include/libpgfe/advanced/blowfish.h" -#include "../include/libpgfe/core/utils.h" +#include "../include/libpgfe/blowfish.h" +#include "../include/libpgfe/utils.h" void blowfish_encrypt_unit_test(ARGS) { struct pgfe_blowfish_ctx ctx; diff --git a/tests/blowfish_test.hpp b/tests/blowfish_test.hpp index 9c340c2..a0d2d98 100644 --- a/tests/blowfish_test.hpp +++ b/tests/blowfish_test.hpp @@ -11,8 +11,8 @@ #include #include -#include "../include/libpgfe/advanced/blowfish.hpp" -#include "../include/libpgfe/core/utils.hpp" +#include "../include/libpgfe/blowfish.hpp" +#include "../include/libpgfe/utils.hpp" void blowfish_encrypt_test(ARGS) { using namespace libpgfe; diff --git a/tests/hash_encoder_test.hpp b/tests/hash_encoder_test.hpp index d13936b..38a2358 100644 --- a/tests/hash_encoder_test.hpp +++ b/tests/hash_encoder_test.hpp @@ -11,8 +11,8 @@ #include #include "../include/libpgfe/hash_encoder.hpp" -#include "../include/libpgfe/core/utils.h" -#include "../include/libpgfe/core/utils.hpp" +#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/utils.hpp" void hash_encoder_test(ARGS) { using namespace std; diff --git a/tests/hmactest.h b/tests/hmactest.h index c1d94ee..718b6f0 100644 --- a/tests/hmactest.h +++ b/tests/hmactest.h @@ -7,9 +7,9 @@ #include "test.h" -#include "../include/libpgfe/core/hmac/hmac.h" -#include "../include/libpgfe/core/hashes/md5.h" -#include "../include/libpgfe/core/utils.h" +#include "../include/libpgfe/hmac/hmac.h" +#include "../include/libpgfe/hashes/md5.h" +#include "../include/libpgfe/utils.h" enum pgfe_algorithm_choice get_alg_choice(char option[]) { enum pgfe_algorithm_choice c; diff --git a/tests/hmactest.hpp b/tests/hmactest.hpp index a37db93..ed532bb 100644 --- a/tests/hmactest.hpp +++ b/tests/hmactest.hpp @@ -10,8 +10,8 @@ #include #include "../include/libpgfe/hmac_encoder.hpp" -#include "../include/libpgfe/core/utils.h" -#include "../include/libpgfe/core/utils.hpp" +#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/utils.hpp" void hmac_encoder_test(ARGS) { using namespace libpgfe; diff --git a/tests/mdtest.h b/tests/mdtest.h index 31fe28f..602663c 100644 --- a/tests/mdtest.h +++ b/tests/mdtest.h @@ -7,8 +7,8 @@ #include "test.h" -#include "../include/libpgfe/core/hashes/md5.h" -#include "../include/libpgfe/core/utils.h" +#include "../include/libpgfe/hashes/md5.h" +#include "../include/libpgfe/utils.h" void md5test(ARGS) { pgfe_encode_t output[PGFE_MD5_DIGEST_SIZE]; diff --git a/tests/otptest.h b/tests/otptest.h index f55307f..36e6b35 100644 --- a/tests/otptest.h +++ b/tests/otptest.h @@ -8,8 +8,8 @@ #include "test.h" #include "../include/libpgfe/hotp.h" -#include "../include/libpgfe/core/hashes/sha2.h" -#include "../include/libpgfe/core/utils.h" +#include "../include/libpgfe/hashes/sha2.h" +#include "../include/libpgfe/utils.h" void hotp_hex(ARGS) { pgfe_encode_t key[100]; diff --git a/tests/otptest.hpp b/tests/otptest.hpp index 171357a..ff06731 100644 --- a/tests/otptest.hpp +++ b/tests/otptest.hpp @@ -11,7 +11,7 @@ #include #include "../include/libpgfe/otp/hotp.hpp" -#include "../include/libpgfe/core/utils.hpp" +#include "../include/libpgfe/utils.hpp" void hotp_hex_test(ARGS) { HOTP hotp{_algstr(argv[2])}; diff --git a/tests/shake_test.h b/tests/shake_test.h index 247257b..896b52b 100644 --- a/tests/shake_test.h +++ b/tests/shake_test.h @@ -10,8 +10,8 @@ #include #include -#include "../include/libpgfe/core/hashes/sha3.h" -#include "../include/libpgfe/core/utils.h" +#include "../include/libpgfe/hashes/sha3.h" +#include "../include/libpgfe/utils.h" void shake_test(ARGS) { size_t bitsize; diff --git a/tests/shatest.h b/tests/shatest.h index c8ebc39..1a2cb32 100644 --- a/tests/shatest.h +++ b/tests/shatest.h @@ -7,10 +7,10 @@ #include "test.h" -#include "../include/libpgfe/core/hashes/sha1.h" -#include "../include/libpgfe/core/hashes/sha2.h" -#include "../include/libpgfe/core/hashes/sha3.h" -#include "../include/libpgfe/core/utils.h" +#include "../include/libpgfe/hashes/sha1.h" +#include "../include/libpgfe/hashes/sha2.h" +#include "../include/libpgfe/hashes/sha3.h" +#include "../include/libpgfe/utils.h" void sha1_test(ARGS) { pgfe_encode_t output[PGFE_SHA1_DIGEST_SIZE]; diff --git a/tests/utilstest.h b/tests/utilstest.h index 0a691e9..0be5c70 100644 --- a/tests/utilstest.h +++ b/tests/utilstest.h @@ -7,7 +7,7 @@ #include "test.h" -#include "../include/libpgfe/core/utils.h" +#include "../include/libpgfe/utils.h" #include void string2hash(ARGS) { From 6c923ccd20d69449231a424cc42535889d5d15b6 Mon Sep 17 00:00:00 2001 From: Charles Dong Date: Wed, 31 May 2023 21:58:39 +0800 Subject: [PATCH 4/8] Update and rename LICENSE to LICENSE-MIT --- LICENSE | 28 ---------------------------- LICENSE-MIT | 21 +++++++++++++++++++++ 2 files changed, 21 insertions(+), 28 deletions(-) delete mode 100644 LICENSE create mode 100644 LICENSE-MIT diff --git a/LICENSE b/LICENSE deleted file mode 100644 index 6780c64..0000000 --- a/LICENSE +++ /dev/null @@ -1,28 +0,0 @@ -BSD 3-Clause License - -Copyright (c) 2022-2023 Charles Dong - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions are met: - -1. Redistributions of source code must retain the above copyright notice, this - list of conditions and the following disclaimer. - -2. Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - -3. Neither the name of the copyright holder nor the names of its - contributors may be used to endorse or promote products derived from - this software without specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" -AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE -FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR -SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER -CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, -OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE -OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/LICENSE-MIT b/LICENSE-MIT new file mode 100644 index 0000000..a0087cd --- /dev/null +++ b/LICENSE-MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 Charles Dong + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 0f25b632a1a1299533ca18e79758d09d1c79f2a5 Mon Sep 17 00:00:00 2001 From: Charles Dong Date: Wed, 31 May 2023 21:59:24 +0800 Subject: [PATCH 5/8] Create LICENSE-APACHE --- LICENSE-APACHE | 201 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) create mode 100644 LICENSE-APACHE diff --git a/LICENSE-APACHE b/LICENSE-APACHE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE-APACHE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. From c856644848da9e0c465a5840e5fe2550db401ea9 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 31 May 2023 22:01:03 +0800 Subject: [PATCH 6/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d1750f6..9a7a90e 100644 --- a/README.md +++ b/README.md @@ -16,7 +16,7 @@ | 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) | | Compiler | LLVM Clang | -| License | BSD 3-Clause | +| License | Dual (MIT / Apache 2.0) | [*Any questions?*](.github/qna.md) From a8f5795c7009f842a25ffd51cee7b74a635408af Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 31 May 2023 22:01:50 +0800 Subject: [PATCH 7/8] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 9a7a90e..e75f2c3 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ ## Introduction -**libpgfe** (IPA: /[ˌlɪbˈpɪɡfiː](http://ipa-reader.xyz/?text=%CB%8Cl%C9%AAb%CB%88p%C9%AA%C9%A1fi%CB%90)/, like "lib-pig-fee") is a free and open-source cryptographic library focusing on flexibility and easy-to-access interfaces, which is written in [C](https://en.wikipedia.org/wiki/C_(programming_language)) and [C++](https://en.wikipedia.org/wiki/C%2B%2B). +**libpgfe** (IPA: /[ˌlɪbˈpɪɡfiː](http://ipa-reader.xyz/?text=%CB%8Cl%C9%AAb%CB%88p%C9%AA%C9%A1fi%CB%90)/, respelling: "lib-PIG-fee") is a free and open-source cryptographic library focusing on flexibility and easy-to-access interfaces, which is written in [C](https://en.wikipedia.org/wiki/C_(programming_language)) and [C++](https://en.wikipedia.org/wiki/C%2B%2B). *libpgfe* currently supports hash encoding (e.g. SHA256, MD5), HMAC encoding, HOTP/TOTP and Base 16/32/64. From cc750f9f9827e33f320a740ba859e931c84d5fd2 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 31 May 2023 22:52:11 +0800 Subject: [PATCH 8/8] Update test code structure --- .gitignore | 4 ++- CMakeLists.txt | 3 +-- Makefile | 2 +- cmake/tests.cmake | 36 +++++++++++++++++++++++++++ tests/CMakeLists.txt | 17 ------------- tests/{ => c}/baseencodetest.h | 4 ++- tests/{ => c}/blowfish_test.h | 4 +-- tests/{ => c}/hmactest.h | 6 ++--- tests/{ => c}/mdtest.h | 4 +-- tests/{ => c}/otptest.h | 6 ++--- tests/{ => c}/shake_test.h | 18 ++++++++------ tests/{ => c}/shatest.h | 22 ++++++++-------- tests/{ => c}/test.c | 0 tests/{ => c}/utilstest.h | 2 +- tests/cmake/base_tests.cmake | 10 ++++---- tests/cmake/blowfish_tests.cmake | 12 ++++----- tests/cmake/hash_tests.cmake | 6 ++--- tests/cmake/hmac_tests.cmake | 4 +-- tests/cmake/otp_tests.cmake | 4 +-- tests/cmake/shake_tests.cmake | 6 ++--- tests/cmake/test_meta.cmake | 2 +- tests/cmake/util_tests.cmake | 18 +++++++------- tests/{ => core}/test.h | 0 tests/{ => cpp}/base_multithread.hpp | 5 ++-- tests/{ => cpp}/base_test.hpp | 6 ++--- tests/{ => cpp}/blowfish_test.hpp | 4 +-- tests/{ => cpp}/hash_encoder_test.hpp | 6 ++--- tests/{ => cpp}/hmactest.hpp | 6 ++--- tests/{ => cpp}/otptest.hpp | 4 +-- tests/{ => cpp}/test.cpp | 0 30 files changed, 122 insertions(+), 99 deletions(-) create mode 100644 cmake/tests.cmake delete mode 100644 tests/CMakeLists.txt rename tests/{ => c}/baseencodetest.h (91%) rename tests/{ => c}/blowfish_test.h (94%) rename tests/{ => c}/hmactest.h (93%) rename tests/{ => c}/mdtest.h (77%) rename tests/{ => c}/otptest.h (88%) rename tests/{ => c}/shake_test.h (82%) rename tests/{ => c}/shatest.h (88%) rename tests/{ => c}/test.c (100%) rename tests/{ => c}/utilstest.h (93%) rename tests/{ => core}/test.h (100%) rename tests/{ => cpp}/base_multithread.hpp (95%) rename tests/{ => cpp}/base_test.hpp (91%) rename tests/{ => cpp}/blowfish_test.hpp (88%) rename tests/{ => cpp}/hash_encoder_test.hpp (80%) rename tests/{ => cpp}/hmactest.hpp (84%) rename tests/{ => cpp}/otptest.hpp (84%) rename tests/{ => cpp}/test.cpp (100%) diff --git a/.gitignore b/.gitignore index d747306..a3d2245 100644 --- a/.gitignore +++ b/.gitignore @@ -55,4 +55,6 @@ build/ lib/ .vscode/ -test/totptest.* \ No newline at end of file +test/totptest.* + +Testing/ \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index fd3ead2..21aa484 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,7 +19,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(src_dir "src") set(include_dir "include") set(cmake_module_dir "cmake") -set(test_dir "tests") list(APPEND cmake_modules "libpgfe") @@ -27,7 +26,7 @@ foreach(mod IN LISTS cmake_modules) include(${cmake_module_dir}/targets/${mod}.cmake) endforeach() -add_subdirectory(${test_dir}) +include(${cmake_module_dir}/tests.cmake) set(CPACK_PROJECT_NAME ${PROJECT_NAME}) set(CPACK_PROJECT_VERSION ${PROJECT_VERSION}) diff --git a/Makefile b/Makefile index 425ea02..290e60d 100644 --- a/Makefile +++ b/Makefile @@ -5,7 +5,7 @@ include metadata.mak all: @echo 'Building...' @cmake . -B $(BUILD_DIR) -G Ninja - @cmake --build $(BUILD_DIR) --config Release -j20 --target pgfe -- + @cmake --build $(BUILD_DIR) --config Release -j20 --target all -- @echo 'Building done' rebuild: clean all diff --git a/cmake/tests.cmake b/cmake/tests.cmake new file mode 100644 index 0000000..549fc55 --- /dev/null +++ b/cmake/tests.cmake @@ -0,0 +1,36 @@ +set(test_dir "tests") + +# CTest +include(CTest) +enable_testing() + +set(test_c_exe pgfe_test_c) +set(test_cpp_exe pgfe_test_cpp) + +## C lib test +add_executable(${test_c_exe} ${test_dir}/c/test.c) + +target_include_directories(${test_c_exe} + PUBLIC ${include_dir} + PRIVATE ${test_dir}/core ${test_dir}/c/ +) + +target_link_libraries(${test_c_exe} pgfe) + +## C++ port test +add_executable(${test_cpp_exe} ${test_dir}/cpp/test.cpp) + +target_include_directories(${test_cpp_exe} + PUBLIC ${include_dir} + PRIVATE ${test_dir}/core ${test_dir}/cpp/ +) + +target_link_libraries(${test_cpp_exe} pgfe) + +list(APPEND cmake_test_modules "base" "blowfish" "hash" "hmac" "otp" "shake" "util") + +include(${test_dir}/${cmake_module_dir}/test_meta.cmake) + +foreach(mod IN LISTS cmake_test_modules) + include(${test_dir}/${cmake_module_dir}/${mod}_tests.cmake) +endforeach() \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt deleted file mode 100644 index b1165f8..0000000 --- a/tests/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -cmake_minimum_required(VERSION 3.26.0) - -include(CTest) -enable_testing() - -include(FetchContent) - -# Fetch GoogleTest -FetchContent_Declare( - googletest - URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip -) -# For Windows: Prevent overriding the parent project's compiler/linker settings -set(gtest_force_shared_crt ON CACHE BOOL "" FORCE) - -# Apply GoogleTest -FetchContent_MakeAvailable(googletest) \ No newline at end of file diff --git a/tests/baseencodetest.h b/tests/c/baseencodetest.h similarity index 91% rename from tests/baseencodetest.h rename to tests/c/baseencodetest.h index 03c63f1..c01cbf8 100644 --- a/tests/baseencodetest.h +++ b/tests/c/baseencodetest.h @@ -9,7 +9,9 @@ #include -#include "../include/libpgfe/base-encoding.h" +#include "libpgfe/base_encoding/base16.h" +#include "libpgfe/base_encoding/base32.h" +#include "libpgfe/base_encoding/base64.h" void base16_encode_test(ARGS) { char cs_out[700]; diff --git a/tests/blowfish_test.h b/tests/c/blowfish_test.h similarity index 94% rename from tests/blowfish_test.h rename to tests/c/blowfish_test.h index f9ad968..7a74c66 100644 --- a/tests/blowfish_test.h +++ b/tests/c/blowfish_test.h @@ -7,8 +7,8 @@ #include "test.h" -#include "../include/libpgfe/blowfish.h" -#include "../include/libpgfe/utils.h" +#include "libpgfe/fishes/blowfish.h" +#include "libpgfe/utils.h" void blowfish_encrypt_unit_test(ARGS) { struct pgfe_blowfish_ctx ctx; diff --git a/tests/hmactest.h b/tests/c/hmactest.h similarity index 93% rename from tests/hmactest.h rename to tests/c/hmactest.h index 718b6f0..58ad4d8 100644 --- a/tests/hmactest.h +++ b/tests/c/hmactest.h @@ -7,9 +7,9 @@ #include "test.h" -#include "../include/libpgfe/hmac/hmac.h" -#include "../include/libpgfe/hashes/md5.h" -#include "../include/libpgfe/utils.h" +#include "libpgfe/hmac/hmac.h" +#include "libpgfe/hashes/md5.h" +#include "libpgfe/utils.h" enum pgfe_algorithm_choice get_alg_choice(char option[]) { enum pgfe_algorithm_choice c; diff --git a/tests/mdtest.h b/tests/c/mdtest.h similarity index 77% rename from tests/mdtest.h rename to tests/c/mdtest.h index 602663c..d71313c 100644 --- a/tests/mdtest.h +++ b/tests/c/mdtest.h @@ -7,8 +7,8 @@ #include "test.h" -#include "../include/libpgfe/hashes/md5.h" -#include "../include/libpgfe/utils.h" +#include "libpgfe/hashes/md5.h" +#include "libpgfe/utils.h" void md5test(ARGS) { pgfe_encode_t output[PGFE_MD5_DIGEST_SIZE]; diff --git a/tests/otptest.h b/tests/c/otptest.h similarity index 88% rename from tests/otptest.h rename to tests/c/otptest.h index 36e6b35..725bf32 100644 --- a/tests/otptest.h +++ b/tests/c/otptest.h @@ -7,9 +7,9 @@ #include "test.h" -#include "../include/libpgfe/hotp.h" -#include "../include/libpgfe/hashes/sha2.h" -#include "../include/libpgfe/utils.h" +#include "libpgfe/hashes/sha2.h" +#include "libpgfe/otp/hotp.h" +#include "libpgfe/utils.h" void hotp_hex(ARGS) { pgfe_encode_t key[100]; diff --git a/tests/shake_test.h b/tests/c/shake_test.h similarity index 82% rename from tests/shake_test.h rename to tests/c/shake_test.h index 896b52b..b5692af 100644 --- a/tests/shake_test.h +++ b/tests/c/shake_test.h @@ -7,11 +7,13 @@ #include "test.h" +#define TEST_FILE1_PATH "../tests/test.txt" + #include #include -#include "../include/libpgfe/hashes/sha3.h" -#include "../include/libpgfe/utils.h" +#include "libpgfe/hashes/sha3.h" +#include "libpgfe/utils.h" void shake_test(ARGS) { size_t bitsize; @@ -22,9 +24,9 @@ void shake_test(ARGS) { sscanf(argv[3], "%u", &hash_type); sscanf(argv[4], "%lu", &bitsize); - size_t byte_size = to_byte(bitsize); + size_t byte_size = pgfe_to_byte(bitsize); - pgfe_encode_t out[byte_size + bit_rem(bitsize)]; + pgfe_encode_t out[byte_size + pgfe_bit_rem(bitsize)]; void (*func)(const pgfe_encode_t data_str[], pgfe_encode_t output[], size_t out_bitlength); alg[3] = 0; @@ -70,13 +72,13 @@ void shake_test_file(ARGS) { sscanf(argv[3], "%u", &hash_type); sscanf(argv[4], "%lu", &bitsize); - size_t byte_size = to_byte(bitsize); + size_t byte_size = pgfe_to_byte(bitsize); - pgfe_encode_t out[byte_size + bit_rem(bitsize)]; - void (*func)(FILE * fp, pgfe_encode_t output[], size_t out_bitlength); + pgfe_encode_t out[byte_size + pgfe_bit_rem(bitsize)]; + void (*func)(FILE *fp, pgfe_encode_t output[], size_t out_bitlength); func = NULL; - FILE *fp = fopen("../test/test.txt", "r"); + FILE *fp = fopen(TEST_FILE1_PATH, "r"); alg[3] = 0; if (!strcasecmp(alg, "raw")) { diff --git a/tests/shatest.h b/tests/c/shatest.h similarity index 88% rename from tests/shatest.h rename to tests/c/shatest.h index 1a2cb32..7e68e05 100644 --- a/tests/shatest.h +++ b/tests/c/shatest.h @@ -7,10 +7,10 @@ #include "test.h" -#include "../include/libpgfe/hashes/sha1.h" -#include "../include/libpgfe/hashes/sha2.h" -#include "../include/libpgfe/hashes/sha3.h" -#include "../include/libpgfe/utils.h" +#define TEST_FILE1_PATH "../tests/test.txt" + +#include "libpgfe/hashes.h" +#include "libpgfe/utils.h" void sha1_test(ARGS) { pgfe_encode_t output[PGFE_SHA1_DIGEST_SIZE]; @@ -22,7 +22,7 @@ void sha1_test(ARGS) { void sha1_file_test(ARGS) { pgfe_encode_t output[PGFE_SHA1_DIGEST_SIZE]; - FILE *fp = fopen("../test/test.txt", "r"); + FILE *fp = fopen(TEST_FILE1_PATH, "r"); pgfe_sha1_encode_f(fp, output); fclose(fp); @@ -46,7 +46,7 @@ void sha256_test(ARGS) { void sha256_file_test(ARGS) { pgfe_encode_t output[PGFE_SHA256_DIGEST_SIZE]; - FILE *fp = fopen("../test/test.txt", "r"); + FILE *fp = fopen(TEST_FILE1_PATH, "r"); pgfe_sha256_encode_f(fp, output); fclose(fp); @@ -70,7 +70,7 @@ void sha512_test(ARGS) { void sha512_file_test(ARGS) { pgfe_encode_t output[PGFE_SHA512_DIGEST_SIZE]; - FILE *fp = fopen("../test/test.txt", "r"); + FILE *fp = fopen(TEST_FILE1_PATH, "r"); pgfe_sha512_encode_f(fp, output); fclose(fp); @@ -101,7 +101,7 @@ void sha3_224_test(ARGS) { void sha3_224_file_test(ARGS) { pgfe_encode_t output[PGFE_SHA3_224_DIGEST_SIZE]; - FILE *fp = fopen("../test/test.txt", "r"); + FILE *fp = fopen(TEST_FILE1_PATH, "r"); pgfe_sha3_224_encode_f(fp, output); fclose(fp); @@ -118,7 +118,7 @@ void sha3_256_test(ARGS) { void sha3_256_file_test(ARGS) { pgfe_encode_t output[PGFE_SHA3_256_DIGEST_SIZE]; - FILE *fp = fopen("../test/test.txt", "r"); + FILE *fp = fopen(TEST_FILE1_PATH, "r"); pgfe_sha3_256_encode_f(fp, output); fclose(fp); @@ -135,7 +135,7 @@ void sha3_384_test(ARGS) { void sha3_384_file_test(ARGS) { pgfe_encode_t output[PGFE_SHA3_384_DIGEST_SIZE]; - FILE *fp = fopen("../test/test.txt", "r"); + FILE *fp = fopen(TEST_FILE1_PATH, "r"); pgfe_sha3_384_encode_f(fp, output); fclose(fp); @@ -152,7 +152,7 @@ void sha3_512_test(ARGS) { void sha3_512_file_test(ARGS) { pgfe_encode_t output[PGFE_SHA3_512_DIGEST_SIZE]; - FILE *fp = fopen("../test/test.txt", "r"); + FILE *fp = fopen(TEST_FILE1_PATH, "r"); pgfe_sha3_512_encode_f(fp, output); fclose(fp); diff --git a/tests/test.c b/tests/c/test.c similarity index 100% rename from tests/test.c rename to tests/c/test.c diff --git a/tests/utilstest.h b/tests/c/utilstest.h similarity index 93% rename from tests/utilstest.h rename to tests/c/utilstest.h index 0be5c70..717e25c 100644 --- a/tests/utilstest.h +++ b/tests/c/utilstest.h @@ -7,7 +7,7 @@ #include "test.h" -#include "../include/libpgfe/utils.h" +#include "libpgfe/utils.h" #include void string2hash(ARGS) { diff --git a/tests/cmake/base_tests.cmake b/tests/cmake/base_tests.cmake index 025c20a..5755fd8 100644 --- a/tests/cmake/base_tests.cmake +++ b/tests/cmake/base_tests.cmake @@ -22,25 +22,25 @@ foreach(alg IN LISTS Base_algorithms) add_test( NAME ${test_name1} - COMMAND pgfetest "${alg}-encode" ${test_item} + COMMAND ${test_c_exe} "${alg}-encode" ${test_item} ) set_property(TEST ${test_name1} PROPERTY PASS_REGULAR_EXPRESSION ${cipher}) add_test( NAME ${test_name2} - COMMAND pgfetest "${alg}-decode" ${cipher} + COMMAND ${test_c_exe} "${alg}-decode" ${cipher} ) set_property(TEST ${test_name2} PROPERTY PASS_REGULAR_EXPRESSION ${test_item}) add_test( NAME ${test_name1_cpp} - COMMAND pgfetestcpp "${alg}_encode" ${test_item} + COMMAND ${test_cpp_exe} "${alg}_encode" ${test_item} ) set_property(TEST ${test_name1_cpp} PROPERTY PASS_REGULAR_EXPRESSION ${cipher}) add_test( NAME ${test_name2_cpp} - COMMAND pgfetestcpp "${alg}_decode" ${cipher} + COMMAND ${test_cpp_exe} "${alg}_decode" ${cipher} ) set_property(TEST ${test_name2_cpp} PROPERTY PASS_REGULAR_EXPRESSION ${test_item}) @@ -51,5 +51,5 @@ endforeach() add_test( NAME base64_multithread - COMMAND pgfetestcpp base_multithread1 + COMMAND ${test_cpp_exe} base_multithread1 ) diff --git a/tests/cmake/blowfish_tests.cmake b/tests/cmake/blowfish_tests.cmake index fd3d68a..a6a5c37 100644 --- a/tests/cmake/blowfish_tests.cmake +++ b/tests/cmake/blowfish_tests.cmake @@ -13,13 +13,13 @@ foreach(item IN ZIP_LISTS Blowfish_keys Blowfish_plains Blowfish_crypts) add_test( NAME ${test_name_enc} - COMMAND pgfetest blowfish_enc_unit ${item_0} ${item_1} + COMMAND ${test_c_exe} blowfish_enc_unit ${item_0} ${item_1} ) set_property(TEST ${test_name_enc} PROPERTY PASS_REGULAR_EXPRESSION ${item_2}) add_test( NAME ${test_name_dec} - COMMAND pgfetest blowfish_dec_unit ${item_0} ${item_2} + COMMAND ${test_c_exe} blowfish_dec_unit ${item_0} ${item_2} ) set_property(TEST ${test_name_dec} PROPERTY PASS_REGULAR_EXPRESSION ${item_1}) @@ -35,25 +35,25 @@ foreach(item IN ZIP_LISTS Blowfish_keys_str Blowfish_plains_str Blowfish_crypts_ add_test( NAME ${test_name_enc} - COMMAND pgfetest blowfish_enc_str ${item_0} ${item_1} + COMMAND ${test_c_exe} blowfish_enc_str ${item_0} ${item_1} ) set_property(TEST ${test_name_enc} PROPERTY PASS_REGULAR_EXPRESSION ${item_2}) add_test( NAME ${test_name_dec} - COMMAND pgfetest blowfish_dec_str ${item_0} ${item_2} + COMMAND ${test_c_exe} blowfish_dec_str ${item_0} ${item_2} ) set_property(TEST ${test_name_dec} PROPERTY PASS_REGULAR_EXPRESSION ${item_1}) add_test( NAME ${test_name_enc_cpp} - COMMAND pgfetestcpp blowfish_encrypt ${item_0} ${item_1} + COMMAND ${test_cpp_exe} blowfish_encrypt ${item_0} ${item_1} ) set_property(TEST ${test_name_enc_cpp} PROPERTY PASS_REGULAR_EXPRESSION ${item_2}) add_test( NAME ${test_name_dec_cpp} - COMMAND pgfetestcpp blowfish_decrypt ${item_0} ${item_2} + COMMAND ${test_cpp_exe} blowfish_decrypt ${item_0} ${item_2} ) set_property(TEST ${test_name_dec_cpp} PROPERTY PASS_REGULAR_EXPRESSION ${item_1}) diff --git a/tests/cmake/hash_tests.cmake b/tests/cmake/hash_tests.cmake index 9b0811f..b093adf 100644 --- a/tests/cmake/hash_tests.cmake +++ b/tests/cmake/hash_tests.cmake @@ -47,13 +47,13 @@ foreach(item IN ZIP_LISTS AlgList HashResults_string1) add_test( NAME ${test_name_c} - COMMAND pgfetest ${item_0} ${test_text} + COMMAND ${test_c_exe} ${item_0} ${test_text} ) set_property(TEST ${test_name_c} PROPERTY PASS_REGULAR_EXPRESSION ${item_1}) add_test( NAME ${test_name_cpp} - COMMAND pgfetestcpp hash_encoder ${item_0} ${test_text} + COMMAND ${test_cpp_exe} hash_encoder ${item_0} ${test_text} ) set_property(TEST ${test_name_cpp} PROPERTY PASS_REGULAR_EXPRESSION ${item_1}) endforeach() @@ -63,7 +63,7 @@ foreach(item IN ZIP_LISTS AlgList_file HashResults_file1) add_test( NAME ${test_name_c} - COMMAND pgfetest "${item_0}_file" test/test.txt + COMMAND ${test_c_exe} "${item_0}_file" test/test.txt ) set_property(TEST ${test_name_c} PROPERTY PASS_REGULAR_EXPRESSION ${item_1}) endforeach() \ No newline at end of file diff --git a/tests/cmake/hmac_tests.cmake b/tests/cmake/hmac_tests.cmake index c6a212c..4c907e9 100644 --- a/tests/cmake/hmac_tests.cmake +++ b/tests/cmake/hmac_tests.cmake @@ -30,13 +30,13 @@ foreach(alg IN LISTS HMAC_alglist) add_test( NAME ${test_name_c} - COMMAND pgfetest hmac ${alg} ${tup_0} ${tup_1} + COMMAND ${test_c_exe} hmac ${alg} ${tup_0} ${tup_1} ) set_property(TEST ${test_name_c} PROPERTY PASS_REGULAR_EXPRESSION ${result}) add_test( NAME ${test_name_cpp} - COMMAND pgfetestcpp hmac_encoder ${alg} ${tup_0} ${tup_1} + COMMAND ${test_cpp_exe} hmac_encoder ${alg} ${tup_0} ${tup_1} ) set_property(TEST ${test_name_cpp} PROPERTY PASS_REGULAR_EXPRESSION ${result}) diff --git a/tests/cmake/otp_tests.cmake b/tests/cmake/otp_tests.cmake index a82580a..373160e 100644 --- a/tests/cmake/otp_tests.cmake +++ b/tests/cmake/otp_tests.cmake @@ -14,13 +14,13 @@ foreach(item IN ZIP_LISTS HOTP_alglist HOTP_inputs HOTP_counters HOTP_results) add_test( NAME ${test_name_c} - COMMAND pgfetest "hotp_hex_${item_0}" ${item_1} ${item_2} + COMMAND ${test_c_exe} "hotp_hex_${item_0}" ${item_1} ${item_2} ) set_property(TEST ${test_name_c} PROPERTY PASS_REGULAR_EXPRESSION ${item_3}) add_test( NAME ${test_name_cpp} - COMMAND pgfetestcpp hotp_hex ${item_0} ${item_1} ${item_2} + COMMAND ${test_cpp_exe} hotp_hex ${item_0} ${item_1} ${item_2} ) set_property(TEST ${test_name_cpp} PROPERTY PASS_REGULAR_EXPRESSION ${item_3}) endforeach() diff --git a/tests/cmake/shake_tests.cmake b/tests/cmake/shake_tests.cmake index 6dc8540..5285b2b 100644 --- a/tests/cmake/shake_tests.cmake +++ b/tests/cmake/shake_tests.cmake @@ -39,7 +39,7 @@ while(${i} LESS ${SHAKE_lengthSize_len}) add_test( NAME ${test_name} - COMMAND pgfetest shake-test ${alg} ${alg_tup_0} ${alg_tup_1} ${text} + COMMAND ${test_c_exe} shake-test ${alg} ${alg_tup_0} ${alg_tup_1} ${text} ) list(GET SHAKE_results ${k} SHAKE_result) @@ -49,7 +49,7 @@ while(${i} LESS ${SHAKE_lengthSize_len}) add_test( NAME ${test_name_cpp} - COMMAND pgfetestcpp hash_encoder "${alg}${alg_tup_0}" ${alg_tup_1} ${text} + COMMAND ${test_cpp_exe} hash_encoder "${alg}${alg_tup_0}" ${alg_tup_1} ${text} ) set_property(TEST ${test_name_cpp} PROPERTY PASS_REGULAR_EXPRESSION ${SHAKE_result}) @@ -62,7 +62,7 @@ while(${i} LESS ${SHAKE_lengthSize_len}) add_test( NAME ${test_name} - COMMAND pgfetest shake-test_file ${alg} ${alg_tup_0} ${alg_tup_1} + COMMAND ${test_c_exe} shake-test_file ${alg} ${alg_tup_0} ${alg_tup_1} ) list(GET SHAKE_results_file ${kf} SHAKE_result_file) diff --git a/tests/cmake/test_meta.cmake b/tests/cmake/test_meta.cmake index cb2bad2..e2c527a 100644 --- a/tests/cmake/test_meta.cmake +++ b/tests/cmake/test_meta.cmake @@ -2,4 +2,4 @@ list(APPEND AlgList md5 sha1 sha224 sha256 sha384 sha512 sha512_224 sha512_256 s set(test_text "hello") set(test_text2 "how are you?") -list(APPEND test_texts ${test_text} ${test_text2}) \ No newline at end of file +list(APPEND test_texts ${test_text} ${test_text2}) diff --git a/tests/cmake/util_tests.cmake b/tests/cmake/util_tests.cmake index 32ffce5..6fa7d0e 100644 --- a/tests/cmake/util_tests.cmake +++ b/tests/cmake/util_tests.cmake @@ -3,40 +3,40 @@ set(test_noisy_hash "0Xaaf4c61ddc+`ZZHHgc5[e8a2dab;:edeKKKKKK0f3b48??//2cdw9aea9 add_test( NAME string_to_hash_normal - COMMAND pgfetest string2hash "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d" + COMMAND ${test_c_exe} string2hash "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d" ) add_test( NAME string_to_hash_odd_length - COMMAND pgfetest string2hash "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434" + COMMAND ${test_c_exe} string2hash "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434" ) add_test( NAME string_to_hash_with_prefix - COMMAND pgfetest string2hash "0xaaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d" + COMMAND ${test_c_exe} string2hash "0xaaf4c61ddcc5e8a2dabede0f3b482cd9aea9434d" ) add_test( NAME string_to_hash_prefix_odd - COMMAND pgfetest string2hash "0Xaaf4c61ddcc5e8a2dabede0f3b482cd9aea9434" + COMMAND ${test_c_exe} string2hash "0Xaaf4c61ddcc5e8a2dabede0f3b482cd9aea9434" ) add_test( NAME string_to_hash_with_suffix - COMMAND pgfetest string2hash "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434dH" + COMMAND ${test_c_exe} string2hash "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434dH" ) add_test( NAME string_to_hash_suffix_odd - COMMAND pgfetest string2hash "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434h" + COMMAND ${test_c_exe} string2hash "aaf4c61ddcc5e8a2dabede0f3b482cd9aea9434h" ) add_test( NAME string_to_hash_both_odd - COMMAND pgfetest string2hash "0Xaaf4c61ddcc5e8a2dabede0f3b482cd9aea9434h" + COMMAND ${test_c_exe} string2hash "0Xaaf4c61ddcc5e8a2dabede0f3b482cd9aea9434h" ) add_test( NAME hash_string_clean - COMMAND pgfetest hash_string_clean ${test_noisy_hash} + COMMAND ${test_c_exe} hash_string_clean ${test_noisy_hash} ) add_test( NAME hash_string_clean_inplace - COMMAND pgfetest hash_string_clean_inplace ${test_noisy_hash} + COMMAND ${test_c_exe} hash_string_clean_inplace ${test_noisy_hash} ) set_property(TEST string_to_hash_normal PROPERTY PASS_REGULAR_EXPRESSION ${test_text_sha1}) diff --git a/tests/test.h b/tests/core/test.h similarity index 100% rename from tests/test.h rename to tests/core/test.h diff --git a/tests/base_multithread.hpp b/tests/cpp/base_multithread.hpp similarity index 95% rename from tests/base_multithread.hpp rename to tests/cpp/base_multithread.hpp index 2f2f46b..ca173d7 100644 --- a/tests/base_multithread.hpp +++ b/tests/cpp/base_multithread.hpp @@ -4,7 +4,6 @@ Copyright (c) 2022-2023 Charles Dong */ - #include "test.h" #include @@ -12,8 +11,8 @@ #include #include -#include "../include/libpgfe/base-encoding.h" -#include "../include/libpgfe/base64.hpp" +#include "libpgfe/base_encoding/base64.h" +#include "libpgfe/base_encoding/base64.hpp" using namespace libpgfe; diff --git a/tests/base_test.hpp b/tests/cpp/base_test.hpp similarity index 91% rename from tests/base_test.hpp rename to tests/cpp/base_test.hpp index 878c993..5c8281d 100644 --- a/tests/base_test.hpp +++ b/tests/cpp/base_test.hpp @@ -7,9 +7,9 @@ #include "test.h" -#include "../include/libpgfe/base16.hpp" -#include "../include/libpgfe/hashes/base32.hpp" -#include "../include/libpgfe/base64.hpp" +#include "libpgfe/base_encoding/base16.hpp" +#include "libpgfe/base_encoding/base32.hpp" +#include "libpgfe/base_encoding/base64.hpp" using namespace std; using namespace libpgfe; diff --git a/tests/blowfish_test.hpp b/tests/cpp/blowfish_test.hpp similarity index 88% rename from tests/blowfish_test.hpp rename to tests/cpp/blowfish_test.hpp index a0d2d98..b89c029 100644 --- a/tests/blowfish_test.hpp +++ b/tests/cpp/blowfish_test.hpp @@ -11,8 +11,8 @@ #include #include -#include "../include/libpgfe/blowfish.hpp" -#include "../include/libpgfe/utils.hpp" +#include "libpgfe/fishes/blowfish.hpp" +#include "libpgfe/utils.hpp" void blowfish_encrypt_test(ARGS) { using namespace libpgfe; diff --git a/tests/hash_encoder_test.hpp b/tests/cpp/hash_encoder_test.hpp similarity index 80% rename from tests/hash_encoder_test.hpp rename to tests/cpp/hash_encoder_test.hpp index 38a2358..a214703 100644 --- a/tests/hash_encoder_test.hpp +++ b/tests/cpp/hash_encoder_test.hpp @@ -10,9 +10,9 @@ #include #include -#include "../include/libpgfe/hash_encoder.hpp" -#include "../include/libpgfe/utils.h" -#include "../include/libpgfe/utils.hpp" +#include "libpgfe/hashes/hash_encoder.hpp" +#include "libpgfe/utils.h" +#include "libpgfe/utils.hpp" void hash_encoder_test(ARGS) { using namespace std; diff --git a/tests/hmactest.hpp b/tests/cpp/hmactest.hpp similarity index 84% rename from tests/hmactest.hpp rename to tests/cpp/hmactest.hpp index ed532bb..e2d8294 100644 --- a/tests/hmactest.hpp +++ b/tests/cpp/hmactest.hpp @@ -9,9 +9,9 @@ #include -#include "../include/libpgfe/hmac_encoder.hpp" -#include "../include/libpgfe/utils.h" -#include "../include/libpgfe/utils.hpp" +#include "libpgfe/hmac/hmac_encoder.hpp" +#include "libpgfe/utils.h" +#include "libpgfe/utils.hpp" void hmac_encoder_test(ARGS) { using namespace libpgfe; diff --git a/tests/otptest.hpp b/tests/cpp/otptest.hpp similarity index 84% rename from tests/otptest.hpp rename to tests/cpp/otptest.hpp index ff06731..ab245a0 100644 --- a/tests/otptest.hpp +++ b/tests/cpp/otptest.hpp @@ -10,8 +10,8 @@ #include #include -#include "../include/libpgfe/otp/hotp.hpp" -#include "../include/libpgfe/utils.hpp" +#include "libpgfe/otp/hotp.hpp" +#include "libpgfe/utils.hpp" void hotp_hex_test(ARGS) { HOTP hotp{_algstr(argv[2])}; diff --git a/tests/test.cpp b/tests/cpp/test.cpp similarity index 100% rename from tests/test.cpp rename to tests/cpp/test.cpp