mirror of
https://github.com/projectacrn/acrn-hypervisor.git
synced 2025-05-20 22:30:39 +00:00
DM: Fix build failure with Openssl 1.1+
Some APIs of Openssl 1.0 are deprecated in Openssl 1.1+. Two different API implementations are adaptable to both Openssl 1.1- and 1.1+. Fixes: #305 Signed-off-by: Huang Yang <yang.huang@intel.com> Signed-off-by: Du Min <minx.du@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
parent
287fc4cb7f
commit
18c355f663
@ -30,6 +30,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
#include <openssl/hmac.h>
|
#include <openssl/hmac.h>
|
||||||
|
#include <openssl/opensslv.h>
|
||||||
|
|
||||||
#include "rpmb.h"
|
#include "rpmb.h"
|
||||||
#include "rpmb_sim.h"
|
#include "rpmb_sim.h"
|
||||||
@ -59,13 +60,15 @@ static int virtio_rpmb_debug = 1;
|
|||||||
#define DPRINTF(params) do { if (virtio_rpmb_debug) printf params; } while (0)
|
#define DPRINTF(params) do { if (virtio_rpmb_debug) printf params; } while (0)
|
||||||
#define WPRINTF(params) (printf params)
|
#define WPRINTF(params) (printf params)
|
||||||
|
|
||||||
|
/* Make rpmb_mac compatible for different openssl versions */
|
||||||
|
#if OPENSSL_VERSION_NUMBER < 0x10100000L
|
||||||
int rpmb_mac(const uint8_t *key, const struct rpmb_frame *frames,
|
int rpmb_mac(const uint8_t *key, const struct rpmb_frame *frames,
|
||||||
size_t frame_cnt, uint8_t *mac)
|
size_t frame_cnt, uint8_t *mac)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int hmac_ret;
|
int hmac_ret;
|
||||||
unsigned int md_len;
|
unsigned int md_len;
|
||||||
struct hmac_ctx_st hmac_ctx;
|
HMAC_CTX hmac_ctx;
|
||||||
|
|
||||||
HMAC_CTX_init(&hmac_ctx);
|
HMAC_CTX_init(&hmac_ctx);
|
||||||
hmac_ret = HMAC_Init_ex(&hmac_ctx, key, 32, EVP_sha256(), NULL);
|
hmac_ret = HMAC_Init_ex(&hmac_ctx, key, 32, EVP_sha256(), NULL);
|
||||||
@ -98,6 +101,52 @@ err:
|
|||||||
|
|
||||||
return hmac_ret ? 0 : -1;
|
return hmac_ret ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
#else
|
||||||
|
int rpmb_mac(const uint8_t *key, const struct rpmb_frame *frames,
|
||||||
|
size_t frame_cnt, uint8_t *mac)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
int hmac_ret;
|
||||||
|
unsigned int md_len;
|
||||||
|
HMAC_CTX *hmac_ctx;
|
||||||
|
|
||||||
|
hmac_ctx = HMAC_CTX_new();
|
||||||
|
if (hmac_ctx == NULL) {
|
||||||
|
DPRINTF(("get hmac_ctx failed\n"));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
hmac_ret = HMAC_Init_ex(hmac_ctx, key, 32, EVP_sha256(), NULL);
|
||||||
|
if (!hmac_ret) {
|
||||||
|
DPRINTF(("HMAC_Init_ex failed\n"));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < frame_cnt; i++) {
|
||||||
|
hmac_ret = HMAC_Update(hmac_ctx, frames[i].data, 284);
|
||||||
|
if (!hmac_ret) {
|
||||||
|
DPRINTF(("HMAC_Update failed\n"));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
hmac_ret = HMAC_Final(hmac_ctx, mac, &md_len);
|
||||||
|
if (md_len != 32) {
|
||||||
|
DPRINTF(("bad md_len %d != 32.\n", md_len));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!hmac_ret) {
|
||||||
|
DPRINTF(("HMAC_Final failed\n"));
|
||||||
|
goto err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err:
|
||||||
|
HMAC_CTX_free(hmac_ctx);
|
||||||
|
|
||||||
|
return hmac_ret ? 0 : -1;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static void rpmb_sim_close(void)
|
static void rpmb_sim_close(void)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user