]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Use stdint integer types instead of BSD legacy ones
authorGuillem Jover <guillem@hadrons.org>
Tue, 12 Aug 2014 10:32:34 +0000 (12:32 +0200)
committerGuillem Jover <guillem@hadrons.org>
Wed, 23 Sep 2015 05:14:21 +0000 (07:14 +0200)
include/bsd/md5.h
include/bsd/stdlib.h
man/arc4random.3
man/mdX.3bsd
src/arc4random.c
src/hash/helper.c
src/hash/md5.c

index 3599640aecbc1e28508bf231bbd82a6e142712e2..56c3cd6ef175d7e7878a92ad301f37e2a45baae9 100644 (file)
 #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
index 0fcb454302a08a4b70e0a9629d0cb0d7dc72b2be..0604cad28d05241034402fd9a15b7ee2b732c5cb 100644 (file)
 #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);
 
index eda74af6523e4834b00282dbd47fc2e1fe59ff2f..90264ceec26769209a15005833e92c42c915b2bf 100644 (file)
 .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
index 8e1b64a234694cc67e644d6f624b86378979c893..095a2692809edbdcafc09a6786fd1710d4a9a1a4 100644 (file)
 .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.
index 20fce09cf5d06f64e240f6f3b19073e485adeb07..fc8db6d5beb8c61b65af774ab6c16eae101978db 100644 (file)
@@ -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);
index fe3f3e71cffaddadda56db4ad84c92b4389dd521..06af1892050c70fd31c33eb1e71cced20823c3d1 100644 (file)
@@ -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
index e60bbd904de3b17a53240617f0e8632b0dab3978..7e9672e763e9867f36e9ac8ea1591cd20a35615e 100644 (file)
@@ -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