All of lore.kernel.org
 help / color / mirror / Atom feed
* Question about ahash export and import
@ 2017-09-26  9:36 Christophe LEROY
  2017-09-26 10:34 ` Gilad Ben-Yossef
  0 siblings, 1 reply; 8+ messages in thread
From: Christophe LEROY @ 2017-09-26  9:36 UTC (permalink / raw)
  To: Herbert Xu, Stephan Müller, linux-crypto

Hello,

Today, the talitos driver dma maps/unmaps context and keys at every 
single request.
I'm looking at doing the dma mapping at hash init and doing unmapping at 
final/finup/digest

However, I'm wondering how to manage hash exports and imports. I was 
initially thinking about doing a dma_sync_for_cpu() before any export 
and a dma_sync_for_device() after any export, but that supposes that the 
dma area is already mapped, which means that we have done the init and 
not yet done a final/finup/digest.

I'm a bit sceptic when reading the following text in include/crypto/hash.h :

@export: Export partial state of the transformation. This function dumps the
  *	    entire state of the ongoing transformation into a provided block of
  *	    data so it can be @import 'ed back later on. This is useful in case
  *	    you want to save partial result of the transformation after
  *	    processing certain amount of data and reload this partial result
  *	    multiple times later on for multiple re-use


Does it mean that import may be called in lieu of hash init, or is hash 
init always called before doing an import ?

Thanks
Christophe

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about ahash export and import
  2017-09-26  9:36 Question about ahash export and import Christophe LEROY
@ 2017-09-26 10:34 ` Gilad Ben-Yossef
  2017-09-26 11:09   ` Kamil Konieczny
  0 siblings, 1 reply; 8+ messages in thread
From: Gilad Ben-Yossef @ 2017-09-26 10:34 UTC (permalink / raw)
  To: Christophe LEROY; +Cc: Herbert Xu, Stephan Müller, linux-crypto

On Tue, Sep 26, 2017 at 12:36 PM, Christophe LEROY
<christophe.leroy@c-s.fr> wrote:
> Hello,
>
> Today, the talitos driver dma maps/unmaps context and keys at every single
> request.
> I'm looking at doing the dma mapping at hash init and doing unmapping at
> final/finup/digest
>
> However, I'm wondering how to manage hash exports and imports. I was
> initially thinking about doing a dma_sync_for_cpu() before any export and a
> dma_sync_for_device() after any export, but that supposes that the dma area
> is already mapped, which means that we have done the init and not yet done a
> final/finup/digest.
>
> I'm a bit sceptic when reading the following text in include/crypto/hash.h :
>
> @export: Export partial state of the transformation. This function dumps the
>  *          entire state of the ongoing transformation into a provided block
> of
>  *          data so it can be @import 'ed back later on. This is useful in
> case
>  *          you want to save partial result of the transformation after
>  *          processing certain amount of data and reload this partial result
>  *          multiple times later on for multiple re-use
>
>
> Does it mean that import may be called in lieu of hash init, or is hash init
> always called before doing an import ?
>

I believe import is called in lieu of init.

See the example is testmgr.c here:
http://elixir.free-electrons.com/linux/latest/source

import is called on a freshly allocated request (save for set_crypt
and set_callback), followed by
a call to update.

Gilad

> Thanks
> Christophe



-- 
Gilad Ben-Yossef
Chief Coffee Drinker

"If you take a class in large-scale robotics, can you end up in a
situation where the homework eats your dog?"
 -- Jean-Baptiste Queru

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about ahash export and import
  2017-09-26 10:34 ` Gilad Ben-Yossef
@ 2017-09-26 11:09   ` Kamil Konieczny
  2017-09-27  9:08     ` Herbert Xu
  0 siblings, 1 reply; 8+ messages in thread
From: Kamil Konieczny @ 2017-09-26 11:09 UTC (permalink / raw)
  To: Gilad Ben-Yossef, Christophe LEROY
  Cc: Herbert Xu, Stephan Müller, linux-crypto

