-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathsalsa20.h
67 lines (62 loc) · 1.98 KB
/
salsa20.h
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
#ifndef _SALSA20_H_
#define _SALSA20_H_
#include <stdint.h>
#include <stddef.h>
/**
* Return codes for s20_crypt
*/
enum s20_status_t
{
S20_SUCCESS,
S20_FAILURE
};
/**
* Key size
* Salsa20 only permits a 128-bit key or a 256-bit key, so these are
* the only two options made available by this library.
*/
enum s20_keylen_t
{
S20_KEYLEN_256,
S20_KEYLEN_128
};
/**
* Encrypts or decrypts messages up to 2^32-1 bytes long, under a 256-
* or 128-bit key and a unique 64-byte nonce. Permits seeking to any
* point within a message.
*
* key Pointer to either a 128-bit or 256-bit key.
* No key-derivation function is applied to this key, and no
* entropy is gathered. It is expected that this key is already
* appropriate for direct use by the Salsa20 algorithm.
*
* keylen Length of the key.
* Must be S20_KEYLEN_256 or S20_KEYLEN_128.
*
* nonce Pointer to an 8-byte nonce.
* Does not have to be random, but must be unique for every
* message under a single key. Nonce reuse destroys message
* confidentiality.
*
* si Stream index.
* This is for seeking within a larger message. If you are only
* working with small messages that are encrypted/decrypted all
* at once (like TLS records), this will always be 0.
*
* buf The data to encrypt or decrypt.
*
* buflen Length of the data in buf.
*
* This function returns either S20_SUCCESS or S20_FAILURE.
* A return of S20_SUCCESS indicates that basic sanity checking on
* parameters succeeded and encryption/decryption was performed.
* A return of S20_FAILURE indicates that basic sanity checking on
* parameters failed and encryption/decryption was not performed.
*/
enum s20_status_t s20_crypt(uint8_t *key,
enum s20_keylen_t keylen,
uint8_t nonce[static 8],
uint32_t si,
uint8_t *buf,
uint32_t buflen);
#endif