Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psa cipher chacha20 multipart operation implementation #20788

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
sys/psa_crypto: chacha20 multipart glue code
  • Loading branch information
Wunderbaeumchen99817 committed Jul 30, 2024
commit a061d2f7eab55000494b46f5b4c3525e89e01f50
1 change: 1 addition & 0 deletions cpu/nrf52/Makefile.features
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ ifneq (,$(filter nrf52840xxaa,$(CPU_MODEL)))
FEATURES_PROVIDED += periph_hash_sha_512
FEATURES_PROVIDED += periph_hmac_sha_256
FEATURES_PROVIDED += periph_cipher_aes_128_cbc
FEATURES_PROVIDED += periph_cipher_chacha20
FEATURES_PROVIDED += periph_ecc_p192r1
FEATURES_PROVIDED += periph_ecc_p256r1
FEATURES_PROVIDED += periph_ecc_ed25519
Expand Down
5 changes: 5 additions & 0 deletions cpu/nrf52/periph/Makefile.dep
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ ifneq (,$(filter periph_cipher_aes_128_cbc,$(USEMODULE)))
USEMODULE += psa_cryptocell_310_aes_cbc
endif

ifneq (,$(filter periph_cipher_chacha20,$(USEMODULE)))
USEPKG += driver_cryptocell_310
USEMODULE += psa_cryptocell_310_cipher_chacha20
endif

ifneq (,$(filter periph_hmac_sha_256,$(USEMODULE)))
USEPKG += driver_cryptocell_310
USEMODULE += psa_cryptocell_310_hmac
Expand Down
2 changes: 2 additions & 0 deletions features.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -851,6 +851,8 @@ groups:
help: A Hardware Random Number Generator (HWRNG) peripheral is present.
- name: periph_cipher_aes_128_cbc
help: AES 128 CBC hardware acceleration present
- name: periph_cipher_chacha20
help: ChaCha20 hardware acceleration present
- name: periph_ecc_p192r1
help: ECC P192R1 hardware acceleration peripheral present.
- name: periph_ecc_p256r1
Expand Down
1 change: 1 addition & 0 deletions makefiles/features_existing.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ FEATURES_EXISTING := \
periph_adc_continuous \
periph_can \
periph_cipher_aes_128_cbc \
periph_cipher_chacha20 \
periph_clic \
periph_coretimer \
periph_cpuid \
Expand Down
1 change: 1 addition & 0 deletions makefiles/features_modules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ USEMODULE += $(PERIPH_FEATURES)
# Add all USED periph_% init modules unless they are blacklisted
PERIPH_IGNORE_MODULES := \
periph_cipher_aes_128_cbc \
periph_cipher_chacha20 \
periph_clic \
periph_common \
periph_coretimer \
Expand Down
1 change: 1 addition & 0 deletions makefiles/pseudomodules.inc.mk
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ PSEUDOMODULES += psa_riot_cipher_aes_128_ecb
PSEUDOMODULES += psa_riot_cipher_aes_128_cbc
PSEUDOMODULES += psa_riot_cipher_aes_192_cbc
PSEUDOMODULES += psa_riot_cipher_aes_256_cbc
PSEUDOMODULES += psa_riot_cipher_chacha20
PSEUDOMODULES += psa_riot_hashes_md5
PSEUDOMODULES += psa_riot_hashes_sha_1
PSEUDOMODULES += psa_riot_hashes_sha_224
Expand Down
1 change: 1 addition & 0 deletions pkg/driver_cryptocell_310/Makefile.include
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ CFLAGS += -Wno-cast-align

PSEUDOMODULES += psa_cryptocell_310_aes_cbc
PSEUDOMODULES += psa_cryptocell_310_aes_common
PSEUDOMODULES += psa_cryptocell_310_cipher_chacha20
PSEUDOMODULES += psa_cryptocell_310_ecc_common
PSEUDOMODULES += psa_cryptocell_310_ecc_p192
PSEUDOMODULES += psa_cryptocell_310_ecc_p256
Expand Down
4 changes: 4 additions & 0 deletions pkg/driver_cryptocell_310/include/cryptocell_310_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
extern "C" {
#endif

#ifdef CPU_NRF52
#define CHECK_POINTER_DMA_ACCESS(p) ((unsigned int)p >= 0x20000000 ? (unsigned int)p < 0x40000000 : 0)

Check warning on line 27 in pkg/driver_cryptocell_310/include/cryptocell_310_util.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
#endif

/**
* @brief Enable CryptoCell module and IRQs.
*
Expand Down
1 change: 1 addition & 0 deletions pkg/driver_cryptocell_310/include/psa_error.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern "C" {
#include "crys_ec_mont_edw_error.h"
#include "crys_hash_error.h"
#include "ssi_aes_error.h"
#include "crys_chacha_error.h"

/**
* @brief Convert CryptoCell CRYS errors to PSA status values
Expand Down
58 changes: 58 additions & 0 deletions pkg/driver_cryptocell_310/include/psa_periph_chacha20_ctx.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2024 TU Dresden
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup pkg_driver_cryptocell_310
* @{
*
* @file
* @brief CryptoCell 310 driver specific ChaCha20 contexts
*
* @author Lennard Melling <lennard.melling@msx.tu-dresden.de>
*
*/
#ifndef PSA_PERIPH_CHACHA20_CTX_H
#define PSA_PERIPH_CHACHA20_CTX_H

#ifdef __cplusplus
extern "C" {
#endif

#include "crys_chacha.h"
#include "kernel_defines.h"

#if IS_USED(MODULE_PERIPH_CIPHER_CHACHA20) || DOXYGEN
/**
* @brief This struct is used to handle the discontinuity between the PSA API
* and the CRYS ChaCha20 API. The PSA API psa_cipher_update() function allows any size
* of input array, but the CRYS implementation only works on multiples of 64B.
* So we store any remainders from the input in the buffer, and if any more data
* is input, we join them with the buffer values. The psa_cipher_finish() function
* will then xcrypt the remaining buffer values.
* The buffer is also used in the setup of the operation. The psa_cipher_~_setup()
* functions only provide the key for the operation, but the CRYS ChaCha20
* implementation also needs the counter and nonce provided by psa_cipher_set_iv().
* So we store the key in the buffer until it is needed in the CRYS ChaCha20 setup.
*/
typedef struct {
uint8_t buffer[CRYS_CHACHA_BLOCK_SIZE_IN_BYTES]; /**< Block buffer */
uint8_t buffer_length; /**< Current length of the data in buffer */
union {
CRYS_CHACHA_EncryptMode_t mode; /**< Mode of the operation */
CRYS_CHACHAUserContext_t post_setup; /**< Context of the CRYS ChaCha20 operation */

Check warning on line 47 in pkg/driver_cryptocell_310/include/psa_periph_chacha20_ctx.h

View workflow job for this annotation

GitHub Actions / static-tests

line is longer than 100 characters
} ctx; /**< Context Setup values */
} psa_cipher_chacha20_ctx_t;

#endif

#ifdef __cplusplus
}
#endif

#endif /* PSA_PERIPH_CHACHA20_CTX_H */
/** @} */
Loading
Loading