Slight clean-up of types, includes and warnings.
This commit is contained in:
@@ -56,8 +56,8 @@
|
||||
#define BCRYPT_SALTSPACE (7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1)
|
||||
#define BCRYPT_HASHSPACE 61
|
||||
|
||||
static int encode_base64(char *, const u_int8_t *, size_t);
|
||||
static int decode_base64(u_int8_t *, size_t, const char *);
|
||||
static int encode_base64(char *, const uint8_t *, size_t);
|
||||
static int decode_base64(uint8_t *, size_t, const char *);
|
||||
|
||||
/*
|
||||
* Generates a salt for this version of crypt.
|
||||
@@ -93,13 +93,13 @@ bcrypt_hashpass(const char *key, const uint8_t *salt, char *encrypted,
|
||||
size_t encryptedlen) {
|
||||
|
||||
blf_ctx state;
|
||||
u_int32_t rounds, i, k;
|
||||
u_int16_t j;
|
||||
uint32_t rounds, i, k;
|
||||
uint16_t j;
|
||||
size_t key_len;
|
||||
u_int8_t salt_len, logr, minor;
|
||||
u_int8_t ciphertext[4 * BCRYPT_WORDS] = "OrpheanBeholderScryDoubt";
|
||||
u_int8_t csalt[BCRYPT_MAXSALT];
|
||||
u_int32_t cdata[BCRYPT_WORDS];
|
||||
uint8_t salt_len, logr, minor;
|
||||
uint8_t ciphertext[4 * BCRYPT_WORDS] = "OrpheanBeholderScryDoubt";
|
||||
uint8_t csalt[BCRYPT_MAXSALT];
|
||||
uint32_t cdata[BCRYPT_WORDS];
|
||||
|
||||
if (encryptedlen < BCRYPT_HASHSPACE)
|
||||
goto inval;
|
||||
@@ -115,7 +115,7 @@ bcrypt_hashpass(const char *key, const uint8_t *salt, char *encrypted,
|
||||
/* Check for minor versions */
|
||||
switch ((minor = salt[1])) {
|
||||
case 'a':
|
||||
key_len = (u_int8_t)(strlen( key ) + 1);
|
||||
key_len = (uint8_t)(strlen( key ) + 1);
|
||||
break;
|
||||
case 'b':
|
||||
/* strlen() returns a size_t, but the function calls
|
||||
@@ -139,7 +139,7 @@ bcrypt_hashpass(const char *key, const uint8_t *salt, char *encrypted,
|
||||
if (!isdigit( (unsigned char)salt[0] ) ||
|
||||
!isdigit( (unsigned char)salt[1] ) || salt[2] != '$')
|
||||
goto inval;
|
||||
logr = (salt[1] - '0') + ((salt[0] - '0') * 10);
|
||||
logr = (uint8_t)((salt[1] - '0') + ((salt[0] - '0') * 10));
|
||||
if (logr < BCRYPT_MINLOGROUNDS || logr > 31)
|
||||
goto inval;
|
||||
/* Computer power doesn't increase linearly, 2^x should be fine */
|
||||
@@ -159,9 +159,9 @@ bcrypt_hashpass(const char *key, const uint8_t *salt, char *encrypted,
|
||||
/* Setting up S-Boxes and Subkeys */
|
||||
Blowfish_initstate( &state );
|
||||
Blowfish_expandstate( &state, csalt, salt_len,
|
||||
(u_int8_t *)key, (u_int16_t)key_len );
|
||||
(uint8_t *)key, (uint16_t)key_len );
|
||||
for (k = 0; k < rounds; k++) {
|
||||
Blowfish_expand0state( &state, (u_int8_t *)key, (u_int16_t)key_len );
|
||||
Blowfish_expand0state( &state, (uint8_t *)key, (uint16_t)key_len );
|
||||
Blowfish_expand0state( &state, csalt, salt_len );
|
||||
}
|
||||
|
||||
@@ -175,13 +175,13 @@ bcrypt_hashpass(const char *key, const uint8_t *salt, char *encrypted,
|
||||
blf_enc( &state, cdata, BCRYPT_WORDS / 2 );
|
||||
|
||||
for (i = 0; i < BCRYPT_WORDS; i++) {
|
||||
ciphertext[4 * i + 3] = cdata[i] & 0xff;
|
||||
ciphertext[4 * i + 3] = (uint8_t)(cdata[i] & 0xff);
|
||||
cdata[i] = cdata[i] >> 8;
|
||||
ciphertext[4 * i + 2] = cdata[i] & 0xff;
|
||||
ciphertext[4 * i + 2] = (uint8_t)(cdata[i] & 0xff);
|
||||
cdata[i] = cdata[i] >> 8;
|
||||
ciphertext[4 * i + 1] = cdata[i] & 0xff;
|
||||
ciphertext[4 * i + 1] = (uint8_t)(cdata[i] & 0xff);
|
||||
cdata[i] = cdata[i] >> 8;
|
||||
ciphertext[4 * i + 0] = cdata[i] & 0xff;
|
||||
ciphertext[4 * i + 0] = (uint8_t)(cdata[i] & 0xff);
|
||||
}
|
||||
|
||||
snprintf( encrypted, 8, "$2%c$%2.2u$", minor, logr );
|
||||
@@ -216,7 +216,7 @@ bcrypt_newhash(const char *pass, int log_rounds, char *hash, size_t hashlen) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
static int __unused
|
||||
bcrypt_checkpass(const char *pass, const char *goodhash) {
|
||||
|
||||
char hash[BCRYPT_HASHSPACE];
|
||||
@@ -237,7 +237,7 @@ bcrypt_checkpass(const char *pass, const char *goodhash) {
|
||||
* Measure this system's performance by measuring the time for 8 rounds.
|
||||
* We are aiming for something that takes around 0.1s, but not too much over.
|
||||
*/
|
||||
static int
|
||||
static int __unused
|
||||
_bcrypt_autorounds(void) {
|
||||
|
||||
struct timespec before, after;
|
||||
@@ -270,10 +270,10 @@ _bcrypt_autorounds(void) {
|
||||
/*
|
||||
* internal utilities
|
||||
*/
|
||||
static const u_int8_t Base64Code[] =
|
||||
static const uint8_t Base64Code[] =
|
||||
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
|
||||
static const u_int8_t index_64[128] = {
|
||||
static const uint8_t index_64[128] = {
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
255, 255, 255, 255, 255, 255, 255, 255, 255, 255,
|
||||
@@ -288,17 +288,17 @@ static const u_int8_t index_64[128] = {
|
||||
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
|
||||
51, 52, 53, 255, 255, 255, 255, 255
|
||||
};
|
||||
#define CHAR64(c) ( (c) > 127 ? (u_int8_t)255 : index_64[(c)])
|
||||
#define CHAR64(c) ( (c) > 127 ? (uint8_t)255 : index_64[(c)])
|
||||
|
||||
/*
|
||||
* read buflen (after decoding) bytes of data from b64data
|
||||
*/
|
||||
static int
|
||||
decode_base64(u_int8_t *buffer, size_t len, const char *b64data) {
|
||||
decode_base64(uint8_t *buffer, size_t len, const char *b64data) {
|
||||
|
||||
u_int8_t *bp = buffer;
|
||||
const u_int8_t *p = (u_int8_t *)b64data;
|
||||
u_int8_t c1, c2, c3, c4;
|
||||
uint8_t *bp = buffer;
|
||||
const uint8_t *p = (uint8_t *)b64data;
|
||||
uint8_t c1, c2, c3, c4;
|
||||
|
||||
while (bp < buffer + len) {
|
||||
c1 = CHAR64( *p );
|
||||
@@ -310,7 +310,7 @@ decode_base64(u_int8_t *buffer, size_t len, const char *b64data) {
|
||||
if (c2 == 255)
|
||||
return -1;
|
||||
|
||||
*bp++ = (u_int8_t)((c1 << 2) | ((c2 & 0x30) >> 4));
|
||||
*bp++ = (uint8_t)((c1 << 2) | ((c2 & 0x30) >> 4));
|
||||
if (bp >= buffer + len)
|
||||
break;
|
||||
|
||||
@@ -318,14 +318,14 @@ decode_base64(u_int8_t *buffer, size_t len, const char *b64data) {
|
||||
if (c3 == 255)
|
||||
return -1;
|
||||
|
||||
*bp++ = (u_int8_t)(((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2));
|
||||
*bp++ = (uint8_t)(((c2 & 0x0f) << 4) | ((c3 & 0x3c) >> 2));
|
||||
if (bp >= buffer + len)
|
||||
break;
|
||||
|
||||
c4 = CHAR64( *(p + 3) );
|
||||
if (c4 == 255)
|
||||
return -1;
|
||||
*bp++ = (u_int8_t)(((c3 & 0x03) << 6) | c4);
|
||||
*bp++ = (uint8_t)(((c3 & 0x03) << 6) | c4);
|
||||
|
||||
p += 4;
|
||||
}
|
||||
@@ -337,16 +337,16 @@ decode_base64(u_int8_t *buffer, size_t len, const char *b64data) {
|
||||
* This works without = padding.
|
||||
*/
|
||||
static int
|
||||
encode_base64(char *b64buffer, const u_int8_t *data, size_t len) {
|
||||
encode_base64(char *b64buffer, const uint8_t *data, size_t len) {
|
||||
|
||||
u_int8_t *bp = (u_int8_t *)b64buffer;
|
||||
const u_int8_t *p = data;
|
||||
u_int8_t c1, c2;
|
||||
uint8_t *bp = (uint8_t *)b64buffer;
|
||||
const uint8_t *p = data;
|
||||
uint8_t c1, c2;
|
||||
|
||||
while (p < data + len) {
|
||||
c1 = *p++;
|
||||
*bp++ = Base64Code[(c1 >> 2)];
|
||||
c1 = (u_int8_t)((c1 & 0x03) << 4);
|
||||
c1 = (uint8_t)((c1 & 0x03) << 4);
|
||||
if (p >= data + len) {
|
||||
*bp++ = Base64Code[c1];
|
||||
break;
|
||||
@@ -354,7 +354,7 @@ encode_base64(char *b64buffer, const u_int8_t *data, size_t len) {
|
||||
c2 = *p++;
|
||||
c1 |= (c2 >> 4) & 0x0f;
|
||||
*bp++ = Base64Code[c1];
|
||||
c1 = (u_int8_t)((c2 & 0x0f) << 2);
|
||||
c1 = (uint8_t)((c2 & 0x0f) << 2);
|
||||
if (p >= data + len) {
|
||||
*bp++ = Base64Code[c1];
|
||||
break;
|
||||
@@ -371,10 +371,10 @@ encode_base64(char *b64buffer, const u_int8_t *data, size_t len) {
|
||||
/*
|
||||
* classic interface
|
||||
*/
|
||||
static u_int8_t *
|
||||
bcrypt_gensalt(u_int8_t log_rounds) {
|
||||
static uint8_t *
|
||||
bcrypt_gensalt(uint8_t log_rounds) {
|
||||
|
||||
static u_int8_t gsalt[BCRYPT_SALTSPACE];
|
||||
static uint8_t gsalt[BCRYPT_SALTSPACE];
|
||||
|
||||
bcrypt_initsalt( log_rounds, gsalt, sizeof( gsalt ) );
|
||||
|
||||
@@ -382,7 +382,7 @@ bcrypt_gensalt(u_int8_t log_rounds) {
|
||||
}
|
||||
|
||||
static char *
|
||||
bcrypt(const char *pass, const u_int8_t *salt) {
|
||||
bcrypt(const char *pass, const uint8_t *salt) {
|
||||
|
||||
static char gencrypted[BCRYPT_HASHSPACE];
|
||||
|
||||
|
@@ -494,7 +494,7 @@ Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
|
||||
}
|
||||
|
||||
void
|
||||
blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len)
|
||||
__unused blf_key(blf_ctx *c, const u_int8_t *k, u_int16_t len)
|
||||
{
|
||||
/* Initialize S-boxes and subkeys with Pi */
|
||||
Blowfish_initstate(c);
|
||||
@@ -517,7 +517,7 @@ blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
|
||||
}
|
||||
|
||||
void
|
||||
blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
|
||||
__unused blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
|
||||
{
|
||||
u_int32_t *d;
|
||||
u_int16_t i;
|
||||
@@ -530,13 +530,12 @@ blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
|
||||
}
|
||||
|
||||
void
|
||||
blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
|
||||
__unused blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
|
||||
{
|
||||
u_int32_t l, r;
|
||||
u_int32_t i;
|
||||
|
||||
for (i = 0; i < len; i += 8) {
|
||||
l = (u_int32_t)data[0] << 24 | (u_int32_t)data[1] << 16 | (u_int32_t)data[2] << 8 | (u_int32_t)data[3];
|
||||
l = (u_int32_t)data[0] << 24 | (u_int32_t)data[1] << 16 | (u_int32_t)data[2] << 8 | (u_int32_t)data[3];
|
||||
r = (u_int32_t)data[4] << 24 | (u_int32_t)data[5] << 16 | (u_int32_t)data[6] << 8 | (u_int32_t)data[7];
|
||||
Blowfish_encipher(c, &l, &r);
|
||||
@@ -553,7 +552,7 @@ blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
|
||||
}
|
||||
|
||||
void
|
||||
blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
|
||||
__unused blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
|
||||
{
|
||||
u_int32_t l, r;
|
||||
u_int32_t i;
|
||||
@@ -575,7 +574,7 @@ blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
|
||||
}
|
||||
|
||||
void
|
||||
blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
|
||||
__unused blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
|
||||
{
|
||||
u_int32_t l, r;
|
||||
u_int32_t i, j;
|
||||
@@ -600,7 +599,7 @@ blf_cbc_encrypt(blf_ctx *c, u_int8_t *iv, u_int8_t *data, u_int32_t len)
|
||||
}
|
||||
|
||||
void
|
||||
blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
|
||||
__unused blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
|
||||
{
|
||||
u_int32_t l, r;
|
||||
u_int8_t *iv;
|
||||
@@ -639,47 +638,3 @@ blf_cbc_decrypt(blf_ctx *c, u_int8_t *iva, u_int8_t *data, u_int32_t len)
|
||||
for (j = 0; j < 8; j++)
|
||||
data[j] ^= iva[j];
|
||||
}
|
||||
|
||||
#if 0
|
||||
void
|
||||
report(u_int32_t data[], u_int16_t len)
|
||||
{
|
||||
u_int16_t i;
|
||||
for (i = 0; i < len; i += 2)
|
||||
printf("Block %0hd: %08lx %08lx.\n",
|
||||
i / 2, data[i], data[i + 1]);
|
||||
}
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
|
||||
blf_ctx c;
|
||||
char key[] = "AAAAA";
|
||||
char key2[] = "abcdefghijklmnopqrstuvwxyz";
|
||||
|
||||
u_int32_t data[10];
|
||||
u_int32_t data2[] =
|
||||
{0x424c4f57l, 0x46495348l};
|
||||
|
||||
u_int16_t i;
|
||||
|
||||
/* First test */
|
||||
for (i = 0; i < 10; i++)
|
||||
data[i] = i;
|
||||
|
||||
blf_key(&c, (u_int8_t *) key, 5);
|
||||
blf_enc(&c, data, 5);
|
||||
blf_dec(&c, data, 1);
|
||||
blf_dec(&c, data + 2, 4);
|
||||
printf("Should read as 0 - 9.\n");
|
||||
report(data, 10);
|
||||
|
||||
/* Second test */
|
||||
blf_key(&c, (u_int8_t *) key2, strlen(key2));
|
||||
blf_enc(&c, data2, 1);
|
||||
printf("\nShould read as: 0x324ed0fe 0xf413a203.\n");
|
||||
report(data2, 2);
|
||||
blf_dec(&c, data2, 1);
|
||||
report(data2, 2);
|
||||
}
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user