EVP_EncryptInit_ex (ctx, cipher, NULL, op->key, op->iv);
EVP_EncryptUpdate (ctx, op->dst, &out_len, op->src, op->len);
- EVP_EncryptFinal_ex (ctx, op->dst + out_len, &out_len);
+ if (out_len < op->len)
+ EVP_EncryptFinal_ex (ctx, op->dst + out_len, &out_len);
op->status = VNET_CRYPTO_OP_STATUS_COMPLETED;
}
return n_ops;
EVP_DecryptInit_ex (ctx, cipher, NULL, op->key, op->iv);
EVP_DecryptUpdate (ctx, op->dst, &out_len, op->src, op->len);
- EVP_DecryptFinal_ex (ctx, op->dst + out_len, &out_len);
+ if (out_len < op->len)
+ EVP_DecryptFinal_ex (ctx, op->dst + out_len, &out_len);
op->status = VNET_CRYPTO_OP_STATUS_COMPLETED;
}
return n_ops;
openssl_ops_hmac (vlib_main_t * vm, vnet_crypto_op_t * ops[], u32 n_ops,
const EVP_MD * md)
{
+ u8 buffer[64];
openssl_per_thread_data_t *ptd = vec_elt_at_index (per_thread_data,
vm->thread_index);
HMAC_CTX *ctx = ptd->hmac_ctx;
- u32 i;
+ u32 i, n_fail = 0;
for (i = 0; i < n_ops; i++)
{
vnet_crypto_op_t *op = ops[i];
unsigned int out_len;
+ size_t sz = op->hmac_trunc_len ? op->hmac_trunc_len : EVP_MD_size (md);
HMAC_Init_ex (ctx, op->key, op->key_len, md, NULL);
HMAC_Update (ctx, op->src, op->len);
- HMAC_Final (ctx, op->dst, &out_len);
+ HMAC_Final (ctx, buffer, &out_len);
+
+ if (op->flags & VNET_CRYPTO_OP_FLAG_HMAC_CHECK)
+ {
+ if ((memcmp (op->dst, buffer, sz)))
+ {
+ n_fail++;
+ op->status = VNET_CRYPTO_OP_STATUS_FAIL_BAD_HMAC;
+ continue;
+ }
+ }
+ else
+ clib_memcpy_fast (op->dst, buffer, sz);
op->status = VNET_CRYPTO_OP_STATUS_COMPLETED;
}
- return n_ops;
+ return n_ops - n_fail;
}
#define _(a, b) \
time_t t;
pid_t pid;
- u32 eidx = vnet_crypto_register_engine (vm, "openssl", 50, "OpenSSL");
clib_error_t *error;
if ((error = vlib_call_init_function (vm, vnet_crypto_init)))
return error;
+ u32 eidx = vnet_crypto_register_engine (vm, "openssl", 50, "OpenSSL");
+
#define _(a, b) \
vnet_crypto_register_ops_handler (vm, eidx, VNET_CRYPTO_OP_##a##_ENC, \
openssl_ops_enc_##a); \