blob: db12320c9852da53c29b0974b064f8836be2233f [file] [log] [blame]
Deepa Dinamani0a976552012-11-28 17:01:27 -08001/* Copyright (c) 2012, The Linux Foundation. All rights reserved.
2 *
3 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
6 * * Redistributions of source code must retain the above copyright
7 * notice, this list of conditions and the following disclaimer.
8 * * Redistributions in binary form must reproduce the above
9 * copyright notice, this list of conditions and the following
10 * disclaimer in the documentation and/or other materials provided
11 * with the distribution.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED
17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#include <debug.h>
30#include <crypto5_wrapper.h>
31
32/* This file is a wrapper to the crypto5_eng.c.
33 * This is required so that we maintian the backward compatibility
34 * with the authentication logic in image_verify.c
35 */
36static struct crypto_dev dev;
37
38void crypto_init_params(struct crypto_init_params * params)
39{
40 crypto5_init_params(&dev, params);
41}
42
43void crypto_eng_cleanup(void)
44{
45 crypto5_cleanup(&dev);
46}
47
48void ce_clock_init(void)
49{
50 /* Clock init is done during crypto_init. */
51}
52
53void crypto_eng_reset(void)
54{
55 /* Reset tied in with the clock init. */
56}
57
58void crypto_eng_init(void)
59{
60 crypto5_init(&dev);
61}
62
63void crypto_set_sha_ctx(void *ctx_ptr,
64 unsigned int bytes_to_write,
65 crypto_auth_alg_type auth_alg,
66 bool first,
67 bool last)
68{
69 crypto_SHA256_ctx *sha256_ctx = (crypto_SHA256_ctx *) ctx_ptr;
70
71 sha256_ctx->flags = 0;
72
73 if (first)
74 sha256_ctx->flags |= CRYPTO_FIRST_CHUNK;
75
76 if (last)
77 sha256_ctx->flags |= CRYPTO_LAST_CHUNK;
78
79 sha256_ctx->bytes_to_write = bytes_to_write;
80
81 crypto5_set_ctx(&dev, ctx_ptr, auth_alg);
82
83 /* Clear the flags. */
84 sha256_ctx->flags = 0;
85}
86
87void crypto_send_data(void *ctx_ptr,
88 unsigned char *data_ptr,
89 unsigned int buff_size,
90 unsigned int bytes_to_write,
91 unsigned int *ret_status)
92{
93 *ret_status = crypto5_send_data(&dev, ctx_ptr, data_ptr);
94}
95
96void crypto_get_digest(unsigned char *digest_ptr,
97 unsigned int *ret_status,
98 crypto_auth_alg_type auth_alg,
99 bool last)
100{
101 *ret_status = crypto5_get_digest(&dev, digest_ptr, auth_alg);
102}
103
104void crypto_get_ctx(void *ctx_ptr)
105{
106 crypto5_get_ctx(&dev, ctx_ptr);
107}
108
109uint32_t crypto_get_max_auth_blk_size()
110{
111 return crypto5_get_max_auth_blk_size(&dev);
112}