Use stdint integer types instead of BSD legacy ones
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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
diff --git a/include/bsd/md5.h b/include/bsd/md5.h
index 3599640..56c3cd6 100644
--- a/include/bsd/md5.h
+++ b/include/bsd/md5.h
@@ -15,26 +15,28 @@
#ifndef _MD5_H_
#define _MD5_H_
+#include <stdint.h>
+
#define MD5_BLOCK_LENGTH 64
#define MD5_DIGEST_LENGTH 16
#define MD5_DIGEST_STRING_LENGTH (MD5_DIGEST_LENGTH * 2 + 1)
typedef struct MD5Context {
- u_int32_t state[4]; /* state */
- u_int64_t count; /* number of bits, mod 2^64 */
- u_int8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
+ uint32_t state[4]; /* state */
+ uint64_t count; /* number of bits, mod 2^64 */
+ uint8_t buffer[MD5_BLOCK_LENGTH]; /* input buffer */
} MD5_CTX;
#include <sys/cdefs.h>
__BEGIN_DECLS
void MD5Init(MD5_CTX *);
-void MD5Update(MD5_CTX *, const u_int8_t *, size_t)
+void MD5Update(MD5_CTX *, const uint8_t *, size_t)
__attribute__((__bounded__(__string__,2,3)));
void MD5Pad(MD5_CTX *);
-void MD5Final(u_int8_t [MD5_DIGEST_LENGTH], MD5_CTX *)
+void MD5Final(uint8_t [MD5_DIGEST_LENGTH], MD5_CTX *)
__attribute__((__bounded__(__minbytes__,1,MD5_DIGEST_LENGTH)));
-void MD5Transform(u_int32_t [4], const u_int8_t [MD5_BLOCK_LENGTH])
+void MD5Transform(uint32_t [4], const uint8_t [MD5_BLOCK_LENGTH])
__attribute__((__bounded__(__minbytes__,1,4)))
__attribute__((__bounded__(__minbytes__,2,MD5_BLOCK_LENGTH)));
char *MD5End(MD5_CTX *, char *)
@@ -43,7 +45,7 @@ char *MD5File(const char *, char *)
__attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
char *MD5FileChunk(const char *, char *, off_t, off_t)
__attribute__((__bounded__(__minbytes__,2,MD5_DIGEST_STRING_LENGTH)));
-char *MD5Data(const u_int8_t *, size_t, char *)
+char *MD5Data(const uint8_t *, size_t, char *)
__attribute__((__bounded__(__string__,1,2)))
__attribute__((__bounded__(__minbytes__,3,MD5_DIGEST_STRING_LENGTH)));
__END_DECLS
diff --git a/include/bsd/stdlib.h b/include/bsd/stdlib.h
index 0fcb454..0604cad 100644
--- a/include/bsd/stdlib.h
+++ b/include/bsd/stdlib.h
@@ -47,11 +47,11 @@
#include <stdint.h>
__BEGIN_DECLS
-u_int32_t arc4random(void);
+uint32_t arc4random(void);
void arc4random_stir(void);
void arc4random_addrandom(u_char *dat, int datlen);
void arc4random_buf(void *_buf, size_t n);
-u_int32_t arc4random_uniform(u_int32_t upper_bound);
+uint32_t arc4random_uniform(uint32_t upper_bound);
int dehumanize_number(const char *str, int64_t *size);
diff --git a/man/arc4random.3 b/man/arc4random.3
index eda74af..90264ce 100644
--- a/man/arc4random.3
+++ b/man/arc4random.3
@@ -45,12 +45,12 @@
.Lb libbsd
.Sh SYNOPSIS
.In bsd/stdlib.h
-.Ft u_int32_t
+.Ft uint32_t
.Fn arc4random "void"
.Ft void
.Fn arc4random_buf "void *buf" "size_t nbytes"
-.Ft u_int32_t
-.Fn arc4random_uniform "u_int32_t upper_bound"
+.Ft uint32_t
+.Fn arc4random_uniform "uint32_t upper_bound"
.Ft void
.Fn arc4random_stir "void"
.Ft void
diff --git a/man/mdX.3bsd b/man/mdX.3bsd
index 8e1b64a..095a269 100644
--- a/man/mdX.3bsd
+++ b/man/mdX.3bsd
@@ -32,13 +32,13 @@
.Ft void
.Fn MDXInit "MDX_CTX *context"
.Ft void
-.Fn MDXUpdate "MDX_CTX *context" "const u_int8_t *data" "size_t len"
+.Fn MDXUpdate "MDX_CTX *context" "const uint8_t *data" "size_t len"
.Ft void
.Fn MDXPad "MDX_CTX *context"
.Ft void
-.Fn MDXFinal "u_int8_t digest[MDX_DIGEST_LENGTH]" "MDX_CTX *context"
+.Fn MDXFinal "uint8_t digest[MDX_DIGEST_LENGTH]" "MDX_CTX *context"
.Ft void
-.Fn MDXTransform "u_int32_t state[4]" "u_int8_t block[MDX_BLOCK_LENGTH]"
+.Fn MDXTransform "uint32_t state[4]" "uint8_t block[MDX_BLOCK_LENGTH]"
.Ft "char *"
.Fn MDXEnd "MDX_CTX *context" "char *buf"
.Ft "char *"
@@ -46,7 +46,7 @@
.Ft "char *"
.Fn MDXFileChunk "const char *filename" "char *buf" "off_t offset" "off_t length"
.Ft "char *"
-.Fn MDXData "const u_int8_t *data" "size_t len" "char *buf"
+.Fn MDXData "const uint8_t *data" "size_t len" "char *buf"
.Sh DESCRIPTION
The MDX functions calculate a 128-bit cryptographic checksum (digest)
for any number of input bytes.
diff --git a/src/arc4random.c b/src/arc4random.c
index 20fce09..fc8db6d 100644
--- a/src/arc4random.c
+++ b/src/arc4random.c
@@ -43,9 +43,9 @@ __FBSDID("$FreeBSD$");
#include <pthread.h>
struct arc4_stream {
- u_int8_t i;
- u_int8_t j;
- u_int8_t s[256];
+ uint8_t i;
+ uint8_t j;
+ uint8_t s[256];
};
#define RANDOMDEV "/dev/urandom"
@@ -65,7 +65,7 @@ static int rs_initialized;
static int rs_stired;
static int arc4_count;
-static inline u_int8_t arc4_getbyte(void);
+static inline uint8_t arc4_getbyte(void);
static void arc4_stir(void);
static inline void
@@ -83,7 +83,7 @@ static inline void
arc4_addrandom(u_char *dat, int datlen)
{
int n;
- u_int8_t si;
+ uint8_t si;
rs.i--;
for (n = 0; n < 256; n++) {
@@ -103,7 +103,7 @@ arc4_stir(void)
struct {
struct timeval tv;
pid_t pid;
- u_int8_t rnd[KEYSIZE];
+ uint8_t rnd[KEYSIZE];
} rdat;
fd = open(RANDOMDEV, O_RDONLY, 0);
@@ -133,10 +133,10 @@ arc4_stir(void)
arc4_count = 1600000;
}
-static inline u_int8_t
+static inline uint8_t
arc4_getbyte(void)
{
- u_int8_t si, sj;
+ uint8_t si, sj;
rs.i = (rs.i + 1);
si = rs.s[rs.i];
@@ -148,10 +148,10 @@ arc4_getbyte(void)
return (rs.s[(si + sj) & 0xff]);
}
-static inline u_int32_t
+static inline uint32_t
arc4_getword(void)
{
- u_int32_t val;
+ uint32_t val;
val = arc4_getbyte() << 24;
val |= arc4_getbyte() << 16;
@@ -199,10 +199,10 @@ arc4random_addrandom(u_char *dat, int datlen)
THREAD_UNLOCK();
}
-u_int32_t
+uint32_t
arc4random(void)
{
- u_int32_t rnd;
+ uint32_t rnd;
THREAD_LOCK();
arc4_check_init();
@@ -239,10 +239,10 @@ arc4random_buf(void *_buf, size_t n)
* [2**32 % upper_bound, 2**32) which maps back to [0, upper_bound)
* after reduction modulo upper_bound.
*/
-u_int32_t
-arc4random_uniform(u_int32_t upper_bound)
+uint32_t
+arc4random_uniform(uint32_t upper_bound)
{
- u_int32_t r, min;
+ uint32_t r, min;
if (upper_bound < 2)
return (0);
diff --git a/src/hash/helper.c b/src/hash/helper.c
index fe3f3e7..06af189 100644
--- a/src/hash/helper.c
+++ b/src/hash/helper.c
@@ -27,7 +27,7 @@ char *
HASHEnd(HASH_CTX *ctx, char *buf)
{
int i;
- u_int8_t digest[HASH_DIGEST_LENGTH];
+ uint8_t digest[HASH_DIGEST_LENGTH];
#ifdef HASH_DIGEST_UPPERCASE
static const char hex[] = "0123456789ABCDEF";
#else
diff --git a/src/hash/md5.c b/src/hash/md5.c
index e60bbd9..7e9672e 100644
--- a/src/hash/md5.c
+++ b/src/hash/md5.c
@@ -37,7 +37,7 @@
(cp)[1] = (value) >> 8; \
(cp)[0] = (value); } while (0)
-static u_int8_t PADDING[MD5_BLOCK_LENGTH] = {
+static uint8_t PADDING[MD5_BLOCK_LENGTH] = {
0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
@@ -71,7 +71,7 @@ MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len)
need = MD5_BLOCK_LENGTH - have;
/* Update bitcount */
- ctx->count += (u_int64_t)len << 3;
+ ctx->count += (uint64_t)len << 3;
if (len >= need) {
if (have != 0) {
@@ -102,7 +102,7 @@ MD5Update(MD5_CTX *ctx, const unsigned char *input, size_t len)
void
MD5Pad(MD5_CTX *ctx)
{
- u_int8_t count[8];
+ uint8_t count[8];
size_t padlen;
/* Convert count to 8 bytes in little endian order. */
@@ -152,19 +152,19 @@ MD5Final(unsigned char digest[MD5_DIGEST_LENGTH], MD5_CTX *ctx)
* the data and converts bytes into longwords for this routine.
*/
void
-MD5Transform(u_int32_t state[4], const u_int8_t block[MD5_BLOCK_LENGTH])
+MD5Transform(uint32_t state[4], const uint8_t block[MD5_BLOCK_LENGTH])
{
- u_int32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4];
+ uint32_t a, b, c, d, in[MD5_BLOCK_LENGTH / 4];
#if BYTE_ORDER == LITTLE_ENDIAN
memcpy(in, block, sizeof(in));
#else
for (a = 0; a < MD5_BLOCK_LENGTH / 4; a++) {
- in[a] = (u_int32_t)(
- (u_int32_t)(block[a * 4 + 0]) |
- (u_int32_t)(block[a * 4 + 1]) << 8 |
- (u_int32_t)(block[a * 4 + 2]) << 16 |
- (u_int32_t)(block[a * 4 + 3]) << 24);
+ in[a] = (uint32_t)(
+ (uint32_t)(block[a * 4 + 0]) |
+ (uint32_t)(block[a * 4 + 1]) << 8 |
+ (uint32_t)(block[a * 4 + 2]) << 16 |
+ (uint32_t)(block[a * 4 + 3]) << 24);
}
#endif