All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tadeusz Struk <tadeusz.struk@intel.com>
To: Markus Stockhausen <stockhausen@collogia.de>
Cc: "linux-crypto@vger.kernel.org" <linux-crypto@vger.kernel.org>
Subject: Re: AW: AW: Best way to align key in AES context
Date: Fri, 13 Feb 2015 16:59:28 -0800	[thread overview]
Message-ID: <54DE9DF0.3070508@intel.com> (raw)
In-Reply-To: <12EF8D94C6F8734FB2FF37B9FBEDD1735F9DE3DA@EXCHANGE.collogia.de>

On 02/13/2015 08:49 AM, Markus Stockhausen wrote:
> thanks for the tip.  I will at least move the data definitions to the beginning of 
> my structure.
> 
> But while it sounds logical for data types that are directly created from that 
> structure I'm unsure about a context. If I understand it correctly a context is 
> dynamically allocated. Could it be possible that the start address is then only 
> 4 bytes aligned?
> 
> So I tried to dive into the magic of alignmask and contexts. This even confuses
> me a little bit more. Nearly all implementations in the crypto tree make use of
> alignmasks >= 3. I guess to be at least 4 bytes aligned. But when accessing the
> context they "only" use crypto_blkcipher_ctx(). This will just return the context
> address while crypto_blkcipher_ctx_aligned() seems to be the right place to 
> return a pointer that is aligned according to the predefined mask.
> 
> Would you recommend to
> 
> a) ignore alignmask and use only __aligned(8) for the structure
> 
> b) to assume ctx will be automatically 8 bytes aligned regardless of __aligned(8)
> flag or cra_alignmask. So nothing to take care about.
> 
> b) or to define structure without __aligned(8) but work with cra_alignmask=7. 
> I fear that this might impose alignment of input/output data to 8 too and lead 
> to unneccessary memcpy() operations.
> 
> Sorry for driving myself nuts but I want to understand if before I send patches.

In this case I think the best way is to define your algorithm with

	.cra_ctxsize = sizeof(struct ppc_aes_ctx) + 8,

and then in enc/dec/setkey do

	struct ppc_aes_ctx *ctx = PTR_ALIGN(crypto_tfm_ctx(tfm), 8);

and you don't need the __aligned(8) in the struct definition.

      reply	other threads:[~2015-02-14  1:03 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <12EF8D94C6F8734FB2FF37B9FBEDD1735F9DD863@EXCHANGE.collogia.de>
2015-02-11 10:28 ` AW: Best way to align key in AES context Markus Stockhausen
2015-02-13 14:47   ` Tadeusz Struk
2015-02-13 16:49     ` AW: " Markus Stockhausen
2015-02-14  0:59       ` Tadeusz Struk [this message]

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=54DE9DF0.3070508@intel.com \
    --to=tadeusz.struk@intel.com \
    --cc=linux-crypto@vger.kernel.org \
    --cc=stockhausen@collogia.de \
    /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.