Skip to content

Commit a6412a3

Browse files
committed
dtls.c: support longer PSK secrets.
Use DTLS_KEY_LENGTH for DTLS_PSK_MAX_KEY_LEN only as default. Signed-off-by: Achim Kraus <achim.kraus@cloudcoap.net>
1 parent 897a60e commit a6412a3

3 files changed

Lines changed: 5 additions & 5 deletions

File tree

crypto.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,9 @@ typedef struct {
9292
#endif /* DTLS_PSK_MAX_CLIENT_IDENTITY_LEN */
9393

9494
/* This is the maximal supported length of the pre-shared key. */
95+
#ifndef DTLS_PSK_MAX_KEY_LEN
9596
#define DTLS_PSK_MAX_KEY_LEN DTLS_KEY_LENGTH
97+
#endif /* DTLS_PSK_MAX_KEY_LEN */
9698

9799
typedef struct {
98100
uint16_t id_length;

dtls.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ calculate_key_block(dtls_context_t *ctx,
952952
dtls_peer_type role) {
953953
(void) ctx;
954954
(void) session;
955-
unsigned char *pre_master_secret;
955+
unsigned char pre_master_secret[2 * (sizeof(uint16) + DTLS_PSK_MAX_KEY_LEN)];
956956
int pre_master_len = 0;
957957
dtls_security_parameters_t *security = dtls_security_params_next(peer);
958958
uint8 master_secret[DTLS_MASTER_SECRET_LENGTH];
@@ -962,7 +962,6 @@ calculate_key_block(dtls_context_t *ctx,
962962
return dtls_alert_fatal_create(DTLS_ALERT_INTERNAL_ERROR);
963963
}
964964

965-
pre_master_secret = security->key_block;
966965
switch (get_key_exchange_algorithm(handshake->cipher_index)) {
967966
case DTLS_KEY_EXCHANGE_PSK:
968967
#ifdef DTLS_PSK
@@ -978,10 +977,9 @@ calculate_key_block(dtls_context_t *ctx,
978977
dtls_crit("no psk key for session available\n");
979978
return len;
980979
}
981-
/* Temporarily use the key_block storage space for the pre master secret. */
982980
pre_master_len = dtls_psk_pre_master_secret(psk, len,
983981
pre_master_secret,
984-
MAX_KEYBLOCK_LENGTH);
982+
sizeof(pre_master_secret));
985983

986984
dtls_debug_hexdump("psk", psk, len);
987985

zephyr/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ if(CONFIG_LIBTINYDTLS)
3939
set(DTLS_ECC Off)
4040
endif()
4141
add_subdirectory(.. build)
42-
target_compile_definitions(tinydtls PUBLIC WITH_ZEPHYR)
42+
target_compile_definitions(tinydtls PUBLIC WITH_ZEPHYR DTLS_PSK_MAX_KEY_LEN=32 DTLS_PSK_MAX_CLIENT_IDENTITY_LEN=48)
4343
target_link_libraries(tinydtls PUBLIC zephyr_interface)
4444
set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS tinydtls)
4545
endif()

0 commit comments

Comments
 (0)