Skip to content
This repository has been archived by the owner on Jan 1, 2025. It is now read-only.

Commit

Permalink
Merge branch 'next'
Browse files Browse the repository at this point in the history
  • Loading branch information
chardoncs committed Oct 26, 2022
2 parents 5b618de + 94b9dff commit 70308ca
Show file tree
Hide file tree
Showing 117 changed files with 1,561 additions and 1,833 deletions.
3 changes: 3 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Komorebi clang-format file
# v0.2.0
#

---
Expand Down Expand Up @@ -48,6 +49,8 @@ BitFieldColonSpacing: After
Language: Cpp

AlwaysBreakTemplateDeclarations: Yes
IndentAccessModifiers: false
AccessModifierOffset: -4

BraceWrapping:
AfterClass: true
Expand Down
31 changes: 31 additions & 0 deletions .github/qna.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Q&A

## Q1: Meaning of the name?

The name "*libpgfe*" used to be an abbreviation of "**Lib**rary of **P**assword **G**eneration **F**ront-**e**nd". Because it is initially designed to be just an HOTP/TOTP library ported to [Nettle](https://www.lysator.liu.se/~nisse/nettle/). But during the development period, more and more algorithms have been directly implemented in this library, so its full name has been deprecated since it may mislead viewers.

Since v0.2.0, *libpgfe* has been "self-sufficient" and does not depend on any third-party library.

## 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.

## Q3: Why not MSVC?

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

Secondly, *libpgfe* need some necessary features that are not included in *MSVC*. For instance, like the C code below:

```c
int main() {
int n = 12;
int arr[n];

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.
86 changes: 50 additions & 36 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,57 +1,71 @@
cmake_minimum_required(VERSION 3.0.0)
cmake_minimum_required(VERSION 3.16.0)

set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

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

set(CMAKE_C_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)

include(CTest)
enable_testing()

set(src_dir "src")
set(include_dir "include")
set(test_dir "test")

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

add_executable(pgfetestcpp test/test.cpp)
${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)
add_executable(pgfetest ${test_dir}/test.c)
# 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(totptestcpp pgfe)

include(test/tests.cmake)
include(test/tests_cpp.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)

set(CPACK_PROJECT_NAME ${PROJECT_NAME})
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
Expand Down
17 changes: 9 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
include meta.mak

.PHONY: all rebuild clean test install uninstall

all:
@echo 'Building...'
@cmake . -B $(BUILD_DIR)
@cmake --build $(BUILD_DIR)
@cmake --build $(BUILD_DIR) --config Release -j18 --
@echo 'Building done'

rebuild: clean all

$(BUILD_DIR):
@mkdir -v $(BUILD_DIR)
@mkdir -vp $(BUILD_DIR)

clean:
@echo 'Cleaning...'
@rm -rf ./$(BUILD_DIR)
@rm -rfv ./$(BUILD_DIR)
@echo 'Cleaning done'

ctest: all
@ctest --test-dir $(BUILD_DIR)
test: all
@ctest --test-dir $(BUILD_DIR) -C Release

install: all
@echo 'Installing headers...'
@mkdir -v $(HEADER_DIR)
@cp -v *.h $(HEADER_DIR)
@cp -v *.hpp $(HEADER_DIR)
@mkdir -vp $(HEADER_DIR)
@cp -v $(INCLUDE_DIR)/* $(HEADER_DIR)
@echo done
@echo 'Installing shared library...'
@cp -v $(TARGET) $(LIB_DIR)
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@

## Introduction

**libpgfe** (IPA: /ˌlɪbˈpɪɡfiː/, like "lib-pig-fee") is a free and open-source cryptographic library focusing on flexibility and easy-to-access interfaces, which provides hash encoding, HOTP/TOTP generation and base encoding/decoding. It 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ː/, 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).

The name "*libpgfe*" used to be an abbreviation of "**Lib**rary of **P**assword **G**eneration **F**ront-**e**nd". Because it is initially designed to be just an HOTP/TOTP library ported to [Nettle](https://www.lysator.liu.se/~nisse/nettle/). But during the development period, more and more algorithms have been directly implemented in this library, so its full name may mislead viewers and has been deprecated.

Since v0.2.0, *libpgfe* has been "self-sufficient" and does not depend on any third-party library.
*libpgfe* currently supports hash encoding (e.g. SHA256, MD5), HMAC encoding, HOTP/TOTP and Base 16/32/64.

| Item | Content |
| :----------- | :------------------ |
Expand All @@ -20,9 +18,13 @@ Since v0.2.0, *libpgfe* has been "self-sufficient" and does not depend on any th
| Compiler | LLVM Clang |
| License | BSD 3-Clause |

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

## Endianness (Byte order)

The implementation philosophy of *libpgfe* assumes that systems running this library are **Little Endian**, since most architectures and OS are Little Endian. Therefore, this library should not run properly on Big Endian systems.
> [*What is it anyway??*](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.

## Tips for compilation

Expand Down
28 changes: 0 additions & 28 deletions algorithm_selectable.cpp

This file was deleted.

39 changes: 0 additions & 39 deletions generic-internal.h

This file was deleted.

60 changes: 0 additions & 60 deletions generic.h

This file was deleted.

Loading

0 comments on commit 70308ca

Please sign in to comment.