Linux cryptographic layer development
 help / color / mirror / Atom feed
From: Steffen Klassert <steffen.klassert@secunet.com>
To: "Kasatkin, Dmitry" <dmitry.kasatkin@intel.com>
Cc: linux-crypto <linux-crypto@vger.kernel.org>
Subject: Re: crypto_ahash_setkey
Date: Wed, 23 Nov 2011 07:08:53 +0100	[thread overview]
Message-ID: <20111123060853.GH20943@secunet.com> (raw)
In-Reply-To: <CALLzPKYbbYV9keL7DAFfHVzn3SqQv3-1X+cJCp2hn2-ey9UpOw@mail.gmail.com>

Hi.

On Wed, Nov 23, 2011 at 12:00:29AM +0200, Kasatkin, Dmitry wrote:
> Hi,
> 
> I have noticed very odd behavior with hmac calculation on my dual
> core, 4 HTs PC.
> I am using async hash API to to calculate hmac over the page.
> I am using "hmac(sha1)" and the same key to calculate different pages.
> 
> I have a work queue, which calculates the hmac like...
> 
> int()
> {
>     tfm = crypto_alloc_ahash(...);
> }
> 
> work_task()
> {
>      crypto_ahash_setkey(tfm, key, keylen);
>      crypto_ahash_digest(req);
> }
> 
> HMAC result "sometimes" is incorrect.

Looks like a race. HMAC precalculates the hash of the ipaded/opaded key
and saves this hash on the transform. So the setkey method should be used
just once in the initialization path.

> 
> But when I move crypto_ahash_setkey() do the initialization code then
> HMAC result is always correct...
> (key is the same, so I can initialize it only once)
> 
> int()
> {
>      tfm = crypto_alloc_ahash(...);
>      crypto_ahash_setkey(tfm, key, keylen);
> }

That's how it should be. And in this case it works, as you
already noticed :)

  reply	other threads:[~2011-11-23  6:08 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-22 22:00 crypto_ahash_setkey Kasatkin, Dmitry
2011-11-23  6:08 ` Steffen Klassert [this message]
2011-11-23  9:09   ` crypto_ahash_setkey Kasatkin, Dmitry
2011-11-23  7:44 ` crypto_ahash_setkey Herbert Xu
2011-11-23  9:08   ` crypto_ahash_setkey Kasatkin, Dmitry
2011-11-23 10:07     ` crypto_ahash_setkey Herbert Xu
2011-11-23 10:25       ` crypto_ahash_setkey Kasatkin, Dmitry

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=20111123060853.GH20943@secunet.com \
    --to=steffen.klassert@secunet.com \
    --cc=dmitry.kasatkin@intel.com \
    --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