Skip to content

Instantly share code, notes, and snippets.

@jbenet
Last active August 29, 2015 14:17
Show Gist options
  • Save jbenet/12609db43c1d09ab519d to your computer and use it in GitHub Desktop.
Save jbenet/12609db43c1d09ab519d to your computer and use it in GitHub Desktop.

Keys have lifetimes. After encrypting a certain number of bytes, keys should be replaced.

What if instead of encrypting large ammounts of our data with keys, we used a method similar to DHE?

protocol

  • given symmetric key (or public key) k
  • given message m
  • generate a one-time symmetric key k2
  • encrypt(k1, k2) -> k2c
  • encrypt(k2, m) -> mc
  • send k2c || mc

symmetric

given:
  m := message
  k := secret symmetric key
  n := nonce()


c := encrypt2(k, n, m):
  ns := [ H(n), H(H(n)), ... ] 

  k2 := keygen()
  k2c := encrypt(k, ns[1], k2)
  
  c := encrypt(k2, ns[2], m)
  return ns[0] || k2c || c

assymetric

given:
  m := message
  pk := public key
  n := nonce()


c := encrypt2(pk, n, m):
  ns := [ H(n), H(H(n)), ... ] 

  k2 := keygen()
  k2c := encrypt(pk, ns[1], k2)
  
  c := encrypt(k2, ns[2], m)
  return ns[0] || k2c || c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment