static int qat_dh_set_secret(struct crypto_kpp *tfm, const void *buf, unsigned int len) { struct qat_dh_ctx *ctx = kpp_tfm_ctx(tfm); struct device *dev = &GET_DEV(ctx->inst->accel_dev); struct dh params; int ret; if (crypto_dh_decode_key(buf, len, ¶ms) < 0) return -EINVAL; /* Free old secret if any */ qat_dh_clear_ctx(dev, ctx); ret = qat_dh_set_params(ctx, ¶ms); if (ret < 0) return ret; ctx->xa = dma_zalloc_coherent(dev, ctx->p_size, &ctx->dma_xa, GFP_KERNEL); if (!ctx->xa) { qat_dh_clear_ctx(dev, ctx); return -ENOMEM; } memcpy(ctx->xa + (ctx->p_size - params.key_size), params.key, params.key_size); return 0; }
static int dh_set_secret(struct crypto_kpp *tfm, void *buf, unsigned int len) { struct dh_ctx *ctx = dh_get_ctx(tfm); struct dh params; if (crypto_dh_decode_key(buf, len, ¶ms) < 0) return -EINVAL; if (dh_set_params(ctx, ¶ms) < 0) return -EINVAL; ctx->xa = mpi_read_raw_data(params.key, params.key_size); if (!ctx->xa) { dh_clear_params(ctx); return -EINVAL; } return 0; }