/*
* Copyright 2015-2018 The OpenSSL Project Authors. All Rights Reserved.
*
- * Licensed under the OpenSSL license (the "License"). You may not use
+ * Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
/* MAC key */
unsigned char *key;
size_t key_len;
+ /* MAC IV (GMAC) */
+ unsigned char *iv;
+ size_t iv_len;
/* Input to MAC */
unsigned char *input;
size_t input_len;
/* Expected output */
unsigned char *output;
size_t output_len;
+ unsigned char *custom;
+ size_t custom_len;
/* Collection of controls */
STACK_OF(OPENSSL_STRING) *controls;
} MAC_DATA;
size_t sz = strlen(alg);
static const char epilogue[] = " by EVP_PKEY";
- if (strcmp(alg + sz - (sizeof(epilogue) - 1), epilogue) == 0)
+ if (sz >= sizeof(epilogue)
+ && strcmp(alg + sz - (sizeof(epilogue) - 1), epilogue) == 0)
sz -= sizeof(epilogue) - 1;
if (strncmp(alg, "HMAC", sz) == 0) {
sk_OPENSSL_STRING_pop_free(mdat->controls, openssl_free);
OPENSSL_free(mdat->alg);
OPENSSL_free(mdat->key);
+ OPENSSL_free(mdat->iv);
+ OPENSSL_free(mdat->custom);
OPENSSL_free(mdat->input);
OPENSSL_free(mdat->output);
}
if (strcmp(keyword, "Key") == 0)
return parse_bin(value, &mdata->key, &mdata->key_len);
+ if (strcmp(keyword, "IV") == 0)
+ return parse_bin(value, &mdata->iv, &mdata->iv_len);
+ if (strcmp(keyword, "Custom") == 0)
+ return parse_bin(value, &mdata->custom, &mdata->custom_len);
if (strcmp(keyword, "Algorithm") == 0) {
mdata->alg = OPENSSL_strdup(value);
if (!mdata->alg)
t->err = "MAC_CTRL_ERROR";
goto err;
}
+ if (expected->custom != NULL) {
+ rv = EVP_MAC_ctrl(ctx, EVP_MAC_CTRL_SET_CUSTOM,
+ expected->custom, expected->custom_len);
+ if (rv == -2) {
+ t->err = "MAC_CTRL_INVALID";
+ goto err;
+ } else if (rv <= 0) {
+ t->err = "MAC_CTRL_ERROR";
+ goto err;
+ }
+ }
+
+ if (expected->iv != NULL) {
+ rv = EVP_MAC_ctrl(ctx, EVP_MAC_CTRL_SET_IV,
+ expected->iv, expected->iv_len);
+ if (rv == -2) {
+ t->err = "MAC_CTRL_INVALID";
+ goto err;
+ } else if (rv <= 0) {
+ t->err = "MAC_CTRL_ERROR";
+ goto err;
+ }
+ }
if (!EVP_MAC_init(ctx)) {
t->err = "MAC_INIT_ERROR";