openssl: Add a prf+ implementation based on OpenSSL's HKDF implementation

The HKDF-Expand() function defined in RFC 5869 is basically the same as
IKEv2's prf+(), so we can use the former to implement the latter.
However, we can only support HMAC-based PRFs this way, which should be
fine as others are rarely used.
This commit is contained in:
Tobias Brunner
2022-04-14 18:54:24 +02:00
parent 9e228de60a
commit 2b9b579af9
4 changed files with 227 additions and 0 deletions
@@ -0,0 +1,45 @@
/*
* Copyright (C) 2022 Tobias Brunner, codelabs GmbH
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
/**
* Implements key derivation functions (KDF) via OpenSSL, in particular prf+,
* which is implemented via OpenSSL's HKDF implementation.
*
* @defgroup openssl_kdf openssl_kdf
* @{ @ingroup openssl_p
*/
#ifndef OPENSSL_KDF_H_
#define OPENSSL_KDF_H_
#include <crypto/kdfs/kdf.h>
/**
* Creates a new kdf_t object.
*
* @param algo algorithm to instantiate
* @param args algorithm-specific arguments
* @return kdf_t object, NULL if not supported
*/
kdf_t *openssl_kdf_create(key_derivation_function_t algo, va_list args);
#endif /** OPENSSL_KDF_H_ @}*/