Go to the documentation of this file.
32 #define TRACE_LEVEL TLS_TRACE_LEVEL
42 #if (TLS_SUPPORT == ENABLED && TLS_CLIENT_SUPPORT == ENABLED && \
43 TLS_MAX_VERSION >= TLS_VERSION_1_3)
66 if(context->cookieLen > 0)
86 extension->length =
htons(
n);
109 uint8_t *
p,
size_t *written)
113 #if (TLS13_DHE_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED || \
114 TLS13_ECDHE_KE_SUPPORT == ENABLED || TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED || \
115 TLS13_HYBRID_KE_SUPPORT == ENABLED || TLS13_PSK_HYBRID_KE_SUPPORT == ENABLED)
133 #if (TLS13_DHE_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED)
138 keyShareEntry->group =
htons(context->namedGroup);
147 error =
mpiExport(&context->dhContext.ya,
154 keyShareEntry->length =
htons(
n);
161 #if (TLS13_ECDHE_KE_SUPPORT == ENABLED || TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED)
166 keyShareEntry->group =
htons(context->namedGroup);
170 error =
ecExport(&context->ecdhContext.params,
171 &context->ecdhContext.qa.q, keyShareEntry->keyExchange, &
n);
177 keyShareEntry->length =
htons(
n);
184 #if (TLS13_HYBRID_KE_SUPPORT == ENABLED || TLS13_PSK_HYBRID_KE_SUPPORT == ENABLED)
189 keyShareEntry->group =
htons(context->namedGroup);
193 error =
ecExport(&context->ecdhContext.params,
194 &context->ecdhContext.qa.q, keyShareEntry->keyExchange, &
n);
201 osMemcpy(keyShareEntry->keyExchange +
n, context->kemContext.pk,
202 context->kemContext.kemAlgo->publicKeySize);
206 n += context->kemContext.kemAlgo->publicKeySize;
209 keyShareEntry->length =
htons(
n);
223 keyShareList->length =
htons(
n);
228 extension->length =
htons(
n);
251 uint8_t *
p,
size_t *written)
255 #if (TLS13_PSK_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED || \
256 TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED || TLS13_PSK_HYBRID_KE_SUPPORT == ENABLED)
275 #if (TLS13_PSK_KE_SUPPORT == ENABLED)
281 pskKeModeList->length = (uint8_t)
n;
286 extension->length =
htons(
n);
318 #if (TLS13_PSK_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED || \
319 TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED || TLS13_PSK_HYBRID_KE_SUPPORT == ENABLED)
349 osMemcpy(pskIdentity->value, context->pskIdentity,
n);
366 n = context->ticketLen;
368 osMemcpy(pskIdentity->value, context->ticket,
n);
380 ticketAge = context->clientHelloTimestamp - context->ticketTimestamp;
385 ticketAge += context->ticketAgeAdd;
409 context->cipherSuite.prfHashAlgo = hashAlgo;
413 pskIdentity->length =
htons(
n);
418 STORE32BE(ticketAge, (uint8_t *) pskIdentity +
n);
420 n +=
sizeof(uint32_t);
423 (*identityList)->length =
htons(
n);
438 pskBinder->length = (uint8_t)
m;
443 (*binderList)->length =
htons(
m);
448 extension->length =
htons(
n);
456 *identityList = NULL;
477 uint8_t *
p,
size_t *written)
481 #if (TLS13_EARLY_DATA_SUPPORT == ENABLED)
484 if(context->earlyDataEnabled && !context->earlyDataRejected)
494 extension->length =
HTONS(0);
531 TRACE_INFO(
" selectedVersion = 0x%04" PRIX16
" (%s)\r\n",
573 if(context->cookie != NULL)
577 context->cookie = NULL;
578 context->cookieLen = 0;
584 if(context->cookie == NULL)
589 context->cookieLen =
n;
612 #if (TLS13_DHE_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED || \
613 TLS13_ECDHE_KE_SUPPORT == ENABLED || TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED || \
614 TLS13_HYBRID_KE_SUPPORT == ENABLED || TLS13_PSK_HYBRID_KE_SUPPORT == ENABLED)
616 if(selectedGroup != NULL)
622 namedGroup =
LOAD16BE(selectedGroup->value);
625 if(namedGroup != context->namedGroup)
633 if(selectedGroup != NULL)
662 #if (TLS13_DHE_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED || \
663 TLS13_ECDHE_KE_SUPPORT == ENABLED || TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED || \
664 TLS13_HYBRID_KE_SUPPORT == ENABLED || TLS13_PSK_HYBRID_KE_SUPPORT == ENABLED)
667 if(serverShare != NULL)
672 namedGroup =
ntohs(serverShare->group);
676 if(namedGroup == context->namedGroup)
686 ntohs(serverShare->length));
696 ntohs(serverShare->length));
707 ntohs(serverShare->length));
732 if(serverShare != NULL)
762 context->selectedIdentity = -1;
764 #if (TLS13_PSK_KE_SUPPORT == ENABLED || TLS13_PSK_DHE_KE_SUPPORT == ENABLED || \
765 TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED || TLS13_PSK_HYBRID_KE_SUPPORT == ENABLED)
767 if(selectedIdentity != NULL)
779 context->selectedIdentity =
LOAD16BE(selectedIdentity->value);
783 if(context->selectedIdentity != 0)
787 hashAlgo = context->cipherSuite.prfHashAlgo;
814 #if (TLS13_PSK_KE_SUPPORT == ENABLED)
820 #if (TLS13_PSK_DHE_KE_SUPPORT == ENABLED)
826 #if (TLS13_PSK_ECDHE_KE_SUPPORT == ENABLED)
832 #if (TLS13_PSK_HYBRID_KE_SUPPORT == ENABLED)
841 if(selectedIdentity != NULL)
866 #if (TLS13_EARLY_DATA_SUPPORT == ENABLED)
872 if(earlyDataIndication != NULL)
877 if(!context->earlyDataEnabled || context->earlyDataRejected)
884 if(context->selectedIdentity != 0)
888 context->earlyDataExtReceived =
TRUE;
894 context->earlyDataExtReceived =
FALSE;
901 if(earlyDataIndication != NULL)
903 context->maxEarlyDataSize =
LOAD32BE(earlyDataIndication->value);
907 context->maxEarlyDataSize = 0;
919 if(earlyDataIndication != NULL)
930 context->maxEarlyDataSize = 0;
@ TLS_EXT_PSK_KEY_EXCHANGE_MODES
#define tlsAllocMem(size)
#define TLS13_PSK_DHE_KE_SUPPORT
uint16_t cipherSuite
Cipher suite identifier.
const HashAlgo * tlsGetHashAlgo(TlsHashAlgo hashAlgoId)
Get the hash algorithm that matches the specified identifier.
@ ERROR_ILLEGAL_PARAMETER
error_t tlsSelectVersion(TlsContext *context, uint16_t version)
Set the TLS version to be used.
#define TLS13_MAX_COOKIE_SIZE
error_t tls13ParseServerKeyShareExtension(TlsContext *context, const Tls13KeyShareEntry *serverShare)
Parse KeyShare extension (ServerHello message)
TlsMessageType
Handshake message type.
error_t tls13FormatCookieExtension(TlsContext *context, uint8_t *p, size_t *written)
Format Cookie extension.
@ TLS13_KEY_EXCH_PSK_HYBRID
bool_t tls13IsHybridKeMethodSupported(TlsContext *context, uint16_t namedGroup)
Check whether a given hybrid key exchange method is supported.
error_t tls13FormatClientEarlyDataExtension(TlsContext *context, uint8_t *p, size_t *written)
Format EarlyData extension.
@ TLS_PSK_KEY_EXCH_MODE_PSK_KE
error_t tls13ParseSelectedGroupExtension(TlsContext *context, const TlsExtension *selectedGroup)
Parse KeyShare extension (HelloRetryRequest message)
@ TLS_PSK_KEY_EXCH_MODE_PSK_DHE_KE
error_t mpiExport(const Mpi *a, uint8_t *data, uint_t length, MpiFormat format)
Integer to octet string conversion.
error_t tls13ParseServerSupportedVersionsExtension(TlsContext *context, const TlsExtension *selectedVersion)
Parse SupportedVersions extension.
#define osMemcpy(dest, src, length)
@ ERROR_UNSUPPORTED_EXTENSION
bool_t tls13IsEcdheGroupSupported(TlsContext *context, uint16_t namedGroup)
Check whether a given ECDHE group is supported.
@ ERROR_FAILURE
Generic error code.
error_t tlsSelectCipherSuite(TlsContext *context, uint16_t identifier)
Set cipher suite.
error_t tls13Decapsulate(TlsContext *context, const uint8_t *keyShare, size_t length)
Decapsulation algorithm.
error_t tls13FormatClientKeyShareExtension(TlsContext *context, uint8_t *p, size_t *written)
Format KeyShare extension (ClientHello message)
@ TLS_TYPE_ENCRYPTED_EXTENSIONS
bool_t tls13IsTicketValid(TlsContext *context)
Check whether a session ticket is valid.
bool_t tls13IsFfdheGroupSupported(TlsContext *context, uint16_t namedGroup)
Check whether a given FFDHE group is supported.
error_t tls13FormatClientPreSharedKeyExtension(TlsContext *context, uint8_t *p, size_t *written, Tls13PskIdentityList **identityList, Tls13PskBinderList **binderList)
Format PreSharedKey extension.
error_t tls13ParseCookieExtension(TlsContext *context, const Tls13Cookie *cookie)
Parse Cookie extension.
#define TLS13_PSK_HYBRID_KE_SUPPORT
@ TLS13_KEY_EXCH_PSK_ECDHE
error_t tls13GenerateSharedSecret(TlsContext *context, const uint8_t *keyShare, size_t length)
(EC)DHE shared secret generation
bool_t tls13IsPskValid(TlsContext *context)
Check whether an externally established PSK is valid.
error_t tls13GenerateKeyShare(TlsContext *context, uint16_t namedGroup)
Key share generation.
error_t tls13ParseServerPreSharedKeyExtension(TlsContext *context, const TlsExtension *selectedIdentity)
Parse PreSharedKey extension.
error_t tls13FormatPskKeModesExtension(TlsContext *context, uint8_t *p, size_t *written)
Format PskKeyExchangeModes extension.
Formatting and parsing of extensions (TLS 1.3 client)
TLS (Transport Layer Security)
error_t ecExport(const EcDomainParameters *params, const EcPoint *a, uint8_t *data, size_t *length)
Convert an EC point to an octet string.
Common interface for hash algorithms.
const char_t * tlsGetVersionName(uint16_t version)
Convert TLS version to string representation.
@ TLS_TYPE_NEW_SESSION_TICKET
#define osMemset(p, value, length)
#define TLS13_PSK_ECDHE_KE_SUPPORT
uint_t mpiGetByteLength(const Mpi *a)
Get the actual length in bytes.
error_t tls13ParseServerEarlyDataExtension(TlsContext *context, TlsMessageType msgType, const TlsExtension *earlyDataIndication)
Parse EarlyData extension.