Skip to content

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
chardoncs committed Oct 30, 2022
2 parents 70308ca + 83aa719 commit e9ffbff
Show file tree
Hide file tree
Showing 86 changed files with 405 additions and 308 deletions.
18 changes: 12 additions & 6 deletions .github/qna.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,23 @@ Since v0.2.0, *libpgfe* has been "self-sufficient" and does not depend on any th
## Q2: Interested in supporting Big Endian?

I will think about it eventually, but not now! Because byte order compatibility will dramatically increase complexity of the code,
and I currently don't have enough time or effort to tackle it. Also, I do not have Big Endian machines or virtual machines, so the additional code would be left untested, which is what I don't want to happen.
and I currently don't have enough time or effort to tackle it. Also, I do not have Big Endian machines or virtual machines, so the additional code would be left untested, which is not what I expect.

## Q3: Why not MSVC?
## Q3: Why not [Assembly Language](https://en.wikipedia.org/wiki/Assembly_language)?

1. I'm not familiar with Assembly.

2. Assembly is machine-dependent.

3. C is fast enough for *libpgfe*. It's no need to use Assembly to do those optimizations.

## Q4: Why not MSVC?

> ***PS:** MSVC = Microsoft Visual C++*
Firstly, this library prioritizes POSIX compatibility, instead of Windows compatibility.
1. This library prioritizes POSIX compatibility, instead of Windows compatibility.

Secondly, *libpgfe* need some necessary features that are not included in *MSVC*. For instance, like the C code below:
2. *libpgfe* needs some necessary features that are not included in *MSVC*. For instance, like the C code below. *MSVC* will refuse to compile that code, because a variable is used as the array's size, while *Clang* and *GCC* are OK with it.

```c
int main() {
Expand All @@ -27,5 +35,3 @@ int main() {
return 0;
}
```

*MSVC* will refuse to compile that code, because of a variable is used as the array's size, while *Clang* and *GCC* are OK with it.
64 changes: 33 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.16.0)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

project(libpgfe VERSION 0.4.0 LANGUAGES C CXX)
project(libpgfe VERSION 0.5.0 LANGUAGES C CXX)

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
Expand All @@ -12,51 +12,53 @@ include(CTest)
enable_testing()

set(src_dir "src")
set(src_c_dir "${src_dir}/c")
set(src_cpp_dir "${src_dir}/cpp")
set(include_dir "include")
set(test_dir "test")

add_library(pgfe SHARED
${src_dir}/generic.c
${src_dir}/generic-internal.c
${src_dir}/templates.c
${src_dir}/utils.c
${src_dir}/sha-internal.c
${src_dir}/sha2-backend.c
${src_dir}/keccak-backend.c
${src_dir}/md5-backend.c
${src_dir}/sha1.c ${src_dir}/sha224.c ${src_dir}/sha256.c ${src_dir}/sha384.c ${src_dir}/sha512.c
${src_dir}/sha3-224.c ${src_dir}/sha3-256.c ${src_dir}/sha3-384.c ${src_dir}/sha3-512.c
${src_dir}/md5.c
${src_dir}/shake.c
${src_dir}/hmac.c
${src_dir}/otp-generic.c
${src_dir}/hotp.c ${src_dir}/totp.c
${src_dir}/base-encoding-internal.c
${src_dir}/base64.c ${src_dir}/base32.c ${src_dir}/base16.c
${src_dir}/sequential_data.cpp
${src_dir}/utils.cpp
${src_dir}/algorithm_selectable.cpp
${src_dir}/hash_encoder.cpp
${src_dir}/hmac_encoder.cpp
${src_dir}/abstract_base_encoding.cpp
${src_dir}/base16.cpp
${src_dir}/base32.cpp
${src_dir}/base64.cpp
${src_dir}/abstract_otp.cpp
${src_dir}/hotp.cpp ${src_dir}/totp.cpp)
${src_c_dir}/generic.c
${src_c_dir}/generic-internal.c
${src_c_dir}/utils.c
${src_c_dir}/hash/sha-internal.c
${src_c_dir}/hash/sha2-backend.c
${src_c_dir}/hash/keccak-backend.c
${src_c_dir}/hash/md5-backend.c
${src_c_dir}/hash/sha1.c ${src_c_dir}/hash/sha224.c ${src_c_dir}/hash/sha256.c ${src_c_dir}/hash/sha384.c ${src_c_dir}/hash/sha512.c
${src_c_dir}/hash/sha3-224.c ${src_c_dir}/hash/sha3-256.c ${src_c_dir}/hash/sha3-384.c ${src_c_dir}/hash/sha3-512.c
${src_c_dir}/hash/md5.c
${src_c_dir}/hash/shake.c
${src_c_dir}/hmac/hmac.c
${src_c_dir}/otp/otp-generic.c
${src_c_dir}/otp/hotp.c ${src_c_dir}/otp/totp.c
${src_c_dir}/base_encoding/base-encoding-internal.c
${src_c_dir}/base_encoding/base64.c ${src_c_dir}/base_encoding/base32.c ${src_c_dir}/base_encoding/base16.c
${src_cpp_dir}/generic.cpp
${src_cpp_dir}/sequential_data.cpp
${src_cpp_dir}/utils.cpp
${src_cpp_dir}/algorithm_selectable.cpp
${src_cpp_dir}/hash/hash_encoder.cpp
${src_cpp_dir}/hmac/hmac_encoder.cpp
${src_cpp_dir}/base_encoding/abstract_base_encoding.cpp
${src_cpp_dir}/base_encoding/base16.cpp
${src_cpp_dir}/base_encoding/base32.cpp
${src_cpp_dir}/base_encoding/base64.cpp
${src_cpp_dir}/otp/abstract_otp.cpp
${src_cpp_dir}/otp/hotp.cpp ${src_cpp_dir}/otp/totp.cpp)
add_executable(pgfetest ${test_dir}/test.c)
add_executable(pgfetestcpp ${test_dir}/test.cpp)
# add_executable(totptest ${test_dir}/totptest.c)
# add_executable(totptestcpp ${test_dir}/totptest.cpp)
add_executable(pgfetestcpp ${test_dir}/test.cpp)

