summaryrefslogtreecommitdiff
path: root/security/keys/securekey_desc.h
blob: 170349ca963ea5a8c23f3af65f8d2344f34cb996 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright 2018 NXP
 *
 */
#ifndef _SECUREKEY_DESC_H_
#define _SECUREKEY_DESC_H_

#include "../../drivers/crypto/caam/compat.h"
#include "../../drivers/crypto/caam/regs.h"
#include "../../drivers/crypto/caam/intern.h"
#include "../../drivers/crypto/caam/desc.h"
#include "../../drivers/crypto/caam/desc_constr.h"
#include "../../drivers/crypto/caam/jr.h"
#include "../../drivers/crypto/caam/error.h"
#include "../../drivers/crypto/caam/pdb.h"

#define SK_BLOB_KEY_SZ		32	/* Blob key size. */
#define SK_BLOB_MAC_SZ		16	/* Blob MAC size. */

/*
 * brief defines different kinds of operations supported by this module.
 */
enum sk_req_type {
	sk_get_random,
	sk_red_blob_enc,
	sk_red_blob_dec,
};


/*
 * struct random_des
 * param[out] rnd_data output buffer for random data.
 */
struct random_desc {
	dma_addr_t rnd_data;
};

/* struct redblob_encap_desc
 * details Structure containing dma address for redblob encapsulation.
 * param[in] in_data input data to redblob encap descriptor.
 * param[out] redblob output buffer for redblob.
 */
struct redblob_encap_desc {
	dma_addr_t in_data;
	dma_addr_t redblob;
};

/* struct redblob_decap_desc
 * details Structure containing dma address for redblob decapsulation.
 * param[in] redblob input buffer to redblob decap descriptor.
 * param[out] out_data output data from redblob decap descriptor.
 */
struct redblob_decap_desc {
	dma_addr_t redblob;
	dma_addr_t out_data;
};

/* struct sk_desc
 * details Structure for securekey descriptor creation.
 * param[in] req_type operation supported.
 * param[in] dma_u union of struct for supported operation.
 */
struct sk_desc {
	u32 req_type;
	union {
		struct redblob_encap_desc redblob_encapdesc;
		struct redblob_decap_desc redblob_decapdesc;
		struct random_desc random_descp;
	} dma_u;
};

/* struct sk_fetch_rnd_data
 * decriptor structure containing key length.
 */
struct sk_fetch_rnd_data {
	void *data;
	size_t key_len;
};

/* struct sk_red_blob_encap
 * details Structure containing buffer pointers for redblob encapsulation.
 * param[in] data Input data.
 * param[in] data_sz size of Input data.
 * param[out] redblob output buffer for redblob.
 * param[in] redblob_sz size of redblob.
 */
struct sk_red_blob_encap {
	void *data;
	uint32_t data_sz;
	void *redblob;
	uint32_t redblob_sz;
};

/* struct sk_red_blob_decap
 * details Structure containing buffer pointers for redblob decapsulation.
 * param[in] redblob Input redblob.
 * param[in] redblob_sz size of redblob.
 * param[out] data output buffer for data.
 * param[in] data_sz size of output data.
 */
struct sk_red_blob_decap {
	void *redblob;
	uint32_t redblob_sz;
	void *data;
	uint32_t data_sz;
};

/* struct sk_req
 * details Structure for securekey request creation.
 * param[in] type operation supported.
 * param[in] req_u union of struct for supported operation.
 * param[out] ret return status of CAAM operation.
 * param[in] mem_pointer memory pointer for allocated kernel memory.
 * param[in] desc_pointer Pointer to securekey descriptor creation structure.
 * param[in] comp struct completion object.
 * param[in] hwdesc contains descriptor instructions.
 */
struct sk_req {
	enum sk_req_type type;
	void *arg;
	union {
		struct sk_red_blob_encap sk_red_blob_encap;
		struct sk_red_blob_decap sk_red_blob_decap;
		struct sk_fetch_rnd_data sk_fetch_rnd_data;
	} req_u;
	int ret;
	void *mem_pointer;
	void *desc_pointer;
	struct completion comp;
	u32 hwdesc[MAX_CAAM_DESCSIZE];
};

int caam_get_random(struct secure_key_payload *p,  enum sk_req_type fetch_rnd,
		    struct device *dev);
int key_blob(struct secure_key_payload *p, enum sk_req_type encap_type,
	     struct device *dev);
int key_deblob(struct secure_key_payload *p, enum sk_req_type decap_type,
	       struct device *dev);

#endif /*_SECUREKEY_DESC_H_*/