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

Commit 70308ca

Browse files
committed
Merge branch 'next'
2 parents 5b618de + 94b9dff commit 70308ca

117 files changed

Lines changed: 1561 additions & 1833 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.clang-format

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#
22
# Komorebi clang-format file
3+
# v0.2.0
34
#
45

56
---
@@ -48,6 +49,8 @@ BitFieldColonSpacing: After
4849
Language: Cpp
4950

5051
AlwaysBreakTemplateDeclarations: Yes
52+
IndentAccessModifiers: false
53+
AccessModifierOffset: -4
5154

5255
BraceWrapping:
5356
AfterClass: true

.github/qna.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Q&A
2+
3+
## Q1: Meaning of the name?
4+
5+
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.
6+
7+
Since v0.2.0, *libpgfe* has been "self-sufficient" and does not depend on any third-party library.
8+
9+
## Q2: Interested in supporting Big Endian?
10+
11+
I will think about it eventually, but not now! Because byte order compatibility will dramatically increase complexity of the code,
12+
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.
13+
14+
## Q3: Why not MSVC?
15+
16+
> ***PS:** MSVC = Microsoft Visual C++*
17+
18+
Firstly, this library prioritizes POSIX compatibility, instead of Windows compatibility.
19+
20+
Secondly, *libpgfe* need some necessary features that are not included in *MSVC*. For instance, like the C code below:
21+
22+
```c
23+
int main() {
24+
int n = 12;
25+
int arr[n];
26+
27+
return 0;
28+
}
29+
```
30+
31+
*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.

CMakeLists.txt

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,71 @@
1-
cmake_minimum_required(VERSION 3.0.0)
1+
cmake_minimum_required(VERSION 3.16.0)
22

33
set(CMAKE_C_COMPILER clang)
44
set(CMAKE_CXX_COMPILER clang++)
55

6-
project(libpgfe VERSION 0.3.2)
6+
project(libpgfe VERSION 0.4.0 LANGUAGES C CXX)
77

88
set(CMAKE_C_STANDARD 11)
99
set(CMAKE_CXX_STANDARD 14)
1010

1111
include(CTest)
1212
enable_testing()
1313

14+
set(src_dir "src")
15+
set(include_dir "include")
16+
set(test_dir "test")
17+
1418
add_library(pgfe SHARED
15-
generic.c
16-
generic-internal.c
17-
templates.c
18-
utils.c
19-
sha-internal.c
20-
sha2-backend.c
21-
keccak-backend.c
22-
md5-backend.c
23-
sha1.c sha224.c sha256.c sha384.c sha512.c sha3-224.c sha3-256.c sha3-384.c sha3-512.c
24-
md5.c
25-
shake.c
26-
hmac.c
27-
otp-generic.c
28-
hotp.c totp.c
29-
base-encoding-internal.c
30-
base64.c base32.c base16.c
31-
sequential_data.cpp
32-
utils.cpp
33-
algorithm_selectable.cpp
34-
hash_encoder.cpp
35-
hmac_encoder.cpp
36-
abstract_base_encoding.cpp
37-
base16.cpp
38-
base32.cpp
39-
base64.cpp
40-
abstract_otp.cpp
41-
hotp.cpp totp.cpp)
42-
add_executable(pgfetest test/test.c)
43-
# add_executable(totptest test/totptest.c)
44-
# add_executable(totptestcpp test/totptest.cpp)
45-
46-
add_executable(pgfetestcpp test/test.cpp)
19+
${src_dir}/generic.c
20+
${src_dir}/generic-internal.c
21+
${src_dir}/templates.c
22+
${src_dir}/utils.c
23+
${src_dir}/sha-internal.c
24+
${src_dir}/sha2-backend.c
25+
${src_dir}/keccak-backend.c
26+
${src_dir}/md5-backend.c
27+
${src_dir}/sha1.c ${src_dir}/sha224.c ${src_dir}/sha256.c ${src_dir}/sha384.c ${src_dir}/sha512.c
28+
${src_dir}/sha3-224.c ${src_dir}/sha3-256.c ${src_dir}/sha3-384.c ${src_dir}/sha3-512.c
29+
${src_dir}/md5.c
30+
${src_dir}/shake.c
31+
${src_dir}/hmac.c
32+
${src_dir}/otp-generic.c
33+
${src_dir}/hotp.c ${src_dir}/totp.c
34+
${src_dir}/base-encoding-internal.c
35+
${src_dir}/base64.c ${src_dir}/base32.c ${src_dir}/base16.c
36+
${src_dir}/sequential_data.cpp
37+
${src_dir}/utils.cpp
38+
${src_dir}/algorithm_selectable.cpp
39+
${src_dir}/hash_encoder.cpp
40+
${src_dir}/hmac_encoder.cpp
41+
${src_dir}/abstract_base_encoding.cpp
42+
${src_dir}/base16.cpp
43+
${src_dir}/base32.cpp
44+
${src_dir}/base64.cpp
45+
${src_dir}/abstract_otp.cpp
46+
${src_dir}/hotp.cpp ${src_dir}/totp.cpp)
47+
add_executable(pgfetest ${test_dir}/test.c)
48+
# add_executable(totptest ${test_dir}/totptest.c)
49+
# add_executable(totptestcpp ${test_dir}/totptest.cpp)
50+
add_executable(pgfetestcpp ${test_dir}/test.cpp)
51+
52+
target_include_directories(pgfe PRIVATE
53+
${src_dir}
54+
${include_dir}
55+
)
4756

