[API reference](https://evolu.dev/docs/api-reference) › [@evolu/common](https://evolu.dev/docs/api-reference/common) › Crypto

Cryptographic utilities.

Type-safe cryptographic operations including random bytes generation, SLIP21
key derivation, XChaCha20-Poly1305 symmetric encryption, PADMÉ padding, and
timing-safe comparisons.

## Random bytes

| Name                                                                                   | Description                                                                                                                                  |
| -------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| [RandomBytes](https://evolu.dev/docs/api-reference/common/Crypto/interfaces/RandomBytes)            | Cryptographically secure random bytes with length-branded results.                                                                           |
| [RandomBytesDep](https://evolu.dev/docs/api-reference/common/Crypto/interfaces/RandomBytesDep)      | Dependency wrapper for [RandomBytes](https://evolu.dev/docs/api-reference/common/Crypto/interfaces/RandomBytes).                                          |
| [Entropy16](https://evolu.dev/docs/api-reference/common/Crypto/type-aliases/Entropy16)              | Cryptographic entropy of exactly 16 bytes.                                                                                                   |
| [Entropy24](https://evolu.dev/docs/api-reference/common/Crypto/type-aliases/Entropy24)              | Cryptographic entropy of exactly 24 bytes.                                                                                                   |
| [Entropy32](https://evolu.dev/docs/api-reference/common/Crypto/type-aliases/Entropy32)              | Cryptographic entropy of exactly 32 bytes.                                                                                                   |
| [Entropy64](https://evolu.dev/docs/api-reference/common/Crypto/type-aliases/Entropy64)              | Cryptographic entropy of exactly 64 bytes.                                                                                                   |
| [Entropy16](https://evolu.dev/docs/api-reference/common/Crypto/variables/Entropy16)                 | Cryptographic entropy of exactly 16 bytes.                                                                                                   |
| [Entropy24](https://evolu.dev/docs/api-reference/common/Crypto/variables/Entropy24)                 | Cryptographic entropy of exactly 24 bytes.                                                                                                   |
| [Entropy32](https://evolu.dev/docs/api-reference/common/Crypto/variables/Entropy32)                 | Cryptographic entropy of exactly 32 bytes.                                                                                                   |
| [Entropy64](https://evolu.dev/docs/api-reference/common/Crypto/variables/Entropy64)                 | Cryptographic entropy of exactly 64 bytes.                                                                                                   |
| [createRandomBytes](https://evolu.dev/docs/api-reference/common/Crypto/functions/createRandomBytes) | Creates [RandomBytes](https://evolu.dev/docs/api-reference/common/Crypto/interfaces/RandomBytes) backed by the platform's secure random number generator. |

## Key derivation

| Function                                                                             | Description                                                       |
| ------------------------------------------------------------------------------------ | ----------------------------------------------------------------- |
| [createSlip21](https://evolu.dev/docs/api-reference/common/Crypto/functions/createSlip21)         | SLIP21.                                                           |
| [deriveSlip21Node](https://evolu.dev/docs/api-reference/common/Crypto/functions/deriveSlip21Node) | Derives a single node in the SLIP-21 hierarchical key derivation. |

## Encryption

| Name                                                                                                                    | Description                                                                                                                                           |
| ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
| [DecryptWithXChaCha20Poly1305Error](https://evolu.dev/docs/api-reference/common/Crypto/interfaces/DecryptWithXChaCha20Poly1305Error) | Error returned by [decryptWithXChaCha20Poly1305](https://evolu.dev/docs/api-reference/common/Crypto/functions/decryptWithXChaCha20Poly1305) when decryption fails. |
| [EncryptionKey](https://evolu.dev/docs/api-reference/common/Crypto/type-aliases/EncryptionKey)                                       | The encryption key for symmetric encryption.                                                                                                          |
| [XChaCha20Poly1305Ciphertext](https://evolu.dev/docs/api-reference/common/Crypto/type-aliases/XChaCha20Poly1305Ciphertext)           | Branded Uint8Array for XChaCha20-Poly1305 encryption.                                                                                                 |
| [EncryptionKey](https://evolu.dev/docs/api-reference/common/Crypto/variables/EncryptionKey)                                          | The encryption key for symmetric encryption.                                                                                                          |
| [XChaCha20Poly1305Ciphertext](https://evolu.dev/docs/api-reference/common/Crypto/variables/XChaCha20Poly1305Ciphertext)              | Branded Uint8Array for XChaCha20-Poly1305 encryption.                                                                                                 |
| [xChaCha20Poly1305NonceLength](https://evolu.dev/docs/api-reference/common/Crypto/variables/xChaCha20Poly1305NonceLength)            | The nonce length for XChaCha20-Poly1305 encryption.                                                                                                   |
| [decryptWithXChaCha20Poly1305](https://evolu.dev/docs/api-reference/common/Crypto/functions/decryptWithXChaCha20Poly1305)            | Decrypts ciphertext with XChaCha20-Poly1305.                                                                                                          |
| [encryptWithXChaCha20Poly1305](https://evolu.dev/docs/api-reference/common/Crypto/functions/encryptWithXChaCha20Poly1305)            | Encrypts plaintext with XChaCha20-Poly1305.                                                                                                           |

## Padding

| Function                                                                                           | Description                                                        |
| -------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
| [createPadmePaddedLength](https://evolu.dev/docs/api-reference/common/Crypto/functions/createPadmePaddedLength) | Returns the PADMÉ padded length for a given input length.          |
| [createPadmePadding](https://evolu.dev/docs/api-reference/common/Crypto/functions/createPadmePadding)           | Creates a PADMÉ padding array of zeros for the given input length. |

## Comparison

| Name                                                                                      | Description                                                                                                                                                       |
| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [TimingSafeEqualDep](https://evolu.dev/docs/api-reference/common/Crypto/interfaces/TimingSafeEqualDep) | Dependency wrapper for [TimingSafeEqual](https://evolu.dev/docs/api-reference/common/Crypto/type-aliases/TimingSafeEqual).                                                     |
| [TimingSafeEqual](https://evolu.dev/docs/api-reference/common/Crypto/type-aliases/TimingSafeEqual)     | Performs a timing-safe comparison of two Uint8Arrays. Returns true if they are equal, false otherwise. Takes constant time regardless of where the arrays differ. |

## Testing

| Function                                                                                       | Description                                          |
| ---------------------------------------------------------------------------------------------- | ---------------------------------------------------- |
| [testCreateRandomBytes](https://evolu.dev/docs/api-reference/common/Crypto/functions/testCreateRandomBytes) | Creates seeded random bytes for deterministic tests. |