target_include_directories(pgfe PRIVATE
${src_dir}
${include_dir}
)

target_link_libraries(pgfetest pgfe)
# target_link_libraries(totptest pgfe)
target_link_libraries(pgfetestcpp pgfe)
# target_link_libraries(totptest pgfe)
# target_link_libraries(totptestcpp pgfe)

include(${test_dir}/cmake/test_meta.cmake)
Expand Down
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
include meta.mak
include metadata.mak

.PHONY: all rebuild clean test install uninstall
.PHONY: all rebuild clean test install uninstall init-scripts

all:
@echo 'Building...'
Expand Down Expand Up @@ -37,3 +37,6 @@ uninstall:
@echo 'Removing shared library...'
@rm -vrf $(LIB_DIR)/$(TARGET_FILE)
@echo done

init-scripts:
@chmod u+x ./scripts/{comment_header,update_meta,deploy}
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@

*libpgfe* currently supports hash encoding (e.g. SHA256, MD5), HMAC encoding, HOTP/TOTP and Base 16/32/64.

| Item | Content |
*libpgfe* is currently under heavy development, more features and optimization will be added in the future.

| Entry | Info |
| :----------- | :------------------ |
| C Standard | [C11 (ISO/IEC 9899:2011)](https://en.wikipedia.org/wiki/C11_(C_standard_revision)) |
| C++ Standard | [C++14 (ISO/IEC 14882:2014)](https://en.wikipedia.org/wiki/C++14) |
Expand All @@ -20,9 +22,7 @@

[*Any questions?*](.github/qna.md)

## Endianness (Byte order)

> [*What is it anyway??*](https://en.wikipedia.org/wiki/Endianness)
## [Endianness (Byte order)](https://en.wikipedia.org/wiki/Endianness)

The implementation philosophy of *libpgfe* assumes that the systems running this library are **Little Endian**, since it is widely used by architectures and OS. Therefore, this library should not run properly on Big Endian systems.

Expand Down
2 changes: 1 addition & 1 deletion include/algorithm_selectable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class AlgorithmSelectable
void select_algorithm(pgfe_algorithm_choice choice);

public:
pgfe_algorithm_choice algorithm();
pgfe_algorithm_choice algorithm() const;
};
} // namespace PGFE
} // namespace chardon55
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

#include <stdbool.h>

#include "generic.h"
#include "../generic.h"

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#ifndef LIBPGFE_GENERIC_INTERNAL_H
#define LIBPGFE_GENERIC_INTERNAL_H

#include "generic.h"
#include "../generic.h"

