File: crypto_stream_xsalsa20.c

package info (click to toggle)
dq 20230101-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,020 kB
  • sloc: ansic: 8,269; makefile: 363; sh: 176; python: 82
file content (27 lines) | stat: -rw-r--r-- 748 bytes parent folder | download | duplicates (3)
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
/*
20140727
Jan Mojzis
Public domain.
*/

#include "crypto_core_hsalsa20.h"
#include "crypto_stream_salsa20.h"
#include "cleanup.h"
#include "crypto_stream_xsalsa20.h"

static const unsigned char sigma[16] = "expand 32-byte k";

int crypto_stream_xsalsa20_tinynacl_xor(unsigned char *c, const unsigned char *m, unsigned long long l, const unsigned char *n, const unsigned char *k) {

    unsigned char subkey[32];

    crypto_core_hsalsa20(subkey, n, k, sigma);
    crypto_stream_salsa20_xor(c, m, l, n + 16, subkey);
    cleanup(subkey);
    return 0;
}

int crypto_stream_xsalsa20_tinynacl(unsigned char *c, unsigned long long l, const unsigned char *n, const unsigned char *k) {

    return crypto_stream_xsalsa20_tinynacl_xor(c, 0, l, n, k);
}