From: Tadeusz Struk <tadeusz.struk@intel.com>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: keescook@chromium.org, jwboyer@redhat.com, smueller@chronox.de,
richard@nod.at, steved@redhat.com, linux-kernel@vger.kernel.org,
dhowells@redhat.com, linux-crypto@vger.kernel.org,
james.l.morris@oracle.com, jkosina@suse.cz,
zohar@linux.vnet.ibm.com, davem@davemloft.net, vgoyal@redhat.com
Subject: Re: [PATCH 2/2] crypto: qat - Don't move data inside output buffer
Date: Fri, 14 Aug 2015 07:21:29 -0700 [thread overview]
Message-ID: <55CDF969.6070704@intel.com> (raw)
In-Reply-To: <20150814062636.GA2799@gondor.apana.org.au>
Hi Herbert,
On 08/13/2015 11:26 PM, Herbert Xu wrote:
> On Thu, Aug 13, 2015 at 11:14:11PM -0700, Tadeusz Struk wrote:
>>
>> Right, but we don't need that anymore.
>
> Why not? If you reduce the size without moving the buffer wouldn't
> it begin with a bunch of zeroes and wouldn't you lose the real bytes
> at the end?
Yes, that was wrong, sorry. The reason I wanted to change it is that
the SW implementation can return a number with leading zeros.
This is because mpi_read_buffer() returns the whole thing.
Because the format of the module signature starts with 0x00, 0x01
the two implementations return a different thing.
For instance SW returned a 512 bytes number starting with 0x00, 0x01
and HW returned 511 bytes number without the 0x00 at the beginning.
Technically both are correct, but then the rsa_signture_verify()
needs to check for both cases, which is not ideal.
To make it return the same thing as SW we can do something like this:
---8<---
Allow for leading zeros in output to make it exactly the same as the
SW implementation.
Change memcpy to memmove because the copy is done within the same buffer.
diff --git a/drivers/crypto/qat/qat_common/qat_asym_algs.c b/drivers/crypto/qat/qat_common/qat_asym_algs.c
index fe352a6..cc450fa 100644
--- a/drivers/crypto/qat/qat_common/qat_asym_algs.c
+++ b/drivers/crypto/qat/qat_common/qat_asym_algs.c
@@ -118,7 +118,13 @@ static void qat_rsa_cb(struct icp_qat_fw_pke_resp *resp)
struct device *dev = &GET_DEV(req->ctx->inst->accel_dev);
int err = ICP_QAT_FW_PKE_RESP_PKE_STAT_GET(
resp->pke_resp_hdr.comn_resp_flags);
- char *ptr = areq->dst;
+#if BYTES_PER_MPI_LIMB == 4
+ u32 *ptr = areq->dst;
+#elif BYTES_PER_MPI_LIMB == 8
+ u64 *ptr = areq->dst;
+#else
+#error please implement for this limb size.
+#endif
err = (err == ICP_QAT_FW_COMN_STATUS_FLAG_OK) ? 0 : -EINVAL;
@@ -140,12 +146,12 @@ static void qat_rsa_cb(struct icp_qat_fw_pke_resp *resp)
areq->dst_len = req->ctx->key_sz;
/* Need to set the corect length of the output */
while (!(*ptr) && areq->dst_len) {
- areq->dst_len--;
+ areq->dst_len -= sizeof(*ptr);
ptr++;
}
if (areq->dst_len != req->ctx->key_sz)
- memcpy(areq->dst, ptr, areq->dst_len);
+ memmove(areq->dst, ptr, areq->dst_len);
akcipher_request_complete(areq, err);
}
next prev parent reply other threads:[~2015-08-14 14:24 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-13 3:54 [PATCH 0/2] crypto: KEYS: convert public key to the akcipher API Tadeusz Struk
2015-08-13 3:54 ` [PATCH 1/2] " Tadeusz Struk
2015-08-13 14:23 ` David Howells
2015-08-13 16:47 ` Tadeusz Struk
2015-08-14 1:09 ` Herbert Xu
2015-08-15 18:08 ` Stephan Mueller
2015-08-24 17:45 ` Tadeusz Struk
2015-08-13 3:54 ` [PATCH 2/2] crypto: qat - Don't move data inside output buffer Tadeusz Struk
2015-08-13 16:40 ` Tadeusz Struk
2015-08-14 5:14 ` Herbert Xu
2015-08-14 6:14 ` Tadeusz Struk
2015-08-14 6:26 ` Herbert Xu
2015-08-14 14:21 ` Tadeusz Struk [this message]
2015-08-17 8:48 ` Herbert Xu
2015-08-14 14:24 ` Tadeusz Struk
2015-08-17 8:50 ` Herbert Xu
2015-08-18 1:05 ` Tadeusz Struk
2015-08-18 2:39 ` Herbert Xu
2015-08-13 13:56 ` [PATCH 0/2] crypto: KEYS: convert public key to the akcipher API David Howells
2015-08-13 16:44 ` Tadeusz Struk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=55CDF969.6070704@intel.com \
--to=tadeusz.struk@intel.com \
--cc=davem@davemloft.net \
--cc=dhowells@redhat.com \
--cc=herbert@gondor.apana.org.au \
--cc=james.l.morris@oracle.com \
--cc=jkosina@suse.cz \
--cc=jwboyer@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=richard@nod.at \
--cc=smueller@chronox.de \
--cc=steved@redhat.com \
--cc=vgoyal@redhat.com \
--cc=zohar@linux.vnet.ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.