| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4413,6 +4413,96 @@ HMACCtxPointer HMACCtxPointer::New() { | |||
| 4413 | 4413 | return HMACCtxPointer(HMAC_CTX_new()); | |
| 4414 | 4414 | } | |
| 4415 | 4415 | ||
| 4416 | + #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 4417 | + EVPMacPointer::EVPMacPointer(EVP_MAC* mac) : mac_(mac) {} | ||
| 4418 | + | ||
| 4419 | + EVPMacPointer::EVPMacPointer(EVPMacPointer&& other) noexcept | ||
| 4420 | + : mac_(std::move(other.mac_)) {} | ||
| 4421 | + | ||
| 4422 | + EVPMacPointer& EVPMacPointer::operator=(EVPMacPointer&& other) noexcept { | ||
| 4423 | + if (this == &other) return *this; | ||
| 4424 | + mac_ = std::move(other.mac_); | ||
| 4425 | + return *this; | ||
| 4426 | + } | ||
| 4427 | + | ||
| 4428 | + EVPMacPointer::~EVPMacPointer() { | ||
| 4429 | + mac_.reset(); | ||
| 4430 | + } | ||
| 4431 | + | ||
| 4432 | + void EVPMacPointer::reset(EVP_MAC* mac) { | ||
| 4433 | + mac_.reset(mac); | ||
| 4434 | + } | ||
| 4435 | + | ||
| 4436 | + EVP_MAC* EVPMacPointer::release() { | ||
| 4437 | + return mac_.release(); | ||
| 4438 | + } | ||
| 4439 | + | ||
| 4440 | + EVPMacPointer EVPMacPointer::Fetch(const char* algorithm) { | ||
| 4441 | + return EVPMacPointer(EVP_MAC_fetch(nullptr, algorithm, nullptr)); | ||
| 4442 | + } | ||
| 4443 | + | ||
| 4444 | + EVPMacCtxPointer::EVPMacCtxPointer(EVP_MAC_CTX* ctx) : ctx_(ctx) {} | ||
| 4445 | + | ||
| 4446 | + EVPMacCtxPointer::EVPMacCtxPointer(EVPMacCtxPointer&& other) noexcept | ||
| 4447 | + : ctx_(std::move(other.ctx_)) {} | ||
| 4448 | + | ||
| 4449 | + EVPMacCtxPointer& EVPMacCtxPointer::operator=( | ||
| 4450 | + EVPMacCtxPointer&& other) noexcept { | ||
| 4451 | + if (this == &other) return *this; | ||
| 4452 | + ctx_ = std::move(other.ctx_); | ||
| 4453 | + return *this; | ||
| 4454 | + } | ||
| 4455 | + | ||
| 4456 | + EVPMacCtxPointer::~EVPMacCtxPointer() { | ||
| 4457 | + ctx_.reset(); | ||
| 4458 | + } | ||
| 4459 | + | ||
| 4460 | + void EVPMacCtxPointer::reset(EVP_MAC_CTX* ctx) { | ||
| 4461 | + ctx_.reset(ctx); | ||
| 4462 | + } | ||
| 4463 | + | ||
| 4464 | + EVP_MAC_CTX* EVPMacCtxPointer::release() { | ||
| 4465 | + return ctx_.release(); | ||
| 4466 | + } | ||
| 4467 | + | ||
| 4468 | + bool EVPMacCtxPointer::init(const Buffer<const void>& key, | ||
| 4469 | + const OSSL_PARAM* params) { | ||
| 4470 | + if (!ctx_) return false; | ||
| 4471 | + return EVP_MAC_init(ctx_.get(), | ||
| 4472 | + static_cast<const unsigned char*>(key.data), | ||
| 4473 | + key.len, | ||
| 4474 | + params) == 1; | ||
| 4475 | + } | ||
| 4476 | + | ||
| 4477 | + bool EVPMacCtxPointer::update(const Buffer<const void>& data) { | ||
| 4478 | + if (!ctx_) return false; | ||
| 4479 | + return EVP_MAC_update(ctx_.get(), | ||
| 4480 | + static_cast<const unsigned char*>(data.data), | ||
| 4481 | + data.len) == 1; | ||
| 4482 | + } | ||
| 4483 | + | ||
| 4484 | + DataPointer EVPMacCtxPointer::final(size_t length) { | ||
| 4485 | + if (!ctx_) return {}; | ||
| 4486 | + auto buf = DataPointer::Alloc(length); | ||
| 4487 | + if (!buf) return {}; | ||
| 4488 | + | ||
| 4489 | + size_t result_len = length; | ||
| 4490 | + if (EVP_MAC_final(ctx_.get(), | ||
| 4491 | + static_cast<unsigned char*>(buf.get()), | ||
| 4492 | + &result_len, | ||
| 4493 | + length) != 1) { | ||
| 4494 | + return {}; | ||
| 4495 | + } | ||
| 4496 | + | ||
| 4497 | + return buf; | ||
| 4498 | + } | ||
| 4499 | + | ||
| 4500 | + EVPMacCtxPointer EVPMacCtxPointer::New(EVP_MAC* mac) { | ||
| 4501 | + if (!mac) return EVPMacCtxPointer(); | ||
| 4502 | + return EVPMacCtxPointer(EVP_MAC_CTX_new(mac)); | ||
| 4503 | + } | ||
| 4504 | + #endif // OPENSSL_VERSION_MAJOR >= 3 | ||
| 4505 | + | ||
| 4416 | 4506 | DataPointer hashDigest(const Buffer<const unsigned char>& buf, | |
| 4417 | 4507 | const EVP_MD* md) { | |
| 4418 | 4508 | if (md == nullptr) return {}; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -229,6 +229,8 @@ class DataPointer; | |||
| 229 | 229 | class DHPointer; | |
| 230 | 230 | class ECKeyPointer; | |
| 231 | 231 | class EVPKeyPointer; | |
| 232 | + class EVPMacCtxPointer; | ||
| 233 | + class EVPMacPointer; | ||
| 232 | 234 | class EVPMDCtxPointer; | |
| 233 | 235 | class SSLCtxPointer; | |
| 234 | 236 | class SSLPointer; | |
@@ -1451,6 +1453,56 @@ class HMACCtxPointer final { | |||
| 1451 | 1453 | DeleteFnPtr<HMAC_CTX, HMAC_CTX_free> ctx_; | |
| 1452 | 1454 | }; | |
| 1453 | 1455 | ||
| 1456 | + #if OPENSSL_VERSION_MAJOR >= 3 | ||
| 1457 | + class EVPMacPointer final { | ||
| 1458 | + public: | ||
| 1459 | + EVPMacPointer() = default; | ||
| 1460 | + explicit EVPMacPointer(EVP_MAC* mac); | ||
| 1461 | + EVPMacPointer(EVPMacPointer&& other) noexcept; | ||
| 1462 | + EVPMacPointer& operator=(EVPMacPointer&& other) noexcept; | ||
| 1463 | + NCRYPTO_DISALLOW_COPY(EVPMacPointer) | ||
| 1464 | + ~EVPMacPointer(); | ||
| 1465 | + | ||
| 1466 | + inline bool operator==(std::nullptr_t) noexcept { return mac_ == nullptr; } | ||
| 1467 | + inline operator bool() const { return mac_ != nullptr; } | ||
| 1468 | + inline EVP_MAC* get() const { return mac_.get(); } | ||
| 1469 | + inline operator EVP_MAC*() const { return mac_.get(); } | ||
| 1470 | + void reset(EVP_MAC* mac = nullptr); | ||
| 1471 | + EVP_MAC* release(); | ||
| 1472 | + | ||
| 1473 | + static EVPMacPointer Fetch(const char* algorithm); | ||
| 1474 | + | ||
| 1475 | + private: | ||
| 1476 | + DeleteFnPtr<EVP_MAC, EVP_MAC_free> mac_; | ||
| 1477 | + }; | ||
| 1478 | + | ||
| 1479 | + class EVPMacCtxPointer final { | ||
| 1480 | + public: | ||
| 1481 | + EVPMacCtxPointer() = default; | ||
| 1482 | + explicit EVPMacCtxPointer(EVP_MAC_CTX* ctx); | ||
| 1483 | + EVPMacCtxPointer(EVPMacCtxPointer&& other) noexcept; | ||
| 1484 | + EVPMacCtxPointer& operator=(EVPMacCtxPointer&& other) noexcept; | ||
| 1485 | + NCRYPTO_DISALLOW_COPY(EVPMacCtxPointer) | ||
| 1486 | + ~EVPMacCtxPointer(); | ||
| 1487 | + | ||
| 1488 | + inline bool operator==(std::nullptr_t) noexcept { return ctx_ == nullptr; } | ||
| 1489 | + inline operator bool() const { return ctx_ != nullptr; } | ||
| 1490 | + inline EVP_MAC_CTX* get() const { return ctx_.get(); } | ||
| 1491 | + inline operator EVP_MAC_CTX*() const { return ctx_.get(); } | ||
| 1492 | + void reset(EVP_MAC_CTX* ctx = nullptr); | ||
| 1493 | + EVP_MAC_CTX* release(); | ||
| 1494 | + | ||
| 1495 | + bool init(const Buffer<const void>& key, const OSSL_PARAM* params = nullptr); | ||
| 1496 | + bool update(const Buffer<const void>& data); | ||
| 1497 | + DataPointer final(size_t length); | ||
| 1498 | + | ||
| 1499 | + static EVPMacCtxPointer New(EVP_MAC* mac); | ||
| 1500 | + | ||
| 1501 | + private: | ||
| 1502 | + DeleteFnPtr<EVP_MAC_CTX, EVP_MAC_CTX_free> ctx_; | ||
| 1503 | + }; | ||
| 1504 | + #endif // OPENSSL_VERSION_MAJOR >= 3 | ||
| 1505 | + | ||
| 1454 | 1506 | #ifndef OPENSSL_NO_ENGINE | |
| 1455 | 1507 | class EnginePointer final { | |
| 1456 | 1508 | public: | |
| Back | FazBrowse Home | New Git URL |
0 commit comments