port ratchet code from Pond
license