// SPDX-License-Identifier: BSD-2-Clause
/*
 * SPDX-FileCopyrightText: Copyright (c) 2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
 */

#ifndef __JETSON_NIST_SP_800_108_KDF_H__
#define __JETSON_NIST_SP_800_108_KDF_H__

/*
 * A software-based NIST-SP 800-108 HMAC KDF.
 * derives keys from a key in a key buffer.
 *
 * key		[in] input key for derivation.
 * key_len	[in] length in bytes of the input key.
 * context	[in] a pointer to a NIST-SP 800-108 context string.
 * context_len	[in] length in bytes of the contexct.
 * label	[in] a pointer to a NIST-SP 800-108 label string.
 * label_len	[in] length in bytes of the label.
 * dk_len	[in] length of the derived key in bytes;
 *		     may be 16 (128 bits) or any multiple of 16.
 * out_dk 	[out] a pointer to the derived key. The function stores
 *		      its result in this location.
 */
TEE_Result nist_sp_800_108_hmac_kdf(const uint8_t *key, uint32_t key_len,
				    char const *context, uint32_t context_len,
				    char const *label, uint32_t label_len,
				    uint32_t dk_len, uint8_t *out_dk);

#if defined(PLATFORM_FLAVOR_t234)
/*
 * A software-based NIST-SP 800-108 CMAC KDF.
 *  derives keys from a key in a key buffer.
 *
 * key		[in] input key for derivation.
 * key_len	[in] length in bytes of the input key.
 * context	[in] a pointer to a NIST-SP 800-108 context string.
 * context_len	[in] length of the context string.
 * label	[in] a pointer to a NIST-SP 800-108 label string.
 * label_len	[in] length of the label string.
 * dk_len	[in] length of the derived key in bytes;
 *		     may be 16 (128 bits) or any multiple of 16.
 * *out_dk 	[out] a pointer to the derived key. The function stores
 *		      its result in this location.
 */
TEE_Result nist_sp_800_108_cmac_kdf(uint8_t *key, uint32_t key_len,
				    char const *context, uint32_t context_len,
				    char const *label, uint32_t label_len,
				    uint32_t dk_len, uint8_t *out_dk);

#define nist_sp_800_108_kdf nist_sp_800_108_cmac_kdf

#elif defined(PLATFORM_FLAVOR_t264)

#define nist_sp_800_108_kdf nist_sp_800_108_hmac_kdf

#endif


#endif /* __JETSON_NIST_SP_800_108_KDF_H__ */
