summaryrefslogtreecommitdiff
path: root/third_party/tinyaes/aes256gcm.h
blob: c7a349a1c40a015f1f32c52db3277c305b0b94e6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#ifndef HYBBX_AES256GCM_H
#define HYBBX_AES256GCM_H

#include <stddef.h>
#include <stdint.h>

#define HYBBX_AES256GCM_KEY_SIZE   32
#define HYBBX_AES256GCM_NONCE_SIZE 12
#define HYBBX_AES256GCM_TAG_SIZE   16

/**
 * AES-256-GCM encrypt. @p ciphertext length equals @p plaintext_len.
 * @p tag receives the 16-byte authentication tag.
 */
int hybbx_aes256gcm_encrypt(const uint8_t key[HYBBX_AES256GCM_KEY_SIZE],
                            const uint8_t nonce[HYBBX_AES256GCM_NONCE_SIZE],
                            const uint8_t *aad, size_t aad_len,
                            const uint8_t *plaintext, size_t plaintext_len,
                            uint8_t *ciphertext,
                            uint8_t tag[HYBBX_AES256GCM_TAG_SIZE]);

/**
 * AES-256-GCM decrypt. Returns 0 on success (tag valid), -1 on failure.
 */
int hybbx_aes256gcm_decrypt(const uint8_t key[HYBBX_AES256GCM_KEY_SIZE],
                            const uint8_t nonce[HYBBX_AES256GCM_NONCE_SIZE],
                            const uint8_t *aad, size_t aad_len,
                            const uint8_t *ciphertext, size_t ciphertext_len,
                            uint8_t *plaintext,
                            const uint8_t tag[HYBBX_AES256GCM_TAG_SIZE]);

#endif
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com