Skip to content

Commit 59b4fdb

Browse files
authored
Use standard C99 uint8_t type instead of u_char type for crypt_freesec (#8610)
1 parent 08d1593 commit 59b4fdb

File tree

2 files changed

+37
-43
lines changed

2 files changed

+37
-43
lines changed

ext/standard/crypt_freesec.c

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,25 +69,25 @@
6969

7070
#define _PASSWORD_EFMT1 '_'
7171

72-
static const u_char IP[64] = {
72+
static const uint8_t IP[64] = {
7373
58, 50, 42, 34, 26, 18, 10, 2, 60, 52, 44, 36, 28, 20, 12, 4,
7474
62, 54, 46, 38, 30, 22, 14, 6, 64, 56, 48, 40, 32, 24, 16, 8,
7575
57, 49, 41, 33, 25, 17, 9, 1, 59, 51, 43, 35, 27, 19, 11, 3,
7676
61, 53, 45, 37, 29, 21, 13, 5, 63, 55, 47, 39, 31, 23, 15, 7
7777
};
7878

79-
static const u_char key_perm[56] = {
79+
static const uint8_t key_perm[56] = {
8080
57, 49, 41, 33, 25, 17, 9, 1, 58, 50, 42, 34, 26, 18,
8181
10, 2, 59, 51, 43, 35, 27, 19, 11, 3, 60, 52, 44, 36,
8282
63, 55, 47, 39, 31, 23, 15, 7, 62, 54, 46, 38, 30, 22,
8383
14, 6, 61, 53, 45, 37, 29, 21, 13, 5, 28, 20, 12, 4
8484
};
8585

86-
static const u_char key_shifts[16] = {
86+
static const uint8_t key_shifts[16] = {
8787
1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1
8888
};
8989

90-
static const u_char comp_perm[48] = {
90+
static const uint8_t comp_perm[48] = {
9191
14, 17, 11, 24, 1, 5, 3, 28, 15, 6, 21, 10,
9292
23, 19, 12, 4, 26, 8, 16, 7, 27, 20, 13, 2,
9393
41, 52, 31, 37, 47, 55, 30, 40, 51, 45, 33, 48,
@@ -98,7 +98,7 @@ static const u_char comp_perm[48] = {
9898
* No E box is used, as it's replaced by some ANDs, shifts, and ORs.
9999
*/
100100

101-
static const u_char sbox[8][64] = {
101+
static const uint8_t sbox[8][64] = {
102102
{
103103
14, 4, 13, 1, 2, 15, 11, 8, 3, 10, 6, 12, 5, 9, 0, 7,
104104
0, 15, 7, 4, 14, 2, 13, 1, 10, 6, 12, 11, 9, 5, 3, 8,
@@ -149,7 +149,7 @@ static const u_char sbox[8][64] = {
149149
}
150150
};
151151

152-
static const u_char pbox[32] = {
152+
static const uint8_t pbox[32] = {
153153
16, 7, 20, 21, 29, 12, 28, 17, 1, 15, 23, 26, 5, 18, 31, 10,
154154
2, 8, 24, 14, 32, 27, 3, 9, 19, 13, 30, 6, 22, 11, 4, 25
155155
};
@@ -166,12 +166,12 @@ static const uint32_t bits32[32] =
166166
0x00000008, 0x00000004, 0x00000002, 0x00000001
167167
};
168168

169-
static const u_char bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
169+
static const uint8_t bits8[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 };
170170

171171
static const unsigned char ascii64[] =
172172
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
173173

174-
static u_char m_sbox[4][4096];
174+
static uint8_t m_sbox[4][4096];
175175
static uint32_t psbox[4][256];
176176
static uint32_t ip_maskl[8][256], ip_maskr[8][256];
177177
static uint32_t fp_maskl[8][256], fp_maskr[8][256];
@@ -211,11 +211,11 @@ _crypt_extended_init(void)
211211
int i, j, b, k, inbit, obit;
212212
uint32_t *p, *il, *ir, *fl, *fr;
213213
const uint32_t *bits28, *bits24;
214-
u_char inv_key_perm[64];
215-
u_char inv_comp_perm[56];
216-
u_char init_perm[64], final_perm[64];
217-
u_char u_sbox[8][64];
218-
u_char un_pbox[32];
214+
uint8_t inv_key_perm[64];
215+
uint8_t inv_comp_perm[56];
216+
uint8_t init_perm[64], final_perm[64];
217+
uint8_t u_sbox[8][64];
218+
uint8_t un_pbox[32];
219219

220220
bits24 = (bits28 = bits32 + 4) + 4;
221221

@@ -374,15 +374,15 @@ des_setkey(const char *key, struct php_crypt_extended_data *data)
374374
int shifts, round;
375375

376376
rawkey0 =
377-
(uint32_t)(u_char)key[3] |
378-
((uint32_t)(u_char)key[2] << 8) |
379-
((uint32_t)(u_char)key[1] << 16) |
380-
((uint32_t)(u_char)key[0] << 24);
377+
(uint32_t)(uint8_t)key[3] |
378+
((uint32_t)(uint8_t)key[2] << 8) |
379+
((uint32_t)(uint8_t)key[1] << 16) |
380+
((uint32_t)(uint8_t)key[0] << 24);
381381
rawkey1 =
382-
(uint32_t)(u_char)key[7] |
383-
((uint32_t)(u_char)key[6] << 8) |
384-
((uint32_t)(u_char)key[5] << 16) |
385-
((uint32_t)(u_char)key[4] << 24);
382+
(uint32_t)(uint8_t)key[7] |
383+
((uint32_t)(uint8_t)key[6] << 8) |
384+
((uint32_t)(uint8_t)key[5] << 16) |
385+
((uint32_t)(uint8_t)key[4] << 24);
386386

387387
if ((rawkey0 | rawkey1)
388388
&& rawkey0 == data->old_rawkey0
@@ -580,15 +580,15 @@ des_cipher(const char *in, char *out, uint32_t salt, int count,
580580
setup_salt(salt, data);
581581

582582
rawl =
583-
(uint32_t)(u_char)in[3] |
584-
((uint32_t)(u_char)in[2] << 8) |
585-
((uint32_t)(u_char)in[1] << 16) |
586-
((uint32_t)(u_char)in[0] << 24);
583+
(uint32_t)(uint8_t)in[3] |
584+
((uint32_t)(uint8_t)in[2] << 8) |
585+
((uint32_t)(uint8_t)in[1] << 16) |
586+
((uint32_t)(uint8_t)in[0] << 24);
587587
rawr =
588-
(uint32_t)(u_char)in[7] |
589-
((uint32_t)(u_char)in[6] << 8) |
590-
((uint32_t)(u_char)in[5] << 16) |
591-
((uint32_t)(u_char)in[4] << 24);
588+
(uint32_t)(uint8_t)in[7] |
589+
((uint32_t)(uint8_t)in[6] << 8) |
590+
((uint32_t)(uint8_t)in[5] << 16) |
591+
((uint32_t)(uint8_t)in[4] << 24);
592592

593593
retval = do_des(rawl, rawr, &l_out, &r_out, count, data);
594594

@@ -610,7 +610,7 @@ _crypt_extended_r(const unsigned char *key, const char *setting,
610610
{
611611
int i;
612612
uint32_t count, salt, l, r0, r1, keybuf[2];
613-
u_char *p, *q;
613+
uint8_t *p, *q;
614614

615615
if (!data->initialized)
616616
des_init_local(data);
@@ -619,8 +619,8 @@ _crypt_extended_r(const unsigned char *key, const char *setting,
619619
* Copy the key, shifting each character up by one bit
620620
* and padding with zeros.
621621
*/
622-
q = (u_char *) keybuf;
623-
while ((size_t)(q - (u_char *) keybuf) < sizeof(keybuf)) {
622+
q = (uint8_t *) keybuf;
623+
while ((size_t)(q - (uint8_t *) keybuf) < sizeof(keybuf)) {
624624
*q++ = *key << 1;
625625
if (*key)
626626
key++;
@@ -660,16 +660,16 @@ _crypt_extended_r(const unsigned char *key, const char *setting,
660660
/*
661661
* And XOR with the next 8 characters of the key.
662662
*/
663-
q = (u_char *) keybuf;
664-
while ((size_t)(q - (u_char *) keybuf) < sizeof(keybuf) && *key)
663+
q = (uint8_t *) keybuf;
664+
while ((size_t)(q - (uint8_t *) keybuf) < sizeof(keybuf) && *key)
665665
*q++ ^= *key++ << 1;
666666

667667
if (des_setkey((char *) keybuf, data))
668668
return(NULL);
669669
}
670670
memcpy(data->output, setting, 9);
671671
data->output[9] = '\0';
672-
p = (u_char *) data->output + 9;
672+
p = (uint8_t *) data->output + 9;
673673
} else {
674674
/*
675675
* "old"-style:
@@ -686,7 +686,7 @@ _crypt_extended_r(const unsigned char *key, const char *setting,
686686

687687
data->output[0] = setting[0];
688688
data->output[1] = setting[1];
689-
p = (u_char *) data->output + 2;
689+
p = (uint8_t *) data->output + 2;
690690
}
691691
setup_salt(salt, data);
692692
/*

ext/standard/crypt_freesec.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
#ifndef _CRYPT_FREESEC_H
22
#define _CRYPT_FREESEC_H
33

4-
#ifdef PHP_WIN32
5-
# ifndef inline
6-
# define inline __inline
7-
# endif
8-
#endif
9-
10-
#include "php_stdint.h"
4+
#include <stdint.h>
115

126
#define MD5_HASH_MAX_LEN 120
137

0 commit comments

Comments
 (0)