xref: /optee_os/core/drivers/crypto/caam/cipher/local.h (revision 6f0990d879055669fb70cffbfab19b4fc0f2d7d9)
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /*
3  * Copyright 2018-2020 NXP
4  *
5  * CAAM Cipher Local header.
6  */
7 #ifndef __LOCAL_H__
8 #define __LOCAL_H__
9 
10 #include <drvcrypt.h>
11 #include <drvcrypt_cipher.h>
12 
13 /*
14  * Definition of the maximum number of CAAM Job descriptor entries
15  */
16 #ifdef CFG_CAAM_64BIT
17 #define MAX_DESC_ENTRIES 22
18 #else
19 #define MAX_DESC_ENTRIES 16
20 #endif
21 
22 /*
23  * Definition of flags tagging which key(s) is required
24  */
25 #define NEED_KEY1  BIT(0)
26 #define NEED_KEY2  BIT(1)
27 #define NEED_IV    BIT(2)
28 #define NEED_TWEAK BIT(3)
29 
30 /*
31  * Cipher Algorithm definition
32  */
33 struct cipheralg {
34 	uint32_t type;             /* Algo type for operation */
35 	uint8_t size_block;        /* Computing block size */
36 	uint8_t size_ctx;          /* CAAM Context Register size */
37 	uint8_t ctx_offset;        /* CAAM Context Register offset */
38 	uint8_t require_key;       /* Tag defining key(s) required */
39 	struct caamdefkey def_key; /* Key size accepted */
40 
41 	TEE_Result (*update)(struct drvcrypt_cipher_update *dupdate);
42 };
43 
44 /*
45  * Full Cipher data SW context
46  */
47 struct cipherdata {
48 	uint32_t *descriptor;        /* Job descriptor */
49 	bool encrypt;                /* Encrypt direction */
50 	struct caambuf key1;         /* First Key */
51 	struct caambuf key2;         /* Second Key */
52 	struct caambuf tweak;        /* XTS Tweak */
53 	struct caambuf ctx;          /* CAAM Context Register */
54 	struct caamblock blockbuf;   /* Temporary Block buffer */
55 	const struct cipheralg *alg; /* Reference to the algo constants */
56 };
57 
58 /*
59  * Update of the cipher operation of complete block except
60  * if last block. Last block can be partial block.
61  *
62  * @ctx      Cipher context
63  * @savectx  Save or not the context
64  * @keyid    Id of the key to be used during operation
65  * @encrypt  Encrypt or decrypt direction
66  * @src      Source data to encrypt/decrypt
67  * @dst      [out] Destination data encrypted/decrypted
68  * @blockbuf Saved block during previous streaming update
69  */
70 enum caam_status caam_cipher_block(struct cipherdata *ctx, bool savectx,
71 				   uint8_t keyid, bool encrypt,
72 				   struct caambuf *src, struct caambuf *dst,
73 				   bool blockbuf);
74 
75 /*
76  * Update of the cipher operation in xts mode.
77  *
78  * @dupdate  Data update object
79  */
80 TEE_Result caam_cipher_update_xts(struct drvcrypt_cipher_update *dupdate);
81 
82 #endif /* __LOCAL_H__ */
83