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

Commit

Permalink
Merge branch 'revision'
Browse files Browse the repository at this point in the history
  • Loading branch information
chardoncs committed Nov 11, 2022
2 parents a52f70c + 56366a2 commit 1bc5935
Show file tree
Hide file tree
Showing 20 changed files with 184 additions and 178 deletions.
25 changes: 25 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
* text=auto

# C
*.h text eol=lf
*.c text eol=lf

# C++
*.hpp text eol=lf
*.cpp text eol=lf

# Other
*.md text eol=lf
*.clang-format text eol=lf
*.mak text eol=lf
*.json text eol=lf
*.cmake text eol=lf
*.txt text eol=lf
*.py text eol=lf

*.png -text
*.jpg -text
*.jpeg -text
*.webp -text

Makefile text eol=lf
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ cmake_minimum_required(VERSION 3.16.0)
set(CMAKE_C_COMPILER clang)
set(CMAKE_CXX_COMPILER clang++)

project(libpgfe VERSION 0.6.0 LANGUAGES C CXX)
project(libpgfe
VERSION 0.5.1
DESCRIPTION "Cryptographic library"
HOMEPAGE_URL "https://github.com/chardon55/libpgfe"
LANGUAGES C CXX
)

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

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

Expand Down
4 changes: 2 additions & 2 deletions include/backend/base-encoding-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_
size_t
__pgfe_unittostr(PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t unit[], char out[], bool padding);

size_t __pgfe_encode_generic(
size_t __pgfe_encode_base_generic(
PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t input[], size_t input_length, char cs_out[]
);

size_t __pgfe_decode_generic(
size_t __pgfe_decode_base_generic(
PGFE_BASE_PARAMS_DEF, pgfe_encode_t (*func)(char), const char basexx_cs[], pgfe_encode_t output[]
);

Expand Down
9 changes: 6 additions & 3 deletions include/sequential_data.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,23 @@ class SequentialData
{
private:
seqdata_t *seq = nullptr;
size_t sz = 0, hex_sz = 0;

char *hex_str = nullptr;
size_t sz = 0, hex_sz = 0;

bool _is_str, _apstr;
bool _is_str = false, _apstr = false;

bool determine_ascii_str();

void check_range(size_t &start, size_t &length) const;

public:
SequentialData(const pgfe_encode_t *, size_t);
SequentialData(const char *);
SequentialData(std::string &);
SequentialData(const SequentialData *);
SequentialData(const SequentialData &);
SequentialData(SequentialData *, bool delete_current);

~SequentialData();

const char *to_cs() const;
Expand Down
8 changes: 4 additions & 4 deletions include/version.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
#define LIBPGFE_VERSION_H

#define LIBPGFE_MAJOR_VERSION 0
#define LIBPGFE_MINOR_VERSION 6
#define LIBPGFE_REVISION 0
#define LIBPGFE_VARIANT "rc1"
#define LIBPGFE_MINOR_VERSION 5
#define LIBPGFE_REVISION 1
#define LIBPGFE_VARIANT ""

#define LIBPGFE_VERSION "0.6.0-rc1"
#define LIBPGFE_VERSION "0.5.1"

#endif
2 changes: 1 addition & 1 deletion metadata.mak
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
PROJECT := libpgfe
VERSION := 0.6.0-rc1
VERSION := 0.5.1

BUILD_DIR := build

Expand Down
2 changes: 1 addition & 1 deletion project.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"name": "libpgfe",
"version": "0.6.0-rc1"
"version": "0.5.1"
}
42 changes: 20 additions & 22 deletions src/c/base_encoding/base-encoding-internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,36 @@

#include "backend/generic-internal.h"

uint8_t __pgfe_build_mask(uint8_t digit_c);
#define __bitsz 8

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

size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_t chunk_size, pgfe_encode_t out[]) {
const uint16_t bitsz = to_bit(sizeof(pgfe_encode_t));
pgfe_encode_t *inp = (pgfe_encode_t *)input, *op = out;
const pgfe_encode_t *inp = input;
pgfe_encode_t *op = out;
size_t low, high, mv_sz, sz_diff;

const uint8_t chunk_mask = __pgfe_build_mask(chunk_size);
const uint8_t chunk_mask = __mkmask(chunk_size);

for (low = 0, high = chunk_size % bitsz; inp - input <= length; inp++, op++) {
for (low = 0, high = chunk_size % __bitsz; inp - input <= length; inp++, op++) {
if (low < high) {
*op = ((*inp) >> (bitsz - high)) & chunk_mask;
*op = ((*inp) >> (__bitsz - high)) & chunk_mask;
inp--;
}
else if (!high) {
*op = (*inp) & chunk_mask;
}
else {
sz_diff = bitsz - low;
sz_diff = __bitsz - low;
mv_sz = chunk_size - sz_diff;
*op = ((*inp) & __pgfe_build_mask(sz_diff)) << mv_sz;
*op = ((*inp) & __mkmask(sz_diff)) << mv_sz;
if (inp - input + 1 < length) {
*op |= ((*(inp + 1)) >> (bitsz - high)) & __pgfe_build_mask(high);
*op |= ((*(inp + 1)) >> (__bitsz - high)) & __mkmask(high);
}
}

low = (low + chunk_size) % bitsz;
high = (high + chunk_size) % bitsz;
low = (low + chunk_size) % __bitsz;
high = (high + chunk_size) % __bitsz;
}

return op - out;
Expand Down Expand Up @@ -75,10 +73,11 @@ size_t __pgfe_unittostr(
return chunk_count;
}

size_t __pgfe_encode_generic(
size_t __pgfe_encode_base_generic(
PGFE_BASE_PARAMS_DEF, const char alphabet[], const pgfe_encode_t input[], size_t input_length, char cs_out[]
) {
pgfe_encode_t input_unit[unit_size], *inp = (pgfe_encode_t *)input;
pgfe_encode_t input_unit[unit_size];
const pgfe_encode_t *inp = input;
size_t i, remain;
char *sp = cs_out;

Expand All @@ -103,15 +102,14 @@ size_t __pgfe_encode_generic(
return sp - cs_out;
}

size_t __pgfe_decode_generic(
size_t __pgfe_decode_base_generic(
PGFE_BASE_PARAMS_DEF, pgfe_encode_t (*func)(char), const char basexx_cs[], pgfe_encode_t output[]
) {
pgfe_encode_t *op, ch, sig, o_unit[unit_size];
const size_t sz_ou = to_bit(sizeof(pgfe_encode_t));
char *sp = (char *)basexx_cs;
size_t i = 0, j;
const char *sp = basexx_cs;
size_t i, j;
uint64_t u;
const uint8_t mask = __pgfe_build_mask(bit_size);
const uint8_t mask = __mkmask(bit_size);

u = 0;
op = output;
Expand All @@ -134,7 +132,7 @@ size_t __pgfe_decode_generic(
}

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

memcpy(op, o_unit, unit_size);
Expand Down
4 changes: 2 additions & 2 deletions src/c/base_encoding/base16.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ inline pgfe_encode_t pgfe_decode_base16_char(char base16_c) {
}

inline size_t pgfe_encode_base16(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE16), BASE16_ALPHABET, input, input_length, cs_out);
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE16), BASE16_ALPHABET, input, input_length, cs_out);
}

size_t pgfe_decode_base16(const char base16_cs[], pgfe_encode_t output[]) {
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE16), pgfe_decode_base16_char, base16_cs, output);
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE16), pgfe_decode_base16_char, base16_cs, output);
}
8 changes: 4 additions & 4 deletions src/c/base_encoding/base32.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,17 @@ inline pgfe_encode_t pgfe_decode_base32hex_char(char base32_c) {
}

