162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci/*
462306a36Sopenharmony_ci * Copyright (C) 2021, Stephan Mueller <smueller@chronox.de>
562306a36Sopenharmony_ci */
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci#ifndef _CRYPTO_KDF108_H
862306a36Sopenharmony_ci#define _CRYPTO_KDF108_H
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci#include <crypto/hash.h>
1162306a36Sopenharmony_ci#include <linux/uio.h>
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci/**
1462306a36Sopenharmony_ci * Counter KDF generate operation according to SP800-108 section 5.1
1562306a36Sopenharmony_ci * as well as SP800-56A section 5.8.1 (Single-step KDF).
1662306a36Sopenharmony_ci *
1762306a36Sopenharmony_ci * @kmd Keyed message digest whose key was set with crypto_kdf108_setkey or
1862306a36Sopenharmony_ci *	unkeyed message digest
1962306a36Sopenharmony_ci * @info optional context and application specific information - this may be
2062306a36Sopenharmony_ci *	 NULL
2162306a36Sopenharmony_ci * @info_vec number of optional context/application specific information entries
2262306a36Sopenharmony_ci * @dst destination buffer that the caller already allocated
2362306a36Sopenharmony_ci * @dlen length of the destination buffer - the KDF derives that amount of
2462306a36Sopenharmony_ci *	 bytes.
2562306a36Sopenharmony_ci *
2662306a36Sopenharmony_ci * To comply with SP800-108, the caller must provide Label || 0x00 || Context
2762306a36Sopenharmony_ci * in the info parameter.
2862306a36Sopenharmony_ci *
2962306a36Sopenharmony_ci * @return 0 on success, < 0 on error
3062306a36Sopenharmony_ci */
3162306a36Sopenharmony_ciint crypto_kdf108_ctr_generate(struct crypto_shash *kmd,
3262306a36Sopenharmony_ci			       const struct kvec *info, unsigned int info_nvec,
3362306a36Sopenharmony_ci			       u8 *dst, unsigned int dlen);
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ci/**
3662306a36Sopenharmony_ci * Counter KDF setkey operation
3762306a36Sopenharmony_ci *
3862306a36Sopenharmony_ci * @kmd Keyed message digest allocated by the caller. The key should not have
3962306a36Sopenharmony_ci *	been set.
4062306a36Sopenharmony_ci * @key Seed key to be used to initialize the keyed message digest context.
4162306a36Sopenharmony_ci * @keylen This length of the key buffer.
4262306a36Sopenharmony_ci * @ikm The SP800-108 KDF does not support IKM - this parameter must be NULL
4362306a36Sopenharmony_ci * @ikmlen This parameter must be 0.
4462306a36Sopenharmony_ci *
4562306a36Sopenharmony_ci * According to SP800-108 section 7.2, the seed key must be at least as large as
4662306a36Sopenharmony_ci * the message digest size of the used keyed message digest. This limitation
4762306a36Sopenharmony_ci * is enforced by the implementation.
4862306a36Sopenharmony_ci *
4962306a36Sopenharmony_ci * SP800-108 allows the use of either a HMAC or a hash primitive. When
5062306a36Sopenharmony_ci * the caller intends to use a hash primitive, the call to
5162306a36Sopenharmony_ci * crypto_kdf108_setkey is not required and the key derivation operation can
5262306a36Sopenharmony_ci * immediately performed using crypto_kdf108_ctr_generate after allocating
5362306a36Sopenharmony_ci * a handle.
5462306a36Sopenharmony_ci *
5562306a36Sopenharmony_ci * @return 0 on success, < 0 on error
5662306a36Sopenharmony_ci */
5762306a36Sopenharmony_ciint crypto_kdf108_setkey(struct crypto_shash *kmd,
5862306a36Sopenharmony_ci			 const u8 *key, size_t keylen,
5962306a36Sopenharmony_ci			 const u8 *ikm, size_t ikmlen);
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci#endif /* _CRYPTO_KDF108_H */
62