Subject: alignmask in the API

The API allows to set an align mask. This mask is considered on the
allocation of cipher's private ctx and the IV (for block cipher). This
mask is ignored in the setkey function (what is fine with me).
encrypt() and decrypt() functions get their data through a scatterlist.
Is my understanding correct that I can't assume any alignment of the
input / output data? If so, is it fungible to modify the caller's code
to respect the aligmask?

Sebastian


2007-04-17 05:35:09

by Herbert Xu

[permalink] [raw]
Subject: Re: alignmask in the API

Sebastian Siewior <[email protected]> wrote:
> The API allows to set an align mask. This mask is considered on the
> allocation of cipher's private ctx and the IV (for block cipher). This
> mask is ignored in the setkey function (what is fine with me).
> encrypt() and decrypt() functions get their data through a scatterlist.
> Is my understanding correct that I can't assume any alignment of the
> input / output data? If so, is it fungible to modify the caller's code
> to respect the aligmask?

It's the API's responsibility to guarantee alignment. So in principle
neither the user nor the algorithm need to worry about alignment.

However, for the sake of performance, the user should take care of
alignment where it is easy to do. For instance, if you have to
allocate memory for an IV or src/dst as a crypto user, you should
try to get something that's aligned properly.

However, there is no point in doing an extra copy for the sake of
alignment since the crypto API will do it for you anyway.

Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Subject: Re: alignmask in the API

* Herbert Xu | 2007-04-17 15:35:05 [+1000]:

>It's the API's responsibility to guarantee alignment. So in principle
>neither the user nor the algorithm need to worry about alignment.
>
>However, there is no point in doing an extra copy for the sake of
>alignment since the crypto API will do it for you anyway.

setkey() is for crypto user is defined as:
static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher
*tfm,
const u8 *key, unsigned int keylen)
{
return crypto_ablkcipher_crt(tfm)->setkey(tfm, key, keylen);
}

If the key is not properly aligned by the caller, the cipher gets an
unaligned key.
What do you recommend?

>Cheers,
Sebastian

2007-05-09 03:40:29

by Herbert Xu

[permalink] [raw]
Subject: Re: alignmask in the API

On Tue, May 08, 2007 at 07:17:01PM +0200, Sebastian Siewior wrote:
>
> setkey() is for crypto user is defined as:
> static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher
> *tfm,
> const u8 *key, unsigned int keylen)
> {
> return crypto_ablkcipher_crt(tfm)->setkey(tfm, key, keylen);
> }
>
> If the key is not properly aligned by the caller, the cipher gets an
> unaligned key.
> What do you recommend?

I recommend that you write a patch :)

We just need some code in {cipher,blkcipher,ablkcipher}.c to check the
alignment and copy it if necessary. Check out how we deal with unaligned
IVs in blkcipher.c for example.

Cheers,
--
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

Subject: Re: alignmask in the API

* Herbert Xu | 2007-05-09 13:40:24 [+1000]:

>On Tue, May 08, 2007 at 07:17:01PM +0200, Sebastian Siewior wrote:
>>
>> setkey() is for crypto user is defined as:
>> static inline int crypto_ablkcipher_setkey(struct crypto_ablkcipher
>> *tfm,
>> const u8 *key, unsigned int keylen)
>> {
>> return crypto_ablkcipher_crt(tfm)->setkey(tfm, key, keylen);
>> }
>>
>> If the key is not properly aligned by the caller, the cipher gets an
>> unaligned key.
>> What do you recommend?
>
>I recommend that you write a patch :)
Okey.

>We just need some code in {cipher,blkcipher,ablkcipher}.c to check the
>alignment and copy it if necessary. Check out how we deal with unaligned
>IVs in blkcipher.c for example.
Will check.

>Cheers,
Sebastian