Go to the documentation of this file.
32 #define TRACE_LEVEL IKE_TRACE_LEVEL
43 #if (IKE_SUPPORT == ENABLED && IKE_CERT_AUTH_SUPPORT == ENABLED)
58 #if (IKE_DSA_SIGN_SUPPORT == ENABLED)
117 #if (IKE_ECDSA_SIGN_SUPPORT == ENABLED)
179 #if (IKE_DSA_SIGN_SUPPORT == ENABLED)
239 #if (IKE_ECDSA_SIGN_SUPPORT == ENABLED)
252 if(
length == (2 * modLen))
308 #if (IKE_RSA_SIGN_SUPPORT == ENABLED)
312 #if (IKE_SHA1_SUPPORT == ENABLED)
322 #if (IKE_SHA256_SUPPORT == ENABLED)
332 #if (IKE_SHA384_SUPPORT == ENABLED)
342 #if (IKE_SHA512_SUPPORT == ENABLED)
360 #if (IKE_RSA_PSS_SIGN_SUPPORT == ENABLED)
390 #if (IKE_DSA_SIGN_SUPPORT == ENABLED)
394 #if (IKE_SHA1_SUPPORT == ENABLED)
404 #if (IKE_SHA256_SUPPORT == ENABLED)
414 #if (IKE_SHA384_SUPPORT == ENABLED)
424 #if (IKE_SHA512_SUPPORT == ENABLED)
442 #if (IKE_ECDSA_SIGN_SUPPORT == ENABLED)
451 #if (IKE_SHA1_SUPPORT == ENABLED)
461 #if (IKE_SHA256_SUPPORT == ENABLED)
471 #if (IKE_SHA384_SUPPORT == ENABLED)
481 #if (IKE_SHA512_SUPPORT == ENABLED)
499 #if (IKE_ED25519_SIGN_SUPPORT == ENABLED)
509 #if (IKE_ED448_SIGN_SUPPORT == ENABLED)
553 #if (IKE_RSA_SIGN_SUPPORT == ENABLED && IKE_SHA1_SUPPORT == ENABLED)
563 #if (IKE_RSA_SIGN_SUPPORT == ENABLED && IKE_SHA256_SUPPORT == ENABLED)
573 #if (IKE_RSA_SIGN_SUPPORT == ENABLED && IKE_SHA384_SUPPORT == ENABLED)
583 #if (IKE_RSA_SIGN_SUPPORT == ENABLED && IKE_SHA512_SUPPORT == ENABLED)
593 #if (IKE_RSA_PSS_SIGN_SUPPORT == ENABLED)
602 #if (IKE_SHA1_SUPPORT == ENABLED)
612 #if (IKE_SHA256_SUPPORT == ENABLED)
622 #if (IKE_SHA384_SUPPORT == ENABLED)
632 #if (IKE_SHA512_SUPPORT == ENABLED)
650 #if (IKE_DSA_SIGN_SUPPORT == ENABLED && IKE_SHA1_SUPPORT == ENABLED)
660 #if (IKE_DSA_SIGN_SUPPORT == ENABLED && IKE_SHA256_SUPPORT == ENABLED)
670 #if (IKE_DSA_SIGN_SUPPORT == ENABLED && IKE_SHA384_SUPPORT == ENABLED)
680 #if (IKE_DSA_SIGN_SUPPORT == ENABLED && IKE_SHA512_SUPPORT == ENABLED)
690 #if (IKE_ECDSA_SIGN_SUPPORT == ENABLED && IKE_SHA1_SUPPORT == ENABLED)
700 #if (IKE_ECDSA_SIGN_SUPPORT == ENABLED && IKE_SHA256_SUPPORT == ENABLED)
710 #if (IKE_ECDSA_SIGN_SUPPORT == ENABLED && IKE_SHA384_SUPPORT == ENABLED)
720 #if (IKE_ECDSA_SIGN_SUPPORT == ENABLED && IKE_SHA512_SUPPORT == ENABLED)
730 #if (IKE_ED25519_SIGN_SUPPORT == ENABLED)
739 #if (IKE_ED448_SIGN_SUPPORT == ENABLED)
766 uint16_t preferredHashAlgoId)
768 #if (IKE_SIGN_HASH_ALGOS_SUPPORT == ENABLED)
781 if((sa->signHashAlgos & (1U <<
n)) != 0)
796 if((sa->signHashAlgos & (1U <<
n)) != 0)
804 #if (IKE_SHA1_SUPPORT == ENABLED)
812 #if (IKE_SHA256_SUPPORT == ENABLED)
820 #if (IKE_SHA384_SUPPORT == ENABLED)
828 #if (IKE_SHA512_SUPPORT == ENABLED)
872 error =
ikeComputePrf(sa, sa->skpi, sa->prfKeyLen,
id, idLen,
881 messageChunks[0].
buffer = sa->initiatorSaInit;
882 messageChunks[0].
length = sa->initiatorSaInitLen;
886 messageChunks[1].
buffer = sa->responderNonce;
887 messageChunks[1].
length = sa->responderNonceLen;
888 messageChunks[2].
buffer = macId;
889 messageChunks[2].
length = sa->prfKeyLen;
890 messageChunks[3].
buffer = NULL;
891 messageChunks[3].
length = 0;
897 error =
ikeComputePrf(sa, sa->skpr, sa->prfKeyLen,
id, idLen, macId);
906 messageChunks[0].
buffer = sa->responderSaInit;
907 messageChunks[0].
length = sa->responderSaInitLen;
911 messageChunks[1].
buffer = sa->initiatorNonce;
912 messageChunks[1].
length = sa->initiatorNonceLen;
913 messageChunks[2].
buffer = macId;
914 messageChunks[2].
length = sa->prfKeyLen;
915 messageChunks[3].
buffer = NULL;
916 messageChunks[3].
length = 0;
938 const uint8_t *
id,
size_t idLen, uint8_t *digest,
bool_t initiator)
948 error =
ikeComputePrf(sa, sa->skpi, sa->prfKeyLen,
id, idLen, macId);
956 hashAlgo->
init(&hashContext);
957 hashAlgo->
update(&hashContext, sa->initiatorSaInit, sa->initiatorSaInitLen);
961 hashAlgo->
update(&hashContext, sa->responderNonce, sa->responderNonceLen);
962 hashAlgo->
update(&hashContext, macId, sa->prfKeyLen);
963 hashAlgo->
final(&hashContext, digest);
969 error =
ikeComputePrf(sa, sa->skpr, sa->prfKeyLen,
id, idLen, macId);
978 hashAlgo->
init(&hashContext);
979 hashAlgo->
update(&hashContext, sa->responderSaInit, sa->responderSaInitLen);
983 hashAlgo->
update(&hashContext, sa->initiatorNonce, sa->initiatorNonceLen);
984 hashAlgo->
update(&hashContext, macId, sa->prfKeyLen);
985 hashAlgo->
final(&hashContext, digest);
IkeCertType
Certificate types.
Generic hash algorithm context.
@ IKE_CERT_TYPE_ECDSA_BRAINPOOLP384R1
const uint8_t SHA512_WITH_RSA_ENCRYPTION_OID[9]
error_t ikeComputePrf(IkeSaEntry *sa, const uint8_t *k, size_t kLen, const void *s, size_t sLen, uint8_t *output)
Pseudorandom function (prf function)
IkeSignAlgo
Signature algorithms.
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.
X509OctetString maskGenHashAlgo
error_t ikeDigestSignedOctets(IkeSaEntry *sa, const HashAlgo *hashAlgo, const uint8_t *id, size_t idLen, uint8_t *digest, bool_t initiator)
Digest signed octets.
const uint8_t RSASSA_PSS_OID[9]
@ IKE_CERT_TYPE_ECDSA_P384
const uint8_t ECDSA_WITH_SHA256_OID[8]
error_t mpiImport(Mpi *r, const uint8_t *data, uint_t length, MpiFormat format)
Octet string to integer conversion.
int_t oidComp(const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2, size_t oidLen2)
Compare object identifiers.
const uint8_t MGF1_OID[9]
error_t ikeSelectSignAlgoId(IkeCertType certType, const HashAlgo *hashAlgo, X509SignAlgoId *signAlgoId)
Select the algorithm identifier that matches the specified certificate type and hash algorithms.
@ IKE_CERT_TYPE_ECDSA_BRAINPOOLP256R1
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.
const uint8_t SHA384_WITH_RSA_ENCRYPTION_OID[9]
#define MAX_HASH_DIGEST_SIZE
error_t mpiExport(const Mpi *a, uint8_t *data, uint_t length, MpiFormat format)
Integer to octet string conversion.
Helper functions for signature generation and verification.
const uint8_t DSA_WITH_SHA384_OID[9]
error_t ikeSelectSignAlgo(const X509SignAlgoId *signAlgoId, IkeSignAlgo *signAlgo, const HashAlgo **hashAlgo)
Select the signature and hash algorithms that match the specified identifier.
const uint8_t SHA256_OID[9]
const uint8_t ECDSA_WITH_SHA384_OID[8]
const uint8_t DSA_WITH_SHA512_OID[9]
error_t ikeFormatEcdsaSignature(EcDomainParameters *params, const EcdsaSignature *signature, uint8_t *data, size_t *length, IkeSignFormat format)
ECDSA signature formatting.
X509OctetString maskGenAlgo
const uint8_t ECDSA_WITH_SHA1_OID[7]
const uint8_t SHA256_WITH_RSA_ENCRYPTION_OID[9]
error_t dsaWriteSignature(const DsaSignature *signature, uint8_t *data, size_t *length)
Encode DSA signature using ASN.1.
@ IKE_CERT_TYPE_ECDSA_BRAINPOOLP512R1
const uint8_t ED448_OID[3]
const uint8_t ECDSA_WITH_SHA512_OID[8]
const uint8_t ED25519_OID[3]
IKEv2 (Internet Key Exchange Protocol)
IkeSignFormat
Signature format.
error_t ecdsaWriteSignature(const EcdsaSignature *signature, uint8_t *data, size_t *length)
Encode ECDSA signature using ASN.1.
@ ERROR_INVALID_SIGNATURE_ALGO
#define IKE_SHA1_DIGEST_SIZE
const uint8_t DSA_WITH_SHA1_OID[7]
const uint8_t DSA_WITH_SHA256_OID[9]
error_t dsaReadSignature(const uint8_t *data, size_t length, DsaSignature *signature)
Read an ASN.1 encoded DSA signature.
const uint8_t SHA512_OID[9]
const uint8_t SHA1_OID[5]
error_t ecdsaReadSignature(const uint8_t *data, size_t length, EcdsaSignature *signature)
Read an ASN.1 encoded ECDSA signature.
Common interface for hash algorithms.
@ IKE_CERT_TYPE_ECDSA_P521
@ ERROR_UNSUPPORTED_SIGNATURE_ALGO
const uint8_t SHA384_OID[9]
@ ERROR_INVALID_SIGNATURE
X509RsaPssParameters rsaPssParams
const uint8_t SHA1_WITH_RSA_ENCRYPTION_OID[9]
IKEv2 algorithm negotiation.
Signature algorithm identifier.
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.
uint_t mpiGetByteLength(const Mpi *a)
Get the actual length in bytes.
@ IKE_CERT_TYPE_ECDSA_P256