diff options
author | tb <> | 2021-10-22 17:43:00 +0000 |
---|---|---|
committer | tb <> | 2021-10-22 17:43:00 +0000 |
commit | 630111fac3e498f4089755b177349fed5f03d466 (patch) | |
tree | e9db7523a04bafb6a41b2bd606f2c2375d1a54c9 | |
parent | 905a18fb7a745ca06dead1b4cb100bd0091673d9 (diff) | |
download | openbsd-630111fac3e498f4089755b177349fed5f03d466.tar.gz openbsd-630111fac3e498f4089755b177349fed5f03d466.tar.bz2 openbsd-630111fac3e498f4089755b177349fed5f03d466.zip |
Switch from u_int and u_char to u32 and u8 to avoid portability issues.
Prompted by a diff by Jonas Termansen.
ok jsing
-rw-r--r-- | src/lib/libcrypto/chacha/chacha-merged.c | 31 |
1 files changed, 14 insertions, 17 deletions
diff --git a/src/lib/libcrypto/chacha/chacha-merged.c b/src/lib/libcrypto/chacha/chacha-merged.c index 67508f208d..d24912daaa 100644 --- a/src/lib/libcrypto/chacha/chacha-merged.c +++ b/src/lib/libcrypto/chacha/chacha-merged.c | |||
@@ -1,41 +1,38 @@ | |||
1 | /* $OpenBSD: chacha-merged.c,v 1.9 2019/01/22 00:59:21 dlg Exp $ */ | 1 | /* $OpenBSD: chacha-merged.c,v 1.10 2021/10/22 17:43:00 tb Exp $ */ |
2 | /* | 2 | /* |
3 | chacha-merged.c version 20080118 | 3 | chacha-merged.c version 20080118 |
4 | D. J. Bernstein | 4 | D. J. Bernstein |
5 | Public domain. | 5 | Public domain. |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <sys/types.h> | ||
9 | |||
10 | #include <stdint.h> | 8 | #include <stdint.h> |
11 | 9 | ||
12 | #define CHACHA_MINKEYLEN 16 | 10 | #define CHACHA_MINKEYLEN 16 |
13 | #define CHACHA_NONCELEN 8 | 11 | #define CHACHA_NONCELEN 8 |
14 | #define CHACHA_CTRLEN 8 | 12 | #define CHACHA_CTRLEN 8 |
15 | #define CHACHA_STATELEN (CHACHA_NONCELEN+CHACHA_CTRLEN) | 13 | #define CHACHA_STATELEN (CHACHA_NONCELEN+CHACHA_CTRLEN) |
16 | #define CHACHA_BLOCKLEN 64 | 14 | #define CHACHA_BLOCKLEN 64 |
17 | 15 | ||
16 | typedef uint8_t u8; | ||
17 | typedef uint32_t u32; | ||
18 | |||
18 | struct chacha_ctx { | 19 | struct chacha_ctx { |
19 | u_int input[16]; | 20 | u32 input[16]; |
20 | uint8_t ks[CHACHA_BLOCKLEN]; | 21 | u8 ks[CHACHA_BLOCKLEN]; |
21 | uint8_t unused; | 22 | u8 unused; |
22 | }; | 23 | }; |
23 | 24 | ||
24 | static inline void chacha_keysetup(struct chacha_ctx *x, const u_char *k, | 25 | static inline void chacha_keysetup(struct chacha_ctx *x, const u8 *k, u32 kbits) |
25 | u_int kbits) | ||
26 | __attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN))); | 26 | __attribute__((__bounded__(__minbytes__, 2, CHACHA_MINKEYLEN))); |
27 | static inline void chacha_ivsetup(struct chacha_ctx *x, const u_char *iv, | 27 | static inline void chacha_ivsetup(struct chacha_ctx *x, const u8 *iv, |
28 | const u_char *ctr) | 28 | const u8 *ctr) |
29 | __attribute__((__bounded__(__minbytes__, 2, CHACHA_NONCELEN))) | 29 | __attribute__((__bounded__(__minbytes__, 2, CHACHA_NONCELEN))) |
30 | __attribute__((__bounded__(__minbytes__, 3, CHACHA_CTRLEN))); | 30 | __attribute__((__bounded__(__minbytes__, 3, CHACHA_CTRLEN))); |
31 | static inline void chacha_encrypt_bytes(struct chacha_ctx *x, const u_char *m, | 31 | static inline void chacha_encrypt_bytes(struct chacha_ctx *x, const u8 *m, |
32 | u_char *c, u_int bytes) | 32 | u8 *c, u32 bytes) |
33 | __attribute__((__bounded__(__buffer__, 2, 4))) | 33 | __attribute__((__bounded__(__buffer__, 2, 4))) |
34 | __attribute__((__bounded__(__buffer__, 3, 4))); | 34 | __attribute__((__bounded__(__buffer__, 3, 4))); |
35 | 35 | ||
36 | typedef unsigned char u8; | ||
37 | typedef unsigned int u32; | ||
38 | |||
39 | typedef struct chacha_ctx chacha_ctx; | 36 | typedef struct chacha_ctx chacha_ctx; |
40 | 37 | ||
41 | #define U8C(v) (v##U) | 38 | #define U8C(v) (v##U) |
@@ -127,7 +124,7 @@ chacha_encrypt_bytes(chacha_ctx *x, const u8 *m, u8 *c, u32 bytes) | |||
127 | u32 j8, j9, j10, j11, j12, j13, j14, j15; | 124 | u32 j8, j9, j10, j11, j12, j13, j14, j15; |
128 | u8 *ctarget = NULL; | 125 | u8 *ctarget = NULL; |
129 | u8 tmp[64]; | 126 | u8 tmp[64]; |
130 | u_int i; | 127 | u32 i; |
131 | 128 | ||
132 | if (!bytes) | 129 | if (!bytes) |
133 | return; | 130 | return; |