4857
target_link_libraries(pgfetest pgfe)
4958
# target_link_libraries(totptest pgfe)
5059
target_link_libraries(pgfetestcpp pgfe)
5160
# target_link_libraries(totptestcpp pgfe)
5261

53-
include(test/tests.cmake)
54-
include(test/tests_cpp.cmake)
62+
include(${test_dir}/cmake/test_meta.cmake)
63+
include(${test_dir}/cmake/hash_tests.cmake)
64+
include(${test_dir}/cmake/hmac_tests.cmake)
65+
include(${test_dir}/cmake/util_tests.cmake)
66+
include(${test_dir}/cmake/base_tests.cmake)
67+
include(${test_dir}/cmake/otp_tests.cmake)
68+
include(${test_dir}/cmake/shake_tests.cmake)
5569

5670
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
5771
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})

Makefile

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
include meta.mak
22

3+
.PHONY: all rebuild clean test install uninstall
4+
35
all:
46
@echo 'Building...'
57
@cmake . -B $(BUILD_DIR)
6-
@cmake --build $(BUILD_DIR)
8+
@cmake --build $(BUILD_DIR) --config Release -j18 --
79
@echo 'Building done'
810

911
rebuild: clean all
1012

1113
$(BUILD_DIR):
12-
@mkdir -v $(BUILD_DIR)
14+
@mkdir -vp $(BUILD_DIR)
1315

1416
clean:
1517
@echo 'Cleaning...'
16-
@rm -rf ./$(BUILD_DIR)
18+
@rm -rfv ./$(BUILD_DIR)
1719
@echo 'Cleaning done'
1820

19-
ctest: all
20-
@ctest --test-dir $(BUILD_DIR)
21+
test: all
22+
@ctest --test-dir $(BUILD_DIR) -C Release
2123

2224
install: all
2325
@echo 'Installing headers...'
24-
@mkdir -v $(HEADER_DIR)
25-
@cp -v *.h $(HEADER_DIR)
26-
@cp -v *.hpp $(HEADER_DIR)
26+
@mkdir -vp $(HEADER_DIR)
27+
@cp -v $(INCLUDE_DIR)/* $(HEADER_DIR)
2728
@echo done
2829
@echo 'Installing shared library...'
2930
@cp -v $(TARGET) $(LIB_DIR)

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77

88
## Introduction
99

10-
**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).
10+
**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).
1111

12-
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.
13-
14-
Since v0.2.0, *libpgfe* has been "self-sufficient" and does not depend on any third-party library.
12+
*libpgfe* currently supports hash encoding (e.g. SHA256, MD5), HMAC encoding, HOTP/TOTP and Base 16/32/64.
1513

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

21+
[*Any questions?*](.github/qna.md)
22+
2323
## Endianness (Byte order)
2424

25-
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.
25+
> [*What is it anyway??*](https://en.wikipedia.org/wiki/Endianness)
26+
27+
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.
2628

2729
## Tips for compilation
2830

algorithm_selectable.cpp

Lines changed: 0 additions & 28 deletions
This file was deleted.

generic-internal.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

generic.h

Lines changed: 0 additions & 60 deletions
This file was deleted.

0 commit comments

Comments
 (0)