blob: 868eca0dd035128a58065a5b7740978414a53154 [file] [log] [blame]
Unnati Gandhie4bed302015-06-03 12:03:24 +05301/* Copyright (c) 2012,2015, The Linux Foundation. All rights reserved.
Deepa Dinamani0a976552012-11-28 17:01:27 -08002 *
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>
Channagoud Kadabi70b616b2015-07-23 10:40:15 -070031#include <platform/clock.h>
Deepa Dinamani0a976552012-11-28 17:01:27 -080032
33/* This file is a wrapper to the crypto5_eng.c.
34 * This is required so that we maintian the backward compatibility
35 * with the authentication logic in image_verify.c
36 */
37static struct crypto_dev dev;
38
39void crypto_init_params(struct crypto_init_params * params)
40{
41 crypto5_init_params(&dev, params);
42}
43
44void crypto_eng_cleanup(void)
45{
46 crypto5_cleanup(&dev);
47}
48
Unnati Gandhie4bed302015-06-03 12:03:24 +053049void crypto_unlock(void)
50{
51 crypto5_unlock_pipes(&dev);
52}
53
Deepa Dinamani0a976552012-11-28 17:01:27 -080054void ce_clock_init(void)
55{
Channagoud Kadabi70b616b2015-07-23 10:40:15 -070056 /* Configure CE clocks. */
57 clock_config_ce(dev.instance);
Deepa Dinamani0a976552012-11-28 17:01:27 -080058}
59
60void crypto_eng_reset(void)
61{
62 /* Reset tied in with the clock init. */
63}
64
65void crypto_eng_init(void)
66{
67 crypto5_init(&dev);
68}
69
70void crypto_set_sha_ctx(void *ctx_ptr,
71 unsigned int bytes_to_write,
72 crypto_auth_alg_type auth_alg,
73 bool first,
74 bool last)
75{
76 crypto_SHA256_ctx *sha256_ctx = (crypto_SHA256_ctx *) ctx_ptr;
77
78 sha256_ctx->flags = 0;
79
80 if (first)
81 sha256_ctx->flags |= CRYPTO_FIRST_CHUNK;
82
83 if (last)
84 sha256_ctx->flags |= CRYPTO_LAST_CHUNK;
85
86 sha256_ctx->bytes_to_write = bytes_to_write;
87
88 crypto5_set_ctx(&dev, ctx_ptr, auth_alg);
89
90 /* Clear the flags. */
91 sha256_ctx->flags = 0;
92}
93
94void crypto_send_data(void *ctx_ptr,
95 unsigned char *data_ptr,
96 unsigned int buff_size,
97 unsigned int bytes_to_write,
98 unsigned int *ret_status)
99{
100 *ret_status = crypto5_send_data(&dev, ctx_ptr, data_ptr);
101}
102
103void crypto_get_digest(unsigned char *digest_ptr,
104 unsigned int *ret_status,
105 crypto_auth_alg_type auth_alg,
106 bool last)
107{
108 *ret_status = crypto5_get_digest(&dev, digest_ptr, auth_alg);
109}
110
111void crypto_get_ctx(void *ctx_ptr)
112{
113 crypto5_get_ctx(&dev, ctx_ptr);
114}
115
116uint32_t crypto_get_max_auth_blk_size()
117{
118 return crypto5_get_max_auth_blk_size(&dev);
Unnati Gandhie4bed302015-06-03 12:03:24 +0530119}