diff options
author | jsing <> | 2014-05-01 13:15:22 +0000 |
---|---|---|
committer | jsing <> | 2014-05-01 13:15:22 +0000 |
commit | 01bc5de569d5ec2e77fcaec43eae5ce76f9c3800 (patch) | |
tree | 84ee4c644a7257b0b1e244eb263e26464f79887b /src/lib/libcrypto/chacha/chacha.c | |
parent | a4b876b424f6cd1cc57b8a19f1d0a213cf99013c (diff) | |
download | openbsd-01bc5de569d5ec2e77fcaec43eae5ce76f9c3800.tar.gz openbsd-01bc5de569d5ec2e77fcaec43eae5ce76f9c3800.tar.bz2 openbsd-01bc5de569d5ec2e77fcaec43eae5ce76f9c3800.zip |
Add ChaCha to libcrypto, based on djb's public domain implementation.
ok deraadt@
Diffstat (limited to 'src/lib/libcrypto/chacha/chacha.c')
-rw-r--r-- | src/lib/libcrypto/chacha/chacha.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/lib/libcrypto/chacha/chacha.c b/src/lib/libcrypto/chacha/chacha.c new file mode 100644 index 0000000000..d76d64de4a --- /dev/null +++ b/src/lib/libcrypto/chacha/chacha.c | |||
@@ -0,0 +1,38 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2014 Joel Sing <jsing@openbsd.org> | ||
3 | * | ||
4 | * Permission to use, copy, modify, and distribute this software for any | ||
5 | * purpose with or without fee is hereby granted, provided that the above | ||
6 | * copyright notice and this permission notice appear in all copies. | ||
7 | * | ||
8 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | ||
9 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | ||
10 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | ||
11 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | ||
12 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | ||
13 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | ||
14 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | ||
15 | */ | ||
16 | |||
17 | #include "chacha-merged.c" | ||
18 | |||
19 | void | ||
20 | CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len, | ||
21 | const unsigned char key[32], const unsigned char iv[8], size_t counter) | ||
22 | { | ||
23 | struct chacha_ctx ctx; | ||
24 | |||
25 | /* | ||
26 | * chacha_ivsetup expects the counter to be in u8. Rather than | ||
27 | * converting size_t to u8 and then back again, pass a counter of | ||
28 | * NULL and manually assign it afterwards. | ||
29 | */ | ||
30 | chacha_keysetup(&ctx, key, 256); | ||
31 | chacha_ivsetup(&ctx, iv, NULL); | ||
32 | if (counter != 0) { | ||
33 | ctx.input[12] = (uint32_t)counter; | ||
34 | ctx.input[13] = (uint32_t)(((uint64_t)counter) >> 32); | ||
35 | } | ||
36 | |||
37 | chacha_encrypt_bytes(&ctx, in, out, (uint32_t)len); | ||
38 | } | ||