
louise
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#1197 · main · 10 min 35 s
1Étoiles
0Forks
0Issues
| 1 | /// Cryptographic hashes, computed by the runtime over `ring` (issue #145: |
| 2 | /// PostgreSQL's SCRAM-SHA-256 needs them), Ed25519 signatures (ADR 0067), |
| 3 | /// and ChaCha20-Poly1305 with HKDF-SHA-256 for encryption at rest |
| 4 | /// (ADR 0071). SHA-1 and MD5 are not offered. |
| 5 | /// |
| 6 | /// These are primitives over raw bytes, not a cryptography library: no key |
| 7 | /// types, no encodings, no nonce bookkeeping. |
| 8 | |
| 9 | /// SHA-256 of `data` (FIPS 180-4). |
| 10 | @extern c "tl_crypto_sha256" |
| 11 | pub fn sha256 :: data: Bytes -> Bytes |
| 12 | |
| 13 | /// HMAC-SHA-256 of `message` under `key` (RFC 2104). |
| 14 | @extern c "tl_crypto_hmac_sha256" |
| 15 | pub fn hmac_sha256 :: key: Bytes message: Bytes -> Bytes |
| 16 | |
| 17 | /// PBKDF2-HMAC-SHA-256 of `password` with `salt` and `iterations` |
| 18 | /// (at least 1), `length` bytes of output (at most 1 MiB). |
| 19 | /// |
| 20 | /// The iteration count is the caller's, so the derivation runs on the |
| 21 | /// runtime's `cpu` blocking pool: a large one never stalls the scheduler. |
| 22 | @extern c "tl_crypto_pbkdf2_sha256" (blocking cpu) |
| 23 | pub fn pbkdf2_hmac_sha256 :: |
| 24 | password: Bytes |
| 25 | salt: Bytes |
| 26 | iterations: Int |
| 27 | length: Int |
| 28 | -> Bytes |
| 29 | |
| 30 | /// Whether `signature` is the Ed25519 signature of `message` under |
| 31 | /// `public_key` (RFC 8032). A key that is not 32 bytes or a signature |
| 32 | /// that is not 64 is no signature: `False`. |
| 33 | @extern c "tl_crypto_ed25519_verify" |
| 34 | pub fn ed25519_verify :: |
| 35 | public_key: Bytes |
| 36 | message: Bytes |
| 37 | signature: Bytes |
| 38 | -> Bool |
| 39 | |
| 40 | /// The Ed25519 public key (32 bytes) of a 32-byte `seed`, RFC 8032's |
| 41 | /// private key. For tests and tools: a server verifies, and its clients |
| 42 | /// keep their seeds. Panics on a seed of another length. |
| 43 | @extern c "tl_crypto_ed25519_public_key" |
| 44 | pub fn ed25519_public_key :: seed: Bytes -> Bytes |
| 45 | |
| 46 | /// The Ed25519 signature (64 bytes) of `message` under the key pair of a |
| 47 | /// 32-byte `seed`. For tests and tools, like `ed25519_public_key`; panics |
| 48 | /// on a seed of another length. |
| 49 | @extern c "tl_crypto_ed25519_sign" |
| 50 | pub fn ed25519_sign :: seed: Bytes message: Bytes -> Bytes |
| 51 | |
| 52 | /// The ChaCha20-Poly1305 sealing of `plaintext` (RFC 8439): the ciphertext, |
| 53 | /// as long as `plaintext`, then a 16-byte tag that also authenticates |
| 54 | /// `aad`, data sent or stored in the clear alongside (an id, a version). |
| 55 | /// |
| 56 | /// `key` is 32 bytes and `nonce` 12; another length panics. A nonce must |
| 57 | /// never repeat under one key: one repeat reveals the two plaintexts' |
| 58 | /// XOR and lets the tag be forged. Random nonces (`random.bytes 12`) are |
| 59 | /// safe for about 2^32 messages per key; derive a key per owner or per |
| 60 | /// purpose (`hkdf_sha256`) to stay far below that. |
| 61 | @extern c "tl_crypto_chacha20_poly1305_seal" |
| 62 | pub fn chacha20_poly1305_seal :: |
| 63 | key: Bytes |
| 64 | nonce: Bytes |
| 65 | plaintext: Bytes |
| 66 | aad: Bytes |
| 67 | -> Bytes |
| 68 | |
| 69 | /// The plaintext of `sealed` if it authenticates under `key`, `nonce` and |
| 70 | /// `aad`, else an `Error`: a changed byte, another key, nonce or `aad`, |
| 71 | /// and a message shorter than its tag are all the same refusal. A key |
| 72 | /// that is not 32 bytes or a nonce that is not 12 panics, as when sealing. |
| 73 | @extern c "tl_crypto_chacha20_poly1305_open" |
| 74 | pub fn chacha20_poly1305_open :: |
| 75 | key: Bytes |
| 76 | nonce: Bytes |
| 77 | sealed: Bytes |
| 78 | aad: Bytes |
| 79 | -> Result<Bytes, String> |
| 80 | |
| 81 | /// HKDF-SHA-256 (RFC 5869), extract then expand: `length` bytes derived |
| 82 | /// from `secret`, with `salt` (empty means RFC 5869's zero salt) and |
| 83 | /// `info`, which names what the bytes are for. Distinct `info`s give |
| 84 | /// independent keys from one secret. `length` is 0 to 8160; another |
| 85 | /// panics. |
| 86 | @extern c "tl_crypto_hkdf_sha256" |
| 87 | pub fn hkdf_sha256 :: secret: Bytes salt: Bytes info: Bytes length: Int -> Bytes |