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

Commit 1bc5935

Browse files
committed
Merge branch 'revision'
2 parents a52f70c + 56366a2 commit 1bc5935

20 files changed

Lines changed: 184 additions & 178 deletions

.gitattributes

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
* text=auto
2+
3+
# C
4+
*.h text eol=lf
5+
*.c text eol=lf
6+
7+
# C++
8+
*.hpp text eol=lf
9+
*.cpp text eol=lf
10+
11+
# Other
12+
*.md text eol=lf
13+
*.clang-format text eol=lf
14+
*.mak text eol=lf
15+
*.json text eol=lf
16+
*.cmake text eol=lf
17+
*.txt text eol=lf
18+
*.py text eol=lf
19+
20+
*.png -text
21+
*.jpg -text
22+
*.jpeg -text
23+
*.webp -text
24+
25+
Makefile text eol=lf

CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ cmake_minimum_required(VERSION 3.16.0)
33
set(CMAKE_C_COMPILER clang)
44
set(CMAKE_CXX_COMPILER clang++)
55

6-
project(libpgfe VERSION 0.6.0 LANGUAGES C CXX)
6+
project(libpgfe
7+
VERSION 0.5.1
8+
DESCRIPTION "Cryptographic library"
9+
HOMEPAGE_URL "https://github.com/chardon55/libpgfe"
10+
LANGUAGES C CXX
11+
)
712

813
set(CMAKE_C_STANDARD 11)
914
set(CMAKE_CXX_STANDARD 14)
@@ -52,7 +57,6 @@ add_executable(pgfetestcpp ${test_dir}/test.cpp)
5257
# add_executable(totptestcpp ${test_dir}/totptest.cpp)
5358

5459
target_include_directories(pgfe PRIVATE
55-
${src_dir}
5660
${include_dir}
5761
)
5862

include/backend/base-encoding-internal.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_
3737
size_t
3838
__pgfe_unittostr(PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t unit[], char out[], bool padding);
3939

