Skip to content

Commit faa4b0f

Browse files
committed
switch to cmake
1 parent 8ac0d68 commit faa4b0f

37 files changed

+86
-122
lines changed

CMakeLists.txt

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
cmake_minimum_required(VERSION 3.0.0)
2+
project(zcrypto VERSION 0.1.0)
3+
4+
include(CTest)
5+
enable_testing()
6+
7+
add_compile_options(-Wall -Wextra -Wuninitialized -Wsign-conversion)
8+
set(CMAKE_C_STANDARD 17)
9+
set(CMAKE_CXX_STANDARD 17)
10+
11+
include_directories(include)
12+
add_subdirectory(src)
13+
add_subdirectory(tests)

Makefile

-85
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

python/setup.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,21 @@
11
# code: utf-8
22

33
import os
4+
import pathlib
45
from distutils.core import setup, Extension
56

67
name = "zcrypto"
78
ver = "0.1"
89

9-
pydir = os.path.dirname(os.path.abspath(__file__))
10-
rootdir = os.path.dirname(pydir)
11-
libdir = os.path.join(rootdir, name)
12-
src = ["../{}/{}".format(name, x) for x in os.listdir(libdir) if x.endswith(".c")]
13-
src.extend([x for x in os.listdir(pydir) if x.endswith(".c")])
14-
print(src)
10+
pydir = pathlib.Path(os.path.abspath(__file__)).parent
11+
rootdir = pydir.parent
12+
inc_dir = rootdir / "include"
13+
src_dir = rootdir / "src"
14+
src = [pydir / "ext.c", src_dir / "sm3.c", src_dir / "sm4.c"]
15+
src = [str(x) for x in src]
1516

1617
setup(
1718
name = name,
1819
version = ver,
19-
ext_modules = [Extension(name, src, include_dirs=[rootdir])]
20+
ext_modules = [Extension(name, src, include_dirs=[inc_dir])]
2021
)

src/CMakeLists.txt

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
set(sources
3+
aes.c
4+
base64.c
5+
hash.c
6+
hashlib.c
7+
md5.c
8+
oaep.c
9+
rsa.c
10+
sha1.c
11+
sha256.c
12+
sm3.c
13+
sm4.c
14+
)
15+
16+
add_library(zcrypto STATIC ${sources})

zcrypto/aes.c renamed to src/aes.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "aes.h"
2-
#include "utils.h"
1+
#include "zcrypto/aes.h"
2+
#include "zcrypto/utils.h"
33

44
static const uint8_t RCBOX[11] = {
55
0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36

zcrypto/base64.c renamed to src/base64.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include <stdint.h>
2-
#include "base64.h"
2+
#include "zcrypto/base64.h"
33

44
static const uint8_t ASCII[] = {
55
"ABCDEFGHIJKLMNOP"

zcrypto/hash.c renamed to src/hash.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <assert.h>
2-
#include "hash.h"
3-
#include "utils.h"
2+
#include "zcrypto/hash.h"
3+
#include "zcrypto/utils.h"
44

55
void _hash_update(hash_blk_update_func blk_update, uint32_t *hash, uint8_t *blk, const uint8_t *data, size_t len, uint64_t *total) {
66
size_t offset = *total % HASH_BLK_SIZE;

zcrypto/hashlib.c renamed to src/hashlib.c

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include <assert.h>
2-
#include "hash.h"
3-
#include "hashlib.h"
4-
#include "sm3.h"
5-
#include "md5.h"
6-
#include "sha1.h"
7-
#include "sha256.h"
8-
#include "utils.h"
2+
#include "zcrypto/hash.h"
3+
#include "zcrypto/hashlib.h"
4+
#include "zcrypto/sm3.h"
5+
#include "zcrypto/md5.h"
6+
#include "zcrypto/sha1.h"
7+
#include "zcrypto/sha256.h"
8+
#include "zcrypto/utils.h"
99

1010
void hash_init(hash_ctx_t *ctx, int alg) {
1111
assert(alg == HASH_ALG_SM3 || alg == HASH_ALG_MD5 || alg == HASH_ALG_SHA1 || alg == HASH_ALG_SHA256);

zcrypto/md5.c renamed to src/md5.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "md5.h"
2-
#include "hash.h"
3-
#include "utils.h"
1+
#include "zcrypto/md5.h"
2+
#include "zcrypto/hash.h"
3+
#include "zcrypto/utils.h"
44

55
static const uint32_t TT[] = {
66
0xd76aa478, 0xe8c7b756, 0x242070db, 0xc1bdceee,

zcrypto/oaep.c renamed to src/oaep.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "sha256.h"
2-
#include "oaep.h"
1+
#include "zcrypto/sha256.h"
2+
#include "zcrypto/oaep.h"
33

44
static void bytes2num(uint32_t *num, const uint8_t *bytes, size_t len) {
55
for (size_t j = 0; j < len; j += 4) {

zcrypto/rsa.c renamed to src/rsa.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <string.h>
2-
#include "rsa.h"
3-
#include "utils.h"
2+
#include "zcrypto/rsa.h"
3+
#include "zcrypto/utils.h"
44

55
#define DEBUG_DUMP 0
66
#if DEBUG_DUMP

zcrypto/sha1.c renamed to src/sha1.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "sha1.h"
2-
#include "hash.h"
3-
#include "utils.h"
1+
#include "zcrypto/sha1.h"
2+
#include "zcrypto/hash.h"
3+
#include "zcrypto/utils.h"
44

55
static inline uint32_t _f0(uint32_t B, uint32_t C, uint32_t D) {
66
return (B & C) | (~B & D);

zcrypto/sha256.c renamed to src/sha256.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "sha256.h"
2-
#include "hash.h"
3-
#include "utils.h"
1+
#include "zcrypto/sha256.h"
2+
#include "zcrypto/hash.h"
3+
#include "zcrypto/utils.h"
44

55
static inline uint32_t CH(uint32_t X, uint32_t Y, uint32_t Z) {
66
return (X & Y) ^ (~X & Z);

zcrypto/sm3.c renamed to src/sm3.c

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
#include "sm3.h"
2-
#include "hash.h"
3-
#include "utils.h"
1+
#include "zcrypto/sm3.h"
2+
#include "zcrypto/hash.h"
3+
#include "zcrypto/utils.h"
44

55
#define T0 0x79cc4519ul
66
#define T1 0x7a879d8aul

zcrypto/sm4.c renamed to src/sm4.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "sm4.h"
2-
#include "utils.h"
1+
#include "zcrypto/sm4.h"
2+
#include "zcrypto/utils.h"
33

44
static const uint8_t SBOX[256] = {
55
0xd6, 0x90, 0xe9, 0xfe, 0xcc, 0xe1, 0x3d, 0xb7,

tests/CMakeLists.txt

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
add_executable(test_aes test_aes.c)
3+
target_link_libraries(test_aes zcrypto)
4+
5+
add_executable(test_base64 test_base64.c)
6+
target_link_libraries(test_base64 zcrypto)
7+
8+
add_executable(test_hash test_hash.c)
9+
target_link_libraries(test_hash zcrypto)
10+
11+
add_executable(test_oaep test_oaep.c)
12+
target_link_libraries(test_oaep zcrypto)
13+
14+
add_executable(test_rsa test_rsa.c)
15+
target_link_libraries(test_rsa zcrypto)
16+
17+
add_executable(test_sm4 test_sm4.c)
18+
target_link_libraries(test_sm4 zcrypto)
19+
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)