You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Secret keys and shared secrets are returned as PHP strings, which are immutable, copied on assignment, and garbage-collected without being wiped. They can persist in freed memory, reach swap, and appear in stack traces or var_dump output.
The FFI scratch buffers are also never cleared before going out of scope — $sk in generateKeypair(), $skBuf and $ss in decapsulate(), $skBuf in sign().
PHP gives you no good way to scrub the returned strings, so that part is arguably a documentation matter. But the FFI buffers are ordinary C memory and can be overwritten before release:
\FFI::memset($skBuf, 0, strlen($secretKey));
liboqs is deliberate about this internally (OQS_MEM_secure_free, OQS_MEM_cleanse); it would be good not to discard the property at the binding boundary.
Two suggestions:
Zero the FFI buffers holding secret key material and shared secrets once they're no longer needed.
Add a note to the security section of the README stating that returned secret keys and shared secrets live in PHP string memory and cannot be reliably erased, so callers should minimise their lifetime and avoid logging or serializing them.
Activity