summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2021-10-22 17:43:00 +0000
committertb <>2021-10-22 17:43:00 +0000
commit630111fac3e498f4089755b177349fed5f03d466 (patch)
treee9db7523a04bafb6a41b2bd606f2c2375d1a54c9
parent905a18fb7a745ca06dead1b4cb100bd0091673d9 (diff)
downloadopenbsd-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.c31
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/*
3chacha-merged.c version 20080118 3chacha-merged.c version 20080118
4D. J. Bernstein 4D. J. Bernstein
5Public domain. 5Public 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
16typedef uint8_t u8;
17typedef uint32_t u32;
18
18struct chacha_ctx { 19struct 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
24static inline void chacha_keysetup(struct chacha_ctx *x, const u_char *k, 25static 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)));
27static inline void chacha_ivsetup(struct chacha_ctx *x, const u_char *iv, 27static 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)));
31static inline void chacha_encrypt_bytes(struct chacha_ctx *x, const u_char *m, 31static 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
36typedef unsigned char u8;
37typedef unsigned int u32;
38
39typedef struct chacha_ctx chacha_ctx; 36typedef 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;