Skip to content

Secret key material is never zeroized #4

Open

Description

@dstebila

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:

  1. Zero the FFI buffers holding secret key material and shared secrets once they're no longer needed.
  2. 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.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions