Skip to content

Commit 8b47123

Browse files
authored
Merge branch 'main' into codex/update-readme-with-pbkdf2-security-notes
2 parents 81d1adf + 51d5e93 commit 8b47123

5 files changed

Lines changed: 101 additions & 1 deletion

File tree

.github/workflows/CI-macOS.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI-macOS
2+
3+
on:
4+
push:
5+
branches:
6+
- main
7+
- release/**
8+
- stable
9+
pull_request:
10+
branches:
11+
- main
12+
- release/**
13+
- codex/**
14+
15+
jobs:
16+
Tests-macOS:
17+
runs-on: macos-latest
18+
strategy:
19+
matrix:
20+
std: [11, 17]
21+
steps:
22+
- uses: actions/checkout@v3
23+
- name: Install dependencies
24+
run: |
25+
brew update
26+
brew uninstall --ignore-dependencies cmake || true
27+
brew install cmake
28+
- name: Configure
29+
run: cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_CXX_STANDARD=${{ matrix.std }}
30+
- name: Build
31+
run: cmake --build build
32+
- name: Run tests
33+
run: cd build && ctest --output-on-failure
34+
vcpkg:
35+
runs-on: macos-latest
36+
steps:
37+
- uses: actions/checkout@v3
38+
- name: Install vcpkg
39+
run: |
40+
git clone https://github.com/microsoft/vcpkg.git
41+
./vcpkg/bootstrap-vcpkg.sh
42+
./vcpkg/vcpkg install gtest
43+
- name: Configure
44+
run: cmake -S . -B build -DBUILD_TESTS=ON -DCMAKE_TOOLCHAIN_FILE=./vcpkg/scripts/buildsystems/vcpkg.cmake
45+
- name: Build
46+
run: cmake --build build
47+
- name: Run tests
48+
run: cd build && ctest --output-on-failure

.github/workflows/benchmarks.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name: Benchmarks
2+
3+
on:
4+
push:
5+
tags:
6+
- '*'
7+
8+
jobs:
9+
benchmark:
10+
runs-on: ubuntu-latest
11+
steps:
12+
- uses: actions/checkout@v3
13+
- name: Install dependencies
14+
run: sudo apt-get update && sudo apt-get install -y cmake hyperfine
15+
- name: Run benchmarks
16+
run: scripts/run_benchmarks.sh

README-RU.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[![Linux](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-Linux.yml/badge.svg?branch=main)](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-Linux.yml)
44
[![Windows](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-Win.yml/badge.svg?branch=main)](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-Win.yml)
5+
[![macOS](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-macOS.yml/badge.svg?branch=main)](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-macOS.yml)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
57

68
Лёгкая `C++11` библиотека для вычисления `HMAC` (hash-based message authentication code), поддерживающая поддерживающая `SHA256`, `SHA512`, `SHA1`, а также одноразовые пароли `HOTP` и `TOTP`.
79

@@ -278,4 +280,4 @@ int main() {
278280
Проект распространяется под лицензией **MIT**.
279281
Это означает, что вы можете свободно использовать, копировать, модифицировать и распространять код, при условии сохранения оригинального уведомления о лицензии.
280282

281-
См. файл [`LICENSE`](./LICENSE) для подробностей.
283+
См. файл [`LICENSE`](./LICENSE) для подробностей.

README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
[![Linux](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-Linux.yml/badge.svg?branch=main)](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-Linux.yml)
44
[![Windows](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-Win.yml/badge.svg?branch=main)](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-Win.yml)
5+
[![macOS](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-macOS.yml/badge.svg?branch=main)](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-macOS.yml)
6+
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
57

68
A lightweight `C++11` library for computing `HMAC` (hash-based message authentication codes), supporting `SHA1`, `SHA256`, `SHA512`, as well as one-time passwords compliant with `HOTP` (RFC 4226) and `TOTP` (RFC 6238).
79

@@ -78,6 +80,10 @@ Alternatively, use the helper script:
7880
scripts/run_tests.sh
7981
```
8082

83+
## Test Vectors
84+
85+
The test suite covers official vectors from [RFC 4231](https://www.rfc-editor.org/rfc/rfc4231) and [RFC 6070](https://www.rfc-editor.org/rfc/rfc6070) and runs in CI.
86+
8187
## 📦 MQL5 Compatibility
8288

8389
The repository includes `sha256.mqh`, `sha512.mqh`, `hmac.mqh`, and `hmac_utils.mqh` files, fully compatible with `MetaTrader 5`.
@@ -207,6 +213,22 @@ The pepper is a secret key stored separately from the hashed password.
207213
- Salts and iteration counts must be unique per password.
208214
- Example serialization: `{magic|ver|prf|salt|iters|dkLen|…}`.
209215
216+
#### PBKDF2-HMAC-SHA256 + AES-GCM
217+
218+
```cpp
219+
#include <hmac_cpp/hmac_utils.hpp>
220+
#include <aes_cpp/aes_utils.hpp>
221+
222+
std::string password = "correct horse battery staple";
223+
std::vector<uint8_t> salt(16, 0x00); // 16 random bytes
224+
auto key = hmac::pbkdf2(password, salt, 100000, 32, hmac::Pbkdf2Hash::Sha256);
225+
226+
std::string plaintext = "secret";
227+
std::vector<uint8_t> aad = {'h','e','a','d','e','r'};
228+
auto pkt = aes_cpp::utils::encrypt_gcm(plaintext, key, aad);
229+
auto restored = aes_cpp::utils::decrypt_gcm_to_string(pkt, key, aad);
230+
```
231+
210232
### HKDF (RFC 5869)
211233

212234
```cpp
@@ -312,6 +334,12 @@ int main() {
312334
**Note:** avoid checking input lengths before calling `constant_time_equal`.
313335
Early length comparisons can leak information through timing side channels.
314336

337+
## Security Notes
338+
339+
- PBKDF2 is CPU-bound and vulnerable to massive GPU/ASIC brute force. Choose high iteration counts or stronger KDFs.
340+
- Every password requires a unique, random salt of sufficient length.
341+
- Salts, iteration counts, and algorithms are not secrets—store them alongside the hash for verification.
342+
315343
## 📚 Resources
316344

317345
* Original [SHA256 implementation](http://www.zedwood.com/article/cpp-sha256-function)

scripts/run_benchmarks.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
cmake -S . -B build-bench -DCMAKE_BUILD_TYPE=Release
5+
cmake --build build-bench --config Release
6+
hyperfine "./build-bench/example"

0 commit comments

Comments
 (0)