On 26.09.2017 12:34, Gilad Ben-Yossef wrote:
> On Tue, Sep 26, 2017 at 12:36 PM, Christophe LEROY
> <christophe.leroy@c-s.fr> wrote:
>> Hello,
>>
>> Today, the talitos driver dma maps/unmaps context and keys at every single
>> request.
>> I'm looking at doing the dma mapping at hash init and doing unmapping at
>> final/finup/digest
>>
>> However, I'm wondering how to manage hash exports and imports. I was
>> initially thinking about doing a dma_sync_for_cpu() before any export and a
>> dma_sync_for_device() after any export, but that supposes that the dma area
>> is already mapped, which means that we have done the init and not yet done a
>> final/finup/digest.
>>
>> I'm a bit sceptic when reading the following text in include/crypto/hash.h :
>>
>> @export: Export partial state of the transformation. This function dumps the
>>  *          entire state of the ongoing transformation into a provided block
>> of
>>  *          data so it can be @import 'ed back later on. This is useful in
>> case
>>  *          you want to save partial result of the transformation after
>>  *          processing certain amount of data and reload this partial result
>>  *          multiple times later on for multiple re-use
>>
>>
>> Does it mean that import may be called in lieu of hash init, or is hash init
>> always called before doing an import ?
>>
> 
> I believe import is called in lieu of init.
> 
> See the example is testmgr.c here:
> http://elixir.free-electrons.com/linux/latest/source
> 
> import is called on a freshly allocated request (save for set_crypt
> and set_callback), followed by
> a call to update.

Both import()/export() are synchronous op, this means they are not allowed
to return -EINPROGRESS nor call complete().

Can import() be called without _any_ init(), for example
after reboot of machine ? Is following scenario valid:

init(), update() 0 or more times, export(),
save exported data to pernament storage
reboot machine
load crypto driver, import() saved state ?

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about ahash export and import
  2017-09-26 11:09   ` Kamil Konieczny
@ 2017-09-27  9:08     ` Herbert Xu
  2017-09-27 14:59       ` Christophe LEROY
  2017-11-24 13:35       ` Kamil Konieczny
  0 siblings, 2 replies; 8+ messages in thread
From: Herbert Xu @ 2017-09-27  9:08 UTC (permalink / raw)
  To: Kamil Konieczny
  Cc: Gilad Ben-Yossef, Christophe LEROY, Stephan Müller, linux-crypto

On Tue, Sep 26, 2017 at 01:09:05PM +0200, Kamil Konieczny wrote:
> 
> Can import() be called without _any_ init(), for example
> after reboot of machine ? Is following scenario valid:

Of course it can.  import must restore the state of the request
to that at the time when export was called.

import does not need to be called after init.  init simply resets
the hash state for new update/final calls.

> init(), update() 0 or more times, export(),
> save exported data to pernament storage
> reboot machine
> load crypto driver, import() saved state ?

Yes this must be supported.

Basically after any update call is complete (you've called the
completion function), you should be able to call export and
completely extract the partial (as opposed to finalised) hash
state.

Remember we need to support an arbitrarily large number of
concurrent hashing operations.  So you cannot keep a hash state
in hardware indefinitely just because the user has not called
finalize on it.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about ahash export and import
  2017-09-27  9:08     ` Herbert Xu
@ 2017-09-27 14:59       ` Christophe LEROY
  2017-09-28 10:25         ` Herbert Xu
  2017-11-24 13:35       ` Kamil Konieczny
  1 sibling, 1 reply; 8+ messages in thread
From: Christophe LEROY @ 2017-09-27 14:59 UTC (permalink / raw)
  To: Herbert Xu, Kamil Konieczny
  Cc: Gilad Ben-Yossef, Stephan Müller, linux-crypto



Le 27/09/2017 à 11:08, Herbert Xu a écrit :
> On Tue, Sep 26, 2017 at 01:09:05PM +0200, Kamil Konieczny wrote:
>>
>> Can import() be called without _any_ init(), for example
>> after reboot of machine ? Is following scenario valid:
> 
> Of course it can.  import must restore the state of the request
> to that at the time when export was called.
> 
> import does not need to be called after init.  init simply resets
> the hash state for new update/final calls.
> 
>> init(), update() 0 or more times, export(),
>> save exported data to pernament storage
>> reboot machine
>> load crypto driver, import() saved state ?
> 
> Yes this must be supported.
> 
> Basically after any update call is complete (you've called the
> completion function), you should be able to call export and
> completely extract the partial (as opposed to finalised) hash
> state.

Can we consider that once an export has been done, no new update call 
will be performed prior to doing an init or an import ? Or should it be 
possible to continue with an update or a final/finup call after an export ?

> 
> Remember we need to support an arbitrarily large number of
> concurrent hashing operations.  So you cannot keep a hash state
> in hardware indefinitely just because the user has not called
> finalize on it.
> 
> Cheers,
> 

Christophe

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about ahash export and import
  2017-09-27 14:59       ` Christophe LEROY
@ 2017-09-28 10:25         ` Herbert Xu
  0 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2017-09-28 10:25 UTC (permalink / raw)
  To: Christophe LEROY
  Cc: Kamil Konieczny, Gilad Ben-Yossef, Stephan Müller, linux-crypto

On Wed, Sep 27, 2017 at 04:59:56PM +0200, Christophe LEROY wrote:
> 
> Can we consider that once an export has been done, no new update call will
> be performed prior to doing an init or an import ? Or should it be possible
> to continue with an update or a final/finup call after an export ?

No export should not affect the ability to perform subsequent
update/finalize calls.  IOW it should be a read-only operation
as far as the hash state is concerned.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about ahash export and import
  2017-09-27  9:08     ` Herbert Xu
  2017-09-27 14:59       ` Christophe LEROY
@ 2017-11-24 13:35       ` Kamil Konieczny
  2017-11-25  0:16         ` Herbert Xu
  1 sibling, 1 reply; 8+ messages in thread
From: Kamil Konieczny @ 2017-11-24 13:35 UTC (permalink / raw)
  To: Herbert Xu
  Cc: Gilad Ben-Yossef, Christophe LEROY, Stephan Müller, linux-crypto

On 27.09.2017 11:08, Herbert Xu wrote:
> On Tue, Sep 26, 2017 at 01:09:05PM +0200, Kamil Konieczny wrote:
>>
>> Can import() be called without _any_ init(), for example
>> after reboot of machine ? Is following scenario valid:
> 
> Of course it can.  import must restore the state of the request
> to that at the time when export was called.
> 
> import does not need to be called after init.  init simply resets
> the hash state for new update/final calls.
> [...]

I have more questions, this time about HMAC export/import.
In doc, there is stated that key can be copied into context transformation.

Should .export copy request context _and_ key used ? Or not ?

When processing requests, can I assume the key in transformation is const until .final ?

Is is possible to have okey derived from different key then ikey ? I think not.

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

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: Question about ahash export and import
  2017-11-24 13:35       ` Kamil Konieczny
@ 2017-11-25  0:16         ` Herbert Xu
  0 siblings, 0 replies; 8+ messages in thread
From: Herbert Xu @ 2017-11-25  0:16 UTC (permalink / raw)
  To: Kamil Konieczny
  Cc: Gilad Ben-Yossef, Christophe LEROY, Stephan Müller, linux-crypto

On Fri, Nov 24, 2017 at 02:35:04PM +0100, Kamil Konieczny wrote:
>
> I have more questions, this time about HMAC export/import.
> In doc, there is stated that key can be copied into context transformation.
> 
> Should .export copy request context _and_ key used ? Or not ?

The key is stored in the tfm so export does not need to touch the
key.  However, sometimes the key is naturally embedded in the hash
state too, e.g., with hmac, in that case it would make sense for
export to copy it as part of the hash state.

> When processing requests, can I assume the key in transformation is const until .final ?

Yes you may.

> Is is possible to have okey derived from different key then ikey ? I think not.

We do not need to support that case.  If the user changes the
key mid-stream it results in undefined behaviour.  However,
the code should not crash though.

Cheers,
-- 
Email: Herbert Xu <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-11-25  0:17 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-09-26  9:36 Question about ahash export and import Christophe LEROY
2017-09-26 10:34 ` Gilad Ben-Yossef
2017-09-26 11:09   ` Kamil Konieczny
2017-09-27  9:08     ` Herbert Xu
2017-09-27 14:59       ` Christophe LEROY
2017-09-28 10:25         ` Herbert Xu
2017-11-24 13:35       ` Kamil Konieczny
2017-11-25  0:16         ` Herbert Xu

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.