From 6e0629d0373b56ad151d80fe0e321fb8c08fbbde Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sat, 27 May 2023 23:18:09 +0800 Subject: [PATCH] Structure refactoring 1 --- CMakeLists.txt | 6 ++- include/backend/keccak-backend.h | 52 ------------------- .../abstract_base_encoding.hpp | 4 +- .../abstract_encoder.hpp | 6 +-- .../abstract_hash_encoder.hpp | 10 ++-- .../{backend_cpp => libpgfe}/abstract_otp.hpp | 8 +-- .../abstract_symmetric_crypter.hpp | 2 +- include/{ => libpgfe}/algorithm-choice.h | 0 .../{ => libpgfe}/algorithm_selectable.hpp | 2 +- include/{ => libpgfe}/base-encoding.h | 2 +- include/{ => libpgfe}/base16.hpp | 2 +- include/{ => libpgfe}/base32.hpp | 2 +- include/{ => libpgfe}/base64.hpp | 2 +- include/{ => libpgfe}/blowfish.h | 2 +- include/{ => libpgfe}/blowfish.hpp | 4 +- include/{ => libpgfe}/exceptions.hpp | 0 include/{ => libpgfe}/generic.h | 2 +- include/{ => libpgfe}/generic.hpp | 12 ++--- include/libpgfe/hash.h | 4 ++ include/{ => libpgfe}/hash_encoder.hpp | 2 +- include/{ => libpgfe}/hmac.h | 11 ++-- include/{ => libpgfe}/hmac_encoder.hpp | 8 +-- include/{ => libpgfe}/hotp.h | 4 +- include/{ => libpgfe}/hotp.hpp | 4 +- include/{ => libpgfe}/md5.h | 3 +- include/libpgfe/otp_types.h | 17 ++++++ include/{ => libpgfe}/sequential_data.hpp | 4 +- include/{ => libpgfe}/sha1.h | 2 +- include/{ => libpgfe}/sha2.h | 2 +- include/{ => libpgfe}/sha3.h | 23 +++++++- include/{ => libpgfe}/totp.h | 3 +- include/{ => libpgfe}/totp.hpp | 4 +- include/{ => libpgfe}/utils.h | 10 +--- include/{ => libpgfe}/utils.hpp | 4 +- include/{ => libpgfe}/version.h | 0 src/c/base_encoding/base-encoding-internal.c | 4 +- .../c/base_encoding}/base-encoding-internal.h | 2 +- src/c/base_encoding/base16.c | 4 +- src/c/base_encoding/base32.c | 6 +-- src/c/base_encoding/base64.c | 4 +- src/c/blowfish/blowfish.c | 2 +- src/c/generic-internal.c | 2 +- {include/backend => src/c}/generic-internal.h | 2 +- src/c/generic.c | 2 +- src/c/hash/keccak-backend.c | 2 +- src/c/hash/keccak-backend.h | 35 +++++++++++++ src/c/hash/md5-backend.c | 2 +- {include/backend => src/c/hash}/md5-backend.h | 2 +- src/c/hash/md5.c | 6 +-- src/c/hash/sha-internal.c | 2 +- .../backend => src/c/hash}/sha-internal.h | 2 +- src/c/hash/sha1.c | 8 +-- src/c/hash/sha2-backend.c | 6 +-- .../backend => src/c/hash}/sha2-backend.h | 4 +- src/c/hash/sha224.c | 6 +-- src/c/hash/sha256.c | 6 +-- src/c/hash/sha3-224.c | 4 +- src/c/hash/sha3-256.c | 4 +- src/c/hash/sha3-384.c | 4 +- src/c/hash/sha3-512.c | 4 +- src/c/hash/sha384.c | 6 +-- src/c/hash/sha512.c | 6 +-- src/c/hash/shake.c | 4 +- {include/backend => src/c/hash}/templates.h | 0 src/c/hmac/hmac.c | 4 +- src/c/otp/hotp.c | 8 +-- src/c/otp/otp-generic.c | 17 +++++- {include/backend => src/c/otp}/otp-generic.h | 17 +++--- src/c/otp/totp.c | 9 ++-- src/c/utils.c | 19 +------ src/cpp/algorithm_selectable.cpp | 2 +- .../base_encoding/abstract_base_encoding.cpp | 2 +- src/cpp/base_encoding/base16.cpp | 4 +- src/cpp/base_encoding/base32.cpp | 4 +- src/cpp/base_encoding/base64.cpp | 4 +- src/cpp/blowfish/blowfish.cpp | 2 +- src/cpp/generic.cpp | 4 +- src/cpp/hash/hash_encoder.cpp | 10 ++-- src/cpp/hmac/hmac_encoder.cpp | 4 +- src/cpp/misc/abstract_symmetric_crypter.cpp | 2 +- src/cpp/otp/abstract_otp.cpp | 4 +- src/cpp/otp/hotp.cpp | 8 +-- src/cpp/otp/totp.cpp | 5 +- src/cpp/sequential_data.cpp | 2 +- src/cpp/utils.cpp | 4 +- test/base_multithread.hpp | 4 +- test/base_test.hpp | 6 +-- test/baseencodetest.h | 2 +- test/blowfish_test.h | 4 +- test/blowfish_test.hpp | 4 +- test/hash_encoder_test.hpp | 6 +-- test/hmactest.h | 6 +-- test/hmactest.hpp | 6 +-- test/mdtest.h | 4 +- test/otptest.h | 6 +-- test/otptest.hpp | 4 +- test/shake_test.h | 4 +- test/shatest.h | 8 +-- test/utilstest.h | 2 +- 99 files changed, 294 insertions(+), 271 deletions(-) delete mode 100644 include/backend/keccak-backend.h rename include/{backend_cpp => libpgfe}/abstract_base_encoding.hpp (96%) rename include/{backend_cpp => libpgfe}/abstract_encoder.hpp (90%) rename include/{backend_cpp => libpgfe}/abstract_hash_encoder.hpp (76%) rename include/{backend_cpp => libpgfe}/abstract_otp.hpp (84%) rename include/{backend_cpp => libpgfe}/abstract_symmetric_crypter.hpp (95%) rename include/{ => libpgfe}/algorithm-choice.h (100%) rename include/{ => libpgfe}/algorithm_selectable.hpp (93%) rename include/{ => libpgfe}/base-encoding.h (98%) rename include/{ => libpgfe}/base16.hpp (91%) rename include/{ => libpgfe}/base32.hpp (92%) rename include/{ => libpgfe}/base64.hpp (92%) rename include/{ => libpgfe}/blowfish.h (96%) rename include/{ => libpgfe}/blowfish.hpp (92%) rename include/{ => libpgfe}/exceptions.hpp (100%) rename include/{ => libpgfe}/generic.h (96%) rename include/{ => libpgfe}/generic.hpp (97%) create mode 100644 include/libpgfe/hash.h rename include/{ => libpgfe}/hash_encoder.hpp (94%) rename include/{ => libpgfe}/hmac.h (98%) rename include/{ => libpgfe}/hmac_encoder.hpp (92%) rename include/{ => libpgfe}/hotp.h (93%) rename include/{ => libpgfe}/hotp.hpp (95%) rename include/{ => libpgfe}/md5.h (94%) create mode 100644 include/libpgfe/otp_types.h rename include/{ => libpgfe}/sequential_data.hpp (95%) rename include/{ => libpgfe}/sha1.h (96%) rename include/{ => libpgfe}/sha2.h (99%) rename include/{ => libpgfe}/sha3.h (86%) rename include/{ => libpgfe}/totp.h (96%) rename include/{ => libpgfe}/totp.hpp (95%) rename include/{ => libpgfe}/utils.h (81%) rename include/{ => libpgfe}/utils.hpp (90%) rename include/{ => libpgfe}/version.h (100%) rename {include/backend => src/c/base_encoding}/base-encoding-internal.h (98%) rename {include/backend => src/c}/generic-internal.h (99%) create mode 100644 src/c/hash/keccak-backend.h rename {include/backend => src/c/hash}/md5-backend.h (93%) rename {include/backend => src/c/hash}/sha-internal.h (93%) rename {include/backend => src/c/hash}/sha2-backend.h (97%) rename {include/backend => src/c/hash}/templates.h (100%) rename {include/backend => src/c/otp}/otp-generic.h (67%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 199458b..f0f0360 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -59,10 +59,14 @@ 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 PRIVATE +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) diff --git a/include/backend/keccak-backend.h b/include/backend/keccak-backend.h deleted file mode 100644 index c294ed2..0000000 --- a/include/backend/keccak-backend.h +++ /dev/null @@ -1,52 +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 "generic-internal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define __PGFE_KECCAK_b 1600 -#define __PGFE_KECCAK_MAX_RATE 1536 - -typedef uint64_t pgfe_keccak_lane_t; - -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 -}; - -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/include/backend_cpp/abstract_base_encoding.hpp b/include/libpgfe/abstract_base_encoding.hpp similarity index 96% rename from include/backend_cpp/abstract_base_encoding.hpp rename to include/libpgfe/abstract_base_encoding.hpp index 81af2d1..99d6a4b 100644 --- a/include/backend_cpp/abstract_base_encoding.hpp +++ b/include/libpgfe/abstract_base_encoding.hpp @@ -15,8 +15,8 @@ #include #include -#include "../generic.h" -#include "../sequential_data.hpp" +#include "libpgfe/generic.h" +#include "libpgfe/sequential_data.hpp" namespace libpgfe { diff --git a/include/backend_cpp/abstract_encoder.hpp b/include/libpgfe/abstract_encoder.hpp similarity index 90% rename from include/backend_cpp/abstract_encoder.hpp rename to include/libpgfe/abstract_encoder.hpp index 3f16248..640be80 100644 --- a/include/backend_cpp/abstract_encoder.hpp +++ b/include/libpgfe/abstract_encoder.hpp @@ -14,9 +14,9 @@ #include #include -#include "../generic.h" -#include "../sequential_data.hpp" -#include "../utils.hpp" +#include "libpgfe/generic.h" +#include "libpgfe/sequential_data.hpp" +#include "libpgfe/utils.hpp" namespace libpgfe { diff --git a/include/backend_cpp/abstract_hash_encoder.hpp b/include/libpgfe/abstract_hash_encoder.hpp similarity index 76% rename from include/backend_cpp/abstract_hash_encoder.hpp rename to include/libpgfe/abstract_hash_encoder.hpp index 348d9c9..060abaa 100644 --- a/include/backend_cpp/abstract_hash_encoder.hpp +++ b/include/libpgfe/abstract_hash_encoder.hpp @@ -13,12 +13,12 @@ #include -#include "abstract_encoder.hpp" +#include "libpgfe/abstract_encoder.hpp" -#include "../algorithm-choice.h" -#include "../algorithm_selectable.hpp" -#include "../generic.h" -#include "../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/backend_cpp/abstract_otp.hpp b/include/libpgfe/abstract_otp.hpp similarity index 84% rename from include/backend_cpp/abstract_otp.hpp rename to include/libpgfe/abstract_otp.hpp index 94023aa..38ba3a8 100644 --- a/include/backend_cpp/abstract_otp.hpp +++ b/include/libpgfe/abstract_otp.hpp @@ -13,10 +13,10 @@ #include -#include "../algorithm_selectable.hpp" -#include "../backend/otp-generic.h" -#include "../generic.h" -#include "../sequential_data.hpp" +#include "libpgfe/algorithm_selectable.hpp" +#include "libpgfe/generic.h" +#include "libpgfe/otp_types.h" +#include "libpgfe/sequential_data.hpp" namespace libpgfe { diff --git a/include/backend_cpp/abstract_symmetric_crypter.hpp b/include/libpgfe/abstract_symmetric_crypter.hpp similarity index 95% rename from include/backend_cpp/abstract_symmetric_crypter.hpp rename to include/libpgfe/abstract_symmetric_crypter.hpp index 7f6f90b..ba9cb0e 100644 --- a/include/backend_cpp/abstract_symmetric_crypter.hpp +++ b/include/libpgfe/abstract_symmetric_crypter.hpp @@ -13,7 +13,7 @@ #include -#include "../sequential_data.hpp" +#include "libpgfe/sequential_data.hpp" namespace libpgfe { diff --git a/include/algorithm-choice.h b/include/libpgfe/algorithm-choice.h similarity index 100% rename from include/algorithm-choice.h rename to include/libpgfe/algorithm-choice.h diff --git a/include/algorithm_selectable.hpp b/include/libpgfe/algorithm_selectable.hpp similarity index 93% rename from include/algorithm_selectable.hpp rename to include/libpgfe/algorithm_selectable.hpp index 73aecaa..c1e9f0b 100644 --- a/include/algorithm_selectable.hpp +++ b/include/libpgfe/algorithm_selectable.hpp @@ -12,7 +12,7 @@ #include #include -#include "algorithm-choice.h" +#include "libpgfe/algorithm-choice.h" namespace libpgfe { diff --git a/include/base-encoding.h b/include/libpgfe/base-encoding.h similarity index 98% rename from include/base-encoding.h rename to include/libpgfe/base-encoding.h index 19cced8..0f36db7 100644 --- a/include/base-encoding.h +++ b/include/libpgfe/base-encoding.h @@ -8,7 +8,7 @@ #ifndef LIBPGFE_BASE_ENCODING_H #define LIBPGFE_BASE_ENCODING_H -#include "generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/base16.hpp b/include/libpgfe/base16.hpp similarity index 91% rename from include/base16.hpp rename to include/libpgfe/base16.hpp index 1bc46a1..ba2ae2d 100644 --- a/include/base16.hpp +++ b/include/libpgfe/base16.hpp @@ -11,7 +11,7 @@ #error libpgfe error: C++ headers are not compatible with C source #endif -#include "backend_cpp/abstract_base_encoding.hpp" +#include "libpgfe/abstract_base_encoding.hpp" namespace libpgfe { diff --git a/include/base32.hpp b/include/libpgfe/base32.hpp similarity index 92% rename from include/base32.hpp rename to include/libpgfe/base32.hpp index 8cfcfd6..4eb7dd6 100644 --- a/include/base32.hpp +++ b/include/libpgfe/base32.hpp @@ -11,7 +11,7 @@ #error libpgfe error: C++ headers are not compatible with C source #endif -#include "backend_cpp/abstract_base_encoding.hpp" +#include "libpgfe/abstract_base_encoding.hpp" namespace libpgfe { diff --git a/include/base64.hpp b/include/libpgfe/base64.hpp similarity index 92% rename from include/base64.hpp rename to include/libpgfe/base64.hpp index 2c88a29..c87b884 100644 --- a/include/base64.hpp +++ b/include/libpgfe/base64.hpp @@ -11,7 +11,7 @@ #error libpgfe error: C++ headers are not compatible with C source #endif -#include "backend_cpp/abstract_base_encoding.hpp" +#include "libpgfe/abstract_base_encoding.hpp" namespace libpgfe { diff --git a/include/blowfish.h b/include/libpgfe/blowfish.h similarity index 96% rename from include/blowfish.h rename to include/libpgfe/blowfish.h index 04a1474..3aaf488 100644 --- a/include/blowfish.h +++ b/include/libpgfe/blowfish.h @@ -13,7 +13,7 @@ extern "C" { #endif -#include "backend/generic-internal.h" +#include "libpgfe/generic.h" #define __PGFE_BF_N 16 #define __PGFE_BF_Np2 18 diff --git a/include/blowfish.hpp b/include/libpgfe/blowfish.hpp similarity index 92% rename from include/blowfish.hpp rename to include/libpgfe/blowfish.hpp index b320467..a89410c 100644 --- a/include/blowfish.hpp +++ b/include/libpgfe/blowfish.hpp @@ -13,8 +13,8 @@ #include -#include "backend_cpp/abstract_symmetric_crypter.hpp" -#include "blowfish.h" +#include "libpgfe/abstract_symmetric_crypter.hpp" +#include "libpgfe/blowfish.h" namespace libpgfe { diff --git a/include/exceptions.hpp b/include/libpgfe/exceptions.hpp similarity index 100% rename from include/exceptions.hpp rename to include/libpgfe/exceptions.hpp diff --git a/include/generic.h b/include/libpgfe/generic.h similarity index 96% rename from include/generic.h rename to include/libpgfe/generic.h index 3b0e5b7..0c11a9b 100644 --- a/include/generic.h +++ b/include/libpgfe/generic.h @@ -11,7 +11,7 @@ #include #include -#include "algorithm-choice.h" +#include "libpgfe/algorithm-choice.h" #ifdef __cplusplus extern "C" { diff --git a/include/generic.hpp b/include/libpgfe/generic.hpp similarity index 97% rename from include/generic.hpp rename to include/libpgfe/generic.hpp index 79e3d24..b62d641 100644 --- a/include/generic.hpp +++ b/include/libpgfe/generic.hpp @@ -14,12 +14,12 @@ #include #include -#include "algorithm-choice.h" -#include "exceptions.hpp" -#include "md5.h" -#include "sha1.h" -#include "sha2.h" -#include "sha3.h" +#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) { \ diff --git a/include/libpgfe/hash.h b/include/libpgfe/hash.h new file mode 100644 index 0000000..aaa6338 --- /dev/null +++ b/include/libpgfe/hash.h @@ -0,0 +1,4 @@ +#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/hash_encoder.hpp b/include/libpgfe/hash_encoder.hpp similarity index 94% rename from include/hash_encoder.hpp rename to include/libpgfe/hash_encoder.hpp index 9a5b76c..821f886 100644 --- a/include/hash_encoder.hpp +++ b/include/libpgfe/hash_encoder.hpp @@ -13,7 +13,7 @@ #error libpgfe error: C++ headers are not compatible with C source #endif -#include "backend_cpp/abstract_hash_encoder.hpp" +#include "libpgfe/abstract_hash_encoder.hpp" #include diff --git a/include/hmac.h b/include/libpgfe/hmac.h similarity index 98% rename from include/hmac.h rename to include/libpgfe/hmac.h index e5e9f17..7de3a03 100644 --- a/include/hmac.h +++ b/include/libpgfe/hmac.h @@ -8,12 +8,11 @@ #ifndef LIBPGFE_HMAC_H #define LIBPGFE_HMAC_H -#include "backend/generic-internal.h" -#include "generic.h" -#include "md5.h" -#include "sha1.h" -#include "sha2.h" -#include "sha3.h" +#include "libpgfe/generic.h" +#include "libpgfe/md5.h" +#include "libpgfe/sha1.h" +#include "libpgfe/sha2.h" +#include "libpgfe/sha3.h" #ifdef __cplusplus extern "C" { diff --git a/include/hmac_encoder.hpp b/include/libpgfe/hmac_encoder.hpp similarity index 92% rename from include/hmac_encoder.hpp rename to include/libpgfe/hmac_encoder.hpp index f8cb60c..6915d88 100644 --- a/include/hmac_encoder.hpp +++ b/include/libpgfe/hmac_encoder.hpp @@ -14,10 +14,10 @@ #include #include -#include "backend_cpp/abstract_hash_encoder.hpp" -#include "generic.h" -#include "generic.hpp" -#include "hmac.h" +#include "libpgfe/abstract_hash_encoder.hpp" +#include "libpgfe/generic.h" +#include "libpgfe/generic.hpp" +#include "libpgfe/hmac.h" namespace libpgfe { diff --git a/include/hotp.h b/include/libpgfe/hotp.h similarity index 93% rename from include/hotp.h rename to include/libpgfe/hotp.h index 8113fd3..2a5a4e8 100644 --- a/include/hotp.h +++ b/include/libpgfe/hotp.h @@ -8,8 +8,8 @@ #ifndef LIBPGFE_HOTP_H #define LIBPGFE_HOTP_H -#include "backend/generic-internal.h" -#include "backend/otp-generic.h" +#include "libpgfe/generic.h" +#include "libpgfe/otp_types.h" #ifdef __cplusplus extern "C" { diff --git a/include/hotp.hpp b/include/libpgfe/hotp.hpp similarity index 95% rename from include/hotp.hpp rename to include/libpgfe/hotp.hpp index f2aa3f3..c31781a 100644 --- a/include/hotp.hpp +++ b/include/libpgfe/hotp.hpp @@ -13,8 +13,8 @@ #include -#include "backend_cpp/abstract_otp.hpp" -#include "base32.hpp" +#include "libpgfe/abstract_otp.hpp" +#include "libpgfe/base32.hpp" namespace libpgfe { diff --git a/include/md5.h b/include/libpgfe/md5.h similarity index 94% rename from include/md5.h rename to include/libpgfe/md5.h index 68ac42f..9b43ecc 100644 --- a/include/md5.h +++ b/include/libpgfe/md5.h @@ -10,8 +10,7 @@ #include -#include "backend/generic-internal.h" -#include "generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/libpgfe/otp_types.h b/include/libpgfe/otp_types.h new file mode 100644 index 0000000..8c9dabf --- /dev/null +++ b/include/libpgfe/otp_types.h @@ -0,0 +1,17 @@ +#ifndef LIBPGFE_OTP_TYPES_H +#define LIBPGFE_OTP_TYPES_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef uint32_t pgfe_otp_t; + +typedef uint64_t pgfe_otp_counter_t; + +typedef pgfe_encode_t pgfe_otp_secret_t; + +#ifdef __cplusplus +} +#endif +#endif \ No newline at end of file diff --git a/include/sequential_data.hpp b/include/libpgfe/sequential_data.hpp similarity index 95% rename from include/sequential_data.hpp rename to include/libpgfe/sequential_data.hpp index 5adc6a7..7eee5a1 100644 --- a/include/sequential_data.hpp +++ b/include/libpgfe/sequential_data.hpp @@ -16,8 +16,8 @@ #include #include -#include "generic.h" -#include "utils.h" +#include "libpgfe/generic.h" +#include "libpgfe/utils.h" namespace libpgfe { diff --git a/include/sha1.h b/include/libpgfe/sha1.h similarity index 96% rename from include/sha1.h rename to include/libpgfe/sha1.h index 2168956..3a4ebb9 100644 --- a/include/sha1.h +++ b/include/libpgfe/sha1.h @@ -10,7 +10,7 @@ #include -#include "backend/generic-internal.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/sha2.h b/include/libpgfe/sha2.h similarity index 99% rename from include/sha2.h rename to include/libpgfe/sha2.h index cc5a242..a184844 100644 --- a/include/sha2.h +++ b/include/libpgfe/sha2.h @@ -10,7 +10,7 @@ #include -#include "backend/generic-internal.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/include/sha3.h b/include/libpgfe/sha3.h similarity index 86% rename from include/sha3.h rename to include/libpgfe/sha3.h index 23d24c7..879a5d2 100644 --- a/include/sha3.h +++ b/include/libpgfe/sha3.h @@ -10,13 +10,32 @@ #include -#include "backend/keccak-backend.h" -#include "generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { #endif +#define __PGFE_KECCAK_MAX_RATE 1536 + +typedef uint64_t pgfe_keccak_lane_t; + +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 +}; + #define PGFE_SHA3_224_DIGEST_SIZE 28 #define PGFE_SHA3_256_DIGEST_SIZE 32 #define PGFE_SHA3_384_DIGEST_SIZE 48 diff --git a/include/totp.h b/include/libpgfe/totp.h similarity index 96% rename from include/totp.h rename to include/libpgfe/totp.h index 7803a74..20cbc80 100644 --- a/include/totp.h +++ b/include/libpgfe/totp.h @@ -11,7 +11,8 @@ #include -#include "backend/otp-generic.h" +#include "libpgfe/generic.h" +#include "libpgfe/otp_types.h" #ifdef __cplusplus extern "C" { diff --git a/include/totp.hpp b/include/libpgfe/totp.hpp similarity index 95% rename from include/totp.hpp rename to include/libpgfe/totp.hpp index 384b758..dddce05 100644 --- a/include/totp.hpp +++ b/include/libpgfe/totp.hpp @@ -11,8 +11,8 @@ #error libpgfe error: C++ headers are not compatible with C source #endif -#include "hotp.hpp" -#include "totp.h" +#include "libpgfe/hotp.hpp" +#include "libpgfe/totp.h" namespace libpgfe { diff --git a/include/utils.h b/include/libpgfe/utils.h similarity index 81% rename from include/utils.h rename to include/libpgfe/utils.h index 4e3f389..de089de 100644 --- a/include/utils.h +++ b/include/libpgfe/utils.h @@ -8,10 +8,7 @@ #ifndef LIBPGFE_UTILS_H #define LIBPGFE_UTILS_H -#include "backend/otp-generic.h" -#include "generic.h" - -#include +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { @@ -34,11 +31,6 @@ size_t pgfe_hash_string_clean_(char hash_s[]); // Calculate length of a hash represented by a string size_t pgfe_hash_length(const char hash_s[]); -// Get current UNIX time -time_t pgfe_curtime(); - -void pgfe_otp_to_string(pgfe_otp_t otp, char *cs_out, size_t digit_c); - #ifdef __cplusplus } #endif diff --git a/include/utils.hpp b/include/libpgfe/utils.hpp similarity index 90% rename from include/utils.hpp rename to include/libpgfe/utils.hpp index cd85b9b..53ac8b9 100644 --- a/include/utils.hpp +++ b/include/libpgfe/utils.hpp @@ -13,8 +13,8 @@ #include -#include "generic.hpp" -#include "sequential_data.hpp" +#include "libpgfe/generic.hpp" +#include "libpgfe/sequential_data.hpp" namespace libpgfe { namespace utils { diff --git a/include/version.h b/include/libpgfe/version.h similarity index 100% rename from include/version.h rename to include/libpgfe/version.h diff --git a/src/c/base_encoding/base-encoding-internal.c b/src/c/base_encoding/base-encoding-internal.c index d1fcbfb..1160a9d 100644 --- a/src/c/base_encoding/base-encoding-internal.c +++ b/src/c/base_encoding/base-encoding-internal.c @@ -5,12 +5,12 @@ Copyright (c) 2022 Charles Dong */ -#include "backend/base-encoding-internal.h" +#include "./base-encoding-internal.h" #include #include -#include "backend/generic-internal.h" +#include "../generic-internal.h" #define __bitsz 8 diff --git a/include/backend/base-encoding-internal.h b/src/c/base_encoding/base-encoding-internal.h similarity index 98% rename from include/backend/base-encoding-internal.h rename to src/c/base_encoding/base-encoding-internal.h index 9e2b46e..e7b4b79 100644 --- a/include/backend/base-encoding-internal.h +++ b/src/c/base_encoding/base-encoding-internal.h @@ -12,7 +12,7 @@ #include -#include "../generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/src/c/base_encoding/base16.c b/src/c/base_encoding/base16.c index 66d2d60..528366e 100644 --- a/src/c/base_encoding/base16.c +++ b/src/c/base_encoding/base16.c @@ -5,9 +5,9 @@ Copyright (c) 2022 Charles Dong */ -#include "base-encoding.h" +#include "libpgfe/base-encoding.h" -#include "backend/base-encoding-internal.h" +#include "./base-encoding-internal.h" // Base 16 alphabet const char BASE16_ALPHABET[] = "0123456789ABCDEF" diff --git a/src/c/base_encoding/base32.c b/src/c/base_encoding/base32.c index 69111bd..f31c3fe 100644 --- a/src/c/base_encoding/base32.c +++ b/src/c/base_encoding/base32.c @@ -5,12 +5,12 @@ Copyright (c) 2022 Charles Dong */ -#include "base-encoding.h" +#include "libpgfe/base-encoding.h" #include -#include "backend/base-encoding-internal.h" -#include "backend/generic-internal.h" +#include "../generic-internal.h" +#include "./base-encoding-internal.h" // Base 32 alphabet // 0123456789ABCDEF diff --git a/src/c/base_encoding/base64.c b/src/c/base_encoding/base64.c index 1289e5b..d67a68d 100644 --- a/src/c/base_encoding/base64.c +++ b/src/c/base_encoding/base64.c @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "base-encoding.h" +#include "libpgfe/base-encoding.h" #include -#include "backend/base-encoding-internal.h" +#include "./base-encoding-internal.h" // Base 64 alphabet // 0123456789ABCDEF diff --git a/src/c/blowfish/blowfish.c b/src/c/blowfish/blowfish.c index a2610c1..5f22b98 100644 --- a/src/c/blowfish/blowfish.c +++ b/src/c/blowfish/blowfish.c @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "blowfish.h" +#include "libpgfe/blowfish.h" #include diff --git a/src/c/generic-internal.c b/src/c/generic-internal.c index d7c4029..bf01583 100644 --- a/src/c/generic-internal.c +++ b/src/c/generic-internal.c @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "backend/generic-internal.h" +#include "./generic-internal.h" #include diff --git a/include/backend/generic-internal.h b/src/c/generic-internal.h similarity index 99% rename from include/backend/generic-internal.h rename to src/c/generic-internal.h index a713d1d..706a7ec 100644 --- a/include/backend/generic-internal.h +++ b/src/c/generic-internal.h @@ -10,7 +10,7 @@ #ifndef LIBPGFE_GENERIC_INTERNAL_H #define LIBPGFE_GENERIC_INTERNAL_H -#include "../generic.h" +#include "libpgfe/generic.h" #ifdef __cplusplus extern "C" { diff --git a/src/c/generic.c b/src/c/generic.c index ae57947..2852ac0 100644 --- a/src/c/generic.c +++ b/src/c/generic.c @@ -5,4 +5,4 @@ Copyright (c) 2022 Charles Dong */ -#include "generic.h" +#include "libpgfe/generic.h" diff --git a/src/c/hash/keccak-backend.c b/src/c/hash/keccak-backend.c index 2efd3a2..04b3222 100644 --- a/src/c/hash/keccak-backend.c +++ b/src/c/hash/keccak-backend.c @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "backend/keccak-backend.h" +#include "./keccak-backend.h" #include #include diff --git a/src/c/hash/keccak-backend.h b/src/c/hash/keccak-backend.h new file mode 100644 index 0000000..acae1bb --- /dev/null +++ b/src/c/hash/keccak-backend.h @@ -0,0 +1,35 @@ +/* + 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.c b/src/c/hash/md5-backend.c index 27abeb6..954e350 100644 --- a/src/c/hash/md5-backend.c +++ b/src/c/hash/md5-backend.c @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "backend/md5-backend.h" +#include "./md5-backend.h" #include diff --git a/include/backend/md5-backend.h b/src/c/hash/md5-backend.h similarity index 93% rename from include/backend/md5-backend.h rename to src/c/hash/md5-backend.h index 649d1ab..ab7eb1d 100644 --- a/include/backend/md5-backend.h +++ b/src/c/hash/md5-backend.h @@ -10,7 +10,7 @@ #ifndef LIBPGFE_MD5_BACKEND_H #define LIBPGFE_MD5_BACKEND_H -#include "generic-internal.h" +#include "../generic-internal.h" #ifdef __cplusplus extern "C" { diff --git a/src/c/hash/md5.c b/src/c/hash/md5.c index 7c2d610..04373fa 100644 --- a/src/c/hash/md5.c +++ b/src/c/hash/md5.c @@ -5,12 +5,12 @@ Copyright (c) 2022 Charles Dong */ -#include "md5.h" +#include "libpgfe/md5.h" #include -#include "backend/md5-backend.h" -#include "backend/templates.h" +#include "./md5-backend.h" +#include "./templates.h" __PGFE_FRONTEND_GEN2(md5); __PGFE_FRONTEND_DEFAULT_GEN2(md5, MD5); diff --git a/src/c/hash/sha-internal.c b/src/c/hash/sha-internal.c index f45f646..afd4fab 100644 --- a/src/c/hash/sha-internal.c +++ b/src/c/hash/sha-internal.c @@ -5,4 +5,4 @@ Copyright (c) 2022 Charles Dong */ -#include "backend/sha-internal.h" +#include "./sha-internal.h" diff --git a/include/backend/sha-internal.h b/src/c/hash/sha-internal.h similarity index 93% rename from include/backend/sha-internal.h rename to src/c/hash/sha-internal.h index d5a2f0a..7ea750e 100644 --- a/include/backend/sha-internal.h +++ b/src/c/hash/sha-internal.h @@ -10,7 +10,7 @@ #ifndef LIBPGFE_SHA_INTERNAL_H #define LIBPGFE_SHA_INTERNAL_H -#include "generic-internal.h" +#include "../generic-internal.h" #ifdef __cplusplus extern "C" { diff --git a/src/c/hash/sha1.c b/src/c/hash/sha1.c index d992aec..0a5a1c4 100644 --- a/src/c/hash/sha1.c +++ b/src/c/hash/sha1.c @@ -5,13 +5,13 @@ Copyright (c) 2022 Charles Dong */ -#include "sha1.h" +#include "libpgfe/sha1.h" #include -#include "backend/generic-internal.h" -#include "backend/sha-internal.h" -#include "backend/templates.h" +#include "../generic-internal.h" +#include "./sha-internal.h" +#include "./templates.h" static const pgfe_word_t __pgfe_sha1_H0[] = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0}; diff --git a/src/c/hash/sha2-backend.c b/src/c/hash/sha2-backend.c index 9d0f0e0..9a55cdf 100644 --- a/src/c/hash/sha2-backend.c +++ b/src/c/hash/sha2-backend.c @@ -5,10 +5,10 @@ Copyright (c) 2022 Charles Dong */ -#include "backend/sha2-backend.h" +#include "./sha2-backend.h" -#include "backend/templates.h" -#include "sha2.h" +#include "./templates.h" +#include "libpgfe/sha2.h" #include diff --git a/include/backend/sha2-backend.h b/src/c/hash/sha2-backend.h similarity index 97% rename from include/backend/sha2-backend.h rename to src/c/hash/sha2-backend.h index 413cf9b..7610316 100644 --- a/include/backend/sha2-backend.h +++ b/src/c/hash/sha2-backend.h @@ -10,9 +10,9 @@ #ifndef LIBPGFE_SHA2_INTERNAL_H #define LIBPGFE_SHA2_INTERNAL_H -#include "sha-internal.h" +#include "./sha-internal.h" -#include "../sha2.h" +#include "libpgfe/sha2.h" #ifdef __cpluslpus extern "C" { diff --git a/src/c/hash/sha224.c b/src/c/hash/sha224.c index f813860..2713fe3 100644 --- a/src/c/hash/sha224.c +++ b/src/c/hash/sha224.c @@ -5,12 +5,12 @@ Copyright (c) 2022 Charles Dong */ -#include "sha2.h" +#include "libpgfe/sha2.h" #include -#include "backend/sha2-backend.h" -#include "backend/templates.h" +#include "./sha2-backend.h" +#include "./templates.h" static const pgfe_word_t __pgfe_sha224_H0[] = { 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4, diff --git a/src/c/hash/sha256.c b/src/c/hash/sha256.c index 790aa26..2f616ba 100644 --- a/src/c/hash/sha256.c +++ b/src/c/hash/sha256.c @@ -5,12 +5,12 @@ Copyright (c) 2022 Charles Dong */ -#include "sha2.h" +#include "libpgfe/sha2.h" #include -#include "backend/sha2-backend.h" -#include "backend/templates.h" +#include "./sha2-backend.h" +#include "./templates.h" static const pgfe_word_t __pgfe_sha256_H0[] = { 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19, diff --git a/src/c/hash/sha3-224.c b/src/c/hash/sha3-224.c index f37437a..b900c3c 100644 --- a/src/c/hash/sha3-224.c +++ b/src/c/hash/sha3-224.c @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "sha3.h" +#include "libpgfe/sha3.h" #include -#include "backend/templates.h" +#include "./templates.h" __PGFE_FRONTEND_GEN2(sha3_224); __PGFE_FRONTEND_DEFAULT_GEN2(sha3_224, SHA3_224); diff --git a/src/c/hash/sha3-256.c b/src/c/hash/sha3-256.c index 637fda6..9155dee 100644 --- a/src/c/hash/sha3-256.c +++ b/src/c/hash/sha3-256.c @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "sha3.h" +#include "libpgfe/sha3.h" #include -#include "backend/templates.h" +#include "./templates.h" __PGFE_FRONTEND_GEN2(sha3_256); __PGFE_FRONTEND_DEFAULT_GEN2(sha3_256, SHA3_256); diff --git a/src/c/hash/sha3-384.c b/src/c/hash/sha3-384.c index c5424e6..6bbfe3b 100644 --- a/src/c/hash/sha3-384.c +++ b/src/c/hash/sha3-384.c @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "sha3.h" +#include "libpgfe/sha3.h" #include -#include "backend/templates.h" +#include "./templates.h" __PGFE_FRONTEND_GEN2(sha3_384); __PGFE_FRONTEND_DEFAULT_GEN2(sha3_384, SHA3_384); diff --git a/src/c/hash/sha3-512.c b/src/c/hash/sha3-512.c index 39142f1..9d63e8d 100644 --- a/src/c/hash/sha3-512.c +++ b/src/c/hash/sha3-512.c @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "sha3.h" +#include "libpgfe/sha3.h" #include -#include "backend/templates.h" +#include "./templates.h" __PGFE_FRONTEND_GEN2(sha3_512); __PGFE_FRONTEND_DEFAULT_GEN2(sha3_512, SHA3_512); diff --git a/src/c/hash/sha384.c b/src/c/hash/sha384.c index 95cad0a..675bd00 100644 --- a/src/c/hash/sha384.c +++ b/src/c/hash/sha384.c @@ -5,12 +5,12 @@ Copyright (c) 2022 Charles Dong */ -#include "sha2.h" +#include "libpgfe/sha2.h" #include -#include "backend/sha2-backend.h" -#include "backend/templates.h" +#include "./sha2-backend.h" +#include "./templates.h" static const pgfe_word_t __pgfe_sha384_H0[] = { 0xC1059ED8, 0xCBBB9D5D, 0x367CD507, 0x629A292A, 0x3070DD17, 0x9159015A, 0xF70E5939, 0x152FECD8, diff --git a/src/c/hash/sha512.c b/src/c/hash/sha512.c index 22327f2..bb83a17 100644 --- a/src/c/hash/sha512.c +++ b/src/c/hash/sha512.c @@ -5,12 +5,12 @@ Copyright (c) 2022 Charles Dong */ -#include "sha2.h" +#include "libpgfe/sha2.h" #include -#include "backend/sha2-backend.h" -#include "backend/templates.h" +#include "./sha2-backend.h" +#include "./templates.h" static const pgfe_word_t __pgfe_sha512_H0[] = { 0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85, 0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A, diff --git a/src/c/hash/shake.c b/src/c/hash/shake.c index 58df97e..6347ac3 100644 --- a/src/c/hash/shake.c +++ b/src/c/hash/shake.c @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "sha3.h" +#include "libpgfe/sha3.h" #include -#include "backend/templates.h" +#include "./templates.h" // RawSHAKE128 diff --git a/include/backend/templates.h b/src/c/hash/templates.h similarity index 100% rename from include/backend/templates.h rename to src/c/hash/templates.h diff --git a/src/c/hmac/hmac.c b/src/c/hmac/hmac.c index 4744757..46a5ee3 100644 --- a/src/c/hmac/hmac.c +++ b/src/c/hmac/hmac.c @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "hmac.h" +#include "libpgfe/hmac.h" #include -#include "backend/generic-internal.h" +#include "../generic-internal.h" #define __pgfe_hmac_tmpl(name, upper) \ void pgfe_hmac_##name##_init(struct pgfe_hmac_##name##_ctx *ctx) { \ diff --git a/src/c/otp/hotp.c b/src/c/otp/hotp.c index 23c142e..0c115f8 100644 --- a/src/c/otp/hotp.c +++ b/src/c/otp/hotp.c @@ -5,12 +5,14 @@ Copyright (c) 2022 Charles Dong */ -#include "hotp.h" +#include "libpgfe/hotp.h" #include -#include "backend/generic-internal.h" -#include "sha1.h" +#include "../generic-internal.h" +#include "./otp-generic.h" + +#include "libpgfe/hash.h" #define __PGFE_SET_SIZE_CASE(upper, lower) \ case upper: \ diff --git a/src/c/otp/otp-generic.c b/src/c/otp/otp-generic.c index 6a9460e..7b7c6fe 100644 --- a/src/c/otp/otp-generic.c +++ b/src/c/otp/otp-generic.c @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "backend/otp-generic.h" +#include "./otp-generic.h" #define __ENS_BIT 8 #define __SIZE 4 @@ -20,4 +20,19 @@ pgfe_otp_t pgfe_dynamically_truncate(const pgfe_encode_t hash[], size_t length) } return code << 1 >> 1; +} + +inline time_t pgfe_curtime() { + return time(NULL); +} + +void pgfe_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--) { + *sp = (char)(otp % 10 + '0'); + otp /= 10; + } + + cs_out[digit_c] = 0; } \ No newline at end of file diff --git a/include/backend/otp-generic.h b/src/c/otp/otp-generic.h similarity index 67% rename from include/backend/otp-generic.h rename to src/c/otp/otp-generic.h index 4b09d0e..fc2904f 100644 --- a/include/backend/otp-generic.h +++ b/src/c/otp/otp-generic.h @@ -11,9 +11,11 @@ #define LIBPGFE_OTP_GENERIC_H #include +#include -#include "../generic.h" -#include "../hmac.h" +#include "libpgfe/generic.h" +#include "libpgfe/hmac.h" +#include "libpgfe/otp_types.h" #ifdef __cplusplus extern "C" { @@ -23,15 +25,14 @@ extern "C" { #define PGFE_OTP_DIGIT_MAX_LIMIT 10 -typedef uint32_t pgfe_otp_t; - -typedef uint64_t pgfe_otp_counter_t; - -typedef pgfe_encode_t pgfe_otp_secret_t; - // Performing dynamic truncation pgfe_otp_t pgfe_dynamically_truncate(const pgfe_encode_t hash[], size_t length); +// Get current UNIX time +time_t pgfe_curtime(); + +void pgfe_otp_to_string(pgfe_otp_t otp, char *cs_out, size_t digit_c); + #ifdef __cplusplus } #endif diff --git a/src/c/otp/totp.c b/src/c/otp/totp.c index 2f59114..efa6113 100644 --- a/src/c/otp/totp.c +++ b/src/c/otp/totp.c @@ -5,12 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "totp.h" +#include "libpgfe/totp.h" -#include "backend/generic-internal.h" -#include "hotp.h" -#include "sha1.h" -#include "utils.h" +#include "../generic-internal.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 diff --git a/src/c/utils.c b/src/c/utils.c index 8653e29..f87d86d 100644 --- a/src/c/utils.c +++ b/src/c/utils.c @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "utils.h" +#include "libpgfe/utils.h" #include -#include "backend/generic-internal.h" +#include "./generic-internal.h" size_t pgfe_hash_to_hex_string(const pgfe_encode_t hash[], size_t hash_length, char out[]) { char *op = out, dual_hex[3]; @@ -108,18 +108,3 @@ size_t pgfe_hash_length(const char hash_s[]) { return len / 2 + len % 2; } - -inline time_t pgfe_curtime() { - return time(NULL); -} - -void pgfe_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--) { - *sp = (char)(otp % 10 + '0'); - otp /= 10; - } - - cs_out[digit_c] = 0; -} \ No newline at end of file diff --git a/src/cpp/algorithm_selectable.cpp b/src/cpp/algorithm_selectable.cpp index dd151fd..e9a16b9 100644 --- a/src/cpp/algorithm_selectable.cpp +++ b/src/cpp/algorithm_selectable.cpp @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "algorithm_selectable.hpp" +#include "libpgfe/algorithm_selectable.hpp" using namespace libpgfe; diff --git a/src/cpp/base_encoding/abstract_base_encoding.cpp b/src/cpp/base_encoding/abstract_base_encoding.cpp index 78ebe9d..4803743 100644 --- a/src/cpp/base_encoding/abstract_base_encoding.cpp +++ b/src/cpp/base_encoding/abstract_base_encoding.cpp @@ -8,7 +8,7 @@ #include #include -#include "backend_cpp/abstract_base_encoding.hpp" +#include "libpgfe/abstract_base_encoding.hpp" #define PGFE_SPACE_MULTIPLE 1.2 diff --git a/src/cpp/base_encoding/base16.cpp b/src/cpp/base_encoding/base16.cpp index 7c657ca..4b77fec 100644 --- a/src/cpp/base_encoding/base16.cpp +++ b/src/cpp/base_encoding/base16.cpp @@ -5,9 +5,9 @@ Copyright (c) 2022 Charles Dong */ -#include "base16.hpp" +#include "libpgfe/base16.hpp" -#include "base-encoding.h" +#include "libpgfe/base-encoding.h" using namespace libpgfe; diff --git a/src/cpp/base_encoding/base32.cpp b/src/cpp/base_encoding/base32.cpp index 6c0fc54..91fd027 100644 --- a/src/cpp/base_encoding/base32.cpp +++ b/src/cpp/base_encoding/base32.cpp @@ -5,9 +5,9 @@ Copyright (c) 2022 Charles Dong */ -#include "base32.hpp" +#include "libpgfe/base32.hpp" -#include "base-encoding.h" +#include "libpgfe/base-encoding.h" using namespace libpgfe; diff --git a/src/cpp/base_encoding/base64.cpp b/src/cpp/base_encoding/base64.cpp index 95d25be..a3b8dc2 100644 --- a/src/cpp/base_encoding/base64.cpp +++ b/src/cpp/base_encoding/base64.cpp @@ -5,9 +5,9 @@ Copyright (c) 2022 Charles Dong */ -#include "base64.hpp" +#include "libpgfe/base64.hpp" -#include "base-encoding.h" +#include "libpgfe/base-encoding.h" using namespace libpgfe; diff --git a/src/cpp/blowfish/blowfish.cpp b/src/cpp/blowfish/blowfish.cpp index 51cf3d6..6a03c4c 100644 --- a/src/cpp/blowfish/blowfish.cpp +++ b/src/cpp/blowfish/blowfish.cpp @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "blowfish.hpp" +#include "libpgfe/blowfish.hpp" #include #include diff --git a/src/cpp/generic.cpp b/src/cpp/generic.cpp index b4ef412..308a565 100644 --- a/src/cpp/generic.cpp +++ b/src/cpp/generic.cpp @@ -8,9 +8,9 @@ #ifndef LIBPGFE_GENERIC_CPP #define LIBPGFE_GENERIC_CPP -#include "generic.hpp" +#include "libpgfe/generic.hpp" -#include "generic.h" +#include "libpgfe/generic.h" namespace libpgfe { diff --git a/src/cpp/hash/hash_encoder.cpp b/src/cpp/hash/hash_encoder.cpp index 90885e0..1cd812b 100644 --- a/src/cpp/hash/hash_encoder.cpp +++ b/src/cpp/hash/hash_encoder.cpp @@ -5,17 +5,15 @@ Copyright (c) 2022 Charles Dong */ -#include "hash_encoder.hpp" +#include "libpgfe/hash_encoder.hpp" #include #include -#include "md5.h" -#include "sha1.h" -#include "sha2.h" -#include "sha3.h" +#include "libpgfe/hash.h" +#include "libpgfe/utils.h" -#include "utils.h" +#include "../../c/generic-internal.h" #define __PGFE_CTX_CREATE_CASE(alg, name) \ case alg: \ diff --git a/src/cpp/hmac/hmac_encoder.cpp b/src/cpp/hmac/hmac_encoder.cpp index 3c79f8e..9a02509 100644 --- a/src/cpp/hmac/hmac_encoder.cpp +++ b/src/cpp/hmac/hmac_encoder.cpp @@ -5,7 +5,9 @@ Copyright (c) 2022 Charles Dong */ -#include "hmac_encoder.hpp" +#include "libpgfe/hmac_encoder.hpp" + +#include "../../c/generic-internal.h" #include diff --git a/src/cpp/misc/abstract_symmetric_crypter.cpp b/src/cpp/misc/abstract_symmetric_crypter.cpp index 81efab8..6acc2df 100644 --- a/src/cpp/misc/abstract_symmetric_crypter.cpp +++ b/src/cpp/misc/abstract_symmetric_crypter.cpp @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "backend_cpp/abstract_symmetric_crypter.hpp" +#include "libpgfe/abstract_symmetric_crypter.hpp" #include diff --git a/src/cpp/otp/abstract_otp.cpp b/src/cpp/otp/abstract_otp.cpp index 9916f52..5c71229 100644 --- a/src/cpp/otp/abstract_otp.cpp +++ b/src/cpp/otp/abstract_otp.cpp @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "backend_cpp/abstract_otp.hpp" +#include "libpgfe/abstract_otp.hpp" #include -#include "base-encoding.h" +#include "libpgfe/base-encoding.h" using namespace libpgfe; diff --git a/src/cpp/otp/hotp.cpp b/src/cpp/otp/hotp.cpp index 185976c..44a535d 100644 --- a/src/cpp/otp/hotp.cpp +++ b/src/cpp/otp/hotp.cpp @@ -5,12 +5,14 @@ Copyright (c) 2022 Charles Dong */ -#include "hotp.hpp" +#include "libpgfe/hotp.hpp" #include -#include "generic.hpp" -#include "hotp.h" +#include "libpgfe/generic.hpp" +#include "libpgfe/hotp.h" + +#include "../../c/generic-internal.h" using namespace libpgfe; diff --git a/src/cpp/otp/totp.cpp b/src/cpp/otp/totp.cpp index 54d1507..eb9e389 100644 --- a/src/cpp/otp/totp.cpp +++ b/src/cpp/otp/totp.cpp @@ -5,9 +5,10 @@ Copyright (c) 2022 Charles Dong */ -#include "totp.hpp" +#include "libpgfe/totp.hpp" +#include "libpgfe/utils.h" -#include "utils.h" +#include "../../c/otp/otp-generic.h" using namespace libpgfe; diff --git a/src/cpp/sequential_data.cpp b/src/cpp/sequential_data.cpp index 808117d..881a2fb 100644 --- a/src/cpp/sequential_data.cpp +++ b/src/cpp/sequential_data.cpp @@ -5,7 +5,7 @@ Copyright (c) 2022 Charles Dong */ -#include "sequential_data.hpp" +#include "libpgfe/sequential_data.hpp" #include #include diff --git a/src/cpp/utils.cpp b/src/cpp/utils.cpp index 28b631c..ae04aef 100644 --- a/src/cpp/utils.cpp +++ b/src/cpp/utils.cpp @@ -5,11 +5,11 @@ Copyright (c) 2022 Charles Dong */ -#include "utils.hpp" +#include "libpgfe/utils.hpp" #include -#include "utils.h" +#include "libpgfe/utils.h" namespace libpgfe { namespace utils { diff --git a/test/base_multithread.hpp b/test/base_multithread.hpp index 7614e22..72bb713 100644 --- a/test/base_multithread.hpp +++ b/test/base_multithread.hpp @@ -12,8 +12,8 @@ #include #include -#include "../include/base-encoding.h" -#include "../include/base64.hpp" +#include "../include/libpgfe/base-encoding.h" +#include "../include/libpgfe/base64.hpp" using namespace libpgfe; diff --git a/test/base_test.hpp b/test/base_test.hpp index b00b3ea..206df57 100644 --- a/test/base_test.hpp +++ b/test/base_test.hpp @@ -7,9 +7,9 @@ #include "test.h" -#include "../include/base16.hpp" -#include "../include/base32.hpp" -#include "../include/base64.hpp" +#include "../include/libpgfe/base16.hpp" +#include "../include/libpgfe/base32.hpp" +#include "../include/libpgfe/base64.hpp" using namespace std; using namespace libpgfe; diff --git a/test/baseencodetest.h b/test/baseencodetest.h index 93a0126..c1621e3 100644 --- a/test/baseencodetest.h +++ b/test/baseencodetest.h @@ -9,7 +9,7 @@ #include -#include "../include/base-encoding.h" +#include "../include/libpgfe/base-encoding.h" void base16_encode_test(ARGS) { char cs_out[700]; diff --git a/test/blowfish_test.h b/test/blowfish_test.h index 230f928..c5fb17c 100644 --- a/test/blowfish_test.h +++ b/test/blowfish_test.h @@ -7,8 +7,8 @@ #include "test.h" -#include "../include/blowfish.h" -#include "../include/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/test/blowfish_test.hpp b/test/blowfish_test.hpp index 0d95e4c..976ec7f 100644 --- a/test/blowfish_test.hpp +++ b/test/blowfish_test.hpp @@ -11,8 +11,8 @@ #include #include -#include "../include/blowfish.hpp" -#include "../include/utils.hpp" +#include "../include/libpgfe/blowfish.hpp" +#include "../include/libpgfe/utils.hpp" void blowfish_encrypt_test(ARGS) { using namespace libpgfe; diff --git a/test/hash_encoder_test.hpp b/test/hash_encoder_test.hpp index a29f46a..b33c062 100644 --- a/test/hash_encoder_test.hpp +++ b/test/hash_encoder_test.hpp @@ -10,9 +10,9 @@ #include #include -#include "../include/hash_encoder.hpp" -#include "../include/utils.h" -#include "../include/utils.hpp" +#include "../include/libpgfe/hash_encoder.hpp" +#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/utils.hpp" void hash_encoder_test(ARGS) { using namespace std; diff --git a/test/hmactest.h b/test/hmactest.h index ebff302..8e715b2 100644 --- a/test/hmactest.h +++ b/test/hmactest.h @@ -7,9 +7,9 @@ #include "test.h" -#include "../include/hmac.h" -#include "../include/md5.h" -#include "../include/utils.h" +#include "../include/libpgfe/hmac.h" +#include "../include/libpgfe/md5.h" +#include "../include/libpgfe/utils.h" enum pgfe_algorithm_choice get_alg_choice(char option[]) { enum pgfe_algorithm_choice c; diff --git a/test/hmactest.hpp b/test/hmactest.hpp index 00c80db..98b8053 100644 --- a/test/hmactest.hpp +++ b/test/hmactest.hpp @@ -9,9 +9,9 @@ #include -#include "../include/hmac_encoder.hpp" -#include "../include/utils.h" -#include "../include/utils.hpp" +#include "../include/libpgfe/hmac_encoder.hpp" +#include "../include/libpgfe/utils.h" +#include "../include/libpgfe/utils.hpp" void hmac_encoder_test(ARGS) { using namespace libpgfe; diff --git a/test/mdtest.h b/test/mdtest.h index e06672a..9ab8e72 100644 --- a/test/mdtest.h +++ b/test/mdtest.h @@ -7,8 +7,8 @@ #include "test.h" -#include "../include/md5.h" -#include "../include/utils.h" +#include "../include/libpgfe/md5.h" +#include "../include/libpgfe/utils.h" void md5test(ARGS) { pgfe_encode_t output[PGFE_MD5_DIGEST_SIZE]; diff --git a/test/otptest.h b/test/otptest.h index 1a00cf1..7a9cc42 100644 --- a/test/otptest.h +++ b/test/otptest.h @@ -7,9 +7,9 @@ #include "test.h" -#include "../include/hotp.h" -#include "../include/sha2.h" -#include "../include/utils.h" +#include "../include/libpgfe/hotp.h" +#include "../include/libpgfe/sha2.h" +#include "../include/libpgfe/utils.h" void hotp_hex(ARGS) { pgfe_encode_t key[100]; diff --git a/test/otptest.hpp b/test/otptest.hpp index 83d42c3..32263c8 100644 --- a/test/otptest.hpp +++ b/test/otptest.hpp @@ -10,8 +10,8 @@ #include #include -#include "../include/hotp.hpp" -#include "../include/utils.hpp" +#include "../include/libpgfe/hotp.hpp" +#include "../include/libpgfe/utils.hpp" void hotp_hex_test(ARGS) { HOTP hotp{_algstr(argv[2])}; diff --git a/test/shake_test.h b/test/shake_test.h index 8774eb0..4a75b3c 100644 --- a/test/shake_test.h +++ b/test/shake_test.h @@ -10,8 +10,8 @@ #include #include -#include "../include/sha3.h" -#include "../include/utils.h" +#include "../include/libpgfe/sha3.h" +#include "../include/libpgfe/utils.h" void shake_test(ARGS) { size_t bitsize; diff --git a/test/shatest.h b/test/shatest.h index 74900c6..af6317a 100644 --- a/test/shatest.h +++ b/test/shatest.h @@ -7,10 +7,10 @@ #include "test.h" -#include "../include/sha1.h" -#include "../include/sha2.h" -#include "../include/sha3.h" -#include "../include/utils.h" +#include "../include/libpgfe/sha1.h" +#include "../include/libpgfe/sha2.h" +#include "../include/libpgfe/sha3.h" +#include "../include/libpgfe/utils.h" void sha1_test(ARGS) { pgfe_encode_t output[PGFE_SHA1_DIGEST_SIZE]; diff --git a/test/utilstest.h b/test/utilstest.h index b476f3f..993cc82 100644 --- a/test/utilstest.h +++ b/test/utilstest.h @@ -7,7 +7,7 @@ #include "test.h" -#include "../include/utils.h" +#include "../include/libpgfe/utils.h" #include void string2hash(ARGS) {