linux-crypto.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kamil Konieczny <k.konieczny@partner.samsung.com>
To: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Ard Biesheuvel <ard.biesheuvel@linaro.org>,
	linux-crypto@vger.kernel.org, herbert@gondor.apana.org.au,
	Vladimir Zapolskiy <vz@mleia.com>,
	"linux-samsung-soc@vger.kernel.org" 
	<linux-samsung-soc@vger.kernel.org>
Subject: Re: [PATCH 2/2] crypto: s5p - use correct block size of 1 for ctr(aes)
Date: Tue, 20 Aug 2019 14:28:03 +0200	[thread overview]
Message-ID: <f7f1babd-5c74-5561-4771-49809398da5f@partner.samsung.com> (raw)
In-Reply-To: <CAJKOXPfR_L4z=sE8ETUB3_6sVV=ab=vntqh-_KvNmsKacEa4qQ@mail.gmail.com>

On 20.08.2019 13:48, Krzysztof Kozlowski wrote:
> On Tue, 20 Aug 2019 at 13:39, Kamil Konieczny
> <k.konieczny@partner.samsung.com> wrote:
>>
>>
>>
>> On 20.08.2019 12:24, Krzysztof Kozlowski wrote:
>>> On Mon, 19 Aug 2019 at 16:24, Ard Biesheuvel <ard.biesheuvel@linaro.org> wrote:
>>>>
>>>> Align the s5p ctr(aes) implementation with other implementations
>>>> of the same mode, by setting the block size to 1.
>>>>
>>>> Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
>>>> ---
>>>>  drivers/crypto/s5p-sss.c | 2 +-
>>>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>>>
>>>> diff --git a/drivers/crypto/s5p-sss.c b/drivers/crypto/s5p-sss.c
>>>> index ef90c58edb1f..010f1bb20dad 100644
>>>> --- a/drivers/crypto/s5p-sss.c
>>>> +++ b/drivers/crypto/s5p-sss.c
>>>> @@ -2173,7 +2173,7 @@ static struct crypto_alg algs[] = {
>>>>                 .cra_flags              = CRYPTO_ALG_TYPE_ABLKCIPHER |
>>>>                                           CRYPTO_ALG_ASYNC |
>>>>                                           CRYPTO_ALG_KERN_DRIVER_ONLY,
>>>> -               .cra_blocksize          = AES_BLOCK_SIZE,
>>>> +               .cra_blocksize          = 1,
>>>
>>> This makes sense but I wonder how does it work later with
>>> s5p_aes_crypt() and its check for request length alignment
>>> (AES_BLOCK_SIZE). With block size of 1 byte, I understand that
>>> req->nbytes can be for example 4 bytes which is not AES block
>>> aligned... If my reasoning is correct, then the CTR mode in s5p-sss is
>>> not fully working.
>>
>> As I remember this case there are allocated buffers with len aligned up
>> AES_BLOCK_SIZE, source data copy to one buf, hw encrypts full block,
>> then nbytes are copy back.

to be precise, hw encrypts align_up(req->nbytes, AES_BLOCK_SIZE)

> Buffer alignment is different thing and it is defined in cra_alignmask.
> I am talking about req->nbytes which should be aligned according to
> s5p_aes_crypt(). But if blocksize is 1 byte, then what possible values
> for req->nbytes?

For AES-CTR, there are blocks of size multiply of AES_BLOCK_SIZE, with last
one which can be of any size

so for req->nbytes valid values are n*AES_BLOCK_SIZE + 0...AES_BLOCK_SIZE-1

-- 
Best regards,
Kamil Konieczny
Samsung R&D Institute Poland


  reply	other threads:[~2019-08-20 12:28 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-19 14:22 [PATCH 0/2] drivers/crypto - s5p fixes Ard Biesheuvel
2019-08-19 14:22 ` [PATCH 1/2] crypto: s5p - deal gracefully with bogus input sizes Ard Biesheuvel
2019-08-20  9:51   ` Kamil Konieczny
2019-08-20 10:07   ` Krzysztof Kozlowski
2019-08-19 14:22 ` [PATCH 2/2] crypto: s5p - use correct block size of 1 for ctr(aes) Ard Biesheuvel
2019-08-20  9:51   ` Kamil Konieczny
2019-08-20 10:24   ` Krzysztof Kozlowski
2019-08-20 10:57     ` Ard Biesheuvel
2019-08-20 11:23       ` Krzysztof Kozlowski
2019-08-20 11:39     ` Kamil Konieczny
2019-08-20 11:48       ` Krzysztof Kozlowski
2019-08-20 12:28         ` Kamil Konieczny [this message]
2019-08-30  8:19 ` [PATCH 0/2] drivers/crypto - s5p fixes Herbert Xu

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=f7f1babd-5c74-5561-4771-49809398da5f@partner.samsung.com \
    --to=k.konieczny@partner.samsung.com \
    --cc=ard.biesheuvel@linaro.org \
    --cc=herbert@gondor.apana.org.au \
    --cc=krzk@kernel.org \
    --cc=linux-crypto@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=vz@mleia.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).