Skip to content

SHA1/SHA224/SHA256 state layouts are not memcpy-safe #742

@karel-m

Description

@karel-m

In my Perl bindings for libtomcrypt (CryptX), I support cloning digest/MAC contexts.

For a long time, I treated hash_state / hmac_state as effectively copyable by value, but with the current SHA1 and SHA224/SHA256 state layouts this is no longer that simple.

The issue is that these states now contain an internal pointer (state) which points into aligned storage inside the same struct (state_buf). After a raw struct copy, the cloned object still points into the original object’s buffer.

One "solution" would be to remove the clone() method from my Perl bindings, but before doing that I wanted to ask whether there is any chance that these state structs will become memcpy-friendly again.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions