2010-10-22 16:55:25

by Allyn, Mark A

[permalink] [raw]
Subject: Questions about ahash

Folks:

I am attempting to implement an ahash instance for a hardware crypto device.

I see that there is a sha1 generic in the soruces a crypto/sha1_generic.c which uses the shash interface. I was hoping to use that, but there is some stuff in the headers that is confusing.

In include/crypto/hash.h, there is a structure crypto_ahash which has pointers to the init, update, final, etc algorithms. These same algorithms are also referred to in the ahash_alg structure.

In the case of shash, the crypto_shash structure does not have pointers to the algorithms.

Why is the crypto_ahash structure so different?

There is a function shash_desc_ctx, but there is no function ahash_des_ctx. In the crys_sha1_init() function of sha1_generic, you call shash_desc_ctx. If I want to use the ahash instead of shash for sha1, then do I use shash_desc_ctx, or do I have to come up with my own ahash_desc_ctx?

Thanks

Mark Allyn


2010-10-25 23:42:09

by Herbert Xu

[permalink] [raw]
Subject: Re: Questions about ahash

Allyn, Mark A <[email protected]> wrote:
> Folks:
>
> I am attempting to implement an ahash instance for a hardware crypto device.
>
> I see that there is a sha1 generic in the soruces a crypto/sha1_generic.c which uses the shash interface. I was hoping to use that, but there is some stuff in the headers that is confusing.

You should use shash only if your hardware is synchronous, e.g.,
the AESNI instruction is a good example where a synchronous
interface is appropriate.

The reason crypto_ahash is so different is because it should be
used where you need an asynchronous interface, where state has
to be stored indefinitely.

> There is a function shash_desc_ctx, but there is no function ahash_des_ctx. In the crys_sha1_init() function of sha1_generic, you call shash_desc_ctx. If I want to use the ahash instead of shash for sha1, then do I use shash_desc_ctx, or do I have to come up with my own ahash_desc_ctx?

The counterpart to shash_desc_ctx is ahash_request_ctx.

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

2010-10-25 23:51:11

by Mark Allyn

[permalink] [raw]
Subject: Re: Questions about ahash


Herbert:

Perhaps this is very fundamential, but what is the difference between
synchronous and asynchronous as far as crypto is concerned? My device
performs encryption and decryption asynchronously in relation to
the main processor in the system. The driver tells the device to
do x, then goes away and does other stuff, then gets an interrupt
when the device is done and ready.

The user space app waits for the device to finish, but the kernel
is doing other stuff in the meantime.


Truly,

Mark Allyn
Portland, Oregon
http://www.allyn.com
971-563-7588

> You should use shash only if your hardware is synchronous, e.g.,
> the AESNI instruction is a good example where a synchronous
> interface is appropriate.
>
> The reason crypto_ahash is so different is because it should be
> used where you need an asynchronous interface, where state has
> to be stored indefinitely.

2010-10-26 00:04:45

by Herbert Xu

[permalink] [raw]
Subject: Re: Questions about ahash

Mark Allyn <[email protected]> wrote:
>
> Herbert:
>
> Perhaps this is very fundamential, but what is the difference between
> synchronous and asynchronous as far as crypto is concerned? My device
> performs encryption and decryption asynchronously in relation to
> the main processor in the system. The driver tells the device to
> do x, then goes away and does other stuff, then gets an interrupt
> when the device is done and ready.

That is clearly a candidate for the ahash interface.

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