ike_sign_misc.h
Go to the documentation of this file.
1 /**
2  * @file ike_sign_misc.h
3  * @brief Helper functions for signature generation and verification
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2022-2025 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.5.0
29  **/
30 
31 #ifndef _IKE_SIGN_MISC_H
32 #define _IKE_SIGN_MISC_H
33 
34 //Dependencies
35 #include "ike/ike.h"
36 
37 //C++ guard
38 #ifdef __cplusplus
39 extern "C" {
40 #endif
41 
42 
43 /**
44  * @brief Signature format
45  **/
46 
47 typedef enum
48 {
52 
53 
54 /**
55  * @brief Signature algorithms
56  **/
57 
58 typedef enum
59 {
68 
69 
70 //IKEv2 related functions
71 error_t ikeFormatDsaSignature(const DsaSignature *signature, uint8_t *data,
72  size_t *length, IkeSignFormat format);
73 
74 error_t ikeFormatEcdsaSignature(const EcdsaSignature *signature, uint8_t *data,
75  size_t *length, IkeSignFormat format);
76 
77 error_t ikeParseDsaSignature(const uint8_t *data, size_t length,
78  DsaSignature *signature, IkeSignFormat format);
79 
80 error_t ikeParseEcdsaSignature(const EcCurve *curve, const uint8_t *data,
81  size_t length, EcdsaSignature *signature, IkeSignFormat format);
82 
83 error_t ikeSelectSignAlgoId(IkeCertType certType, const HashAlgo *hashAlgo,
84  X509SignAlgoId *signAlgoId);
85 
86 error_t ikeSelectSignAlgo(const X509SignAlgoId *signAlgoId,
87  IkeSignAlgo *signAlgo, const HashAlgo **hashAlgo);
88 
90  uint16_t preferredHashAlgoId);
91 
92 error_t ikeGetSignedOctets(IkeSaEntry *sa, const uint8_t *id, size_t idLen,
93  uint8_t *macId, DataChunk *messageChunks, bool_t initiator);
94 
96  const uint8_t *id, size_t idLen, uint8_t *digest, bool_t initiator);
97 
98 //C++ guard
99 #ifdef __cplusplus
100 }
101 #endif
102 
103 #endif
@ IKE_SIGN_ALGO_ED448
Definition: ike_sign_misc.h:66
@ IKE_SIGN_ALGO_NONE
Definition: ike_sign_misc.h:60
ECDSA signature.
Definition: ecdsa.h:63
IkeCertType
Certificate types.
Definition: ike.h:1345
int bool_t
Definition: compiler_port.h:61
IkeSignAlgo
Signature algorithms.
Definition: ike_sign_misc.h:59
uint8_t data[]
Definition: ethernet.h:222
@ IKE_SIGN_ALGO_RSA
Definition: ike_sign_misc.h:61
error_t
Error codes.
Definition: error.h:43
error_t ikeParseDsaSignature(const uint8_t *data, size_t length, DsaSignature *signature, IkeSignFormat format)
DSA signature parsing.
@ IKE_SIGN_ALGO_RSA_PSS
Definition: ike_sign_misc.h:62
error_t ikeDigestSignedOctets(IkeSaEntry *sa, const HashAlgo *hashAlgo, const uint8_t *id, size_t idLen, uint8_t *digest, bool_t initiator)
Digest signed octets.
error_t ikeParseEcdsaSignature(const EcCurve *curve, const uint8_t *data, size_t length, EcdsaSignature *signature, IkeSignFormat format)
ECDSA signature parsing.
error_t ikeFormatEcdsaSignature(const EcdsaSignature *signature, uint8_t *data, size_t *length, IkeSignFormat format)
ECDSA signature formatting.
@ IKE_SIGN_FORMAT_ASN1
Definition: ike_sign_misc.h:50
error_t ikeGetSignedOctets(IkeSaEntry *sa, const uint8_t *id, size_t idLen, uint8_t *macId, DataChunk *messageChunks, bool_t initiator)
Retrieve the octets to be signed using EdDSA.
uint8_t length
Definition: tcp.h:375
@ IKE_SIGN_ALGO_DSA
Definition: ike_sign_misc.h:63
IKEv2 (Internet Key Exchange Protocol)
IkeSignFormat
Signature format.
Definition: ike_sign_misc.h:48
Data chunk descriptor.
Definition: crypto.h:1017
#define IkeSaEntry
Definition: ike.h:800
error_t ikeSelectSignAlgo(const X509SignAlgoId *signAlgoId, IkeSignAlgo *signAlgo, const HashAlgo **hashAlgo)
Select the signature and hash algorithms that match the specified identifier.
@ IKE_SIGN_FORMAT_RAW
Definition: ike_sign_misc.h:49
const HashAlgo * ikeSelectSignHashAlgo(IkeSaEntry *sa, uint16_t preferredHashAlgoId)
Select the hash algorithm to be used for signing.
error_t ikeFormatDsaSignature(const DsaSignature *signature, uint8_t *data, size_t *length, IkeSignFormat format)
DSA signature formatting.
Definition: ike_sign_misc.c:55
@ IKE_SIGN_ALGO_ECDSA
Definition: ike_sign_misc.h:64
Common interface for hash algorithms.
Definition: crypto.h:1082
DSA signature.
Definition: dsa.h:85
#define EcCurve
Definition: ec.h:346
error_t ikeSelectSignAlgoId(IkeCertType certType, const HashAlgo *hashAlgo, X509SignAlgoId *signAlgoId)
Select the algorithm identifier that matches the specified certificate type and hash algorithms.
@ IKE_SIGN_ALGO_ED25519
Definition: ike_sign_misc.h:65
Signature algorithm identifier.
Definition: x509_common.h:1088