tree: fe7d0c07a4f36388a007b1d8e7eb3639003ae549
  1. apple/
  2. obsolete/
  3. test/
  4. aead.cc
  5. aead.h
  6. aead_unittest.cc
  7. aes_cbc.cc
  8. aes_cbc.h
  9. aes_cbc_unittest.cc
  10. aes_ctr.cc
  11. aes_ctr.h
  12. aes_ctr_unittest.cc
  13. BUILD.gn
  14. chaps_support.cc
  15. chaps_support.h
  16. cose.cc
  17. cose.h
  18. cose_unittest.cc
  19. crypto_export.h
  20. DEPS
  21. DIR_METADATA
  22. ecdsa_utils.cc
  23. ecdsa_utils.h
  24. ecdsa_utils_unittest.cc
  25. encrypt.cc
  26. encrypt.h
  27. encrypt_unittest.cc
  28. evp.cc
  29. evp.h
  30. evp_unittest.cc
  31. features.cc
  32. features.gni
  33. features.h
  34. hash.cc
  35. hash.h
  36. hash_unittest.cc
  37. hmac.cc
  38. hmac.h
  39. hmac_unittest.cc
  40. hpke.cc
  41. hpke.h
  42. hpke_unittest.cc
  43. kdf.cc
  44. kdf.h
  45. kdf_unittest.cc
  46. kem.cc
  47. kem.h
  48. kem_unittest.cc
  49. kex.cc
  50. kex.h
  51. kex_unittest.cc
  52. keypair.cc
  53. keypair.h
  54. keypair_unittest.cc
  55. mock_unexportable_key.cc
  56. mock_unexportable_key.h
  57. mock_unexportable_key_provider.cc
  58. mock_unexportable_key_provider.h
  59. nss_crypto_module_delegate.h
  60. nss_key_util.cc
  61. nss_key_util.h
  62. nss_key_util_unittest.cc
  63. nss_util.cc
  64. nss_util.h
  65. nss_util_chromeos.cc
  66. nss_util_internal.h
  67. nss_util_unittest.cc
  68. openssl_util.cc
  69. openssl_util.h
  70. OWNERS
  71. pem.cc
  72. pem.h
  73. pem_unittest.cc
  74. PLAN.md
  75. process_bound_string.cc
  76. process_bound_string.h
  77. process_bound_string_unittest.cc
  78. random.cc
  79. random.h
  80. random_unittest.cc
  81. README.md
  82. scoped_capi_types.h
  83. scoped_cng_types.h
  84. scoped_fake_unexportable_key_provider.cc
  85. scoped_fake_unexportable_key_provider.h
  86. scoped_fake_user_verifying_key_provider.cc
  87. scoped_fake_user_verifying_key_provider.h
  88. scoped_mock_unexportable_key_provider.cc
  89. scoped_mock_unexportable_key_provider.h
  90. scoped_nss_types.h
  91. scoped_test_nss_chromeos_user.cc
  92. scoped_test_nss_chromeos_user.h
  93. scoped_test_nss_db.cc
  94. scoped_test_nss_db.h
  95. scoped_test_system_nss_key_slot.cc
  96. scoped_test_system_nss_key_slot.h
  97. secure_hash.cc
  98. secure_hash.h
  99. secure_hash_unittest.cc
  100. secure_util.cc
  101. secure_util.h
  102. sha2.cc
  103. sha2.h
  104. sha2_unittest.cc
  105. sign.cc
  106. sign.h
  107. sign_unittest.cc
  108. signature_verifier.cc
  109. signature_verifier.h
  110. signature_verifier_unittest.cc
  111. subtle_passkey.cc
  112. subtle_passkey.h
  113. test_support.cc
  114. test_support.h
  115. tpm.rs
  116. tpm_parser.cc
  117. tpm_parser.h
  118. tpm_parser_unittest.cc
  119. tpm_unittest.rs
  120. unexportable_key.cc
  121. unexportable_key.h
  122. unexportable_key_metrics.cc
  123. unexportable_key_metrics.h
  124. unexportable_key_metrics_unittest.cc
  125. unexportable_key_software_unsecure.cc
  126. unexportable_key_unittest.cc
  127. unexportable_key_win.cc
  128. unexportable_key_win.h
  129. user_verifying_key.cc
  130. user_verifying_key.h
  131. user_verifying_key_mac.mm
  132. user_verifying_key_mac_unittest.mm
  133. user_verifying_key_win.cc
crypto/README.md

//crypto README

This directory contains implementations of crypto primitives for use in Chromium. Most of these are either:

  • Wrappers around platform-specific APIs (DPAPI, libsecret, etc), so that code elsewhere in Chromium can use cross-platform abstractions, or
  • Wrappers around BoringSSL APIs that use Chromium-native types like base::span and similar

There is very little actual cryptographic code in //crypto - it is mostly wrappers.

This directory has recently been refactored, and as a result some of the APIs are deprecated. They are marked as such in their header files, along with notes pointing you towards their replacements.

Commonly-Used Interfaces

Many interfaces in this directory are deprecated and being changed or removed; check the comment at the top of the header file before using them.

Recommended Primitives & Constructions

If you are designing a new protocol in Chromium using cryptography, these are our recommended primitives and constructions to use. They balance performance with security, are “post-quantum”, and have reasonably well-understood margins of safety.

  • If you need to encrypt to a public key, use HPKE with ML-KEM-768, HKDF-SHA256, and AES-128-GCM via crypto/hpke.
  • If you need to encrypt to a symmetric key, use AES-128-GCM via crypto/aead.
  • If you need to sign with a private key, use ML-DSA-44 via crypto/sign.
  • If you need to sign with a symmetric key, use HMAC-SHA256 via crypto/hmac.
  • If you need to hash, use SHA256 via crypto/hash.
  • If you need to do key exchange, use ML-KEM-768 via crypto/kem.

Advice For Clients

  • Ciphertext, keys, certificates, and other cryptographic material are generally sequences of bytes, not characters, so prefer using byte-oriented types to represent them: vector<uint8_t>, array<uint8_t>, and span<uint8_t> rather than string and string_view.
  • To serialize private keys, use keypair::PrivateKey::ToPrivateKeyInfo(), which returns a PKCS#8 PrivateKeyInfo structure serialized as a byte vector. To unserialize keys in this format, use keypair::PrivateKey::FromPrivateKeyInfo().
  • To serialize public keys, use keypair::PublicKey::ToSubjectPublicKeyInfo() or keypair::PrivateKey::ToSubjectPublicKeyInfo(), which return a X.509 SubjectPublicKeyInfo structure serialized as a byte vector. To unserialize public keys in this format, use keypair::PublicKey::FromSubjectPublicKeyInfo().
  • SubjectPublicKeyInfo and PrivateKeyInfo can represent many kinds of keys, so code that expects a specific kind of key must check the kind after deserialization.
  • To serialize symmetric keys (AEAD, HMAC, or symmetric encryption keys), use a raw sequence of bytes for the key material. Represent these keys in memory using vector<uint8_t>, array<uint8_t>, or span<uint8_t> directly.