1 /* 2 * Copyright (c) 2021-2022, Arm Limited. All rights reserved. 3 * 4 * SPDX-License-Identifier: BSD-3-Clause 5 * 6 */ 7 8 /** \file cc3xx_internal_chacha20.h 9 * 10 * This file contains the declarations of the internal functions to 11 * perform symmetric encryption and decryption using the Chacha20 12 * algorithm 13 * 14 */ 15 16 #ifndef CC3XX_INTERNAL_CHACHA20_H 17 #define CC3XX_INTERNAL_CHACHA20_H 18 19 #include "psa/crypto.h" 20 #include "chacha_driver.h" 21 22 #ifdef __cplusplus 23 extern "C" { 24 #endif 25 26 /** 27 * \brief Initialize the specified ChaCha20 context. 28 */ 29 void cc3xx_chacha20_init(ChachaContext_t *ctx); 30 31 /** 32 * \brief Release and clear the specified ChaCha20 context. 33 */ 34 void cc3xx_chacha20_free(ChachaContext_t *ctx); 35 36 /** 37 * \brief Set the encryption/decryption key. 38 */ 39 psa_status_t cc3xx_chacha20_setkey( 40 ChachaContext_t *ctx, 41 const uint8_t *key, 42 size_t key_size); 43 44 /** 45 * \brief Set the nonce. 46 */ 47 psa_status_t cc3xx_chacha20_set_nonce(ChachaContext_t *ctx, 48 const uint8_t *nonce, 49 size_t nonce_size); 50 51 /** 52 * \brief Set the initial counter value. 53 */ 54 psa_status_t cc3xx_chacha20_set_counter(ChachaContext_t *ctx, 55 uint32_t counter); 56 57 /** 58 * \brief Encrypt/decrypt data. 59 */ 60 psa_status_t cc3xx_chacha20_update( 61 ChachaContext_t *ctx, 62 const uint8_t *input, 63 size_t input_len, 64 uint8_t *output, 65 size_t output_size, 66 size_t *output_len); 67 /** 68 * \brief Finalize encryption/decryption. 69 */ 70 psa_status_t cc3xx_chacha20_finish( 71 ChachaContext_t *ctx, 72 uint8_t *output, 73 size_t output_size, 74 size_t *output_length); 75 76 #ifdef __cplusplus 77 } 78 #endif 79 #endif /* CC3XX_INTERNAL_CHACHA20_H */ 80