I don't think you want to look at the source code, and I don't think you want to look at Telegram. You should have a look at the Signal Protocol: https://en.m.wikipedia.org/wiki/Signal_Protocol. It's well documented. Maybe there are libraries which implement it.
(Though I still think that "how can I protect against TLS being broken?" is the wrong question and you should instead ask "how can I ensure that TLS doesn't break?".)
(Though I still think that "how can I protect against TLS being broken?" is the wrong question and you should instead ask "how can I ensure that TLS doesn't break?".)