1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2019, Linaro Limited 4 */ 5 6 #ifndef __CRYPTO_CRYPTO_IMPL_H 7 #define __CRYPTO_CRYPTO_IMPL_H 8 9 #include <tee_api_types.h> 10 11 /* 12 * The crypto context used by the crypto_hash_*() functions is defined by 13 * struct crypto_hash_ctx. 14 */ 15 struct crypto_hash_ctx { 16 const struct crypto_hash_ops *ops; 17 }; 18 19 struct crypto_hash_ops { 20 TEE_Result (*init)(struct crypto_hash_ctx *ctx); 21 TEE_Result (*update)(struct crypto_hash_ctx *ctx, const uint8_t *data, 22 size_t len); 23 TEE_Result (*final)(struct crypto_hash_ctx *ctx, uint8_t *digest, 24 size_t len); 25 void (*free_ctx)(struct crypto_hash_ctx *ctx); 26 void (*copy_state)(struct crypto_hash_ctx *dst_ctx, 27 struct crypto_hash_ctx *src_ctx); 28 }; 29 30 #define CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(name, type) \ 31 static inline TEE_Result \ 32 crypto_##name##_alloc_ctx(struct crypto_##type##_ctx **ctx __unused) \ 33 { return TEE_ERROR_NOT_IMPLEMENTED; } 34 35 #if defined(CFG_CRYPTO_MD5) 36 TEE_Result crypto_md5_alloc_ctx(struct crypto_hash_ctx **ctx); 37 #else 38 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(md5, hash) 39 #endif 40 41 #if defined(CFG_CRYPTO_SHA1) 42 TEE_Result crypto_sha1_alloc_ctx(struct crypto_hash_ctx **ctx); 43 #else 44 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha1, hash) 45 #endif 46 47 #if defined(CFG_CRYPTO_SHA224) 48 TEE_Result crypto_sha224_alloc_ctx(struct crypto_hash_ctx **ctx); 49 #else 50 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha224, hash) 51 #endif 52 53 #if defined(CFG_CRYPTO_SHA256) 54 TEE_Result crypto_sha256_alloc_ctx(struct crypto_hash_ctx **ctx); 55 #else 56 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha256, hash) 57 #endif 58 59 #if defined(CFG_CRYPTO_SHA384) 60 TEE_Result crypto_sha384_alloc_ctx(struct crypto_hash_ctx **ctx); 61 #else 62 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha384, hash) 63 #endif 64 65 #if defined(CFG_CRYPTO_SHA512) 66 TEE_Result crypto_sha512_alloc_ctx(struct crypto_hash_ctx **ctx); 67 #else 68 CRYPTO_ALLOC_CTX_NOT_IMPLEMENTED(sha512, hash) 69 #endif 70 71 #endif /*__CRYPTO_CRYPTO_IMPL_H*/ 72