summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/chacha/chacha.c
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
committercvs2svn <admin@example.com>2025-04-14 17:32:06 +0000
commiteb8dd9dca1228af0cd132f515509051ecfabf6f6 (patch)
treeedb6da6af7e865d488dc1a29309f1e1ec226e603 /src/lib/libcrypto/chacha/chacha.c
parent247f0352e0ed72a4f476db9dc91f4d982bc83eb2 (diff)
downloadopenbsd-tb_20250414.tar.gz
openbsd-tb_20250414.tar.bz2
openbsd-tb_20250414.zip
This commit was manufactured by cvs2git to create tag 'tb_20250414'.tb_20250414
Diffstat (limited to 'src/lib/libcrypto/chacha/chacha.c')
-rw-r--r--src/lib/libcrypto/chacha/chacha.c112
1 files changed, 0 insertions, 112 deletions
diff --git a/src/lib/libcrypto/chacha/chacha.c b/src/lib/libcrypto/chacha/chacha.c
deleted file mode 100644
index b60e3c4f27..0000000000
--- a/src/lib/libcrypto/chacha/chacha.c
+++ /dev/null
@@ -1,112 +0,0 @@
1/* $OpenBSD: chacha.c,v 1.10 2023/07/05 16:17:20 beck Exp $ */
2/*
3 * Copyright (c) 2014 Joel Sing <jsing@openbsd.org>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17
18#include <stdint.h>
19
20#include <openssl/chacha.h>
21
22#include "chacha-merged.c"
23
24void
25ChaCha_set_key(ChaCha_ctx *ctx, const unsigned char *key, uint32_t keybits)
26{
27 chacha_keysetup((chacha_ctx *)ctx, key, keybits);
28 ctx->unused = 0;
29}
30LCRYPTO_ALIAS(ChaCha_set_key);
31
32void
33ChaCha_set_iv(ChaCha_ctx *ctx, const unsigned char *iv,
34 const unsigned char *counter)
35{
36 chacha_ivsetup((chacha_ctx *)ctx, iv, counter);
37 ctx->unused = 0;
38}
39LCRYPTO_ALIAS(ChaCha_set_iv);
40
41void
42ChaCha(ChaCha_ctx *ctx, unsigned char *out, const unsigned char *in, size_t len)
43{
44 unsigned char *k;
45 uint64_t n;
46 int i, l;
47
48 /* Consume remaining keystream, if any exists. */
49 if (ctx->unused > 0) {
50 k = ctx->ks + 64 - ctx->unused;
51 l = (len > ctx->unused) ? ctx->unused : len;
52 for (i = 0; i < l; i++)
53 *(out++) = *(in++) ^ *(k++);
54 ctx->unused -= l;
55 len -= l;
56 }
57
58 while (len > 0) {
59 if ((n = len) > UINT32_MAX)
60 n = UINT32_MAX;
61
62 chacha_encrypt_bytes((chacha_ctx *)ctx, in, out, (uint32_t)n);
63
64 in += n;
65 out += n;
66 len -= n;
67 }
68}
69LCRYPTO_ALIAS(ChaCha);
70
71void
72CRYPTO_chacha_20(unsigned char *out, const unsigned char *in, size_t len,
73 const unsigned char key[32], const unsigned char iv[8], uint64_t counter)
74{
75 struct chacha_ctx ctx;
76 uint64_t n;
77
78 /*
79 * chacha_ivsetup expects the counter to be in u8. Rather than
80 * converting size_t to u8 and then back again, pass a counter of
81 * NULL and manually assign it afterwards.
82 */
83 chacha_keysetup(&ctx, key, 256);
84 chacha_ivsetup(&ctx, iv, NULL);
85 if (counter != 0) {
86 ctx.input[12] = (uint32_t)counter;
87 ctx.input[13] = (uint32_t)(counter >> 32);
88 }
89
90 while (len > 0) {
91 if ((n = len) > UINT32_MAX)
92 n = UINT32_MAX;
93
94 chacha_encrypt_bytes(&ctx, in, out, (uint32_t)n);
95
96 in += n;
97 out += n;
98 len -= n;
99 }
100}
101LCRYPTO_ALIAS(CRYPTO_chacha_20);
102
103void
104CRYPTO_xchacha_20(unsigned char *out, const unsigned char *in, size_t len,
105 const unsigned char key[32], const unsigned char iv[24])
106{
107 uint8_t subkey[32];
108
109 CRYPTO_hchacha_20(subkey, key, iv);
110 CRYPTO_chacha_20(out, in, len, subkey, iv + 16, 0);
111}
112LCRYPTO_ALIAS(CRYPTO_xchacha_20);