Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Stephan Mueller <smueller@chronox.de>
To: Herbert Xu <herbert@gondor.apana.org.au>
Cc: linux-crypto@vger.kernel.org
Subject: Re: [PATCH] crypto: add key wrapping block chaining mode
Date: Wed, 22 Apr 2015 14:44:08 +0200	[thread overview]
Message-ID: <1821606.i9q3K48O5i@myon.chronox.de> (raw)
In-Reply-To: <20150422054846.GA7804@gondor.apana.org.au>

Am Mittwoch, 22. April 2015, 13:48:46 schrieb Herbert Xu:

Hi Herbert,

> On Wed, Apr 22, 2015 at 06:36:59AM +0200, Stephan Mueller wrote:
> > +static int crypto_kw_decrypt(struct aead_request *req)
> > +{
> > +	struct crypto_aead *aead = crypto_aead_reqtfm(req);
> > +	struct crypto_kw_ctx *ctx = crypto_aead_ctx(aead);
> > +	struct crypto_cipher *tfm = ctx->child;
> > +	unsigned long alignmask = crypto_cipher_alignmask(tfm);
> > +	unsigned int src_nbytes, dst_nbytes, i;
> > +	struct scatter_walk src_walk, dst_walk;
> > +	struct crypto_kw_block block;
> 
> Why isn't this aligned like tbe_buffer?
> 
> > +	u8 tmpblock[SEMIBSIZE];
> > +	u64 t = 6 * ((req->cryptlen - SEMIBSIZE) >> 3);
> > +	int ret = -EAGAIN;
> > +	struct scatterlist src, dst;
> > +	/* IV of KW defined by section 6.2 */
> > +	u8 *default_iv = "\xA6\xA6\xA6\xA6\xA6\xA6\xA6\xA6";
> > +	unsigned int outcryptlen = req->cryptlen - SEMIBSIZE;
> > +
> > +	/*
> > +	 * Require at least 3 semiblocks as defined in SP800-38F and ensure
> > +	 * that the given data is aligned to semiblock.
> > +	 */
> > +	if (req->cryptlen < (3 * SEMIBSIZE) || req->cryptlen % 8)
> > +		return -EINVAL;
> > +
> > +	/*
> > +	 * src scatterlist is read only. dst scatterlist is r/w. During the
> > +	 * first loop, src points to req->src and dst to req->dst. For any
> > +	 * subsequent round, the code operates on req->dst only.
> > +	 */
> > +	crypto_kw_copy_scatterlist(req->src, &src);
> > +	crypto_kw_copy_scatterlist(req->dst, &dst);
> > +
> > +	for (i = 0; i < 6; i++) {
> > +		u8 tbe_buffer[SEMIBSIZE + alignmask];
> > +		/* alignment for the crypto_xor operation */
> 
> You're setting alignmask to that of the child transform, which
> may have no requirements on alignment at all.  So you need to
> ensure that it's at least 4-byte aligned for crypto_xor.

Will do in next installment.
> 
> > +	inst->alg.cra_alignmask = alg->cra_alignmask | (__alignof__(u64) - 1);
> 
> Where does this 8-byte alignment requirement come from?

Well, I am accessing the data in 8-byte chunks. Moreover, in the scatterwalk 
copy functions, I search through the scatterlists in 8 byte increments. If, 
say, a scatterwalk is not a multiple of 8 bytes, the scatterwalk logic will 
not process the last chunk of memory.
> 
> You also never actually pass any input data directly to the child,
> except for the key so you don't need to specify the child's alignment
> here at all.

Will change that.
> 
> Cheers,


-- 
Ciao
Stephan

  reply	other threads:[~2015-04-22 12:44 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-04-22  4:36 [PATCH] crypto: add key wrapping block chaining mode Stephan Mueller
2015-04-22  5:48 ` Herbert Xu
2015-04-22 12:44   ` Stephan Mueller [this message]
2015-04-23  1:39     ` Herbert Xu
2015-04-23  1:40       ` Stephan Mueller
2015-04-22  5:53 ` Herbert Xu
2015-04-22  6:13   ` Herbert Xu
2015-04-22 12:23     ` Stephan Mueller
2015-04-22 14:11       ` Stephan Mueller
2015-04-23  1:37         ` Herbert Xu
2015-04-23  1:33       ` Herbert Xu
2015-04-23  1:39         ` Stephan Mueller
2015-04-23  1:46           ` Herbert Xu
2015-04-23  1:58             ` Stephan Mueller
2015-04-23  2:03               ` Herbert Xu
2015-04-23  2:51             ` Stephan Mueller
2015-04-23  2:55               ` Herbert Xu
2015-04-23 13:42                 ` Stephan Mueller
2015-04-23 23:21                   ` Herbert Xu
2015-04-24  0:22                     ` Stephan Mueller
2015-04-24  0:24                       ` Herbert Xu
2015-04-22  6:06 ` 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=1821606.i9q3K48O5i@myon.chronox.de \
    --to=smueller@chronox.de \
    --cc=herbert@gondor.apana.org.au \
    --cc=linux-crypto@vger.kernel.org \
    /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