-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathcli.c
35 lines (32 loc) · 1.13 KB
/
cli.c
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
#include <stdio.h>
#include <string.h>
#include "salsa20.h"
int main(int argc, char *argv[])
{
if (!(argc == 3 && strlen(argv[1]) == 16 && strlen(argv[2]) == 8)) {
puts("salsa20 demo program");
puts("");
puts("Will encrypt or decrypt from standard input (the operation");
puts("is reversible for salsa20) until EOF, using a 128-bit key.");
puts("WARNING: Do not use this program for serious security. No");
puts(" appropriate key expansion function is used for");
puts(" converting a password to a cryptographic key.");
puts(" Use this program as a demo ONLY.");
puts("");
puts("Usage:");
puts("salsa20 <16-character key> <8-character nonce>");
return 1;
}
int in;
// Stream index
uint32_t si = 0;
while ((in = getchar()) != EOF) {
uint8_t c = in;
// Encrypt a single character at a time
// key 128-bit key nonce encrypt one byte
if (s20_crypt((uint8_t *) argv[1], S20_KEYLEN_128, (uint8_t *) argv[2], si++, &c, 1) == S20_FAILURE)
puts("Error: encryption failed");
putchar(c);
}
return 0;
}