1 /*
2  * Copyright (c) 2001-2022 Arm Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef  _CHACHA_DRIVER_H
8 #define  _CHACHA_DRIVER_H
9 
10 #include "driver_defs.h"
11 
12 #ifdef __cplusplus
13 extern "C"
14 {
15 #endif
16 
17 /******************************************************************************
18 *               TYPE DEFINITIONS
19 ******************************************************************************/
20 /* State information required to support arbitrarily long multipart calls */
21 typedef struct ChachaState {
22     uint8_t keystream[CHACHA_BLOCK_SIZE_BYTES]; /*!< Equals 64 byte of data */
23     uint8_t keystream_start; /*!< Index pointing to keystream data start */
24 } ChachaState_t;
25 
26 /* The context data-base used by the CHACHA functions on the low level */
27 typedef struct ChachaContext {
28     /* IV buffer */
29     uint32_t    nonceBuf[CHACHA_IV_96_SIZE_WORDS];
30     /* CHACHA block counter */
31     uint32_t    blockCounterLsb;
32     uint32_t    blockCounterMsb;
33     /* CHACHA Key: fixed size is 256 bit */
34     uint32_t    keyBuf[CHACHA_256_BIT_KEY_SIZE_WORDS];
35     /* Decrypt / Encrypt */
36     cryptoDirection_t dir;
37     /* data input addr type */
38     dataAddrType_t inputDataAddrType;
39     /* data output addr type */
40     dataAddrType_t outputDataAddrType;
41     /* CHACHA iv size */
42     chachaNonceSize_t nonceSize;
43     /* State to support multipart APIs */
44     ChachaState_t state;
45 } ChachaContext_t;
46 
47 /******************************************************************************
48 *               FUNCTION PROTOTYPES
49 ******************************************************************************/
50 /*!
51  * This function is used to process block(s) of data using the CHACHA machine.
52  *
53  * \param chachaCtx - A pointer to the CHACHA context buffer.
54  * \param pInputBuffInfo A structure which represents the data input buffer.
55  * \param pOutputBuffInfo A structure which represents the data output buffer.
56  * \param inDataSize - number of bytes to process.
57  *
58  * \return drvError_t defined in driver_defs.h.
59  */
60 drvError_t ProcessChacha(ChachaContext_t *chachaCtx, CCBuffInfo_t *pInputBuffInfo, CCBuffInfo_t *pOutputBuffInfo, uint32_t inDataSize);
61 
62 #ifdef __cplusplus
63 }
64 #endif
65 
66 #endif /* _CHACHA_DRIVER_H */
67