fix: Additional medium-priority bugs and documentation
Bug 7: MAC2 buffer size
- Changed from fixed 1024-byte buffer to dynamic allocation
- Uses malloc/free for packets up to WG_MAX_PACKET_SIZE
Documentation:
- Added comments about WG_TYPE constants sharing values (intentional)
- Added note about platform-specific RNG for embedded systems
- system_rng() uses POSIX /dev/urandom - replace for u-boot/ESP32
Known limitations:
- chain_key initialization uses simplified version (peer_public_key directly)
Full handshake would use HASH("Noise_IKpsk2_25519...")
- For test phase, simplified version is acceptable
Test results: 29 passed, 3 failed (unchanged)
This commit is contained in:
@@ -74,3 +74,7 @@ install(FILES include/se050_wireguard.h
|
||||
# Install library
|
||||
install(TARGETS se050_wireguard
|
||||
ARCHIVE DESTINATION lib)
|
||||
|
||||
# Note: For embedded platforms (ESP32, u-boot), replace system_rng() with
|
||||
# platform-specific RNG (e.g., get_random_bytes() for ESP32)
|
||||
# See se050_wireguard.c for details.
|
||||
|
||||
+11
-3
@@ -22,6 +22,7 @@
|
||||
#include "se050_crypto_utils.h"
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
/* =========================================================================
|
||||
* WireGuard Protocol Constants
|
||||
@@ -364,16 +365,23 @@ int se050_wireguard_compute_mac2(se050_wireguard_session_t *session,
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Concatenate packet + mac1 */
|
||||
uint8_t data[1024];
|
||||
if (packet_len + WG_MAC1_SIZE > sizeof(data)) {
|
||||
/* Use dynamic allocation for large packets */
|
||||
if (packet_len + WG_MAC1_SIZE > WG_MAX_PACKET_SIZE) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
uint8_t *data = malloc(packet_len + WG_MAC1_SIZE);
|
||||
if (!data) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
memcpy(data, packet, packet_len);
|
||||
memcpy(data + packet_len, mac1, WG_MAC1_SIZE);
|
||||
|
||||
se050_hmac_blake2s(mac2, session->cookie_secret, 32,
|
||||
data, packet_len + WG_MAC1_SIZE);
|
||||
|
||||
free(data);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user