Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CI add clang-format check. #52

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 28 additions & 10 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,34 @@ permissions:
contents: read

jobs:
check-format:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: clang-format check
uses: jidicula/[email protected]
with:
clang-format-version: '17'
include-regex: '^\./(app|examples|include|perf|src|test)/.*\.(c|h)$'
minimal:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install packages
run: |
sudo apt-get update
sudo apt-get -y install cmake python3 python3-pip python3-pytest
# TODO
# because of local development using act forbidden by firewall,
# install cmake manually and simplify python & pytest env setup
sudo apt-get -y install cmake python3 python3-pip
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build
- name: Build
run: cmake --build ${{github.workspace}}/build
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
run: |
python3 -m venv ${{github.workspace}}/.venv
source ${{github.workspace}}/.venv/bin/activate
pip3 install -r ${{github.workspace}}/test/requirements.txt
ctest -C ${{env.BUILD_TYPE}}
- name: debug
if: ${{ failure() }}
run: |
Expand All @@ -41,20 +51,24 @@ jobs:
strategy:
fail-fast: false
matrix:
module: [asn1, sm3, sm4, ascon]
module: [ascon, asn1, hmac, oscore, sm3, sm4]
steps:
- uses: actions/checkout@v3
- name: install packages
run: |
sudo apt-get update
sudo apt-get -y install cmake python3 python3-pip python3-pytest
sudo apt-get -y install cmake python3 python3-pip
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DWITH_${{matrix.module}}=ON
- name: Build
run: cmake --build ${{github.workspace}}/build
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
run: |
python3 -m venv ${{github.workspace}}/.venv
source ${{github.workspace}}/.venv/bin/activate
pip3 install -r ${{github.workspace}}/test/requirements.txt
ctest -C ${{env.BUILD_TYPE}}
- name: debug
if: ${{ failure() }}
run: |
Expand All @@ -67,14 +81,18 @@ jobs:
- name: install packages
run: |
sudo apt-get update
sudo apt-get -y install cmake python3 python3-pip python3-pytest
sudo apt-get -y install cmake python3 python3-pip
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DWITH_ALL=ON
- name: Build
run: cmake --build ${{github.workspace}}/build
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
run: |
python3 -m venv ${{github.workspace}}/.venv
source ${{github.workspace}}/.venv/bin/activate
pip3 install -r ${{github.workspace}}/test/requirements.txt
ctest -C ${{env.BUILD_TYPE}}
- name: debug
if: ${{ failure() }}
run: |
Expand Down
13 changes: 8 additions & 5 deletions .github/workflows/compiler-zoo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

name: Compiler Zoo CI

on: [push]
on: [pull_request, push]

permissions:
contents: read
Expand Down Expand Up @@ -79,6 +79,7 @@ jobs:

runs-on: ${{ matrix.zoo.distro }}
steps:
- uses: actions/checkout@v3
- name: install packages
run: |
llvm_ppa_name="${{ matrix.zoo.llvm-ppa-name }}"
Expand All @@ -104,16 +105,18 @@ jobs:

sudo apt-get update
sudo apt-get -y install ${{ matrix.zoo.cc }}
sudo apt-get -y install cmake python3 python3-pytest

- uses: actions/checkout@v3
sudo apt-get -y install cmake python3 python3-pip
- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -D CMAKE_C_COMPILER=${{ matrix.zoo.cc }} -DWITH_ALL=ON
- name: Build
run: cmake --build ${{github.workspace}}/build
- name: Test
working-directory: ${{github.workspace}}/build
run: ctest -C ${{env.BUILD_TYPE}}
run: |
python3 -m venv ${{github.workspace}}/.venv
source ${{github.workspace}}/.venv/bin/activate
pip3 install -r ${{github.workspace}}/test/requirements.txt
ctest -C ${{env.BUILD_TYPE}}
- name: debug
if: ${{ failure() }}
run: |
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8)

PROJECT(tongsuo-mini)
PROJECT(tongsuo-mini LANGUAGES C)

if (MSVC)
# warning level 4 and all warnings as errors
Expand Down
79 changes: 47 additions & 32 deletions README.cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,64 @@
铜锁迷你版(tongsuo-mini),中文名称“迷你锁”,是一个轻量级的密码学算法库,专为嵌入式系统和物联网设备等资源受限场景提供常用的密码学算法和安全传输协议,并可以适应超低内存和存储的极限要求。“迷你锁”通过高度模块化,允许用户在编译时只开启需要的功能,不浪费存储空间。
同时,通过紧凑的内存对齐等方式,压缩运行时内存。

## 构建依赖

迷你锁依赖于cmake进行构建,以及python工具链进行自动化测试,具体来说,有:
## 特性

* cmake
* python
* pytest
迷你锁(tongsuo-mini)提供如下特性:

上述工具在不同操作系统的安装方式也有所不同,请参考对应操作系统的安装说明。以下是在macOS上安装上述构建依赖的一个典型例子(基于homebrew):
* 高度可定制的模块化编译
* 轻量级密码学算法
* ASCON AEAD
* ASCON HASH
* 轻量级安全通信协议
* OSCORE
* EDHOC\*
* 基于可预测逻辑的动态二进制加载能力\*
* 传统密码学算法
* 商用密码算法:SM2\*,SM3,SM4
* 国际密码学算法\*:AES,SHA系列,RSA,ECDSA,EdDSA
* 传统安全通信协议
* TLS协议\*
* TLCP协议\*

