Skip to content
Closed
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
10 changes: 5 additions & 5 deletions cxx/random.hh
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
class Random
{
public:
enum class Stream : uint32_t {
wm_pattern = 0xe58eb537,
wm_mask = 0xfd19fc82,
wm_convcode = 0x7ecf1f7a,
img_comment = 0x7abcde01,
enum class Stream : uint8_t {
wm_pattern = 1,
wm_mask = 2,
wm_convcode = 3,
img_comment = 4,
Comment on lines +31 to +34

Choose a reason for hiding this comment

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

critical

Changing the enum values will alter the generated pseudo-random sequences. This is a critical breaking change that will prevent watermarks created with older versions of this tool from being read correctly.

The Random::seed function was already using only the lower 8 bits of the Stream enum value by casting it to uint8_t.

To maintain backward compatibility, I suggest using the lower 8 bits of the original uint32_t values.

The original values and their lower 8 bits are:

  • wm_pattern: 0xe58eb537 -> 0x37
  • wm_mask: 0xfd19fc82 -> 0x82
  • wm_convcode: 0x7ecf1f7a -> 0x7a
  • img_comment: 0x7abcde01 -> 0x01

These are all unique and would preserve the behavior of the random number generator, making this change non-breaking.

    wm_pattern  = 0x37,
    wm_mask     = 0x82,
    wm_convcode = 0x7a,
    img_comment = 0x01,

};
private:
gcry_cipher_hd_t aes_ctr_cipher = nullptr;
Expand Down
Loading