1. Cryptographers come up with the algorithms and protocols with their mathematical proofs applied to their properties.
2. Someone uses tools like CRYPTOL for algorithms or AnBx for protocols to generate the code.
http://www.dsi.unive.it/~modesti/anbx/
3. The code is run through visual inspections, static analysis tools like ASTREE or SPARK, tests, covert channel analysis, and so on. Modified if problems are found.
4. An optimizing version of a certified compiler like CompCert produces the object code.
5. It's distributed with public key cryptography and/or Merkle Signatures if people don't trust that. There's modern versions with efficient or unlimited signing.
6. Optionally, a subversion-resistant process builds the fist compiler and checkers in stages.
Btw, here's two things Galois did with their contracts that mainstream security folks are mostly ignoring instead of building on or applying:
http://www.cryptol.net/
http://ivorylang.org/
And a repo with the rest that uses the magical power of open source to counter people's fears and improve the world:
https://github.com/galoisinc
At least some of them have stars in the three digits. I'm impressed an open-source crowd giving it that much attention. Maybe cuz it's on GitHub. The rest might need to go on there, too, for better odds of adoption. Using Google and Save As... are apparently major obstacles of adoption these days. Idk as I'm still trying to figure it out.