#ifdef __cplusplus
extern "C" {
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions include/otp-generic.h → include/backend/otp-generic.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

#include <stdint.h>

#include "generic.h"
#include "hmac.h"
#include "../generic.h"
#include "../hmac.h"

#ifdef __cplusplus
extern "C" {
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion include/sha2-backend.h → include/backend/sha2-backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
#define LIBPGFE_SHA2_INTERNAL_H

#include "sha-internal.h"
#include "sha2.h"

#include "../sha2.h"

#ifdef __cpluslpus
extern "C" {
Expand Down
6 changes: 3 additions & 3 deletions src/templates.c → include/backend/templates.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/*
libpgfe
templates.c
templates.h
Copyright (c) 2022 Charles Dong
*/

#ifndef LIBPGFE_TEMPLATES_C
#define LIBPGFE_TEMPLATES_C
#ifndef LIBPGFE_TEMPLATES_H
#define LIBPGFE_TEMPLATES_H

#ifdef __cplusplus
extern "C" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <mutex>
#include <string>

#include "generic.h"
#include "sequential_data.hpp"
#include "../generic.h"
#include "../sequential_data.hpp"

namespace chardon55 {
namespace PGFE {
Expand Down Expand Up @@ -63,10 +63,10 @@ class AbstractBaseEncoding
SequentialData decode(const char *);
SequentialData decode(std::string &);

base_short_size_t unit_size();
base_short_size_t chunk_size();
base_short_size_t bit_size();
base_short_size_t alphabet_size();
base_short_size_t unit_size() const;
base_short_size_t chunk_size() const;
base_short_size_t bit_size() const;
base_short_size_t alphabet_size() const;
};

} // namespace PGFE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
#include <cstring>
#include <string>

#include "generic.h"
#include "sequential_data.hpp"
#include "utils.hpp"
#include "../generic.h"
#include "../sequential_data.hpp"
#include "../utils.hpp"

namespace chardon55 {
namespace PGFE {
Expand All @@ -39,7 +39,7 @@ class AbstractEncoder
update(sd.to_pgfe_seq(sz), sz);
}

virtual SequentialData *get_digest() {
virtual const SequentialData *get_digest() {
return nullptr;
}
}; // namespace AbstractEncoder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,28 @@
#include <string>

#include "abstract_encoder.hpp"
#include "algorithm-choice.h"
#include "algorithm_selectable.hpp"
#include "generic.h"
#include "generic.hpp"

#include "../algorithm-choice.h"
#include "../algorithm_selectable.hpp"
#include "../generic.h"
#include "../generic.hpp"

namespace chardon55 {
namespace PGFE {

class AbstractHashEncoder : public AbstractEncoder, public AlgorithmSelectable
{
protected:
size_t digsz, blocksz;

public:
size_t digest_size() const {
return digsz;
}

size_t block_size() const {
return blocksz;
}
};

} // namespace PGFE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@

#include <string>

#include "algorithm_selectable.hpp"
#include "generic.h"
#include "otp-generic.h"
#include "sequential_data.hpp"
#include "../algorithm_selectable.hpp"
#include "../backend/otp-generic.h"
#include "../generic.h"
#include "../sequential_data.hpp"

namespace chardon55 {
namespace PGFE {
Expand All @@ -31,11 +31,11 @@ class AbstractOTP : public AlgorithmSelectable

virtual void set_counter(pgfe_otp_counter_t){};

virtual pgfe_otp_t generate(uint8_t digit_count = 6) {
virtual pgfe_otp_t generate(uint8_t digit_count = 6) const {
return 0;
}

virtual std::string generate_str(uint8_t digit_count = 6);
virtual std::string generate_str(uint8_t digit_count = 6) const;
};

} // namespace PGFE
Expand Down
2 changes: 1 addition & 1 deletion include/base16.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#error libpgfe error: C++ headers are not compatible with C source
#endif

#include "abstract_base_encoding.hpp"
#include "backend_cpp/abstract_base_encoding.hpp"

namespace chardon55 {
namespace PGFE {
Expand Down
4 changes: 2 additions & 2 deletions include/base32.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#error libpgfe error: C++ headers are not compatible with C source
#endif

#include "abstract_base_encoding.hpp"
#include "backend_cpp/abstract_base_encoding.hpp"

namespace chardon55 {
namespace PGFE {
Expand All @@ -28,7 +28,7 @@ class Base32 : public AbstractBaseEncoding
public:
Base32(bool hex_mode = false);

bool is_hex_mode() {
bool is_hex_mode() const {
return hexm;
}
};
Expand Down
4 changes: 2 additions & 2 deletions include/base64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#error libpgfe error: C++ headers are not compatible with C source
#endif

#include "abstract_base_encoding.hpp"
#include "backend_cpp/abstract_base_encoding.hpp"

namespace chardon55 {
namespace PGFE {
Expand All @@ -28,7 +28,7 @@ class Base64 : public AbstractBaseEncoding
public:
Base64(bool url_safe_mode = false);

bool is_url_safe_mode() {
bool is_url_safe_mode() const {
return _url_safe_mode;
}
};
Expand Down
Loading

0 comments on commit e9ffbff

Please sign in to comment.