Derive Secret

Aa function for deriving new secrets from an initial secret. It’s defined as:

function Derive (key, feed_id, prev_msg_id, labels, length) {
  var info = ['envelope', feed_id, prev_msg_id].concat(labels)

  return HKDF.Expand(key, encode(info), length)
}

Design

We want to derive unique keys which are very unlikely to collide with other keys, where “unlikely” means: - won’t happen by chance - won’t be easy to trick a user to performing a particular derivation

By baking the context (feed_id and prev_msg_id) into the info used to derive new secrets, we make the derive function very specific.

This has the side-effect that we can use zero’d nonces for encryption, because we can be very sure that the same key will not be generated twice.