From 3d6280ede44d6e3df062bf21a8207cf3145af95e Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 2 Nov 2022 23:13:38 +0800 Subject: [PATCH 01/14] Add .gitattributes --- .gitattributes | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .gitattributes diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 0000000..5ee79ac --- /dev/null +++ b/.gitattributes @@ -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 +*.text text eol=lf +*.py text eol=lf + +*.png -text +*.jpg -text +*.jpeg -text +*.webp -text + +Makefile text eol=lf \ No newline at end of file From 2807ca2ec5488cf7fa5bdb2dd0b862b605bbffe3 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Wed, 2 Nov 2022 23:15:22 +0800 Subject: [PATCH 02/14] Update .gitattributes --- .gitattributes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitattributes b/.gitattributes index 5ee79ac..a340ac7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -14,7 +14,7 @@ *.mak text eol=lf *.json text eol=lf *.cmake text eol=lf -*.text text eol=lf +*.txt text eol=lf *.py text eol=lf *.png -text From 3c7dbe177d59bbb64696cba5a4336fbf622a947f Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sat, 5 Nov 2022 20:35:18 +0800 Subject: [PATCH 03/14] Add features --- include/sequential_data.hpp | 9 ++++++--- src/cpp/sequential_data.cpp | 21 ++++++++++++++++----- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/include/sequential_data.hpp b/include/sequential_data.hpp index 90829f5..23f29f1 100644 --- a/include/sequential_data.hpp +++ b/include/sequential_data.hpp @@ -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; diff --git a/src/cpp/sequential_data.cpp b/src/cpp/sequential_data.cpp index b030668..1043705 100644 --- a/src/cpp/sequential_data.cpp +++ b/src/cpp/sequential_data.cpp @@ -8,6 +8,7 @@ #include "sequential_data.hpp" #include +#include using namespace chardon55::PGFE; @@ -34,6 +35,8 @@ SequentialData::SequentialData(std::string &cpp_s) SequentialData::SequentialData(const SequentialData *sd) : SequentialData((const pgfe_encode_t *)sd->seq, sd->sz) {} +SequentialData::SequentialData(const SequentialData &sd) : SequentialData(&sd) {} + SequentialData::SequentialData(SequentialData *sd, bool delete_current) : SequentialData((const pgfe_encode_t *)sd->seq, sd->sz) { if (delete_current) { @@ -72,7 +75,7 @@ std::string SequentialData::to_hex_str() const { } const pgfe_encode_t *SequentialData::to_pgfe_seq() const { - return seq; + return (const pgfe_encode_t *)seq; } const pgfe_encode_t *SequentialData::to_pgfe_seq(size_t &length_out) const { @@ -102,16 +105,24 @@ bool SequentialData::determine_ascii_str() { return true; } +inline void SequentialData::check_range(size_t &start, size_t &length) const { + if (start >= sz) { + throw new std::out_of_range("Parameter 'start' is larger than the size"); + } + + if (length > sz - start) { + length = sz - start; + } +} + SequentialData *SequentialData::truncate(size_t start, size_t length) const { + check_range(start, length); return new SequentialData(&seq[start], length); } SequentialData *SequentialData::truncate(size_t start, size_t length, bool inplace) { if (inplace) { - if (start) { - memcpy(seq, seq + start, length); - } - + check_range(start, length); memset(seq + length, 0, sz - length); sz = length; return nullptr; From 8178c012dd69fa3e37d0e0b7b884c114413ca8c9 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sat, 5 Nov 2022 20:54:25 +0800 Subject: [PATCH 04/14] Update constant types --- src/c/hash/keccak-backend.c | 25 +++++++++++++++---------- src/c/hash/sha1.c | 9 ++------- src/c/hash/sha2-backend.c | 3 ++- src/c/hash/sha224.c | 5 +++-- src/c/hash/sha256.c | 5 +++-- src/c/hash/sha384.c | 2 +- src/c/hash/sha512.c | 6 +++--- 7 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/c/hash/keccak-backend.c b/src/c/hash/keccak-backend.c index 4134b3c..ffc44fc 100644 --- a/src/c/hash/keccak-backend.c +++ b/src/c/hash/keccak-backend.c @@ -10,16 +10,21 @@ #include #include -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]; diff --git a/src/c/hash/sha1.c b/src/c/hash/sha1.c index fe13d7c..cebe2bc 100644 --- a/src/c/hash/sha1.c +++ b/src/c/hash/sha1.c @@ -11,7 +11,7 @@ #include "backend/sha-internal.h" #include "backend/templates.h" -const pgfe_word_t __pgfe_sha1_H0[] = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0}; +static const pgfe_word_t __pgfe_sha1_H0[] = {0x67452301, 0xEFCDAB89, 0x98BADCFE, 0x10325476, 0xC3D2E1F0}; __PGFE_FRONTEND_GEN2(sha1) __PGFE_FRONTEND_DEFAULT_GEN2(sha1, SHA1) @@ -22,12 +22,7 @@ __PGFE_SHA_DIGEST(sha1, SHA1) void __pgfe_sha1_process_block(struct pgfe_sha1_ctx *ctx) { // Constants in SHA1 - static const pgfe_word_t K[] = { - 0x5A827999, - 0x6ED9EBA1, - 0x8F1BBCDC, - 0xCA62C1D6, - }; + static const pgfe_word_t K[] = {0x5A827999, 0x6ED9EBA1, 0x8F1BBCDC, 0xCA62C1D6}; uint8_t i, ix4; pgfe_word_t tmp, ws[80], A, B, C, D, E; diff --git a/src/c/hash/sha2-backend.c b/src/c/hash/sha2-backend.c index 8c8d42f..9d0f0e0 100644 --- a/src/c/hash/sha2-backend.c +++ b/src/c/hash/sha2-backend.c @@ -23,7 +23,8 @@ void __pgfe_sha256_process_block(struct pgfe_sha256_ctx *ctx) { 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85, 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070, 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3, - 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2}; + 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2, + }; size_t i, ix4; pgfe_word_t tmp1, tmp2, ws[PGFE_SHA256_BLOCK_SIZE], A, B, C, D, E, F, G, H; diff --git a/src/c/hash/sha224.c b/src/c/hash/sha224.c index e1d4cde..7a092de 100644 --- a/src/c/hash/sha224.c +++ b/src/c/hash/sha224.c @@ -10,8 +10,9 @@ #include "backend/sha2-backend.h" #include "backend/templates.h" -const pgfe_word_t __pgfe_sha224_H0[] = {0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, - 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4}; +static const pgfe_word_t __pgfe_sha224_H0[] = { + 0xC1059ED8, 0x367CD507, 0x3070DD17, 0xF70E5939, 0xFFC00B31, 0x68581511, 0x64F98FA7, 0xBEFA4FA4, +}; __PGFE_FRONTEND_GEN2(sha224) __PGFE_FRONTEND_DEFAULT_GEN2(sha224, SHA224) diff --git a/src/c/hash/sha256.c b/src/c/hash/sha256.c index 27f35af..1ca2258 100644 --- a/src/c/hash/sha256.c +++ b/src/c/hash/sha256.c @@ -10,8 +10,9 @@ #include "backend/sha2-backend.h" #include "backend/templates.h" -const pgfe_word_t __pgfe_sha256_H0[] = {0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, - 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19}; +static const pgfe_word_t __pgfe_sha256_H0[] = { + 0x6A09E667, 0xBB67AE85, 0x3C6EF372, 0xA54FF53A, 0x510E527F, 0x9B05688C, 0x1F83D9AB, 0x5BE0CD19, +}; __PGFE_FRONTEND_GEN2(sha256) __PGFE_FRONTEND_DEFAULT_GEN2(sha256, SHA256) diff --git a/src/c/hash/sha384.c b/src/c/hash/sha384.c index 41db829..86e0481 100644 --- a/src/c/hash/sha384.c +++ b/src/c/hash/sha384.c @@ -10,7 +10,7 @@ #include "backend/sha2-backend.h" #include "backend/templates.h" -const pgfe_word_t __pgfe_sha384_H0[] = { +static const pgfe_word_t __pgfe_sha384_H0[] = { 0xC1059ED8, 0xCBBB9D5D, 0x367CD507, 0x629A292A, 0x3070DD17, 0x9159015A, 0xF70E5939, 0x152FECD8, 0xFFC00B31, 0x67332667, 0x68581511, 0x8EB44A87, 0x64F98FA7, 0xDB0C2E0D, 0xBEFA4FA4, 0x47B5481D, }; diff --git a/src/c/hash/sha512.c b/src/c/hash/sha512.c index 2e80ddf..e3ae3a5 100644 --- a/src/c/hash/sha512.c +++ b/src/c/hash/sha512.c @@ -10,17 +10,17 @@ #include "backend/sha2-backend.h" #include "backend/templates.h" -const pgfe_word_t __pgfe_sha512_H0[] = { +static const pgfe_word_t __pgfe_sha512_H0[] = { 0xF3BCC908, 0x6A09E667, 0x84CAA73B, 0xBB67AE85, 0xFE94F82B, 0x3C6EF372, 0x5F1D36F1, 0xA54FF53A, 0xADE682D1, 0x510E527F, 0x2B3E6C1F, 0x9B05688C, 0xFB41BD6B, 0x1F83D9AB, 0x137E2179, 0x5BE0CD19, }; -const pgfe_word_t __pgfe_sha512_224_H0[] = { +static const pgfe_word_t __pgfe_sha512_224_H0[] = { 0x19544DA2, 0x8C3D37C8, 0x89DCD4D6, 0x73E19966, 0x32FF9C82, 0x1DFAB7AE, 0x582F9FCF, 0x679DD514, 0x7BD44DA8, 0x0F6D2B69, 0x04C48942, 0x77E36F73, 0x6A1D36C8, 0x3F9D85A8, 0x91D692A1, 0x1112E6AD, }; -const pgfe_word_t __pgfe_sha512_256_H0[] = { +static const pgfe_word_t __pgfe_sha512_256_H0[] = { 0xFC2BF72C, 0x22312194, 0xC84C64C2, 0x9F555FA3, 0x6F53B151, 0x2393B86B, 0x5940EABD, 0x96387719, 0xA88EFFE3, 0x96283EE2, 0x53863992, 0xBE5E1E25, 0x2C85B8AA, 0x2B0199FC, 0x81C52CA2, 0x0EB72DDC, }; From 4aea7cd223b98c9dcef448891914d91b30340048 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Sat, 5 Nov 2022 22:12:17 +0800 Subject: [PATCH 05/14] Refactor MD5 --- src/c/hash/md5-backend.c | 172 ++++++++++++++++----------------------- 1 file changed, 69 insertions(+), 103 deletions(-) diff --git a/src/c/hash/md5-backend.c b/src/c/hash/md5-backend.c index 2e32304..33e4a6d 100644 --- a/src/c/hash/md5-backend.c +++ b/src/c/hash/md5-backend.c @@ -9,23 +9,6 @@ #include -#define S11 7 -#define S12 12 -#define S13 17 -#define S14 22 -#define S21 5 -#define S22 9 -#define S23 14 -#define S24 20 -#define S31 4 -#define S32 11 -#define S33 16 -#define S34 23 -#define S41 6 -#define S42 10 -#define S43 15 -#define S44 21 - #define F(x, y, z) (((x) & (y)) | ((~x) & (z))) #define G(x, y, z) (((x) & (z)) | ((y) & (~z))) #define H(x, y, z) ((x) ^ (y) ^ (z)) @@ -33,10 +16,56 @@ #define _ROUND_TRAN(a, apl, b, x, s, ac) ((a) += (apl) + (x) + (uint32_t)(ac), (a) = clshift((a), (s)), (a) += (b)) -#define FF(a, b, c, d, x, s, ac) _ROUND_TRAN(a, F((b), (c), (d)), b, x, s, ac) -#define GG(a, b, c, d, x, s, ac) _ROUND_TRAN(a, G((b), (c), (d)), b, x, s, ac) -#define HH(a, b, c, d, x, s, ac) _ROUND_TRAN(a, H((b), (c), (d)), b, x, s, ac) -#define II(a, b, c, d, x, s, ac) _ROUND_TRAN(a, I((b), (c), (d)), b, x, s, ac) +#define _O(i, offset, limit) (((i) + (offset)) % (limit)) + +static const uint8_t __S[4][4] = { + {7, 12, 17, 22}, + {5, 9, 14, 20}, + {4, 11, 16, 23}, + {6, 10, 15, 21}, +}; + +static const uint8_t __idx[4][16] = { + {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}, + {1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12}, + {5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2 }, + {0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9 }, +}; + +static const uint32_t __ac[4][16] = { + {0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee, 0xf57c0faf, 0x4787c62a, 0xa8304613, 0xfd469501, 0x698098d8, + 0x8b44f7af, 0xffff5bb1, 0x895cd7be, 0x6b901122, 0xfd987193, 0xa679438e, 0x49b40821}, + {0xf61e2562, 0xc040b340, 0x265e5a51, 0xe9b6c7aa, 0xd62f105d, 0x2441453, 0xd8a1e681, 0xe7d3fbc8, 0x21e1cde6, + 0xc33707d6, 0xf4d50d87, 0x455a14ed, 0xa9e3e905, 0xfcefa3f8, 0x676f02d9, 0x8d2a4c8a}, + {0xfffa3942, 0x8771f681, 0x6d9d6122, 0xfde5380c, 0xa4beea44, 0x4bdecfa9, 0xf6bb4b60, 0xbebfbc70, 0x289b7ec6, + 0xeaa127fa, 0xd4ef3085, 0x4881d05, 0xd9d4d039, 0xe6db99e5, 0x1fa27cf8, 0xc4ac5665}, + {0xf4292244, 0x432aff97, 0xab9423a7, 0xfc93a039, 0x655b59c3, 0x8f0ccc92, 0xffeff47d, 0x85845dd1, 0x6fa87e4f, + 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391}, +}; + +void __F( + uint8_t r, pgfe_word_t *a, pgfe_word_t b, pgfe_word_t c, pgfe_word_t d, pgfe_word_t x, uint8_t s, uint32_t ac +) { + switch (r) { + case 0: + _ROUND_TRAN(*a, F(b, c, d), b, x, s, ac); + break; + case 1: + _ROUND_TRAN(*a, G(b, c, d), b, x, s, ac); + break; + + case 2: + _ROUND_TRAN(*a, H(b, c, d), b, x, s, ac); + break; + + case 3: + _ROUND_TRAN(*a, I(b, c, d), b, x, s, ac); + break; + + default: + break; + } +} void __pgfe_md5_decode(const pgfe_encode_t input[], size_t length, pgfe_word_t output[]) { size_t i, ix4; @@ -61,93 +90,30 @@ void __pgfe_md5_encode(pgfe_word_t input[], size_t length, pgfe_encode_t output[ } void __pgfe_md5_transform(pgfe_word_t state[4], const pgfe_encode_t block[64]) { - pgfe_word_t a, b, c, d, x[16]; + pgfe_word_t x[16], buf[4]; + uint16_t r, i; - a = state[0]; - b = state[1]; - c = state[2]; - d = state[3]; + buf[3] = state[0]; + buf[2] = state[1]; + buf[1] = state[2]; + buf[0] = state[3]; __pgfe_md5_decode(block, 64, x); - // Round 1 - FF(a, b, c, d, x[0], S11, 0xd76aa478); // 1 - FF(d, a, b, c, x[1], S12, 0xe8c7b756); // 2 - FF(c, d, a, b, x[2], S13, 0x242070db); // 3 - FF(b, c, d, a, x[3], S14, 0xc1bdceee); // 4 - FF(a, b, c, d, x[4], S11, 0xf57c0faf); // 5 - FF(d, a, b, c, x[5], S12, 0x4787c62a); // 6 - FF(c, d, a, b, x[6], S13, 0xa8304613); // 7 - FF(b, c, d, a, x[7], S14, 0xfd469501); // 8 - FF(a, b, c, d, x[8], S11, 0x698098d8); // 9 - FF(d, a, b, c, x[9], S12, 0x8b44f7af); // 10 - FF(c, d, a, b, x[10], S13, 0xffff5bb1); // 11 - FF(b, c, d, a, x[11], S14, 0x895cd7be); // 12 - FF(a, b, c, d, x[12], S11, 0x6b901122); // 13 - FF(d, a, b, c, x[13], S12, 0xfd987193); // 14 - FF(c, d, a, b, x[14], S13, 0xa679438e); // 15 - FF(b, c, d, a, x[15], S14, 0x49b40821); // 16 - - // Round 2 - GG(a, b, c, d, x[1], S21, 0xf61e2562); // 17 - GG(d, a, b, c, x[6], S22, 0xc040b340); // 18 - GG(c, d, a, b, x[11], S23, 0x265e5a51); // 19 - GG(b, c, d, a, x[0], S24, 0xe9b6c7aa); // 20 - GG(a, b, c, d, x[5], S21, 0xd62f105d); // 21 - GG(d, a, b, c, x[10], S22, 0x2441453); // 22 - GG(c, d, a, b, x[15], S23, 0xd8a1e681); // 23 - GG(b, c, d, a, x[4], S24, 0xe7d3fbc8); // 24 - GG(a, b, c, d, x[9], S21, 0x21e1cde6); // 25 - GG(d, a, b, c, x[14], S22, 0xc33707d6); // 26 - GG(c, d, a, b, x[3], S23, 0xf4d50d87); // 27 - GG(b, c, d, a, x[8], S24, 0x455a14ed); // 28 - GG(a, b, c, d, x[13], S21, 0xa9e3e905); // 29 - GG(d, a, b, c, x[2], S22, 0xfcefa3f8); // 30 - GG(c, d, a, b, x[7], S23, 0x676f02d9); // 31 - GG(b, c, d, a, x[12], S24, 0x8d2a4c8a); // 32 - - // Round 3 - HH(a, b, c, d, x[5], S31, 0xfffa3942); // 33 - HH(d, a, b, c, x[8], S32, 0x8771f681); // 34 - HH(c, d, a, b, x[11], S33, 0x6d9d6122); // 35 - HH(b, c, d, a, x[14], S34, 0xfde5380c); // 36 - HH(a, b, c, d, x[1], S31, 0xa4beea44); // 37 - HH(d, a, b, c, x[4], S32, 0x4bdecfa9); // 38 - HH(c, d, a, b, x[7], S33, 0xf6bb4b60); // 39 - HH(b, c, d, a, x[10], S34, 0xbebfbc70); // 40 - HH(a, b, c, d, x[13], S31, 0x289b7ec6); // 41 - HH(d, a, b, c, x[0], S32, 0xeaa127fa); // 42 - HH(c, d, a, b, x[3], S33, 0xd4ef3085); // 43 - HH(b, c, d, a, x[6], S34, 0x4881d05); // 44 - HH(a, b, c, d, x[9], S31, 0xd9d4d039); // 45 - HH(d, a, b, c, x[12], S32, 0xe6db99e5); // 46 - HH(c, d, a, b, x[15], S33, 0x1fa27cf8); // 47 - HH(b, c, d, a, x[2], S34, 0xc4ac5665); // 48 - - // Round 4 - II(a, b, c, d, x[0], S41, 0xf4292244); // 49 - II(d, a, b, c, x[7], S42, 0x432aff97); // 50 - II(c, d, a, b, x[14], S43, 0xab9423a7); // 51 - II(b, c, d, a, x[5], S44, 0xfc93a039); // 52 - II(a, b, c, d, x[12], S41, 0x655b59c3); // 53 - II(d, a, b, c, x[3], S42, 0x8f0ccc92); // 54 - II(c, d, a, b, x[10], S43, 0xffeff47d); // 55 - II(b, c, d, a, x[1], S44, 0x85845dd1); // 56 - II(a, b, c, d, x[8], S41, 0x6fa87e4f); // 57 - II(d, a, b, c, x[15], S42, 0xfe2ce6e0); // 58 - II(c, d, a, b, x[6], S43, 0xa3014314); // 59 - II(b, c, d, a, x[13], S44, 0x4e0811a1); // 60 - II(a, b, c, d, x[4], S41, 0xf7537e82); // 61 - II(d, a, b, c, x[11], S42, 0xbd3af235); // 62 - II(c, d, a, b, x[2], S43, 0x2ad7d2bb); // 63 - II(b, c, d, a, x[9], S44, 0xeb86d391); // 64 - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; + // Round 1 - 4 + for (r = 0; r < 4; r++) { + for (i = 0; i < 16; i++) { + __F(r, &buf[_O(i, 3, 4)], buf[_O(i, 2, 4)], buf[_O(i, 1, 4)], buf[_O(i, 0, 4)], x[__idx[r][i]], + __S[r][i % 4], __ac[r][i]); + } + } + + state[0] += buf[3]; + state[1] += buf[2]; + state[2] += buf[1]; + state[3] += buf[0]; // Wipe sensitive data from the RAM memset(x, 0, sizeof(x)); - a = b = c = d = 0; + memset(buf, 0, 16); } \ No newline at end of file From fc961d45b0e02a3cca751b9dad39fd1221f48f6b Mon Sep 17 00:00:00 2001 From: chardon55 Date: Tue, 8 Nov 2022 17:54:11 +0800 Subject: [PATCH 06/14] Refactor MD5 implementation --- src/c/hash/md5-backend.c | 58 +++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/src/c/hash/md5-backend.c b/src/c/hash/md5-backend.c index 33e4a6d..27abeb6 100644 --- a/src/c/hash/md5-backend.c +++ b/src/c/hash/md5-backend.c @@ -43,29 +43,23 @@ static const uint32_t __ac[4][16] = { 0xfe2ce6e0, 0xa3014314, 0x4e0811a1, 0xf7537e82, 0xbd3af235, 0x2ad7d2bb, 0xeb86d391}, }; -void __F( - uint8_t r, pgfe_word_t *a, pgfe_word_t b, pgfe_word_t c, pgfe_word_t d, pgfe_word_t x, uint8_t s, uint32_t ac -) { - switch (r) { - case 0: - _ROUND_TRAN(*a, F(b, c, d), b, x, s, ac); - break; - case 1: - _ROUND_TRAN(*a, G(b, c, d), b, x, s, ac); - break; - - case 2: - _ROUND_TRAN(*a, H(b, c, d), b, x, s, ac); - break; - - case 3: - _ROUND_TRAN(*a, I(b, c, d), b, x, s, ac); - break; - - default: - break; +#define __F(r, a, b, c, d, x, s, ac) \ + switch (r) { \ + case 0: \ + _ROUND_TRAN((a), F((b), (c), (d)), (b), (x), (s), (ac)); \ + break; \ + case 1: \ + _ROUND_TRAN((a), G((b), (c), (d)), (b), (x), (s), (ac)); \ + break; \ + case 2: \ + _ROUND_TRAN((a), H((b), (c), (d)), (b), (x), (s), (ac)); \ + break; \ + case 3: \ + _ROUND_TRAN((a), I((b), (c), (d)), (b), (x), (s), (ac)); \ + break; \ + default: \ + break; \ } -} void __pgfe_md5_decode(const pgfe_encode_t input[], size_t length, pgfe_word_t output[]) { size_t i, ix4; @@ -93,25 +87,27 @@ void __pgfe_md5_transform(pgfe_word_t state[4], const pgfe_encode_t block[64]) { pgfe_word_t x[16], buf[4]; uint16_t r, i; - buf[3] = state[0]; - buf[2] = state[1]; - buf[1] = state[2]; - buf[0] = state[3]; + // Copy to the buffer reversely + buf[3] = state[0]; // a + buf[2] = state[1]; // b + buf[1] = state[2]; // c + buf[0] = state[3]; // d __pgfe_md5_decode(block, 64, x); // Round 1 - 4 for (r = 0; r < 4; r++) { for (i = 0; i < 16; i++) { - __F(r, &buf[_O(i, 3, 4)], buf[_O(i, 2, 4)], buf[_O(i, 1, 4)], buf[_O(i, 0, 4)], x[__idx[r][i]], + __F(r, buf[_O(i, 3, 4)], buf[_O(i, 2, 4)], buf[_O(i, 1, 4)], buf[_O(i, 0, 4)], x[__idx[r][i]], __S[r][i % 4], __ac[r][i]); } } - state[0] += buf[3]; - state[1] += buf[2]; - state[2] += buf[1]; - state[3] += buf[0]; + // Add back + state[0] += buf[3]; // a + state[1] += buf[2]; // b + state[2] += buf[1]; // c + state[3] += buf[0]; // d // Wipe sensitive data from the RAM memset(x, 0, sizeof(x)); From 2eff831eb544830ac84a77e126977f2937b83e57 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Tue, 8 Nov 2022 18:17:06 +0800 Subject: [PATCH 07/14] Update CMakeLists.txt --- CMakeLists.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a630ec..9d560df 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -52,7 +52,6 @@ add_executable(pgfetestcpp ${test_dir}/test.cpp) # add_executable(totptestcpp ${test_dir}/totptest.cpp) target_include_directories(pgfe PRIVATE - ${src_dir} ${include_dir} ) From c34209c96e2ed30dd8d82a77d8fee4a874cc4d3a Mon Sep 17 00:00:00 2001 From: chardon55 Date: Tue, 8 Nov 2022 18:32:36 +0800 Subject: [PATCH 08/14] Update CMakeLists.txt --- CMakeLists.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9d560df..11e120d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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.6.0 + DESCRIPTION "Cryptographic library" + HOMEPAGE_URL "https://github.com/chardon55/libpgfe" + LANGUAGES C CXX +) set(CMAKE_C_STANDARD 11) set(CMAKE_CXX_STANDARD 14) From ff3fb1c84039e3bfc239ada4e0369b5849ba7f11 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Fri, 11 Nov 2022 11:03:31 +0800 Subject: [PATCH 09/14] Refactor generic base --- src/c/base_encoding/base-encoding-internal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/c/base_encoding/base-encoding-internal.c b/src/c/base_encoding/base-encoding-internal.c index 12880ea..16c58a6 100644 --- a/src/c/base_encoding/base-encoding-internal.c +++ b/src/c/base_encoding/base-encoding-internal.c @@ -18,8 +18,9 @@ inline uint8_t __pgfe_build_mask(uint8_t digit_c) { } 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; + static const uint16_t bitsz = to_bit(sizeof(pgfe_encode_t)); + 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); From 932d21d2552c1f5851f317e638b6ac8950b58802 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Fri, 11 Nov 2022 11:07:20 +0800 Subject: [PATCH 10/14] Refactoring --- src/c/base_encoding/base-encoding-internal.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/c/base_encoding/base-encoding-internal.c b/src/c/base_encoding/base-encoding-internal.c index 16c58a6..96e9f4e 100644 --- a/src/c/base_encoding/base-encoding-internal.c +++ b/src/c/base_encoding/base-encoding-internal.c @@ -11,11 +11,7 @@ #include "backend/generic-internal.h" -uint8_t __pgfe_build_mask(uint8_t digit_c); - -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 >> (8 - (digit))) size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_t chunk_size, pgfe_encode_t out[]) { static const uint16_t bitsz = to_bit(sizeof(pgfe_encode_t)); @@ -23,7 +19,7 @@ size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_ 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++) { if (low < high) { @@ -36,9 +32,9 @@ size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_ else { 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); } } @@ -112,7 +108,7 @@ size_t __pgfe_decode_generic( char *sp = (char *)basexx_cs; size_t i = 0, j; uint64_t u; - const uint8_t mask = __pgfe_build_mask(bit_size); + const uint8_t mask = __mkmask(bit_size); u = 0; op = output; From d34fe729b92046ba7d82bf485abb4f3b74b67089 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Fri, 11 Nov 2022 11:08:36 +0800 Subject: [PATCH 11/14] Refactoring --- src/c/base_encoding/base-encoding-internal.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/c/base_encoding/base-encoding-internal.c b/src/c/base_encoding/base-encoding-internal.c index 96e9f4e..a60968a 100644 --- a/src/c/base_encoding/base-encoding-internal.c +++ b/src/c/base_encoding/base-encoding-internal.c @@ -13,33 +13,34 @@ #define __mkmask(digit) (UINT8_MAX >> (8 - (digit))) +#define __bitsz 8 + size_t __pgfe_transform_codes(const pgfe_encode_t input[], size_t length, uint8_t chunk_size, pgfe_encode_t out[]) { - static const uint16_t bitsz = to_bit(sizeof(pgfe_encode_t)); const pgfe_encode_t *inp = input; pgfe_encode_t *op = out; size_t low, high, mv_sz, sz_diff; 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) & __mkmask(sz_diff)) << mv_sz; if (inp - input + 1 < length) { - *op |= ((*(inp + 1)) >> (bitsz - high)) & __mkmask(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; From ebfefe4918d026862ed4638e3f67503b71a9a341 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Fri, 11 Nov 2022 11:09:17 +0800 Subject: [PATCH 12/14] Refactoring --- src/c/base_encoding/base-encoding-internal.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/c/base_encoding/base-encoding-internal.c b/src/c/base_encoding/base-encoding-internal.c index a60968a..f0d6912 100644 --- a/src/c/base_encoding/base-encoding-internal.c +++ b/src/c/base_encoding/base-encoding-internal.c @@ -11,10 +11,10 @@ #include "backend/generic-internal.h" -#define __mkmask(digit) (UINT8_MAX >> (8 - (digit))) - #define __bitsz 8 +#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 pgfe_encode_t *inp = input; pgfe_encode_t *op = out; From 7aa26785d3388483d59abce1c95a3e7e894d9897 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Fri, 11 Nov 2022 11:14:28 +0800 Subject: [PATCH 13/14] Update version --- CMakeLists.txt | 2 +- include/version.h | 13 +++---------- metadata.mak | 2 +- project.json | 2 +- 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11e120d..b28f5d7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,7 +4,7 @@ set(CMAKE_C_COMPILER clang) set(CMAKE_CXX_COMPILER clang++) project(libpgfe - VERSION 0.6.0 + VERSION 0.5.1 DESCRIPTION "Cryptographic library" HOMEPAGE_URL "https://github.com/chardon55/libpgfe" LANGUAGES C CXX diff --git a/include/version.h b/include/version.h index 0023b03..054232b 100644 --- a/include/version.h +++ b/include/version.h @@ -1,18 +1,11 @@ -/* - libpgfe - version.h - - Copyright (c) 2022 Charles Dong -*/ - #ifndef LIBPGFE_VERSION_H #define LIBPGFE_VERSION_H #define LIBPGFE_MAJOR_VERSION 0 -#define LIBPGFE_MINOR_VERSION 6 -#define LIBPGFE_REVISION 0 +#define LIBPGFE_MINOR_VERSION 5 +#define LIBPGFE_REVISION 1 #define LIBPGFE_VARIANT "dev" -#define LIBPGFE_VERSION "0.6.0-dev" +#define LIBPGFE_VERSION "0.5.1-dev" #endif diff --git a/metadata.mak b/metadata.mak index c7f35a1..3d62a60 100644 --- a/metadata.mak +++ b/metadata.mak @@ -1,5 +1,5 @@ PROJECT := libpgfe -VERSION := 0.6.0-dev +VERSION := 0.5.1-dev BUILD_DIR := build diff --git a/project.json b/project.json index 1575f13..149798d 100644 --- a/project.json +++ b/project.json @@ -1,4 +1,4 @@ { "name": "libpgfe", - "version": "0.6.0-dev" + "version": "0.5.1-dev" } \ No newline at end of file From 56366a2c2f20af7ca85a26c08b8d6857187aa948 Mon Sep 17 00:00:00 2001 From: chardon55 Date: Fri, 11 Nov 2022 11:22:25 +0800 Subject: [PATCH 14/14] Refactoring --- include/backend/base-encoding-internal.h | 4 ++-- src/c/base_encoding/base-encoding-internal.c | 14 +++++++------- src/c/base_encoding/base16.c | 4 ++-- src/c/base_encoding/base32.c | 8 ++++---- src/c/base_encoding/base64.c | 6 +++--- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/include/backend/base-encoding-internal.h b/include/backend/base-encoding-internal.h index ccee40d..de006f7 100644 --- a/include/backend/base-encoding-internal.h +++ b/include/backend/base-encoding-internal.h @@ -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[] ); diff --git a/src/c/base_encoding/base-encoding-internal.c b/src/c/base_encoding/base-encoding-internal.c index f0d6912..dd39f56 100644 --- a/src/c/base_encoding/base-encoding-internal.c +++ b/src/c/base_encoding/base-encoding-internal.c @@ -73,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; @@ -101,13 +102,12 @@ 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 = __mkmask(bit_size); @@ -132,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); diff --git a/src/c/base_encoding/base16.c b/src/c/base_encoding/base16.c index 46fba76..66d2d60 100644 --- a/src/c/base_encoding/base16.c +++ b/src/c/base_encoding/base16.c @@ -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); } \ No newline at end of file diff --git a/src/c/base_encoding/base32.c b/src/c/base_encoding/base32.c index 197f8f3..69111bd 100644 --- a/src/c/base_encoding/base32.c +++ b/src/c/base_encoding/base32.c @@ -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); } \ No newline at end of file diff --git a/src/c/base_encoding/base64.c b/src/c/base_encoding/base64.c index 086332a..1289e5b 100644 --- a/src/c/base_encoding/base64.c +++ b/src/c/base_encoding/base64.c @@ -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); } \ No newline at end of file