struct atmel_sha_dev;
/*
- * .statesize = sizeof(struct atmel_sha_state) must be <= PAGE_SIZE / 8 as
+ * .statesize = sizeof(struct atmel_sha_reqctx) must be <= PAGE_SIZE / 8 as
* tested by the ahash_prepare_alg() function.
*/
-struct atmel_sha_state {
- u8 digest[SHA512_DIGEST_SIZE];
- u8 buffer[SHA_BUFFER_LEN];
- u64 digcnt[2];
- size_t bufcnt;
-};
-
struct atmel_sha_reqctx {
struct atmel_sha_dev *dd;
unsigned long flags;
size_t block_size;
- u8 buffer[0] __aligned(sizeof(u32));
+ u8 buffer[SHA_BUFFER_LEN + SHA512_BLOCK_SIZE] __aligned(sizeof(u32));
};
struct atmel_sha_ctx {
static int atmel_sha_export(struct ahash_request *req, void *out)
{
const struct atmel_sha_reqctx *ctx = ahash_request_ctx(req);
- struct atmel_sha_state state;
-
- memcpy(state.digest, ctx->digest, SHA512_DIGEST_SIZE);
- memcpy(state.buffer, ctx->buffer, ctx->bufcnt);
- state.bufcnt = ctx->bufcnt;
- state.digcnt[0] = ctx->digcnt[0];
- state.digcnt[1] = ctx->digcnt[1];
- /* out might be unaligned. */
- memcpy(out, &state, sizeof(state));
+ memcpy(out, ctx, sizeof(*ctx));
return 0;
}
static int atmel_sha_import(struct ahash_request *req, const void *in)
{
struct atmel_sha_reqctx *ctx = ahash_request_ctx(req);
- struct atmel_sha_state state;
-
- /* in might be unaligned. */
- memcpy(&state, in, sizeof(state));
- memcpy(ctx->digest, state.digest, SHA512_DIGEST_SIZE);
- memcpy(ctx->buffer, state.buffer, state.bufcnt);
- ctx->bufcnt = state.bufcnt;
- ctx->digcnt[0] = state.digcnt[0];
- ctx->digcnt[1] = state.digcnt[1];
+ memcpy(ctx, in, sizeof(*ctx));
return 0;
}
static int atmel_sha_cra_init(struct crypto_tfm *tfm)
{
crypto_ahash_set_reqsize(__crypto_ahash_cast(tfm),
- sizeof(struct atmel_sha_reqctx) +
- SHA_BUFFER_LEN + SHA512_BLOCK_SIZE);
+ sizeof(struct atmel_sha_reqctx));
return 0;
}
.import = atmel_sha_import,
.halg = {
.digestsize = SHA1_DIGEST_SIZE,
- .statesize = sizeof(struct atmel_sha_state),
+ .statesize = sizeof(struct atmel_sha_reqctx),
.base = {
.cra_name = "sha1",
.cra_driver_name = "atmel-sha1",
.import = atmel_sha_import,
.halg = {
.digestsize = SHA256_DIGEST_SIZE,
- .statesize = sizeof(struct atmel_sha_state),
+ .statesize = sizeof(struct atmel_sha_reqctx),
.base = {
.cra_name = "sha256",
.cra_driver_name = "atmel-sha256",
.import = atmel_sha_import,
.halg = {
.digestsize = SHA224_DIGEST_SIZE,
- .statesize = sizeof(struct atmel_sha_state),
+ .statesize = sizeof(struct atmel_sha_reqctx),
.base = {
.cra_name = "sha224",
.cra_driver_name = "atmel-sha224",
.import = atmel_sha_import,
.halg = {
.digestsize = SHA384_DIGEST_SIZE,
- .statesize = sizeof(struct atmel_sha_state),
+ .statesize = sizeof(struct atmel_sha_reqctx),
.base = {
.cra_name = "sha384",
.cra_driver_name = "atmel-sha384",
.import = atmel_sha_import,
.halg = {
.digestsize = SHA512_DIGEST_SIZE,
- .statesize = sizeof(struct atmel_sha_state),
+ .statesize = sizeof(struct atmel_sha_reqctx),
.base = {
.cra_name = "sha512",
.cra_driver_name = "atmel-sha512",