ike_algorithms.h
Go to the documentation of this file.
1 /**
2  * @file ike_algorithms.h
3  * @brief IKEv2 algorithm negotiation
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2022-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneIPSEC Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.0
29  **/
30 
31 #ifndef _IKE_ALGORITHMS_H
32 #define _IKE_ALGORITHMS_H
33 
34 //Dependencies
35 #include "ike/ike.h"
36 
37 //Invalid transform identifier
38 #define IKE_TRANSFORM_ID_INVALID 0xFFFF
39 
40 //C++ guard
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 
46 /**
47  * @brief Encryption algorithm
48  **/
49 
50 typedef struct
51 {
52  uint16_t id;
53  uint16_t keyLen;
54 } IkeEncAlgo;
55 
56 
57 //IKEv2 related functions
58 error_t ikeSelectEncAlgo(IkeSaEntry *sa, uint16_t encAlgoId,
59  size_t encKeyLen);
60 
61 error_t ikeSelectAuthAlgo(IkeSaEntry *sa, uint16_t authAlgoId);
62 error_t ikeSelectPrfAlgo(IkeSaEntry *sa, uint16_t prfAlgoId);
63 
65  uint16_t keyLen, IkeProposal *proposal, uint8_t **lastSubstruc);
66 
68  uint8_t **lastSubstruc);
69 
71  IkeProposal *proposal, uint8_t **lastSubstruc);
72 
74  IkeProposal *proposal, uint8_t **lastSubstruc);
75 
77  IkeProposal *proposal, uint8_t **lastSubstruc);
78 
80  IkeProposal *proposal, uint8_t **lastSubstruc);
81 
83  const IkeProposal *proposal, size_t proposalLen);
84 
86  const uint16_t *algoList, uint_t algoListLen, const IkeProposal *proposal,
87  size_t proposalLen);
88 
89 uint16_t ikeSelectKeTransform(IkeContext *context, const IkeProposal *proposal,
90  size_t proposalLen);
91 
93  const IkeProposal *proposal, size_t proposalLen);
94 
95 uint16_t ikeSelectAuthTransform(IkeContext *context, const IkeProposal *proposal,
96  size_t proposalLen);
97 
98 uint16_t ikeSelectPrfTransform(IkeContext *context, const IkeProposal *proposal,
99  size_t proposalLen);
100 
102  size_t spiSize);
103 
105  const IkeSaPayload *payload);
106 
108 
110  const IkeSaPayload *payload);
111 
112 bool_t ikeIsAeadEncAlgo(uint16_t encAlgoId);
113 bool_t ikeIsVariableLengthKeyEncAlgo(uint16_t encAlgoId);
114 
115 bool_t ikeIsDhKeyExchangeAlgo(uint16_t groupNum);
116 bool_t ikeIsEcdhKeyExchangeAlgo(uint16_t groupNum);
117 
118 const EcCurveInfo *ikeGetEcdhCurveInfo(uint16_t groupNum);
119 error_t ikeLoadEcdhParams(EcDomainParameters *params, uint16_t groupNum);
120 
121 uint16_t ikeSelectDefaultDhGroup(void);
122 bool_t ikeIsDhGroupSupported(uint16_t groupNum);
123 
124 bool_t ikeIsHashAlgoSupported(uint16_t hashAlgoId);
125 
126 //C++ guard
127 #ifdef __cplusplus
128 }
129 #endif
130 
131 #endif
unsigned int uint_t
Definition: compiler_port.h:50
int bool_t
Definition: compiler_port.h:53
error_t
Error codes.
Definition: error.h:43
IKEv2 (Internet Key Exchange Protocol)
uint16_t transformId
Definition: ike.h:1326
IkeProposal
Definition: ike.h:1312
IkeSaPayload
Definition: ike.h:1295
#define IkeChildSaEntry
Definition: ike.h:686
#define IkeContext
Definition: ike.h:678
uint8_t transformType
Definition: ike.h:1324
uint8_t spiSize
Definition: ike.h:1309
IkeTransformType
Transform types.
Definition: ike.h:779
#define IkeSaEntry
Definition: ike.h:682
bool_t ikeIsEcdhKeyExchangeAlgo(uint16_t groupNum)
Test if the group number identifies an ECDH key exchange algorithm.
uint16_t ikeSelectTransform(IkeTransformType transformType, const uint16_t *algoList, uint_t algoListLen, const IkeProposal *proposal, size_t proposalLen)
Transform negotiation.
uint_t ikeGetNumTransforms(IkeTransformType transformType, const IkeProposal *proposal, size_t proposalLen)
Get the number of transforms that match a given transform type.
const IkeEncAlgo * ikeSelectEncTransform(IkeContext *context, const IkeProposal *proposal, size_t proposalLen)
Encryption transform negotiation.
error_t ikeAddSupportedKeTransforms(IkeContext *context, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported key exchange transforms to the proposal.
error_t ikeSelectChildSaProposal(IkeChildSaEntry *childSa, const IkeSaPayload *payload)
Select a single proposal (AH or ESP protocol)
bool_t ikeIsAeadEncAlgo(uint16_t encAlgoId)
Test if the transform ID identifies an AEAD encryption algorithm.
error_t ikeSelectAuthAlgo(IkeSaEntry *sa, uint16_t authAlgoId)
Select the relevant MAC algorithm.
error_t ikeSelectEncAlgo(IkeSaEntry *sa, uint16_t encAlgoId, size_t encKeyLen)
Select the relevant encryption algorithm.
error_t ikeCheckSaProposal(IkeSaEntry *sa, const IkeSaPayload *payload)
Check whether the selected proposal is acceptable (IKE protocol)
error_t ikeAddSupportedEncTransforms(IkeContext *context, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported encryption transforms to the proposal.
bool_t ikeIsDhKeyExchangeAlgo(uint16_t groupNum)
Test if the group number identifies a DH key exchange algorithm.
const EcCurveInfo * ikeGetEcdhCurveInfo(uint16_t groupNum)
Get the elliptic curve that matches the specified group number.
uint16_t ikeSelectKeTransform(IkeContext *context, const IkeProposal *proposal, size_t proposalLen)
Key exchange transform negotiation.
error_t ikeSelectSaProposal(IkeSaEntry *sa, const IkeSaPayload *payload, size_t spiSize)
Select a single proposal (IKE protocol)
error_t ikeAddTransform(IkeTransformType transformType, uint16_t transformId, uint16_t keyLen, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported transforms to the proposal.
error_t ikeCheckChildSaProposal(IkeChildSaEntry *childSa, const IkeSaPayload *payload)
Check whether the selected proposal is acceptable (AH or ESP protocol)
error_t ikeLoadEcdhParams(EcDomainParameters *params, uint16_t groupNum)
Load the EC parameters that match the specified group number.
bool_t ikeIsHashAlgoSupported(uint16_t hashAlgoId)
Check whether a given signature hash algorithm is supported.
error_t ikeAddSupportedPrfTransforms(IkeContext *context, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported PRF transforms to the proposal.
uint16_t ikeSelectDefaultDhGroup(void)
Get the default Diffie-Hellman group number.
error_t ikeAddSupportedAuthTransforms(IkeContext *context, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported integrity transforms to the proposal.
bool_t ikeIsVariableLengthKeyEncAlgo(uint16_t encAlgoId)
Test if the transform ID identifies a variable-length key encryption algorithm.
uint16_t ikeSelectAuthTransform(IkeContext *context, const IkeProposal *proposal, size_t proposalLen)
Integrity transform negotiation.
uint16_t ikeSelectPrfTransform(IkeContext *context, const IkeProposal *proposal, size_t proposalLen)
PRF transform negotiation.
error_t ikeAddSupportedTransforms(IkeContext *context, IkeProposal *proposal, uint8_t **lastSubstruc)
Add the supported IKE transforms to the proposal.
error_t ikeSelectPrfAlgo(IkeSaEntry *sa, uint16_t prfAlgoId)
Select the relevant PRF algorithm.
bool_t ikeIsDhGroupSupported(uint16_t groupNum)
Check whether a given Diffie-Hellman group is supported.
uint8_t payload[]
Definition: ipv6.h:277
Elliptic curve parameters.
Definition: ec_curves.h:295
EC domain parameters.
Definition: ec.h:76
Encryption algorithm.
uint16_t keyLen
uint16_t id