README.md

# Themis Erlang NIF

The Themis Erlang NIF module provides an interface to the [Themis](https://github.com/cossacklabs/themis) cryptographic framework.


## Installation

Clone the repository and build the project:

```bash
git clone https://codeberg.org/N3TC4T/themis_nif.git
cd themis_nif
make
```

## Module Overview

The `themis_nif` module exports several functions for generating keys and encrypting/decrypting messages.

### Available Functions

| Function Name                | Arity | Description                                                |
|------------------------------|-------|------------------------------------------------------------|
| `gen_ec_key_pair/0`         | 0     | Generates an ECC (Elliptic Curve Cryptography) key pair. |
| `gen_rsa_key_pair/0`        | 0     | Generates an RSA key pair.                                |
| `gen_sym_key/0`             | 0     | Generates a symmetric key.                                |
| `gen_sym_key/1`             | 1     | Generates a symmetric key of specified length.           |
| `is_valid_key/1`            | 1     | Checks if the provided key is valid.                     |
| `is_private_key/1`          | 1     | Checks if the provided key is a private key.             |
| `is_public_key/1`           | 1     | Checks if the provided key is a public key.              |
| `cell_seal_encrypt/2`       | 2     | Encrypts a message using a key (no context).             |
| `cell_seal_encrypt/3`       | 3     | Encrypts a message using a key with a specified context.  |
| `cell_seal_decrypt/2`       | 2     | Decrypts a message using a key (no context).             |
| `cell_seal_decrypt/3`       | 3     | Decrypts a message using a key with a specified context.  |

### Error Handling

If any function is called without valid arguments or if the NIF library is not loaded, the functions will return an error tuple as shown below:

```erlang
{error, reason}   % Reason can be any error code from the themis_nif library
```

### Loading the NIF

The NIFs are loaded dynamically when the module is invoked, using the `on_load/0` function. Ensure that the necessary shared object file is correctly placed in the designated directory.

### Example Usage

```erlang
% Generate an EC key pair
{PublicKey, PrivateKey} = themis_nif:gen_ec_key_pair(),

% Validate a key
isValid = themis_nif:is_valid_key(PublicKey),

% Encrypt a message
EncryptedMessage = themis_nif:cell_seal_encrypt(PrivateKey, <<"Hello, World!">>),

% Decrypt the message
DecryptedMessage = themis_nif:cell_seal_decrypt(PrivateKey, EncryptedMessage).
```

## Contributing

Feel free to contribute by forking the repository and making pull requests for enhancements, bug fixes, or new features.