Skip to content

Commit fbdb9ea

Browse files
committed
docs: document versioning and build policies
1 parent 15dab32 commit fbdb9ea

5 files changed

Lines changed: 73 additions & 17 deletions

File tree

CMakeLists.txt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ project(hmac_cpp VERSION 0.3.0 LANGUAGES CXX)
44
option(HMACCPP_BUILD_EXAMPLES "Build the example program" OFF)
55
option(HMACCPP_BUILD_TESTS "Build the test suite" OFF)
66
option(HMACCPP_BUILD_BENCH "Build benchmarks" OFF)
7+
option(HMACCPP_BUILD_SHARED "Build hmac_cpp as a shared library" OFF)
8+
9+
if(HMACCPP_BUILD_SHARED)
10+
set(BUILD_SHARED_LIBS ON)
11+
endif()
712

813
set(HMAC_SOURCES
914
src/sha1.cpp
@@ -23,6 +28,7 @@ set(HMAC_HEADERS
2328
include/hmac_cpp/sha512.hpp
2429
include/hmac_cpp/secure_buffer.hpp
2530
include/hmac_cpp/encoding.hpp
31+
include/hmac_cpp/version.hpp
2632
)
2733

2834
add_library(hmac_cpp ${HMAC_SOURCES})
@@ -91,6 +97,9 @@ install(FILES
9197
DESTINATION lib/cmake/hmac_cpp
9298
)
9399

100+
configure_file(cmake/hmac_cpp.pc.in "${CMAKE_CURRENT_BINARY_DIR}/hmac_cpp.pc" @ONLY)
101+
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/hmac_cpp.pc" DESTINATION lib/pkgconfig)
102+
94103
if(HMACCPP_BUILD_TESTS)
95104
enable_testing()
96105
include(FetchContent)

README.md

Lines changed: 44 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,20 @@ CI covers Linux/Windows/macOS. Tested with GCC, Clang, and MSVC; requires C++11.
3232

3333
---
3434

35+
## 📈 Versioning / SemVer policy
36+
37+
* Follows [Semantic Versioning](https://semver.org).
38+
* MAJOR: breaking changes to headers or exported symbols.
39+
* MINOR: backward-compatible additions.
40+
* PATCH: bug fixes and internal changes.
41+
42+
Version macros live in `<hmac_cpp/version.hpp>`:
43+
`HMAC_CPP_VERSION_MAJOR`, `HMAC_CPP_VERSION_MINOR`,
44+
`HMAC_CPP_VERSION_PATCH`, and `HMAC_CPP_VERSION`.
45+
See [CHANGELOG.md](CHANGELOG.md) for history.
46+
47+
---
48+
3549
## 🔧 Build & Installation
3650

3751
Examples, tests, and benchmarks are OFF by default. Enable via:
@@ -40,6 +54,10 @@ Examples, tests, and benchmarks are OFF by default. Enable via:
4054
* `HMACCPP_BUILD_TESTS`
4155
* `HMACCPP_BUILD_BENCH`
4256

57+
The library builds **static** by default. Use `-DHMACCPP_BUILD_SHARED=ON`
58+
to produce a shared library. The `HMAC_CPP_API` macro is empty for static
59+
builds and controls symbol export/import for shared builds.
60+
4361
### Build
4462

4563
```bash
@@ -51,23 +69,21 @@ cmake --build build
5169

5270
```bash
5371
cmake --install build --prefix _install
72+
# MSVC
73+
cmake --install build --config Release --prefix _install
5474
```
5575

5676
Install layout:
5777

5878
```
5979
_install/
60-
├─ include/hmac_cpp/
61-
│ ├─ hmac.hpp
62-
│ ├─ hmac_utils.hpp
63-
│ ├─ sha1.hpp
64-
│ ├─ sha256.hpp
65-
│ ├─ sha512.hpp
66-
│ └─ secure_buffer.hpp # if included in your build
67-
└─ lib/
68-
└─ libhmac_cpp.a
80+
├── include/hmac_cpp/...
81+
└── lib/
82+
└── libhmac_cpp.a
6983
```
7084

85+
A `hmac_cpp.pc` file is installed for `pkg-config`.
86+
7187
### Consume with CMake
7288

7389
```cmake
@@ -80,6 +96,10 @@ target_link_libraries(my_app PRIVATE hmac_cpp::hmac_cpp)
8096
```bash
8197
# adjust paths to your prefix
8298
g++ example.cpp -std=c++11 -I_install/include -L_install/lib -lhmac_cpp
99+
# MSVC
100+
cl /EHsc example.cpp /I _install\include /link /LIBPATH:_install\lib hmac_cpp.lib
101+
# pkg-config
102+
c++ example.cpp $(pkg-config --cflags --libs hmac_cpp)
83103
```
84104

85105
Predefined MinGW build scripts are available: `build_*.bat`.
@@ -154,6 +174,8 @@ auto key = hmac::pbkdf2_hmac_sha256(password, salt, iters, 32); // 32 = AES-256
154174
* **Iterations**: tune for \~100–250 ms on target hardware (e.g., desktop ≈ 600k, laptop ≈ 300k, mobile ≈ 150k; adjust).
155175
* **Derived key length**: 32 bytes; **PRF**: HMAC-SHA256.
156176

177+
> PBKDF2 is CPU-bound; for user passwords prefer memory-hard KDFs such as Argon2 or scrypt if available.
178+
157179
**Serialization example** (binary):
158180

159181
```
@@ -262,12 +284,14 @@ ctest --test-dir build --output-on-failure
262284

263285
Covered vectors:
264286

265-
* HMAC — **RFC 4231**
266-
* PBKDF2 — **RFC 6070**
267-
* HOTP — **RFC 4226** (Appendix D)
268-
* TOTP — **RFC 6238** (Appendix B)
287+
| Suite | RFC |
288+
| ------ | --- |
289+
| HMAC | RFC 4231 |
290+
| PBKDF2 | RFC 6070 |
291+
| HOTP | RFC 4226 (App D) |
292+
| TOTP | RFC 6238 (App B) |
269293

270-
CI runs these on Linux/Windows/macOS.
294+
CI: [GitHub Actions](https://github.com/NewYaroslav/hmac-cpp/actions).
271295

272296
---
273297

@@ -302,15 +326,18 @@ g++ example.cpp -std=c++11 -I_install/include -L_install/lib -lhmac_cpp
302326
MSVC:
303327

304328
```bat
305-
cl /EHsc example.cpp /I _install\include /link /LIBPATH:_install\lib hmach_cpp.lib
329+
cl /EHsc example.cpp /I _install\include /link /LIBPATH:_install\lib hmac_cpp.lib
306330
```
307331

308332
---
309333

310334
## ⚠️ Exceptions & Contracts
311335

312-
* Functions may throw `std::invalid_argument` (bad params) and `std::runtime_error` (internal errors).
313-
* `constant_time_equal` assumes lengths are public; compare sizes first.
336+
* `pbkdf2`, `hkdf_*`, HOTP/TOTP, and time-token helpers validate parameters and throw
337+
`std::invalid_argument`; time-token helpers also throw `std::runtime_error` if the
338+
system clock fails.
339+
* `base64_decode` and `base32_decode` are `noexcept` and return `false` on invalid input.
340+
* `constant_time_equal` is `noexcept`; compare sizes first.
314341
* PBKDF2 limits: `dkLen ≤ (2^32−1)·hLen`; iterations ≥ 1; salt length ≥ 16 recommended.
315342
* HKDF limits: `L ≤ 255·HashLen`.
316343
* Thread-safety: functions are stateless and thread-safe given separate buffers.

cmake/hmac_cpp.pc.in

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
prefix=@CMAKE_INSTALL_PREFIX@
2+
exec_prefix=${prefix}
3+
libdir=${exec_prefix}/lib
4+
includedir=${prefix}/include
5+
6+
Name: hmac_cpp
7+
Description: HMAC/PBKDF2/HKDF library
8+
Version: @PROJECT_VERSION@
9+
Libs: -L${libdir} -lhmac_cpp
10+
Cflags: -I${includedir}

include/hmac_cpp/hmac_utils.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ namespace hmac_cpp {
7676

7777
/// PBKDF2 Security Notes:
7878
/// - Use a random salt of at least 16 bytes and never reuse it.
79+
/// - PBKDF2 is CPU-bound; prefer Argon2 or scrypt for user passwords when available.
7980
/// - Choose iterations so the derivation takes about 200–500 ms on 2025 hardware.
8081
/// - Store {salt, iterations} with the ciphertext or hash; these values are public.
8182
/// - Salts and iteration counts must be unique per password.

include/hmac_cpp/version.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#ifndef HMAC_CPP_VERSION_HPP
2+
#define HMAC_CPP_VERSION_HPP
3+
4+
#define HMAC_CPP_VERSION_MAJOR 0
5+
#define HMAC_CPP_VERSION_MINOR 3
6+
#define HMAC_CPP_VERSION_PATCH 0
7+
#define HMAC_CPP_VERSION "0.3.0"
8+
9+
#endif // HMAC_CPP_VERSION_HPP

0 commit comments

Comments
 (0)