2
0

Slight clean-up of types, includes and warnings.

This commit is contained in:
Maarten Billemont 2017-08-30 09:39:35 -04:00
parent 91828cbad7
commit 23af56c150
10 changed files with 93 additions and 145 deletions

View File

@ -22,7 +22,7 @@
#ifndef _MPW_ALGORITHM_H #ifndef _MPW_ALGORITHM_H
#define _MPW_ALGORITHM_H #define _MPW_ALGORITHM_H
typedef enum( unsigned int, MPAlgorithmVersion ) { typedef mpw_enum( unsigned int, MPAlgorithmVersion ) {
/** V0 did math with chars whose signedness was platform-dependent. */ /** V0 did math with chars whose signedness was platform-dependent. */
MPAlgorithmVersion0, MPAlgorithmVersion0,
/** V1 miscounted the byte-length of multi-byte site names. */ /** V1 miscounted the byte-length of multi-byte site names. */

View File

@ -82,8 +82,8 @@ static MPMasterKey mpw_masterKey_v0(
} }
static MPSiteKey mpw_siteKey_v0( static MPSiteKey mpw_siteKey_v0(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext) { MPKeyPurpose keyPurpose, const char *keyContext) {
const char *keyScope = mpw_scopeForPurpose( keyPurpose ); const char *keyScope = mpw_scopeForPurpose( keyPurpose );
trc( "keyScope: %s\n", keyScope ); trc( "keyScope: %s\n", keyScope );
@ -126,7 +126,7 @@ static MPSiteKey mpw_siteKey_v0(
} }
static const char *mpw_sitePasswordFromTemplate_v0( static const char *mpw_sitePasswordFromTemplate_v0(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam) { MPMasterKey __unused masterKey, MPSiteKey siteKey, MPResultType resultType, const char __unused *resultParam) {
// Determine the template. // Determine the template.
const char *_siteKey = (const char *)siteKey; const char *_siteKey = (const char *)siteKey;
@ -155,7 +155,7 @@ static const char *mpw_sitePasswordFromTemplate_v0(
} }
static const char *mpw_sitePasswordFromCrypt_v0( static const char *mpw_sitePasswordFromCrypt_v0(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *cipherText) { MPMasterKey masterKey, MPSiteKey __unused siteKey, MPResultType __unused resultType, const char *cipherText) {
if (!cipherText) { if (!cipherText) {
err( "Missing encrypted state.\n" ); err( "Missing encrypted state.\n" );
@ -185,7 +185,7 @@ static const char *mpw_sitePasswordFromCrypt_v0(
} }
static const char *mpw_sitePasswordFromDerive_v0( static const char *mpw_sitePasswordFromDerive_v0(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam) { MPMasterKey __unused masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
switch (resultType) { switch (resultType) {
case MPResultTypeDeriveKey: { case MPResultTypeDeriveKey: {
@ -228,7 +228,7 @@ static const char *mpw_sitePasswordFromDerive_v0(
} }
static const char *mpw_siteState_v0( static const char *mpw_siteState_v0(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *plainText) { MPMasterKey masterKey, MPSiteKey __unused siteKey, MPResultType __unused resultType, const char *plainText) {
// Encrypt // Encrypt
size_t bufSize = strlen( plainText ); size_t bufSize = strlen( plainText );

View File

@ -28,14 +28,14 @@
MPMasterKey mpw_masterKey_v0( MPMasterKey mpw_masterKey_v0(
const char *fullName, const char *masterPassword); const char *fullName, const char *masterPassword);
MPSiteKey mpw_siteKey_v0( MPSiteKey mpw_siteKey_v0(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext); MPKeyPurpose keyPurpose, const char *keyContext);
const char *mpw_sitePasswordFromCrypt_v0( const char *mpw_sitePasswordFromCrypt_v0(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *cipherText); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_sitePasswordFromDerive_v0( const char *mpw_sitePasswordFromDerive_v0(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_siteState_v0( const char *mpw_siteState_v0(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *state); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state);
// Algorithm version overrides. // Algorithm version overrides.
static MPMasterKey mpw_masterKey_v1( static MPMasterKey mpw_masterKey_v1(
@ -45,14 +45,14 @@ static MPMasterKey mpw_masterKey_v1(
} }
static MPSiteKey mpw_siteKey_v1( static MPSiteKey mpw_siteKey_v1(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext) { MPKeyPurpose keyPurpose, const char *keyContext) {
return mpw_siteKey_v0( masterKey, siteName, siteCounter, keyPurpose, keyContext ); return mpw_siteKey_v0( masterKey, siteName, siteCounter, keyPurpose, keyContext );
} }
static const char *mpw_sitePasswordFromTemplate_v1( static const char *mpw_sitePasswordFromTemplate_v1(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam) { MPMasterKey __unused masterKey, MPSiteKey siteKey, MPResultType resultType, const char __unused *resultParam) {
// Determine the template. // Determine the template.
const char *template = mpw_templateForType( resultType, siteKey[0] ); const char *template = mpw_templateForType( resultType, siteKey[0] );
@ -77,19 +77,19 @@ static const char *mpw_sitePasswordFromTemplate_v1(
} }
static const char *mpw_sitePasswordFromCrypt_v1( static const char *mpw_sitePasswordFromCrypt_v1(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *cipherText) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
return mpw_sitePasswordFromCrypt_v0( masterKey, siteKey, resultType, cipherText ); return mpw_sitePasswordFromCrypt_v0( masterKey, siteKey, resultType, cipherText );
} }
static const char *mpw_sitePasswordFromDerive_v1( static const char *mpw_sitePasswordFromDerive_v1(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_sitePasswordFromDerive_v0( masterKey, siteKey, resultType, resultParam ); return mpw_sitePasswordFromDerive_v0( masterKey, siteKey, resultType, resultParam );
} }
static const char *mpw_siteState_v1( static const char *mpw_siteState_v1(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *state) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) {
return mpw_siteState_v0( masterKey, siteKey, resultType, state ); return mpw_siteState_v0( masterKey, siteKey, resultType, state );
} }

View File

@ -29,13 +29,13 @@
MPMasterKey mpw_masterKey_v1( MPMasterKey mpw_masterKey_v1(
const char *fullName, const char *masterPassword); const char *fullName, const char *masterPassword);
const char *mpw_sitePasswordFromTemplate_v1( const char *mpw_sitePasswordFromTemplate_v1(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_sitePasswordFromCrypt_v1( const char *mpw_sitePasswordFromCrypt_v1(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *cipherText); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_sitePasswordFromDerive_v1( const char *mpw_sitePasswordFromDerive_v1(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_siteState_v1( const char *mpw_siteState_v1(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *state); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state);
// Algorithm version overrides. // Algorithm version overrides.
static MPMasterKey mpw_masterKey_v2( static MPMasterKey mpw_masterKey_v2(
@ -45,8 +45,8 @@ static MPMasterKey mpw_masterKey_v2(
} }
static MPSiteKey mpw_siteKey_v2( static MPSiteKey mpw_siteKey_v2(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext) { MPKeyPurpose keyPurpose, const char *keyContext) {
const char *keyScope = mpw_scopeForPurpose( keyPurpose ); const char *keyScope = mpw_scopeForPurpose( keyPurpose );
trc( "keyScope: %s\n", keyScope ); trc( "keyScope: %s\n", keyScope );
@ -87,25 +87,25 @@ static MPSiteKey mpw_siteKey_v2(
} }
static const char *mpw_sitePasswordFromTemplate_v2( static const char *mpw_sitePasswordFromTemplate_v2(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_sitePasswordFromTemplate_v1( masterKey, siteKey, resultType, resultParam ); return mpw_sitePasswordFromTemplate_v1( masterKey, siteKey, resultType, resultParam );
} }
static const char *mpw_sitePasswordFromCrypt_v2( static const char *mpw_sitePasswordFromCrypt_v2(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *cipherText) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
return mpw_sitePasswordFromCrypt_v1( masterKey, siteKey, resultType, cipherText ); return mpw_sitePasswordFromCrypt_v1( masterKey, siteKey, resultType, cipherText );
} }
static const char *mpw_sitePasswordFromDerive_v2( static const char *mpw_sitePasswordFromDerive_v2(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_sitePasswordFromDerive_v1( masterKey, siteKey, resultType, resultParam ); return mpw_sitePasswordFromDerive_v1( masterKey, siteKey, resultType, resultParam );
} }
static const char *mpw_siteState_v2( static const char *mpw_siteState_v2(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *state) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) {
return mpw_siteState_v1( masterKey, siteKey, resultType, state ); return mpw_siteState_v1( masterKey, siteKey, resultType, state );
} }

View File

@ -27,16 +27,16 @@
// Inherited functions. // Inherited functions.
MPSiteKey mpw_siteKey_v2( MPSiteKey mpw_siteKey_v2(
MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext); MPKeyPurpose keyPurpose, const char *keyContext);
const char *mpw_sitePasswordFromTemplate_v2( const char *mpw_sitePasswordFromTemplate_v2(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_sitePasswordFromCrypt_v2( const char *mpw_sitePasswordFromCrypt_v2(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *cipherText); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText);
const char *mpw_sitePasswordFromDerive_v2( const char *mpw_sitePasswordFromDerive_v2(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam);
const char *mpw_siteState_v2( const char *mpw_siteState_v2(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *state); MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state);
// Algorithm version overrides. // Algorithm version overrides.
static MPMasterKey mpw_masterKey_v3( static MPMasterKey mpw_masterKey_v3(
@ -73,32 +73,32 @@ static MPMasterKey mpw_masterKey_v3(
} }
static MPSiteKey mpw_siteKey_v3( static MPSiteKey mpw_siteKey_v3(
const MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter,
const MPKeyPurpose keyPurpose, const char *keyContext) { MPKeyPurpose keyPurpose, const char *keyContext) {
return mpw_siteKey_v2( masterKey, siteName, siteCounter, keyPurpose, keyContext ); return mpw_siteKey_v2( masterKey, siteName, siteCounter, keyPurpose, keyContext );
} }
static const char *mpw_sitePasswordFromTemplate_v3( static const char *mpw_sitePasswordFromTemplate_v3(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_sitePasswordFromTemplate_v2( masterKey, siteKey, resultType, resultParam ); return mpw_sitePasswordFromTemplate_v2( masterKey, siteKey, resultType, resultParam );
} }
static const char *mpw_sitePasswordFromCrypt_v3( static const char *mpw_sitePasswordFromCrypt_v3(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *cipherText) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText) {
return mpw_sitePasswordFromCrypt_v2( masterKey, siteKey, resultType, cipherText ); return mpw_sitePasswordFromCrypt_v2( masterKey, siteKey, resultType, cipherText );
} }
static const char *mpw_sitePasswordFromDerive_v3( static const char *mpw_sitePasswordFromDerive_v3(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam) {
return mpw_sitePasswordFromDerive_v2( masterKey, siteKey, resultType, resultParam ); return mpw_sitePasswordFromDerive_v2( masterKey, siteKey, resultType, resultParam );
} }
static const char *mpw_siteState_v3( static const char *mpw_siteState_v3(
MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *state) { MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state) {
return mpw_siteState_v2( masterKey, siteKey, resultType, state ); return mpw_siteState_v2( masterKey, siteKey, resultType, state );
} }

View File

@ -25,7 +25,7 @@
//// Types. //// Types.
typedef enum( unsigned int, MPMarshallFormat ) { typedef mpw_enum( unsigned int, MPMarshallFormat ) {
/** Generate a key for authentication. */ /** Generate a key for authentication. */
MPMarshallFormatNone, MPMarshallFormatNone,
/** Generate a key for authentication. */ /** Generate a key for authentication. */
@ -36,7 +36,7 @@ typedef enum( unsigned int, MPMarshallFormat ) {
MPMarshallFormatDefault = MPMarshallFormatJSON, MPMarshallFormatDefault = MPMarshallFormatJSON,
}; };
typedef enum( unsigned int, MPMarshallErrorType ) { typedef mpw_enum( unsigned int, MPMarshallErrorType ) {
/** The marshalling operation completed successfully. */ /** The marshalling operation completed successfully. */
MPMarshallSuccess, MPMarshallSuccess,
/** An error in the structure of the marshall file interrupted marshalling. */ /** An error in the structure of the marshall file interrupted marshalling. */

View File

@ -16,16 +16,9 @@
// LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>. // LICENSE file. Alternatively, see <http://www.gnu.org/licenses/>.
//============================================================================== //==============================================================================
#include <stdlib.h>
#include <stdio.h>
#include <string.h> #include <string.h>
#include <ctype.h> #include <ctype.h>
#ifdef COLOR
#include <curses.h>
#include <term.h>
#endif
#include "mpw-types.h" #include "mpw-types.h"
#include "mpw-util.h" #include "mpw-util.h"

View File

@ -24,9 +24,9 @@
#include <stdbool.h> #include <stdbool.h>
#ifdef NS_ENUM #ifdef NS_ENUM
#define enum(_type, _name) NS_ENUM(_type, _name) #define mpw_enum(_type, _name) NS_ENUM(_type, _name)
#else #else
#define enum(_type, _name) _type _name; enum #define mpw_enum(_type, _name) _type _name; enum
#endif #endif
//// Types. //// Types.
@ -37,7 +37,7 @@ typedef const uint8_t *MPMasterKey;
typedef const uint8_t *MPSiteKey; typedef const uint8_t *MPSiteKey;
typedef const char *MPKeyID; typedef const char *MPKeyID;
typedef enum( uint8_t, MPKeyPurpose ) { typedef mpw_enum( uint8_t, MPKeyPurpose ) {
/** Generate a key for authentication. */ /** Generate a key for authentication. */
MPKeyPurposeAuthentication, MPKeyPurposeAuthentication,
/** Generate a name for identification. */ /** Generate a name for identification. */
@ -47,7 +47,7 @@ typedef enum( uint8_t, MPKeyPurpose ) {
}; };
// bit 4 - 9 // bit 4 - 9
typedef enum( uint16_t, MPResultTypeClass ) { typedef mpw_enum( uint16_t, MPResultTypeClass ) {
/** Use the site key to generate a password from a template. */ /** Use the site key to generate a password from a template. */
MPResultTypeClassTemplate = 1 << 4, MPResultTypeClassTemplate = 1 << 4,
/** Use the site key to encrypt and decrypt a stateful entity. */ /** Use the site key to encrypt and decrypt a stateful entity. */
@ -57,7 +57,7 @@ typedef enum( uint16_t, MPResultTypeClass ) {
}; };
// bit 10 - 15 // bit 10 - 15
typedef enum( uint16_t, MPSiteFeature ) { typedef mpw_enum( uint16_t, MPSiteFeature ) {
/** Export the key-protected content data. */ /** Export the key-protected content data. */
MPSiteFeatureExportContent = 1 << 10, MPSiteFeatureExportContent = 1 << 10,
/** Never export content. */ /** Never export content. */
@ -67,7 +67,7 @@ typedef enum( uint16_t, MPSiteFeature ) {
}; };
// bit 0-3 | MPResultTypeClass | MPSiteFeature // bit 0-3 | MPResultTypeClass | MPSiteFeature
typedef enum( uint32_t, MPResultType ) { typedef mpw_enum( uint32_t, MPResultType ) {
/** pg^VMAUBk5x3p%HP%i4= */ /** pg^VMAUBk5x3p%HP%i4= */
MPResultTypeTemplateMaximum = 0x0 | MPResultTypeClassTemplate | 0x0, MPResultTypeTemplateMaximum = 0x0 | MPResultTypeClassTemplate | 0x0,
/** BiroYena8:Kixa */ /** BiroYena8:Kixa */
@ -96,7 +96,7 @@ typedef enum( uint32_t, MPResultType ) {
MPResultTypeDefault = MPResultTypeTemplateLong, MPResultTypeDefault = MPResultTypeTemplateLong,
}; };
typedef enum ( uint32_t, MPCounterValue ) { typedef mpw_enum ( uint32_t, MPCounterValue ) {
/** Use a time-based counter value, resulting in a TOTP generator. */ /** Use a time-based counter value, resulting in a TOTP generator. */
MPCounterValueTOTP = 0, MPCounterValueTOTP = 0,
/** The initial value for a site's counter. */ /** The initial value for a site's counter. */

View File

@ -56,8 +56,8 @@
#define BCRYPT_SALTSPACE (7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1) #define BCRYPT_SALTSPACE (7 + (BCRYPT_MAXSALT * 4 + 2) / 3 + 1)
#define BCRYPT_HASHSPACE 61 #define BCRYPT_HASHSPACE 61
static int encode_base64(char *, const u_int8_t *, size_t); static int encode_base64(char *, const uint8_t *, size_t);
static int decode_base64(u_int8_t *, size_t, const char *); static int decode_base64(uint8_t *, size_t, const char *);
/* /*
* Generates a salt for this version of crypt. * 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) { size_t encryptedlen) {
blf_ctx state; blf_ctx state;
u_int32_t rounds, i, k; uint32_t rounds, i, k;
u_int16_t j; uint16_t j;
size_t key_len; size_t key_len;
u_int8_t salt_len, logr, minor; uint8_t salt_len, logr, minor;
u_int8_t ciphertext[4 * BCRYPT_WORDS] = "OrpheanBeholderScryDoubt"; uint8_t ciphertext[4 * BCRYPT_WORDS] = "OrpheanBeholderScryDoubt";
u_int8_t csalt[BCRYPT_MAXSALT]; uint8_t csalt[BCRYPT_MAXSALT];
u_int32_t cdata[BCRYPT_WORDS]; uint32_t cdata[BCRYPT_WORDS];
if (encryptedlen < BCRYPT_HASHSPACE) if (encryptedlen < BCRYPT_HASHSPACE)
goto inval; goto inval;
@ -115,7 +115,7 @@ bcrypt_hashpass(const char *key, const uint8_t *salt, char *encrypted,
/* Check for minor versions */ /* Check for minor versions */
switch ((minor = salt[1])) { switch ((minor = salt[1])) {
case 'a': case 'a':
key_len = (u_int8_t)(strlen( key ) + 1); key_len = (uint8_t)(strlen( key ) + 1);
break; break;
case 'b': case 'b':
/* strlen() returns a size_t, but the function calls /* 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] ) || if (!isdigit( (unsigned char)salt[0] ) ||
!isdigit( (unsigned char)salt[1] ) || salt[2] != '$') !isdigit( (unsigned char)salt[1] ) || salt[2] != '$')
goto inval; 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) if (logr < BCRYPT_MINLOGROUNDS || logr > 31)
goto inval; goto inval;
/* Computer power doesn't increase linearly, 2^x should be fine */ /* 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 */ /* Setting up S-Boxes and Subkeys */
Blowfish_initstate( &state ); Blowfish_initstate( &state );
Blowfish_expandstate( &state, csalt, salt_len, 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++) { 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 ); 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 ); blf_enc( &state, cdata, BCRYPT_WORDS / 2 );
for (i = 0; i < BCRYPT_WORDS; i++) { 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; 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; 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; 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 ); 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; return 0;
} }
static int static int __unused
bcrypt_checkpass(const char *pass, const char *goodhash) { bcrypt_checkpass(const char *pass, const char *goodhash) {
char hash[BCRYPT_HASHSPACE]; 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. * 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. * We are aiming for something that takes around 0.1s, but not too much over.
*/ */
static int static int __unused
_bcrypt_autorounds(void) { _bcrypt_autorounds(void) {
struct timespec before, after; struct timespec before, after;
@ -270,10 +270,10 @@ _bcrypt_autorounds(void) {
/* /*
* internal utilities * internal utilities
*/ */
static const u_int8_t Base64Code[] = static const uint8_t Base64Code[] =
"./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; "./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, 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, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 255, 255, 255, 255, 255 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 * read buflen (after decoding) bytes of data from b64data
*/ */
static int 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; uint8_t *bp = buffer;
const u_int8_t *p = (u_int8_t *)b64data; const uint8_t *p = (uint8_t *)b64data;
u_int8_t c1, c2, c3, c4; uint8_t c1, c2, c3, c4;
while (bp < buffer + len) { while (bp < buffer + len) {
c1 = CHAR64( *p ); c1 = CHAR64( *p );
@ -310,7 +310,7 @@ decode_base64(u_int8_t *buffer, size_t len, const char *b64data) {
if (c2 == 255) if (c2 == 255)
return -1; return -1;
*bp++ = (u_int8_t)((c1 << 2) | ((c2 & 0x30) >> 4)); *bp++ = (uint8_t)((c1 << 2) | ((c2 & 0x30) >> 4));
if (bp >= buffer + len) if (bp >= buffer + len)
break; break;
@ -318,14 +318,14 @@ decode_base64(u_int8_t *buffer, size_t len, const char *b64data) {
if (c3 == 255) if (c3 == 255)
return -1; 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) if (bp >= buffer + len)
break; break;
c4 = CHAR64( *(p + 3) ); c4 = CHAR64( *(p + 3) );
if (c4 == 255) if (c4 == 255)
return -1; return -1;
*bp++ = (u_int8_t)(((c3 & 0x03) << 6) | c4); *bp++ = (uint8_t)(((c3 & 0x03) << 6) | c4);
p += 4; p += 4;
} }
@ -337,16 +337,16 @@ decode_base64(u_int8_t *buffer, size_t len, const char *b64data) {
* This works without = padding. * This works without = padding.
*/ */
static int 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; uint8_t *bp = (uint8_t *)b64buffer;
const u_int8_t *p = data; const uint8_t *p = data;
u_int8_t c1, c2; uint8_t c1, c2;
while (p < data + len) { while (p < data + len) {
c1 = *p++; c1 = *p++;
*bp++ = Base64Code[(c1 >> 2)]; *bp++ = Base64Code[(c1 >> 2)];
c1 = (u_int8_t)((c1 & 0x03) << 4); c1 = (uint8_t)((c1 & 0x03) << 4);
if (p >= data + len) { if (p >= data + len) {
*bp++ = Base64Code[c1]; *bp++ = Base64Code[c1];
break; break;
@ -354,7 +354,7 @@ encode_base64(char *b64buffer, const u_int8_t *data, size_t len) {
c2 = *p++; c2 = *p++;
c1 |= (c2 >> 4) & 0x0f; c1 |= (c2 >> 4) & 0x0f;
*bp++ = Base64Code[c1]; *bp++ = Base64Code[c1];
c1 = (u_int8_t)((c2 & 0x0f) << 2); c1 = (uint8_t)((c2 & 0x0f) << 2);
if (p >= data + len) { if (p >= data + len) {
*bp++ = Base64Code[c1]; *bp++ = Base64Code[c1];
break; break;
@ -371,10 +371,10 @@ encode_base64(char *b64buffer, const u_int8_t *data, size_t len) {
/* /*
* classic interface * classic interface
*/ */
static u_int8_t * static uint8_t *
bcrypt_gensalt(u_int8_t log_rounds) { 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 ) ); bcrypt_initsalt( log_rounds, gsalt, sizeof( gsalt ) );
@ -382,7 +382,7 @@ bcrypt_gensalt(u_int8_t log_rounds) {
} }
static char * static char *
bcrypt(const char *pass, const u_int8_t *salt) { bcrypt(const char *pass, const uint8_t *salt) {
static char gencrypted[BCRYPT_HASHSPACE]; static char gencrypted[BCRYPT_HASHSPACE];

View File

@ -494,7 +494,7 @@ Blowfish_expandstate(blf_ctx *c, const u_int8_t *data, u_int16_t databytes,
} }
void 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 */ /* Initialize S-boxes and subkeys with Pi */
Blowfish_initstate(c); Blowfish_initstate(c);
@ -517,7 +517,7 @@ blf_enc(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
} }
void 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_int32_t *d;
u_int16_t i; u_int16_t i;
@ -530,13 +530,12 @@ blf_dec(blf_ctx *c, u_int32_t *data, u_int16_t blocks)
} }
void 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 l, r;
u_int32_t i; u_int32_t i;
for (i = 0; i < len; i += 8) { 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]; 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]; 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); Blowfish_encipher(c, &l, &r);
@ -553,7 +552,7 @@ blf_ecb_encrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
} }
void 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 l, r;
u_int32_t i; u_int32_t i;
@ -575,7 +574,7 @@ blf_ecb_decrypt(blf_ctx *c, u_int8_t *data, u_int32_t len)
} }
void 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 l, r;
u_int32_t i, j; 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 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_int32_t l, r;
u_int8_t *iv; 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++) for (j = 0; j < 8; j++)
data[j] ^= iva[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