Skip to content

Commit

Permalink
Adapt other EVP code to use EVP_MAC instead of direct implementation …
Browse files Browse the repository at this point in the history
…calls

The EVP_PKEY methods for CMAC and HMAC needed a rework, although it
wasn't much change apart from name changes.

This also meant that EVP_PKEY_new_CMAC_key() needed an adjustment.
(the possibility to rewrite this function to work with any MAC is yet
to be explored)

Reviewed-by: Paul Dale <[email protected]>
(Merged from openssl#7484)
  • Loading branch information
levitte committed Oct 30, 2018
1 parent e74a435 commit b8d77c9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
7 changes: 3 additions & 4 deletions crypto/cmac/cm_ameth.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2010-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2010-2018 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the OpenSSL license (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
Expand All @@ -10,7 +10,6 @@
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/evp.h>
#include <openssl/cmac.h>
#include "internal/asn1_int.h"

/*
Expand All @@ -25,8 +24,8 @@ static int cmac_size(const EVP_PKEY *pkey)

static void cmac_key_free(EVP_PKEY *pkey)
{
CMAC_CTX *cmctx = EVP_PKEY_get0(pkey);
CMAC_CTX_free(cmctx);
EVP_MAC_CTX *cmctx = EVP_PKEY_get0(pkey);
EVP_MAC_CTX_free(cmctx);
}

const EVP_PKEY_ASN1_METHOD cmac_asn1_meth = {
Expand Down
8 changes: 5 additions & 3 deletions crypto/evp/p_lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
{
#ifndef OPENSSL_NO_CMAC
EVP_PKEY *ret = EVP_PKEY_new();
CMAC_CTX *cmctx = CMAC_CTX_new();
EVP_MAC_CTX *cmctx = EVP_MAC_CTX_new_id(EVP_MAC_CMAC);

if (ret == NULL
|| cmctx == NULL
Expand All @@ -328,7 +328,9 @@ EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,
goto err;
}

if (!CMAC_Init(cmctx, priv, len, cipher, e)) {
if (EVP_MAC_ctrl(cmctx, EVP_MAC_CTRL_SET_ENGINE, e) <= 0
|| EVP_MAC_ctrl(cmctx, EVP_MAC_CTRL_SET_CIPHER, cipher) <= 0
|| EVP_MAC_ctrl(cmctx, EVP_MAC_CTRL_SET_KEY, priv, len) <= 0) {
EVPerr(EVP_F_EVP_PKEY_NEW_CMAC_KEY, EVP_R_KEY_SETUP_FAILED);
goto err;
}
Expand All @@ -338,7 +340,7 @@ EVP_PKEY *EVP_PKEY_new_CMAC_key(ENGINE *e, const unsigned char *priv,

err:
EVP_PKEY_free(ret);
CMAC_CTX_free(cmctx);
EVP_MAC_CTX_free(cmctx);
return NULL;
#else
EVPerr(EVP_F_EVP_PKEY_NEW_CMAC_KEY,
Expand Down

0 comments on commit b8d77c9

Please sign in to comment.