File crypto-openssl-10.cpp of Package failed_git-crypt
```cpp
#include "crypto-openssl.h"
#include <openssl/aes.h>
#include <openssl/hmac.h>
#include <openssl/evp.h>
#include <cstring>
struct Aes_ecb_encryptor::Impl {
AES_KEY key;
};
Aes_ecb_encryptor::Aes_ecb_encryptor(const unsigned char* raw_key) {
impl = new Impl();
if (AES_set_encrypt_key(raw_key, KEY_LEN * 8, &(impl->key)) != 0) {
delete impl;
throw std::runtime_error("Failed to set AES encryption key");
}
}
Aes_ecb_encryptor::~Aes_ecb_encryptor() {
delete impl;
}
void Aes_ecb_encryptor::encrypt(const unsigned char* plain, unsigned char* cipher) {
AES_encrypt(plain, cipher, &(impl->key));
}
struct Hmac_sha1_state::Impl {
HMAC_CTX* ctx;
};
Hmac_sha1_state::Hmac_sha1_state(const unsigned char* key, int key_len) {
impl = new Impl();
impl->ctx = HMAC_CTX_new();
if (!impl->ctx || HMAC_Init_ex(impl->ctx, key, key_len, EVP_sha1(), nullptr) != 1) {
HMAC_CTX_free(impl->ctx);
delete impl;
throw std::runtime_error("Failed to initialize HMAC context");
}
}
Hmac_sha1_state::~Hmac_sha1_state() {
if (impl->ctx) {
HMAC_CTX_free(impl->ctx);
}
delete impl;
}
void Hmac_sha1_state::update(const unsigned char* data, size_t len) {
if (HMAC_Update(impl->ctx, data, len) != 1) {
throw std::runtime_error("HMAC update failed");
}
}
void Hmac_sha1_state::final(unsigned char* digest) {
unsigned int len = 0;
if (HMAC_Final(impl->ctx, digest, &len) != 1) {
throw std::runtime_error("HMAC finalization failed");
}
}
```
### Explanation of Changes:
1. **Replaced `HMAC_CTX` with `HMAC_CTX*`:**
- In OpenSSL 3.0, `HMAC_CTX` is an opaque structure, so we use a pointer (`HMAC_CTX*`) instead of directly declaring it.
2. **Updated `HMAC_CTX` management functions:**
- Replaced `HMAC_cleanup` with `HMAC_CTX_free`, which is the modern way to free an HMAC context.
- Used `HMAC_CTX_new` to allocate a new HMAC context.
3. **Updated HMAC initialization:**
- Used `HMAC_Init_ex` with the `EVP_sha1()` function to initialize the HMAC context.
These changes ensure compatibility with OpenSSL 3.0 while maintaining the functionality of the original code.