# Signal Protocol - Learnings ### Protocol Overview - this is a simplified sequence diagram for signal protocol flow - Sources: - [End-To-End Encryption with the Signal Protocol](https://engineering.mindlinksoft.com/end-to-end-encryption-with-the-signal-protocol/) - [whatsApp security spec (also using signal protocol)](https://scontent.whatsapp.net/v/t61.22868-34/68135620_760356657751682_6212997528851833559_n.pdf/WhatsApp-Security-Whitepaper.pdf?_nc_sid=41cc27&_nc_ohc=Zci5Ahx3flkAX9kesNu&_nc_ht=scontent.whatsapp.net&oh=e0a2f612019b25c17ca29b71fb685293&oe=5F612D53) - [Demystifying the Signal Protocol for End-to-End Encryption (E2EE)](https://medium.com/@justinomora/demystifying-the-signal-protocol-for-end-to-end-encryption-e2ee-ad6a567e6cb4) - (1) ms = ECDH(ik-a, prepk-b) || ECDH(eprek-a, ipk-b) || ECDH(eprek-a, prepk-b) || ECDH(eprek-a, eprepk-b). ``` mermaid sequenceDiagram participant A as Initiator(Alice) participant S as Server participant B as Responder(Bobby) par [Registration] A-->>A: 1. long-term identity key(ik) A-->>A: 2. medium-term "signed prekey"(prek) A-->>A: 3. multiple short term "one-time prekeys" keys)eprek A-->>A: 4. signature to prek using ik A-->>S: send public pub keys of 1~4(pre-key bundle) B-->>B: generate ik, prek, eprek, sign prek w ik B-->>S: send pre-key bundle (ipk, prepk, sig of prepk w ik, multiple eprepk) and [Alice Session Setup] A-->>S: request Bobby PubKeys S-->>A: ipk-b, prepk-b, sig of prepk-b, eprepk-b(if available) S-->>S: removes the sent eprepk-b A-->>A: generate ephemeral ratchet public key(rchpk) and ephemeral key (ek/epk) A-->>A: calculates master secret(ms) with several ECDH (1) A-->>A: use HKDF and derive root key/chaining keys(rk, ck) from ms and [Bobby Session Setup] loop Until Bobby responds A-->>B: rchpk-a & epk-a & ipk-a, identifier for eprepk-b used, message (hi!) end B-->>B: makes sure bobby knows which ik, prek, eprek Alice used B-->>B: derives ms with received keys and [Symmetric ratchet stage] A-->>A: KDF(ck) -> new mk & updated ck A-->>A: encrypt message, delete old ck A-->>B: second message(how are you?), new eprk and [Asymmetric ratchet stage] B-->>B: generate eprk B-->>B: derive ck, mk B-->>B: encrypt message B->>A: eprk, first message (hello!) end ```