aboutsummaryrefslogtreecommitdiff
path: root/sys/contrib/libsodium/src/libsodium/include/sodium/crypto_secretstream_xchacha20poly1305.h
blob: 7d3fa2a9e39a10fa7a78244399cdfe700f5b7e0e (plain) (blame)
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef crypto_secretstream_xchacha20poly1305_H
#define crypto_secretstream_xchacha20poly1305_H

#include <stddef.h>

#include "crypto_aead_xchacha20poly1305.h"
#include "crypto_stream_chacha20.h"
#include "export.h"

#ifdef __cplusplus
# ifdef __GNUC__
#  pragma GCC diagnostic ignored "-Wlong-long"
# endif
extern "C" {
#endif

#define crypto_secretstream_xchacha20poly1305_ABYTES \
    (1U + crypto_aead_xchacha20poly1305_ietf_ABYTES)
SODIUM_EXPORT
size_t crypto_secretstream_xchacha20poly1305_abytes(void);

#define crypto_secretstream_xchacha20poly1305_HEADERBYTES \
    crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
SODIUM_EXPORT
size_t crypto_secretstream_xchacha20poly1305_headerbytes(void);

#define crypto_secretstream_xchacha20poly1305_KEYBYTES \
    crypto_aead_xchacha20poly1305_ietf_KEYBYTES
SODIUM_EXPORT
size_t crypto_secretstream_xchacha20poly1305_keybytes(void);

#define crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX \
    SODIUM_MIN(SODIUM_SIZE_MAX, ((1ULL << 32) - 2ULL) * 64ULL)
SODIUM_EXPORT
size_t crypto_secretstream_xchacha20poly1305_messagebytes_max(void);

#define crypto_secretstream_xchacha20poly1305_TAG_MESSAGE 0x00
SODIUM_EXPORT
unsigned char crypto_secretstream_xchacha20poly1305_tag_message(void);

#define crypto_secretstream_xchacha20poly1305_TAG_PUSH    0x01
SODIUM_EXPORT
unsigned char crypto_secretstream_xchacha20poly1305_tag_push(void);

#define crypto_secretstream_xchacha20poly1305_TAG_REKEY   0x02
SODIUM_EXPORT
unsigned char crypto_secretstream_xchacha20poly1305_tag_rekey(void);

#define crypto_secretstream_xchacha20poly1305_TAG_FINAL \
    (crypto_secretstream_xchacha20poly1305_TAG_PUSH | \
     crypto_secretstream_xchacha20poly1305_TAG_REKEY)
SODIUM_EXPORT
unsigned char crypto_secretstream_xchacha20poly1305_tag_final(void);

typedef struct crypto_secretstream_xchacha20poly1305_state {
    unsigned char k[crypto_stream_chacha20_ietf_KEYBYTES];
    unsigned char nonce[crypto_stream_chacha20_ietf_NONCEBYTES];
    unsigned char _pad[8];
} crypto_secretstream_xchacha20poly1305_state;

SODIUM_EXPORT
size_t crypto_secretstream_xchacha20poly1305_statebytes(void);

SODIUM_EXPORT
void crypto_secretstream_xchacha20poly1305_keygen
   (unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]);

SODIUM_EXPORT
int crypto_secretstream_xchacha20poly1305_init_push
   (crypto_secretstream_xchacha20poly1305_state *state,
    unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES],
    const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]);

SODIUM_EXPORT
int crypto_secretstream_xchacha20poly1305_push
   (crypto_secretstream_xchacha20poly1305_state *state,
    unsigned char *c, unsigned long long *clen_p,
    const unsigned char *m, unsigned long long mlen,
    const unsigned char *ad, unsigned long long adlen, unsigned char tag);

SODIUM_EXPORT
int crypto_secretstream_xchacha20poly1305_init_pull
   (crypto_secretstream_xchacha20poly1305_state *state,
    const unsigned char header[crypto_secretstream_xchacha20poly1305_HEADERBYTES],
    const unsigned char k[crypto_secretstream_xchacha20poly1305_KEYBYTES]);

SODIUM_EXPORT
int crypto_secretstream_xchacha20poly1305_pull
   (crypto_secretstream_xchacha20poly1305_state *state,
    unsigned char *m, unsigned long long *mlen_p, unsigned char *tag_p,
    const unsigned char *c, unsigned long long clen,
    const unsigned char *ad, unsigned long long adlen);

SODIUM_EXPORT
void crypto_secretstream_xchacha20poly1305_rekey
    (crypto_secretstream_xchacha20poly1305_state *state);

#ifdef __cplusplus
}
#endif

#endif