40-
size_t __pgfe_encode_generic(
40+
size_t __pgfe_encode_base_generic(
4141
PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t input[], size_t input_length, char cs_out[]
4242
);
4343

44-
size_t __pgfe_decode_generic(
44+
size_t __pgfe_decode_base_generic(
4545
PGFE_BASE_PARAMS_DEF, pgfe_encode_t (*func)(char), const char basexx_cs[], pgfe_encode_t output[]
4646
);
4747

include/sequential_data.hpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,23 @@ class SequentialData
2828
{
2929
private:
3030
seqdata_t *seq = nullptr;
31-
size_t sz = 0, hex_sz = 0;
32-
3331
char *hex_str = nullptr;
32+
size_t sz = 0, hex_sz = 0;
3433

35-
bool _is_str, _apstr;
34+
bool _is_str = false, _apstr = false;
3635

3736
bool determine_ascii_str();
3837

38+
void check_range(size_t &start, size_t &length) const;
39+
3940
public:
4041
SequentialData(const pgfe_encode_t *, size_t);
4142
SequentialData(const char *);
4243
SequentialData(std::string &);
4344
SequentialData(const SequentialData *);
45+
SequentialData(const SequentialData &);
4446
SequentialData(SequentialData *, bool delete_current);
47+
4548
~SequentialData();
4649

4750
const char *to_cs() const;

include/version.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#define LIBPGFE_VERSION_H
1010

1111
#define LIBPGFE_MAJOR_VERSION 0
12-
#define LIBPGFE_MINOR_VERSION 6
13-
#define LIBPGFE_REVISION 0
14-
#define LIBPGFE_VARIANT "rc1"
12+
#define LIBPGFE_MINOR_VERSION 5
13+
#define LIBPGFE_REVISION 1
14+
#define LIBPGFE_VARIANT ""
1515

16-
#define LIBPGFE_VERSION "0.6.0-rc1"
16+
#define LIBPGFE_VERSION "0.5.1"
1717

1818
#endif

metadata.mak

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
PROJECT := libpgfe
2-
VERSION := 0.6.0-rc1
2+
VERSION := 0.5.1
33

44
BUILD_DIR := build
55

project.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"name": "libpgfe",
3-
"version": "0.6.0-rc1"
3+
"version": "0.5.1"
44
}

src/c/base_encoding/base-encoding-internal.c

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,38 +11,36 @@
1111

1212
#include "backend/generic-internal.h"
1313

14-
uint8_t __pgfe_build_mask(uint8_t digit_c);
14+
#define __bitsz 8
1515

16-
inline uint8_t __pgfe_build_mask(uint8_t digit_c) {
17-
return UINT8_MAX >> (to_bit(sizeof(uint8_t)) - digit_c);
18-
}
16+
#define __mkmask(digit) (UINT8_MAX >> (__bitsz - (digit)))
1917

2018
size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_t chunk_size, pgfe_encode_t out[]) {
21-
const uint16_t bitsz = to_bit(sizeof(pgfe_encode_t));
22-
pgfe_encode_t *inp = (pgfe_encode_t *)input, *op = out;
19+
const pgfe_encode_t *inp = input;
20+
pgfe_encode_t *op = out;
2321
size_t low, high, mv_sz, sz_diff;
2422

25-
const uint8_t chunk_mask = __pgfe_build_mask(chunk_size);
23+
const uint8_t chunk_mask = __mkmask(chunk_size);
2624

27-
for (low = 0, high = chunk_size % bitsz; inp - input <= length; inp++, op++) {
25+
for (low = 0, high = chunk_size % __bitsz; inp - input <= length; inp++, op++) {
2826
if (low < high) {
29-
*op = ((*inp) >> (bitsz - high)) & chunk_mask;
27+
*op = ((*inp) >> (__bitsz - high)) & chunk_mask;
3028
inp--;
3129
}
3230
else if (!high) {
3331
*op = (*inp) & chunk_mask;
3432
}
3533
else {
36-
sz_diff = bitsz - low;
34+
sz_diff = __bitsz - low;
3735
mv_sz = chunk_size - sz_diff;
38-
*op = ((*inp) & __pgfe_build_mask(sz_diff)) << mv_sz;
36+
*op = ((*inp) & __mkmask(sz_diff)) << mv_sz;
3937
if (inp - input + 1 < length) {
40-
*op |= ((*(inp + 1)) >> (bitsz - high)) & __pgfe_build_mask(high);
38+
*op |= ((*(inp + 1)) >> (__bitsz - high)) & __mkmask(high);
4139
}
4240
}
4341

44-
low = (low + chunk_size) % bitsz;
45-
high = (high + chunk_size) % bitsz;
42+
low = (low + chunk_size) % __bitsz;
43+
high = (high + chunk_size) % __bitsz;
4644
}
4745

4846
return op - out;
@@ -75,10 +73,11 @@ size_t __pgfe_unittostr(
7573
return chunk_count;
7674
}
7775

78-
size_t __pgfe_encode_generic(
76+
size_t __pgfe_encode_base_generic(
7977
PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t input[], size_t input_length, char cs_out[]
8078
) {
81-
pgfe_encode_t input_unit[unit_size], *inp = (pgfe_encode_t *)input;
79+
pgfe_encode_t input_unit[unit_size];
80+
const pgfe_encode_t *inp = input;
8281
size_t i, remain;
8382
char *sp = cs_out;
8483

@@ -103,15 +102,14 @@ size_t __pgfe_encode_generic(
103102
return sp - cs_out;
104103
}
105104

106-
size_t __pgfe_decode_generic(
105+
size_t __pgfe_decode_base_generic(
107106
PGFE_BASE_PARAMS_DEF, pgfe_encode_t (*func)(char), const char basexx_cs[], pgfe_encode_t output[]
108107
) {
109108
pgfe_encode_t *op, ch, sig, o_unit[unit_size];
110-
const size_t sz_ou = to_bit(sizeof(pgfe_encode_t));
111-
char *sp = (char *)basexx_cs;
112-
size_t i = 0, j;
109+
const char *sp = basexx_cs;
110+
size_t i, j;
113111
uint64_t u;
114-
const uint8_t mask = __pgfe_build_mask(bit_size);
112+
const uint8_t mask = __mkmask(bit_size);
115113

116114
u = 0;
117115
op = output;
@@ -134,7 +132,7 @@ size_t __pgfe_decode_generic(
134132
}
135133

136134
for (j = 0; j < unit_size; j++) {
137-
o_unit[j] = (pgfe_encode_t)((u >> (sz_ou * (unit_size - j - 1))) & 0xFF);
135+
o_unit[j] = (pgfe_encode_t)((u >> (__bitsz * (unit_size - j - 1))) & 0xFF);
138136
}
139137

140138
memcpy(op, o_unit, unit_size);

src/c/base_encoding/base16.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ inline pgfe_encode_t pgfe_decode_base16_char(char base16_c) {
3333
}
3434

3535
inline size_t pgfe_encode_base16(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
36-
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE16), BASE16_ALPHABET, input, input_length, cs_out);
36+
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE16), BASE16_ALPHABET, input, input_length, cs_out);
3737
}
3838

3939
size_t pgfe_decode_base16(const char base16_cs[], pgfe_encode_t output[]) {
40-
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE16), pgfe_decode_base16_char, base16_cs, output);
40+
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE16), pgfe_decode_base16_char, base16_cs, output);
4141
}

src/c/base_encoding/base32.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,17 @@ inline pgfe_encode_t pgfe_decode_base32hex_char(char base32_c) {
6969
}
7070

7171
inline size_t pgfe_encode_base32(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
72-
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET, input, input_length, cs_out);
72+
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET, input, input_length, cs_out);
7373
}
7474

7575
inline size_t pgfe_encode_base32hex(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
76-
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET_EXTHEX, input, input_length, cs_out);
76+
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET_EXTHEX, input, input_length, cs_out);
7777
}
7878

7979
inline size_t pgfe_decode_base32(const char base32_cs[], pgfe_encode_t output[]) {
80-
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32_char, base32_cs, output);
80+
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32_char, base32_cs, output);
8181
}
8282

8383
inline size_t pgfe_decode_base32hex(const char base32_cs[], pgfe_encode_t output[]) {
84-
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32hex_char, base32_cs, output);
84+
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32hex_char, base32_cs, output);
8585
}

0 commit comments

Comments
 (0)