crypto: ccp - Limit the amount of information exported
[firefly-linux-kernel-4.4.55.git] / drivers / crypto / ccp / ccp-crypto-sha.c
index 3aae58def10650107b6c837f3d5eb39728049393..a67128a7af2345c7ef7327bd75b1b293c2dec268 100644 (file)
@@ -210,9 +210,14 @@ static int ccp_sha_digest(struct ahash_request *req)
 static int ccp_sha_export(struct ahash_request *req, void *out)
 {
        struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
-       struct ccp_sha_req_ctx *state = out;
+       struct ccp_sha_exp_ctx *state = out;
 
-       *state = *rctx;
+       state->type = rctx->type;
+       state->msg_bits = rctx->msg_bits;
+       state->first = rctx->first;
+       memcpy(state->ctx, rctx->ctx, sizeof(state->ctx));
+       state->buf_count = rctx->buf_count;
+       memcpy(state->buf, rctx->buf, sizeof(state->buf));
 
        return 0;
 }
@@ -220,9 +225,14 @@ static int ccp_sha_export(struct ahash_request *req, void *out)
 static int ccp_sha_import(struct ahash_request *req, const void *in)
 {
        struct ccp_sha_req_ctx *rctx = ahash_request_ctx(req);
-       const struct ccp_sha_req_ctx *state = in;
+       const struct ccp_sha_exp_ctx *state = in;
 
-       *rctx = *state;
+       rctx->type = state->type;
+       rctx->msg_bits = state->msg_bits;
+       rctx->first = state->first;
+       memcpy(rctx->ctx, state->ctx, sizeof(rctx->ctx));
+       rctx->buf_count = state->buf_count;
+       memcpy(rctx->buf, state->buf, sizeof(rctx->buf));
 
        return 0;
 }
@@ -428,7 +438,7 @@ static int ccp_register_sha_alg(struct list_head *head,
 
        halg = &alg->halg;
        halg->digestsize = def->digest_size;
-       halg->statesize = sizeof(struct ccp_sha_req_ctx);
+       halg->statesize = sizeof(struct ccp_sha_exp_ctx);
 
        base = &halg->base;
        snprintf(base->cra_name, CRYPTO_MAX_ALG_NAME, "%s", def->name);