blob: 0be227aec76d434838d27082db8166186df358dd [file] [log] [blame]
Unnati Gandhid42c0212015-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>
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
Unnati Gandhid42c0212015-06-03 12:03:24 +053048void crypto_unlock(void)
49{
50 crypto5_unlock_pipes(&dev);
51}
52
Deepa Dinamani0a976552012-11-28 17:01:27 -080053void ce_clock_init(void)
54{
55 /* Clock init is done during crypto_init. */
56}
57
58void crypto_eng_reset(void)
59{
60 /* Reset tied in with the clock init. */
61}
62
63void crypto_eng_init(void)
64{
65 crypto5_init(&dev);
66}
67
68void crypto_set_sha_ctx(void *ctx_ptr,
69 unsigned int bytes_to_write,
70 crypto_auth_alg_type auth_alg,
71 bool first,
72 bool last)
73{
74 crypto_SHA256_ctx *sha256_ctx = (crypto_SHA256_ctx *) ctx_ptr;
75
76 sha256_ctx->flags = 0;
77
78 if (first)
79 sha256_ctx->flags |= CRYPTO_FIRST_CHUNK;
80
81 if (last)
82 sha256_ctx->flags |= CRYPTO_LAST_CHUNK;
83
84 sha256_ctx->bytes_to_write = bytes_to_write;
85
86 crypto5_set_ctx(&dev, ctx_ptr, auth_alg);
87
88 /* Clear the flags. */
89 sha256_ctx->flags = 0;
90}
91
92void crypto_send_data(void *ctx_ptr,
93 unsigned char *data_ptr,
94 unsigned int buff_size,
95 unsigned int bytes_to_write,
96 unsigned int *ret_status)
97{
98 *ret_status = crypto5_send_data(&dev, ctx_ptr, data_ptr);
99}
100
101void crypto_get_digest(unsigned char *digest_ptr,
102 unsigned int *ret_status,
103 crypto_auth_alg_type auth_alg,
104 bool last)
105{
106 *ret_status = crypto5_get_digest(&dev, digest_ptr, auth_alg);
107}
108
109void crypto_get_ctx(void *ctx_ptr)
110{
111 crypto5_get_ctx(&dev, ctx_ptr);
112}
113
114uint32_t crypto_get_max_auth_blk_size()
115{
116 return crypto5_get_max_auth_blk_size(&dev);
Unnati Gandhid42c0212015-06-03 12:03:24 +0530117}