inline size_t pgfe_encode_base32(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET, input, input_length, cs_out);
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET, input, input_length, cs_out);
}

inline size_t pgfe_encode_base32hex(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET_EXTHEX, input, input_length, cs_out);
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE32), BASE32_ALPHABET_EXTHEX, input, input_length, cs_out);
}

inline size_t pgfe_decode_base32(const char base32_cs[], pgfe_encode_t output[]) {
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32_char, base32_cs, output);
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32_char, base32_cs, output);
}

inline size_t pgfe_decode_base32hex(const char base32_cs[], pgfe_encode_t output[]) {
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32hex_char, base32_cs, output);
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE32), pgfe_decode_base32hex_char, base32_cs, output);
}
6 changes: 3 additions & 3 deletions src/c/base_encoding/base64.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ inline pgfe_encode_t pgfe_decode_base64_char(char base64_c) {
}

inline size_t pgfe_encode_base64(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET, input, input_length, cs_out);
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET, input, input_length, cs_out);
}

inline size_t pgfe_encode_base64_url(const pgfe_encode_t input[], size_t input_length, char cs_out[]) {
return __pgfe_encode_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET_FS, input, input_length, cs_out);
return __pgfe_encode_base_generic(PGFE_BASE_PARAMS(BASE64), BASE64_ALPHABET_FS, input, input_length, cs_out);
}

inline size_t pgfe_decode_base64(const char base64_cs[], pgfe_encode_t output[]) {
return __pgfe_decode_generic(PGFE_BASE_PARAMS(BASE64), pgfe_decode_base64_char, base64_cs, output);
return __pgfe_decode_base_generic(PGFE_BASE_PARAMS(BASE64), pgfe_decode_base64_char, base64_cs, output);
}
25 changes: 15 additions & 10 deletions src/c/hash/keccak-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,21 @@
#include <stdlib.h>
#include <string.h>

const uint16_t _r[24] = {1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44};

const uint64_t _RC[24] = {0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 0x8000000080008000,
0x000000000000808b, 0x0000000080000001, 0x8000000080008081, 0x8000000000008009,
0x000000000000008a, 0x0000000000000088, 0x0000000080008009, 0x000000008000000a,
0x000000008000808b, 0x800000000000008b, 0x8000000000008089, 0x8000000000008003,
0x8000000000008002, 0x8000000000000080, 0x000000000000800a, 0x800000008000000a,
0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008};

const uint16_t _piln[24] = {10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1};
static const uint16_t _r[24] = {
1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 2, 14, 27, 41, 56, 8, 25, 43, 62, 18, 39, 61, 20, 44,
};

static const uint64_t _RC[24] = {
0x0000000000000001, 0x0000000000008082, 0x800000000000808a, 0x8000000080008000, 0x000000000000808b,
0x0000000080000001, 0x8000000080008081, 0x8000000000008009, 0x000000000000008a, 0x0000000000000088,
0x0000000080008009, 0x000000008000000a, 0x000000008000808b, 0x800000000000008b, 0x8000000000008089,
0x8000000000008003, 0x8000000000008002, 0x8000000000000080, 0x000000000000800a, 0x800000008000000a,
0x8000000080008081, 0x8000000000008080, 0x0000000080000001, 0x8000000080008008,
};

static const uint16_t _piln[24] = {
10, 7, 11, 17, 18, 3, 5, 16, 8, 21, 24, 4, 15, 23, 19, 13, 12, 2, 20, 14, 22, 9, 6, 1,
};

void transform(pgfe_keccak_bitcube_t A, uint64_t RC) {
pgfe_keccak_lane_t C[5];
Expand Down
Loading

0 comments on commit 1bc5935

Please sign in to comment.