1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright 2018-2020 NXP 4 * 5 * Cipher interface calling the crypto driver. 6 */ 7 #ifndef __DRVCRYPT_CIPHER_H__ 8 #define __DRVCRYPT_CIPHER_H__ 9 10 #include <crypto/crypto_impl.h> 11 #include <tee_api_types.h> 12 13 /* 14 * Cipher operation context 15 */ 16 struct crypto_cipher { 17 struct crypto_cipher_ctx cipher_ctx; /* Crypto cipher API context */ 18 void *ctx; /* Cipher context */ 19 struct drvcrypt_cipher *op; /* Reference to the operation */ 20 }; 21 22 /* 23 * Cipher algorithm initialization data 24 */ 25 struct drvcrypt_cipher_init { 26 void *ctx; /* Software context */ 27 bool encrypt; /* Encrypt or decrypt direction */ 28 struct drvcrypt_buf key1; /* First key */ 29 struct drvcrypt_buf key2; /* Second key */ 30 struct drvcrypt_buf iv; /* Initial vector */ 31 }; 32 33 /* 34 * Cipher algorithm update data 35 */ 36 struct drvcrypt_cipher_update { 37 void *ctx; /* Software context */ 38 bool encrypt; /* Encrypt or decrypt direction */ 39 bool last; /* Last block to handle */ 40 struct drvcrypt_buf src; /* Buffer source (message or cipher) */ 41 struct drvcrypt_buf dst; /* Buffer dest (message or cipher) */ 42 }; 43 44 /* 45 * Crypto library cipher driver operations 46 */ 47 struct drvcrypt_cipher { 48 /* Allocate context */ 49 TEE_Result (*alloc_ctx)(void **ctx, uint32_t algo); 50 /* Free context */ 51 void (*free_ctx)(void *ctx); 52 /* Initialize the cipher operation */ 53 TEE_Result (*init)(struct drvcrypt_cipher_init *dinit); 54 /* Update the cipher operation */ 55 TEE_Result (*update)(struct drvcrypt_cipher_update *dupdate); 56 /* Finalize the cipher operation */ 57 void (*final)(void *ctx); 58 /* Copy cipher context */ 59 void (*copy_state)(void *dst_ctx, void *src_ctx); 60 }; 61 62 /* 63 * Register a cipher processing driver in the crypto API 64 * 65 * @ops - Driver operations 66 */ drvcrypt_register_cipher(struct drvcrypt_cipher * ops)67static inline TEE_Result drvcrypt_register_cipher(struct drvcrypt_cipher *ops) 68 { 69 return drvcrypt_register(CRYPTO_CIPHER, (void *)ops); 70 } 71 72 #endif /* __DRVCRYPT_CIPHER_H__ */ 73