ike_sign_misc.c File Reference

Helper functions for signature generation and verification. More...

#include "ike/ike.h"
#include "ike/ike_algorithms.h"
#include "ike/ike_sign_misc.h"
#include "ike/ike_key_material.h"
#include "encoding/oid.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   IKE_TRACE_LEVEL
 

Functions

error_t ikeFormatDsaSignature (const DsaSignature *signature, uint8_t *data, size_t *length, IkeSignFormat format)
 DSA signature formatting. More...
 
error_t ikeFormatEcdsaSignature (EcDomainParameters *params, const EcdsaSignature *signature, uint8_t *data, size_t *length, IkeSignFormat format)
 ECDSA signature formatting. More...
 
error_t ikeParseDsaSignature (const uint8_t *data, size_t length, DsaSignature *signature, IkeSignFormat format)
 DSA signature parsing. More...
 
error_t ikeParseEcdsaSignature (EcDomainParameters *params, const uint8_t *data, size_t length, EcdsaSignature *signature, IkeSignFormat format)
 ECDSA signature parsing. More...
 
error_t ikeSelectSignAlgoId (IkeCertType certType, const HashAlgo *hashAlgo, X509SignAlgoId *signAlgoId)
 Select the algorithm identifier that matches the specified certificate type and hash algorithms. More...
 
error_t ikeSelectSignAlgo (const X509SignAlgoId *signAlgoId, IkeSignAlgo *signAlgo, const HashAlgo **hashAlgo)
 Select the signature and hash algorithms that match the specified identifier. More...
 
const HashAlgoikeSelectSignHashAlgo (IkeSaEntry *sa, uint16_t preferredHashAlgoId)
 Select the hash algorithm to be used for signing. More...
 
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. More...
 
error_t ikeDigestSignedOctets (IkeSaEntry *sa, const HashAlgo *hashAlgo, const uint8_t *id, size_t idLen, uint8_t *digest, bool_t initiator)
 Digest signed octets. More...
 

Detailed Description

Helper functions for signature generation and verification.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2022-2024 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneIPSEC Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.4.4

Definition in file ike_sign_misc.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   IKE_TRACE_LEVEL

Definition at line 32 of file ike_sign_misc.c.

Function Documentation

◆ ikeDigestSignedOctets()

error_t ikeDigestSignedOctets ( IkeSaEntry sa,
const HashAlgo hashAlgo,
const uint8_t *  id,
size_t  idLen,
uint8_t *  digest,
bool_t  initiator 
)

Digest signed octets.

Parameters
[in]saPointer to the IKE SA
[in]hashAlgoUnderlying hash function
[in]idMAC authentication data
[in]idLenMAC authentication data
[out]digestCalculated digest
[in]initiatorSpecifies whether the digest is performed at initiator or responder side
Returns
Error code

Definition at line 937 of file ike_sign_misc.c.

◆ ikeFormatDsaSignature()

error_t ikeFormatDsaSignature ( const DsaSignature signature,
uint8_t *  data,
size_t *  length,
IkeSignFormat  format 
)

DSA signature formatting.

Parameters
[in]signature(R, S) integer pair
[out]dataPointer to the buffer where to store the encoded signature
[out]lengthLength of the encoded signature, in bytes
[in]formatSignature format (raw or ASN.1)
Returns
Error code

Definition at line 55 of file ike_sign_misc.c.

◆ ikeFormatEcdsaSignature()

error_t ikeFormatEcdsaSignature ( EcDomainParameters params,
const EcdsaSignature signature,
uint8_t *  data,
size_t *  length,
IkeSignFormat  format 
)

ECDSA signature formatting.

Parameters
[in]paramsEC domain parameters
[in]signature(R, S) integer pair
[out]dataPointer to the buffer where to store the encoded signature
[out]lengthLength of the encoded signature, in bytes
[in]formatSignature format (raw or ASN.1)
Returns
Error code

Definition at line 113 of file ike_sign_misc.c.

◆ ikeGetSignedOctets()

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.

Parameters
[in]saPointer to the IKE SA
[in]idMAC authentication data
[in]idLenMAC authentication data
[out]macIdTemporary buffer needed to calculate MACedID
[out]messageChunksArray of data chunks representing the message to be signed
[in]initiatorSpecifies whether the digest is performed at initiator or responder side
Returns
Error code

Definition at line 863 of file ike_sign_misc.c.

◆ ikeParseDsaSignature()

error_t ikeParseDsaSignature ( const uint8_t *  data,
size_t  length,
DsaSignature signature,
IkeSignFormat  format 
)

DSA signature parsing.

Parameters
[in]dataPointer to the encoded signature
[in]lengthLength of the encoded signature, in bytes
[out]signature(R, S) integer pair
[in]formatSignature format (raw or ASN.1)
Returns
Error code

Definition at line 176 of file ike_sign_misc.c.

◆ ikeParseEcdsaSignature()

error_t ikeParseEcdsaSignature ( EcDomainParameters params,
const uint8_t *  data,
size_t  length,
EcdsaSignature signature,
IkeSignFormat  format 
)

ECDSA signature parsing.

Parameters
[in]paramsEC domain parameters
[in]dataPointer to the encoded signature
[in]lengthLength of the encoded signature, in bytes
[out]signature(R, S) integer pair
[in]formatSignature format (raw or ASN.1)
Returns
Error code

Definition at line 236 of file ike_sign_misc.c.

◆ ikeSelectSignAlgo()

error_t ikeSelectSignAlgo ( const X509SignAlgoId signAlgoId,
IkeSignAlgo signAlgo,
const HashAlgo **  hashAlgo 
)

Select the signature and hash algorithms that match the specified identifier.

Parameters
[in]signAlgoIdSignature algorithm identifier
[out]signAlgoSignature algorithm
[out]hashAlgoHash algorithm
Returns
Error code

Definition at line 539 of file ike_sign_misc.c.

◆ ikeSelectSignAlgoId()

error_t ikeSelectSignAlgoId ( IkeCertType  certType,
const HashAlgo hashAlgo,
X509SignAlgoId signAlgoId 
)

Select the algorithm identifier that matches the specified certificate type and hash algorithms.

Parameters
[in]certTypeCertificate type
[in]hashAlgoHash algorithm
[out]signAlgoIdSignature algorithm identifier
Returns
Error code

Definition at line 300 of file ike_sign_misc.c.

◆ ikeSelectSignHashAlgo()

const HashAlgo* ikeSelectSignHashAlgo ( IkeSaEntry sa,
uint16_t  preferredHashAlgoId 
)

Select the hash algorithm to be used for signing.

Parameters
[in]saPointer to the IKE SA
[in]preferredHashAlgoIdPreferred hash algorithm (provided as a hint)
Returns
Signature hash algorithm

Definition at line 765 of file ike_sign_misc.c.