Skip to content

Commit

Permalink
dtls.c: support longer PSK secrets.
Browse files Browse the repository at this point in the history
Use DTLS_KEY_LENGTH for DTLS_PSK_MAX_KEY_LEN only as default.

Signed-off-by: Achim Kraus <[email protected]>
  • Loading branch information
boaks committed Nov 18, 2023
1 parent 897a60e commit a6412a3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
2 changes: 2 additions & 0 deletions crypto.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ typedef struct {
#endif /* DTLS_PSK_MAX_CLIENT_IDENTITY_LEN */

/* This is the maximal supported length of the pre-shared key. */
#ifndef DTLS_PSK_MAX_KEY_LEN
#define DTLS_PSK_MAX_KEY_LEN DTLS_KEY_LENGTH
#endif /* DTLS_PSK_MAX_KEY_LEN */

typedef struct {
uint16_t id_length;
Expand Down
6 changes: 2 additions & 4 deletions dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ calculate_key_block(dtls_context_t *ctx,
dtls_peer_type role) {
(void) ctx;
(void) session;
unsigned char *pre_master_secret;
unsigned char pre_master_secret[2 * (sizeof(uint16) + DTLS_PSK_MAX_KEY_LEN)];
int pre_master_len = 0;
dtls_security_parameters_t *security = dtls_security_params_next(peer);
uint8 master_secret[DTLS_MASTER_SECRET_LENGTH];
Expand All @@ -962,7 +962,6 @@ calculate_key_block(dtls_context_t *ctx,
return dtls_alert_fatal_create(DTLS_ALERT_INTERNAL_ERROR);
}

pre_master_secret = security->key_block;
switch (get_key_exchange_algorithm(handshake->cipher_index)) {
case DTLS_KEY_EXCHANGE_PSK:
#ifdef DTLS_PSK
Expand All @@ -978,10 +977,9 @@ calculate_key_block(dtls_context_t *ctx,
dtls_crit("no psk key for session available\n");
return len;
}
/* Temporarily use the key_block storage space for the pre master secret. */
pre_master_len = dtls_psk_pre_master_secret(psk, len,
pre_master_secret,
MAX_KEYBLOCK_LENGTH);
sizeof(pre_master_secret));

dtls_debug_hexdump("psk", psk, len);

Expand Down
2 changes: 1 addition & 1 deletion zephyr/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ if(CONFIG_LIBTINYDTLS)
set(DTLS_ECC Off)
endif()
add_subdirectory(.. build)
target_compile_definitions(tinydtls PUBLIC WITH_ZEPHYR)
target_compile_definitions(tinydtls PUBLIC WITH_ZEPHYR DTLS_PSK_MAX_KEY_LEN=32 DTLS_PSK_MAX_CLIENT_IDENTITY_LEN=48)
target_link_libraries(tinydtls PUBLIC zephyr_interface)
set_property(GLOBAL APPEND PROPERTY ZEPHYR_INTERFACE_LIBS tinydtls)
endif()

0 comments on commit a6412a3

Please sign in to comment.