diff src/blowfish.c @ 2199:014a996ac896 vim73

Use UINT32_T in the code, define it to uint32_t or unsigned int. Better autoconf check for uint32_t.
author Bram Moolenaar <bram@vim.org>
date Wed, 19 May 2010 21:57:45 +0200
parents f9aec8acb188
children cccb71c2c5c1
line wrap: on
line diff
--- a/src/blowfish.c
+++ b/src/blowfish.c
@@ -21,7 +21,7 @@
 #define BF_OFB_LEN  (8*(BF_BLOCK))
 
 typedef union {
-    uint32_t ul[2];
+    UINT32_T ul[2];
     char_u   uc[8];
 } block8;
 
@@ -36,14 +36,14 @@ typedef union {
 # endif
 #endif
 
-static void bf_e_block __ARGS((uint32_t *p_xl, uint32_t *p_xr));
+static void bf_e_block __ARGS((UINT32_T *p_xl, UINT32_T *p_xr));
 static void bf_e_cblock __ARGS((char_u *block));
-static int bf_check_tables __ARGS((uint32_t ipa[18], uint32_t sbi[4][256], uint32_t val));
+static int bf_check_tables __ARGS((UINT32_T ipa[18], UINT32_T sbi[4][256], UINT32_T val));
 static int bf_self_test __ARGS((void));
 
 /* Blowfish code */
-static uint32_t pax[18];
-static uint32_t ipa[18] = {
+static UINT32_T pax[18];
+static UINT32_T ipa[18] = {
     0x243f6a88u, 0x85a308d3u, 0x13198a2eu,
     0x03707344u, 0xa4093822u, 0x299f31d0u,
     0x082efa98u, 0xec4e6c89u, 0x452821e6u,
@@ -52,8 +52,8 @@ static uint32_t ipa[18] = {
     0xb5470917u, 0x9216d5d9u, 0x8979fb1bu
 };
 
-static uint32_t sbx[4][256];
-static uint32_t sbi[4][256] = {
+static UINT32_T sbx[4][256];
+static UINT32_T sbi[4][256] = {
    {0xd1310ba6u, 0x98dfb5acu, 0x2ffd72dbu, 0xd01adfb7u,
     0xb8e1afedu, 0x6a267e96u, 0xba7c9045u, 0xf12c7f99u,
     0x24a19947u, 0xb3916cf7u, 0x0801f2e2u, 0x858efc16u,
@@ -331,10 +331,10 @@ static uint32_t sbi[4][256] = {
 
     static void
 bf_e_block(p_xl, p_xr)
-    uint32_t *p_xl;
-    uint32_t *p_xr;
+    UINT32_T *p_xl;
+    UINT32_T *p_xr;
 {
-    uint32_t temp, xl = *p_xl, xr = *p_xr;
+    UINT32_T temp, xl = *p_xl, xr = *p_xr;
 
     F1(0) F2(1) F1(2) F2(3) F1(4) F2(5) F1(6) F2(7)
     F1(8) F2(9) F1(10) F2(11) F1(12) F2(13) F1(14) F2(15)
@@ -346,10 +346,10 @@ bf_e_block(p_xl, p_xr)
 #if 0  /* not used */
     static void
 bf_d_block(p_xl, p_xr)
-    uint32_t *p_xl;
-    uint32_t *p_xr;
+    UINT32_T *p_xl;
+    UINT32_T *p_xr;
 {
-    uint32_t temp, xl = *p_xl, xr = *p_xr;
+    UINT32_T temp, xl = *p_xl, xr = *p_xr;
     F1(17) F2(16) F1(15) F2(14) F1(13) F2(12) F1(11) F2(10)
     F1(9) F2(8) F1(7) F2(6) F1(5) F2(4) F1(3) F2(2)
     xl ^= pax[1];
@@ -401,7 +401,7 @@ bf_key_init(password)
     char_u *password;
 {
     int      i, j, keypos = 0;
-    uint32_t val, data_l, data_r;
+    UINT32_T val, data_l, data_r;
     char_u   *key;
     int      keylen;
 
@@ -447,12 +447,12 @@ bf_key_init(password)
  */
     static int
 bf_check_tables(ipa, sbi, val)
-    uint32_t ipa[18];
-    uint32_t sbi[4][256];
-    uint32_t val;
+    UINT32_T ipa[18];
+    UINT32_T sbi[4][256];
+    UINT32_T val;
 {
     int i, j;
-    uint32_t c = 0;
+    UINT32_T c = 0;
 
     for (i = 0; i < 18; i++)
 	c ^= ipa[i];
@@ -467,7 +467,7 @@ typedef struct {
     char_u   plaintxt[8];
     char_u   cryptxt[8];
     char_u   badcryptxt[8]; /* cryptxt when big/little endian is wrong */
-    uint32_t keysum;
+    UINT32_T keysum;
 } struct_bf_test_data;
 
 /*
@@ -493,6 +493,14 @@ bf_self_test()
     int    i, bn;
     int    err = 0;
     block8 bk;
+    UINT32_T ui = 0xffffffffUL;
+
+    /* We can't simply use sizeof(UINT32_T), it would generate a compiler
+     * warning. */
+    if (ui != 0xffffffffUL || ui + 1 != 0) {
+	err++;
+	EMSG(_("E820: sizeof(uint32_t) != 4"));
+    }
 
     if (!bf_check_tables(ipa, sbi, 0x6ffa520a))
 	err++;