2024-03-16 03:10:00 +03:00
|
|
|
//
|
2024-08-31 05:53:41 +03:00
|
|
|
// OpenSSL implementation classes
|
2024-03-16 03:10:00 +03:00
|
|
|
//
|
|
|
|
// Copyright (c) Microsoft Corporation. Licensed under the MIT license.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/rand.h>
|
2024-05-02 02:46:15 +03:00
|
|
|
#include <openssl/sha.h>
|
|
|
|
#include <symcrypt.h>
|
|
|
|
#include <stdint.h>
|
2024-03-16 03:10:00 +03:00
|
|
|
#include <vector>
|
|
|
|
class ImpOpenssl {
|
|
|
|
public:
|
2024-05-02 02:46:15 +03:00
|
|
|
static constexpr const char * name = "OpenSSL";
|
2024-03-16 03:10:00 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
class XtsImpState<ImpOpenssl, AlgXtsAes> {
|
|
|
|
public:
|
|
|
|
EVP_CIPHER_CTX* encCtx;
|
|
|
|
EVP_CIPHER_CTX* decCtx;
|
|
|
|
};
|
|
|
|
|
2024-03-29 06:39:59 +03:00
|
|
|
template<>
|
|
|
|
class AuthEncImpState<ImpOpenssl, AlgAes, ModeGcm> {
|
|
|
|
public:
|
|
|
|
EVP_CIPHER_CTX* encCtx;
|
|
|
|
EVP_CIPHER_CTX* decCtx;
|
|
|
|
BOOLEAN inComputation;
|
|
|
|
};
|
|
|
|
|
2024-04-12 03:00:10 +03:00
|
|
|
template<>
|
|
|
|
class RsaSignImpState<ImpOpenssl, AlgRsaSignPss> {
|
|
|
|
public:
|
|
|
|
EVP_PKEY *pkey;
|
|
|
|
EVP_PKEY_CTX *pkey_ctx;
|
|
|
|
};
|
|
|
|
|
2024-05-02 02:46:15 +03:00
|
|
|
template<>
|
|
|
|
class HashImpState<ImpOpenssl, AlgSha256> {
|
|
|
|
public:
|
|
|
|
BOOLEAN isReset;
|
|
|
|
EVP_MD *md;
|
|
|
|
EVP_MD_CTX *mdCtx;
|
|
|
|
struct constants_t {
|
|
|
|
static constexpr SIZE_T inputBlockLen = SYMCRYPT_SHA256_INPUT_BLOCK_SIZE;
|
|
|
|
static constexpr SIZE_T resultLen = SYMCRYPT_SHA256_RESULT_SIZE;
|
|
|
|
static constexpr const char *const algorithm = "SHA2-256";
|
|
|
|
} constants;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
class HashImpState<ImpOpenssl, AlgSha384> {
|
|
|
|
public:
|
|
|
|
BOOLEAN isReset;
|
|
|
|
EVP_MD *md;
|
|
|
|
EVP_MD_CTX *mdCtx;
|
|
|
|
struct constants_t {
|
|
|
|
static constexpr SIZE_T inputBlockLen = SYMCRYPT_SHA384_INPUT_BLOCK_SIZE;
|
|
|
|
static constexpr SIZE_T resultLen = SYMCRYPT_SHA384_RESULT_SIZE;
|
|
|
|
static constexpr const char *const algorithm = "SHA2-384";
|
|
|
|
} constants;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
class HashImpState<ImpOpenssl, AlgSha512> {
|
|
|
|
public:
|
|
|
|
BOOLEAN isReset;
|
|
|
|
EVP_MD *md;
|
|
|
|
EVP_MD_CTX *mdCtx;
|
|
|
|
struct constants_t {
|
|
|
|
static constexpr SIZE_T inputBlockLen = SYMCRYPT_SHA512_INPUT_BLOCK_SIZE;
|
|
|
|
static constexpr SIZE_T resultLen = SYMCRYPT_SHA512_RESULT_SIZE;
|
|
|
|
static constexpr const char *const algorithm = "SHA2-512";
|
|
|
|
} constants;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
class HashImpState<ImpOpenssl, AlgSha3_256> {
|
|
|
|
public:
|
|
|
|
BOOLEAN isReset;
|
|
|
|
EVP_MD *md;
|
|
|
|
EVP_MD_CTX *mdCtx;
|
|
|
|
struct constants_t {
|
|
|
|
static constexpr SIZE_T inputBlockLen = SYMCRYPT_SHA3_256_INPUT_BLOCK_SIZE;
|
|
|
|
static constexpr SIZE_T resultLen = SYMCRYPT_SHA3_256_RESULT_SIZE;
|
|
|
|
static constexpr const char *const algorithm = "SHA3-256";
|
|
|
|
} constants;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
class HashImpState<ImpOpenssl, AlgSha3_384> {
|
|
|
|
public:
|
|
|
|
BOOLEAN isReset;
|
|
|
|
EVP_MD *md;
|
|
|
|
EVP_MD_CTX *mdCtx;
|
|
|
|
struct constants_t {
|
|
|
|
static constexpr SIZE_T inputBlockLen = SYMCRYPT_SHA3_384_INPUT_BLOCK_SIZE;
|
|
|
|
static constexpr SIZE_T resultLen = SYMCRYPT_SHA3_384_RESULT_SIZE;
|
|
|
|
static constexpr const char *const algorithm = "SHA3-384";
|
|
|
|
} constants;
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
class HashImpState<ImpOpenssl, AlgSha3_512> {
|
|
|
|
public:
|
|
|
|
BOOLEAN isReset;
|
|
|
|
EVP_MD *md;
|
|
|
|
EVP_MD_CTX *mdCtx;
|
|
|
|
struct constants_t {
|
|
|
|
static constexpr SIZE_T inputBlockLen = SYMCRYPT_SHA3_512_INPUT_BLOCK_SIZE;
|
|
|
|
static constexpr SIZE_T resultLen = SYMCRYPT_SHA3_512_RESULT_SIZE;
|
|
|
|
static constexpr const char *const algorithm = "SHA3-512";
|
|
|
|
} constants;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2024-03-16 03:10:00 +03:00
|
|
|
VOID
|
2024-03-29 06:39:59 +03:00
|
|
|
addOpensslAlgs();
|