~~~
brew install cmake
brew install python
sudo pip3 install -r test/requirements.txt
~~~
注:\*号表示待开发

## 构建

构建使用cmake,下载源代码后进入源代码根目录执行
构建依赖cmake,make和C编译器(gcc或者clang),基于源代码构建迷你锁如下

```bash
# 下载源代码
git clone https://github.com/Tongsuo-Project/tongsuo-mini
cd tongsuo-mini

mkdir build
cd build
cmake ..
make
make test

# 编译所有模块使用-DWITH_ALL=ON, 编译指定模块-DWITH_<module>=ON,例如-DWITH_ASCON=ON
dongbeiouba marked this conversation as resolved.
Show resolved Hide resolved
# 查看所有可用的编译选项, cmake -LH ..
cmake -DWITH_ALL=ON ..
make -j

# 安装
make install
```

## 特性
## 测试

迷你锁(tongsuo-mini)提供如下特性
测试使用Python3,在test目录下创建虚拟环境并安装依赖

* 高度可定制的模块化编译
* 轻量级密码学算法
* ASCON AEAD
* ASCON HASH
* 轻量级安全通信协议
* OSCORE
* EDHOC
* 基于可预测逻辑的动态二进制加载能力
* 传统密码学算法
* 商用密码算法:SM2,SM3,SM4
* 国际密码学算法:AES,SHA系列,RSA,ECDSA,EdDSA
* 传统安全通信协议
* TLS协议
* TLCP协议
```bash
cd test
python3 -m venv .venv
source .venv/bin/activate
pip3 install -r test/requirements.txt
```

然后在build目录下执行:
```bash
ctest
```
或者在test目录下执行:
```bash
pytest .
```
83 changes: 51 additions & 32 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,68 @@ Tongsuo-mini can be used in constrained environment while requiring small memory

Tongsuo-mini is a member project of the Tongsuo open source community.

## Build Dependency

Tongsuo-mini's build system depends on 'cmake' and it utilizes toolchain provided by Python for automated testing.
## Feature

* cmake
* python
* pytest
Tongsuo-mini has the following features:

The installation of the dependency is very different in various operating systems. This is a typical example on macOS as follows (based on homebrew):
* Highly configurable modular build system
* Lightweight cryptographic algorithm
* ASCON AEAD
* ASCON HASH
* Lightweight secure network protocol
* OSCORE
* EDHOC\*
* Dynamic binary loading based on predication logic\*
* Oridnary cryptography algorithm
* Chinese Shangmi: SM2\*,SM3,SM4
* others\*: AES, SHA, RSA, ECDSA, EdDSA
* Ordinary secure network protocol
* TLS\*
* TLCP\*

~~~
brew install cmake
brew install python
sudo pip3 install -r test/requirements.txt
~~~
Note: \* means the feature is under development

## Build

Use the 'cmake' to build Tongsuo-mini. Run the following steps after Tongsuo-mini has been cloned into a local directory (inside that dir):
The build depends on cmake, make and C compiler (gcc or clang).
Build tongsuo-mini from the source code as follows:

```bash
# Download source code
git clone https://github.com/Tongsuo-Project/tongsuo-mini
cd tongsuo-mini

mkdir build
cd build
cmake ..
make
make test

# Compile all modules with -DWITH_ALL=ON, compile specific module with -DWITH_<module>=ON, e.g. -DWITH_ASCON=ON
dongbeiouba marked this conversation as resolved.
Show resolved Hide resolved
# View all available compilation options, cmake -LH ..
cmake -DWITH_ALL=ON ..
make -j

# If you need to install
make install
```

## Feature
## Test

Tongsuo-mini has the following features:
To test with Python3, create a virtual environment in the test directory and install the dependencies:

* Highly configurable modular build system
* Lightweight cryptographic algorithm
* ASCON AEAD
* ASCON HASH
* Lightweight secure network protocol
* OSCORE
* EDHOC
* Dynamic binary loading based on predication logic
* Oridnary cryptography algorithm
* Chinese Shangmi: SM2,SM3,SM4
* others: AES, SHA, RSA, ECDSA, EdDSA
* Ordinary secure network protocol
* TLS/DTLS
* TLCP
```bash
cd test
python3 -m venv .venv
source .venv/bin/activate
pip3 install -r test/requirements.txt
```

Then run the command in the build directory:

```bash
ctest
```

Or run the command in the test directory:

```bash
pytest .
```
7 changes: 3 additions & 4 deletions app/minisuo.c
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ static int ascon_aead_handler(int argc, char **argv)
}

if (ad != NULL && strlen(ad) > 0) {
if (tsm_ascon_aead_update(ctx, (unsigned char*)ad, strlen(ad), NULL, NULL) != TSM_OK) {
if (tsm_ascon_aead_update(ctx, (unsigned char *)ad, strlen(ad), NULL, NULL) != TSM_OK) {
goto end;
}
}
Expand Down Expand Up @@ -498,10 +498,9 @@ static cmd_handler cmds[] = {
{"ascon-aead", ascon_aead_handler},
{"ascon-hash", ascon_hash_handler},
#endif
{"\0", NULL}
};
{"\0", NULL}};

#define N_CMD (int)(sizeof(cmds)/sizeof(cmds[0]))
#define N_CMD (int)(sizeof(cmds) / sizeof(cmds[0]))

void print_help(void)
{
Expand Down
Loading