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-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_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 
75  const EcdsaSignature *signature, uint8_t *data, size_t *length,
76  IkeSignFormat format);
77 
78 error_t ikeParseDsaSignature(const uint8_t *data, size_t length,
79  DsaSignature *signature, IkeSignFormat format);
80 
82  size_t length, EcdsaSignature *signature, IkeSignFormat format);
83 
84 error_t ikeSelectSignAlgoId(IkeCertType certType, const HashAlgo *hashAlgo,
85  X509SignAlgoId *signAlgoId);
86 
87 error_t ikeSelectSignAlgo(const X509SignAlgoId *signAlgoId,
88  IkeSignAlgo *signAlgo, const HashAlgo **hashAlgo);
89 
91  uint16_t preferredHashAlgoId);
92 
93 error_t ikeGetSignedOctets(IkeSaEntry *sa, const uint8_t *id, size_t idLen,
94  uint8_t *macId, EddsaMessageChunk *messageChunks, bool_t initiator);
95 
97  const uint8_t *id, size_t idLen, uint8_t *digest, bool_t initiator);
98 
99 //C++ guard
100 #ifdef __cplusplus
101 }
102 #endif
103 
104 #endif
int bool_t
Definition: compiler_port.h:53
error_t
Error codes.
Definition: error.h:43
uint8_t data[]
Definition: ethernet.h:222
IKEv2 (Internet Key Exchange Protocol)
IkeCertType
Certificate types.
Definition: ike.h:1222
#define IkeSaEntry
Definition: ike.h:682
error_t ikeSelectSignAlgoId(IkeCertType certType, const HashAlgo *hashAlgo, X509SignAlgoId *signAlgoId)
Select the algorithm identifier that matches the specified certificate type and hash algorithms.
error_t ikeGetSignedOctets(IkeSaEntry *sa, const uint8_t *id, size_t idLen, uint8_t *macId, EddsaMessageChunk *messageChunks, bool_t initiator)
Retrieve the octets to be signed using EdDSA.
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(EcDomainParameters *params, const uint8_t *data, size_t length, EcdsaSignature *signature, IkeSignFormat format)
ECDSA signature parsing.
error_t ikeParseDsaSignature(const uint8_t *data, size_t length, DsaSignature *signature, IkeSignFormat format)
DSA signature parsing.
const HashAlgo * ikeSelectSignHashAlgo(IkeSaEntry *sa, uint16_t preferredHashAlgoId)
Select the hash algorithm to be used for signing.
IkeSignFormat
Signature format.
Definition: ike_sign_misc.h:48
@ IKE_SIGN_FORMAT_RAW
Definition: ike_sign_misc.h:49
@ IKE_SIGN_FORMAT_ASN1
Definition: ike_sign_misc.h:50
error_t ikeFormatDsaSignature(const DsaSignature *signature, uint8_t *data, size_t *length, IkeSignFormat format)
DSA signature formatting.
Definition: ike_sign_misc.c:55
error_t ikeFormatEcdsaSignature(EcDomainParameters *params, const EcdsaSignature *signature, uint8_t *data, size_t *length, IkeSignFormat format)
ECDSA signature formatting.
IkeSignAlgo
Signature algorithms.
Definition: ike_sign_misc.h:59
@ IKE_SIGN_ALGO_ECDSA
Definition: ike_sign_misc.h:64
@ IKE_SIGN_ALGO_NONE
Definition: ike_sign_misc.h:60
@ IKE_SIGN_ALGO_RSA
Definition: ike_sign_misc.h:61
@ IKE_SIGN_ALGO_DSA
Definition: ike_sign_misc.h:63
@ IKE_SIGN_ALGO_ED25519
Definition: ike_sign_misc.h:65
@ IKE_SIGN_ALGO_RSA_PSS
Definition: ike_sign_misc.h:62
@ IKE_SIGN_ALGO_ED448
Definition: ike_sign_misc.h:66
error_t ikeSelectSignAlgo(const X509SignAlgoId *signAlgoId, IkeSignAlgo *signAlgo, const HashAlgo **hashAlgo)
Select the signature and hash algorithms that match the specified identifier.
DSA signature.
Definition: dsa.h:84
EC domain parameters.
Definition: ec.h:76
ECDSA signature.
Definition: ecdsa.h:49
Message chunk descriptor.
Definition: eddsa.h:71
Common interface for hash algorithms.
Definition: crypto.h:1014
Signature algorithm identifier.
Definition: x509_common.h:1033
uint8_t length
Definition: tcp.h:368