Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Sources/WireGuardKitC/x25519.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@ void curve25519_derive_public_key(uint8_t public_key[32], const uint8_t private_

void curve25519_generate_private_key(uint8_t private_key[32])
{
assert(CCRandomGenerateBytes(private_key, 32) == kCCSuccess);
CCRNGStatus status = CCRandomGenerateBytes(private_key, 32);
assert(status == kCCSuccess);
Comment on lines +175 to +176
Copy link

Copilot AI Mar 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assert is compiled out when NDEBUG is set, so in release builds status becomes unused (potential warning) and, more importantly, failures from CCRandomGenerateBytes would be silently ignored and the function would proceed to clamp whatever bytes are in private_key. Consider handling status != kCCSuccess outside of assert (e.g., return an error to callers or fail fast) so key generation cannot succeed with invalid/undefined entropy in production builds.

Copilot uses AI. Check for mistakes.
private_key[31] = (private_key[31] & 127) | 64;
private_key[0] &= 248;
}
Loading