|
2 | 2 |
|
3 | 3 | [](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-Linux.yml) |
4 | 4 | [](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-Win.yml) |
| 5 | +[](https://github.com/NewYaroslav/hmac-cpp/actions/workflows/CI-macOS.yml) |
| 6 | +[](LICENSE) |
5 | 7 |
|
6 | 8 | 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). |
7 | 9 |
|
@@ -78,6 +80,10 @@ Alternatively, use the helper script: |
78 | 80 | scripts/run_tests.sh |
79 | 81 | ``` |
80 | 82 |
|
| 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 | + |
81 | 87 | ## 📦 MQL5 Compatibility |
82 | 88 |
|
83 | 89 | 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. |
207 | 213 | - Salts and iteration counts must be unique per password. |
208 | 214 | - Example serialization: `{magic|ver|prf|salt|iters|dkLen|…}`. |
209 | 215 |
|
| 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 | + |
210 | 232 | ### HKDF (RFC 5869) |
211 | 233 |
|
212 | 234 | ```cpp |
@@ -312,6 +334,12 @@ int main() { |
312 | 334 | **Note:** avoid checking input lengths before calling `constant_time_equal`. |
313 | 335 | Early length comparisons can leak information through timing side channels. |
314 | 336 |
|
| 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 | + |
315 | 343 | ## 📚 Resources |
316 | 344 |
|
317 | 345 | * Original [SHA256 implementation](http://www.zedwood.com/article/cpp-sha256-function) |
|
0 commit comments