]> git.lizzy.rs Git - plan9front.git/blob - sys/man/2/salsa
vt: implement proper selections (thanks Ori_B)
[plan9front.git] / sys / man / 2 / salsa
1 .TH SALSA 2
2 .SH NAME
3 setupSalsastate, salsa_setblock, salsa_setiv, salsa_encrypt, salsa_encrypt2, hsalsa
4 \- salsa20 encryption
5 .SH SYNOPSIS
6 .B #include <u.h>
7 .br
8 .B #include <libc.h>
9 .br
10 .B #include <libsec.h>
11 .PP
12 .B
13 void setupSalsastate(Salsastate *s, uchar key[], ulong keylen, uchar *iv, ulong ivlen, int rounds)
14 .PP
15 .B
16 void salsa_encrypt(uchar *data, ulong len, Salsastate *s)
17 .PP
18 .B
19 void salsa_encrypt2(uchar *src, uchar *dst, ulong len, Salsastate *s)
20 .PP
21 .B
22 void salsa_setblock(Salsastate *s, u64int blockno)
23 .PP
24 .B
25 void salsa_setiv(Salsastate *s, uchar *iv);
26 .PP
27 .B
28 void hsalsa(uchar h[32], uchar *key, ulong keylen, uchar nonce[16], int rounds);
29 .SH DESCRIPTION
30 .PP
31 Salsa20 is a stream cipher designed by D J Berstein. It has an underlying block size of 64 bytes
32 (named as constant
33 .BR SalsaBsize ).
34 It supports key sizes of 128 and 256-bit (recommended).
35 .PP
36 .I SetupSalsastate
37 takes a reference to a
38 .B Salsastate
39 structure, a
40 .I key
41 of
42 .I keylen
43 bytes, which should normally be
44 .BR SalsaKeylen = 32 ,
45 a
46 .I iv
47 or nonce of
48 .I ivlen
49 bytes (can be
50 .BR SalsaIVlen = 8
51 or
52 .BR XSalsaIVlen = 24 ,
53 set to all zeros if the
54 .I iv
55 argument is nil),
56 and the number of
57 .I rounds
58 (set to the default of 20 if the argument is zero).
59 .PP
60 .I Salsa_encrypt
61 encrypts
62 .I len
63 bytes of
64 .I buf
65 in place using the
66 .B Salsastate
67 in
68 .IR s .
69 .I Len
70 can be any byte length.
71 Encryption and decryption are the same operation given the same starting state
72 .IR s .
73 .PP
74 .I Salsa_encrypt2
75 is similar, but encrypts
76 .I len
77 bytes of
78 .I src
79 into
80 .I dst
81 without modifying
82 .IR src .
83 .PP
84 .I Salsa_setblock
85 sets the Salsa block counter for the next encryption to
86 .IR blockno ,
87 allowing seeking in an encrypted stream.
88 .PP
89 .I Salsa_setiv
90 sets the the initialization vector (nonce) to
91 .IR iv .
92 .PP
93 .I Hsalsa
94 is a key expansion function that takes a 128 or
95 256-bit key and a 128-bit nonce and produces a new
96 256-bit key.
97 .SH SOURCE
98 .B /sys/src/libsec/port/salsa.c
99 .SH SEE ALSO
100 .IR chacha (2)
101 .br
102 .B http://cr.yp.to/snuffle.html#specification