Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
chardoncs committed Jun 19, 2023
2 parents c47910f + 43098ff commit b07ee40
Show file tree
Hide file tree
Showing 17 changed files with 31 additions and 55 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.26.0)

project(libpgfe
VERSION 0.7.0
VERSION 0.7.1
DESCRIPTION "Cryptographic library"
HOMEPAGE_URL "https://github.com/chardon55/libpgfe"
LANGUAGES C CXX
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# libpgfe
# libpgfe (Legacy C/C++ edition)

![Version](https://img.shields.io/github/v/tag/chardon55/libpgfe?color=brightgreen&label=version)
![License](https://img.shields.io/github/license/chardon55/libpgfe)
Expand Down
11 changes: 2 additions & 9 deletions include/libpgfe/version.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
/*
libpgfe
version.h
Copyright (c) 2022-2023 Charles Dong
*/

#ifndef LIBPGFE_VERSION_H
#define LIBPGFE_VERSION_H

#define LIBPGFE_MAJOR_VERSION 0
#define LIBPGFE_MINOR_VERSION 7
#define LIBPGFE_REVISION 0
#define LIBPGFE_REVISION 1
#define LIBPGFE_VARIANT ""

#define LIBPGFE_VERSION "0.7.0"
#define LIBPGFE_VERSION "0.7.1"

#endif
4 changes: 2 additions & 2 deletions metadata.mak
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
PROJECT := libpgfe
VERSION := 0.7.0
VERSION := 0.7.1

BUILD_DIR := build

INCLUDE_DIR := include
SRC_DIR := src

HEADER_DIR := /usr/local/include/libpgfe
HEADER_DIR := /usr/local/include
LIB_DIR := /usr/lib
TARGET_DIR := $(BUILD_DIR)
TARGET_FILE := $(PROJECT).so
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.7.0"
"version": "0.7.1"
}
8 changes: 6 additions & 2 deletions scripts/metadata.mak.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@ BUILD_DIR := build
INCLUDE_DIR := include
SRC_DIR := src

HEADER_DIR := /usr/local/include/libpgfe
HEADER_DIR := /usr/local/include
LIB_DIR := /usr/lib
TARGET_DIR := $(BUILD_DIR)
TARGET_FILE := $(PROJECT).so

TARGET := $(TARGET_DIR)/$(TARGET_FILE)
TEST_TARGET := $(TARGET_DIR)/$(TEST_BIN)
TEST_TARGET := $(TARGET_DIR)/$(TEST_BIN)

DEFAULT_CMAKE_TOOLCHAIN_FILE := ./cmake/toolchains/x86_64-linux-gnu-clang.cmake

NDK_ROOT := ~/Android/Sdk/ndk/23.1.7779620/
2 changes: 1 addition & 1 deletion scripts/update_meta.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

FILES = {
"scripts/metadata.mak.in": "metadata.mak",
"scripts/version.h.template": "include/version.h",
"scripts/version.h.template": "include/libpgfe/version.h",
}


Expand Down
4 changes: 1 addition & 3 deletions src/fishes/blowfish.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ Blowfish::Blowfish(const pgfe_encode_t *key, size_t length) {

Blowfish::Blowfish(const std::string &key) : Blowfish(key.c_str()) {}

Blowfish::~Blowfish() {
memset(&ctx, 0, sizeof(ctx));
}
Blowfish::~Blowfish() {}

SequentialData Blowfish::encrypt(const pgfe_encode_t *seq, size_t length) {
size_t sz = length + length % 8;
Expand Down
3 changes: 0 additions & 3 deletions src/hashes/keccak-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ static void transform(pgfe_keccak_bitcube_t A, uint64_t RC) {
}
}

// Wipe sensitive data from RAM
memset(C, 0, 40);

// Iota
A[0][0] ^= RC;
}
Expand Down
4 changes: 0 additions & 4 deletions src/hashes/md5-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,4 @@ void md5_transform(pgfe_word_t state[4], const pgfe_encode_t block[64]) {
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));
memset(buf, 0, 16);
}
2 changes: 0 additions & 2 deletions src/hashes/md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ void pgfe_md5_digest(struct pgfe_md5_ctx *ctx, pgfe_encode_t output[]) {
pgfe_md5_update(ctx, PADDING, padding_len);
pgfe_md5_update(ctx, chunk, 8);

// Wipe sensitive data from the RAM
memset(ctx->block, 0, sizeof(ctx->block));
ctx->count[0] = ctx->count[1] = 0;

md5_encode(ctx->state, PGFE_MD5_DIGEST_SIZE, output);
Expand Down
4 changes: 0 additions & 4 deletions src/hashes/sha1.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,6 @@ static void sha1_process_block(struct pgfe_sha1_ctx *ctx) {
ctx->state[4] += E;

ctx->index = 0;

// Wipe sensitive data
tmp = A = B = C = D = E = 0;
memset(ws, 0, sizeof(ws));
}

static void sha1_padding(struct pgfe_sha1_ctx *ctx) {
Expand Down
16 changes: 0 additions & 16 deletions src/hashes/sha2-backend.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ void sha256_process_block(struct pgfe_sha256_ctx *ctx) {
ctx->state[7] += H;

ctx->index = 0;

// Wipe data from RAM
tmp1 = tmp2 = A = B = C = D = E = F = G = H = 0;
memset(ws, 0, PGFE_SHA256_BLOCK_SIZE);
}

void sha224n256_padding(struct pgfe_sha256_ctx *ctx) {
Expand Down Expand Up @@ -112,10 +108,6 @@ void sha224n256_digest(struct pgfe_sha256_ctx *ctx, pgfe_encode_t output[], uint

sha224n256_padding(ctx);

// Wipe sensitive data from the RAM
memset(ctx->block, 0, sizeof(ctx->block));
ctx->len_low = ctx->len_high = 0;

// Write output
for (i = 0; i < digest_size; i++) {
output[i] = (pgfe_encode_t)(ctx->state[i >> 2] >> 8 * (3 - (i & 3)));
Expand Down Expand Up @@ -195,10 +187,6 @@ void sha384n512_process_block(struct pgfe_sha512_ctx *ctx) {
ctx->state[7] += H;

ctx->index = 0;

// Wipe data from RAM
tmp1 = tmp2 = tmp = A = B = C = D = E = F = G = H = 0;
memset(ws, 0, 80);
}

void sha384n512_update(struct pgfe_sha512_ctx *ctx, const pgfe_encode_t input[], size_t length) {
Expand Down Expand Up @@ -267,10 +255,6 @@ void sha384n512_digest(struct pgfe_sha512_ctx *ctx, pgfe_encode_t output[], uint

sha384n512_padding(ctx, PADDING_HEADER);

// Wipe data from RAM
memset(ctx->block, 0, sizeof(ctx->block));
ctx->len_high = ctx->len_low = 0;

for (i = 0; i < digest_size; i++) {
output[i] = (uint8_t)(ctx->state[i >> 3] >> (8 * (7 - (i % 8))));
}
Expand Down
5 changes: 0 additions & 5 deletions src/hmac/hmac.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,6 @@
pgfe_##name##_encode_multiple( \
output, 2, ctx->k_o_pad, PGFE_##upper##_BLOCK_SIZE, mid_hash, PGFE_##upper##_DIGEST_SIZE \
); \
\
/* Wipe buffers' data */ \
memset(mid_hash, 0, PGFE_##upper##_DIGEST_SIZE); \
memset(ctx->k_i_pad, 0, PGFE_##upper##_BLOCK_SIZE); \
memset(ctx->k_o_pad, 0, PGFE_##upper##_BLOCK_SIZE); \
} \
inline void pgfe_hmac_##name( \
const pgfe_encode_t key[], size_t key_length, const pgfe_encode_t data[], size_t length, \
Expand Down
12 changes: 12 additions & 0 deletions tests/c/mdtest.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,24 @@

#include "test.h"

#define TEST_FILE1_PATH "../tests/test.txt"

#include "libpgfe/hashes/md5.h"
#include "libpgfe/utils.h"

void md5test(ARGS) {
pgfe_encode_t output[PGFE_MD5_DIGEST_SIZE];

pgfe_md5_encode_default((pgfe_encode_t *)argv[2], output);
pgfe_print_hash(output, PGFE_MD5_DIGEST_SIZE);
}

void md5_file_test(ARGS) {
pgfe_encode_t output[PGFE_MD5_DIGEST_SIZE];

FILE *fp = fopen(TEST_FILE1_PATH, "r");
pgfe_md5_encode_f(fp, output);
fclose(fp);

pgfe_print_hash(output, PGFE_MD5_DIGEST_SIZE);
}
1 change: 1 addition & 0 deletions tests/c/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ int main(ARGS) {
TEST_CASE("shake-test_file", shake_test_file);

TEST_CASE("md5", md5test)
TEST_CASE("md5_file", md5_file_test)

TEST_CASE("hmac", hmac_test)

Expand Down
4 changes: 3 additions & 1 deletion tests/cmake/hash_tests.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,10 @@ list(APPEND HashResults_string1 "720aea11019ef06440fbf05d87aa24680a2153df3907b23
# SHA3-512
list(APPEND HashResults_string1 "75d527c368f2efe848ecf6b073a36767800805e9eef2b1857d5f984f036eb6df891d75f72d9b154518c1cd58835286d1da9a38deba3de98b5a53e5ed78a84976")

list(APPEND AlgList_file sha1 sha256 sha512 sha3_224 sha3_256 sha3_384 sha3_512)
list(APPEND AlgList_file md5 sha1 sha256 sha512 sha3_224 sha3_256 sha3_384 sha3_512)

# MD5
list(APPEND HashResults_file1 "2272be522b715d5541cff37c92ad4124")
# SHA1
list(APPEND HashResults_file1 "65d7d52df994f64a0e993794222124645242e00f")
# SHA256
Expand Down

0 comments on commit b07ee40

Please sign in to comment.