deriveOptimalByteLengthForEphemeralKeys function
Derives the optimal byte length for ephemeral keys based on safe prime size.
This function returns a byte length that matches the safe prime's bit length, optimizing for security with negligible performance impact. Ephemeral keys of this length provide maximum security for the given safe prime.
Parameters:
safePrimeBitLength
: Bit length of the safe prime (e.g., 2048 for a 2048-bit prime).
Returns: Optimal byte length for ephemeral keys (safePrimeBitLength / 8).
For example, a 2048-bit safe prime would result in 256-byte ephemeral keys.
Implementation
int deriveOptimalByteLengthForEphemeralKeys(int safePrimeBitLength) {
return safePrimeBitLength ~/ 8;
}