From 23af56c150405d6334edd4b23545891db175aea1 Mon Sep 17 00:00:00 2001 From: Maarten Billemont Date: Wed, 30 Aug 2017 09:39:35 -0400 Subject: [PATCH] Slight clean-up of types, includes and warnings. --- core/c/mpw-algorithm.h | 2 +- core/c/mpw-algorithm_v0.c | 12 ++-- core/c/mpw-algorithm_v1.c | 22 +++---- core/c/mpw-algorithm_v2.c | 20 +++--- core/c/mpw-algorithm_v3.c | 24 +++---- core/c/mpw-marshall.h | 4 +- core/c/mpw-types.c | 7 --- core/c/mpw-types.h | 14 ++--- platform-independent/cli-c/cli/bcrypt.h | 76 +++++++++++------------ platform-independent/cli-c/cli/blowfish.h | 57 ++--------------- 10 files changed, 93 insertions(+), 145 deletions(-) diff --git a/core/c/mpw-algorithm.h b/core/c/mpw-algorithm.h index 811edcf7..7840c387 100644 --- a/core/c/mpw-algorithm.h +++ b/core/c/mpw-algorithm.h @@ -22,7 +22,7 @@ #ifndef _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. */ MPAlgorithmVersion0, /** V1 miscounted the byte-length of multi-byte site names. */ diff --git a/core/c/mpw-algorithm_v0.c b/core/c/mpw-algorithm_v0.c index 676af24f..8d6e338d 100644 --- a/core/c/mpw-algorithm_v0.c +++ b/core/c/mpw-algorithm_v0.c @@ -82,8 +82,8 @@ static MPMasterKey mpw_masterKey_v0( } static MPSiteKey mpw_siteKey_v0( - MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, - const MPKeyPurpose keyPurpose, const char *keyContext) { + MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, + MPKeyPurpose keyPurpose, const char *keyContext) { const char *keyScope = mpw_scopeForPurpose( keyPurpose ); trc( "keyScope: %s\n", keyScope ); @@ -126,7 +126,7 @@ static MPSiteKey mpw_siteKey_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. const char *_siteKey = (const char *)siteKey; @@ -155,7 +155,7 @@ static const char *mpw_sitePasswordFromTemplate_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) { err( "Missing encrypted state.\n" ); @@ -185,7 +185,7 @@ static const char *mpw_sitePasswordFromCrypt_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) { case MPResultTypeDeriveKey: { @@ -228,7 +228,7 @@ static const char *mpw_sitePasswordFromDerive_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 size_t bufSize = strlen( plainText ); diff --git a/core/c/mpw-algorithm_v1.c b/core/c/mpw-algorithm_v1.c index 265c8de0..2c898f2e 100644 --- a/core/c/mpw-algorithm_v1.c +++ b/core/c/mpw-algorithm_v1.c @@ -28,14 +28,14 @@ MPMasterKey mpw_masterKey_v0( const char *fullName, const char *masterPassword); MPSiteKey mpw_siteKey_v0( - MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, - const MPKeyPurpose keyPurpose, const char *keyContext); + MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, + MPKeyPurpose keyPurpose, const char *keyContext); 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( - MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *resultParam); + MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *resultParam); 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. static MPMasterKey mpw_masterKey_v1( @@ -45,14 +45,14 @@ static MPMasterKey mpw_masterKey_v1( } static MPSiteKey mpw_siteKey_v1( - MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, - const MPKeyPurpose keyPurpose, const char *keyContext) { + MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, + MPKeyPurpose keyPurpose, const char *keyContext) { return mpw_siteKey_v0( masterKey, siteName, siteCounter, keyPurpose, keyContext ); } 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. const char *template = mpw_templateForType( resultType, siteKey[0] ); @@ -77,19 +77,19 @@ static const char *mpw_sitePasswordFromTemplate_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 ); } 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 ); } 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 ); } diff --git a/core/c/mpw-algorithm_v2.c b/core/c/mpw-algorithm_v2.c index 0ae751a8..be466dfa 100644 --- a/core/c/mpw-algorithm_v2.c +++ b/core/c/mpw-algorithm_v2.c @@ -29,13 +29,13 @@ MPMasterKey mpw_masterKey_v1( const char *fullName, const char *masterPassword); 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( - MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *cipherText); + MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText); 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( - MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *state); + MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state); // Algorithm version overrides. static MPMasterKey mpw_masterKey_v2( @@ -45,8 +45,8 @@ static MPMasterKey mpw_masterKey_v2( } static MPSiteKey mpw_siteKey_v2( - MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, - const MPKeyPurpose keyPurpose, const char *keyContext) { + MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, + MPKeyPurpose keyPurpose, const char *keyContext) { const char *keyScope = mpw_scopeForPurpose( keyPurpose ); trc( "keyScope: %s\n", keyScope ); @@ -87,25 +87,25 @@ static MPSiteKey mpw_siteKey_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 ); } 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 ); } 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 ); } 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 ); } diff --git a/core/c/mpw-algorithm_v3.c b/core/c/mpw-algorithm_v3.c index c090f402..e5be8239 100644 --- a/core/c/mpw-algorithm_v3.c +++ b/core/c/mpw-algorithm_v3.c @@ -27,16 +27,16 @@ // Inherited functions. MPSiteKey mpw_siteKey_v2( - MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, - const MPKeyPurpose keyPurpose, const char *keyContext); + MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, + MPKeyPurpose keyPurpose, const char *keyContext); 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( - MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *cipherText); + MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *cipherText); 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( - MPMasterKey masterKey, MPSiteKey siteKey, const MPResultType resultType, const char *state); + MPMasterKey masterKey, MPSiteKey siteKey, MPResultType resultType, const char *state); // Algorithm version overrides. static MPMasterKey mpw_masterKey_v3( @@ -73,32 +73,32 @@ static MPMasterKey mpw_masterKey_v3( } static MPSiteKey mpw_siteKey_v3( - const MPMasterKey masterKey, const char *siteName, const MPCounterValue siteCounter, - const MPKeyPurpose keyPurpose, const char *keyContext) { + MPMasterKey masterKey, const char *siteName, MPCounterValue siteCounter, + MPKeyPurpose keyPurpose, const char *keyContext) { return mpw_siteKey_v2( masterKey, siteName, siteCounter, keyPurpose, keyContext ); } 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 ); } 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 ); } 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 ); } 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 ); } diff --git a/core/c/mpw-marshall.h b/core/c/mpw-marshall.h index 1aaf23e1..6f039c0f 100644 --- a/core/c/mpw-marshall.h +++ b/core/c/mpw-marshall.h @@ -25,7 +25,7 @@ //// Types. -typedef enum( unsigned int, MPMarshallFormat ) { +typedef mpw_enum( unsigned int, MPMarshallFormat ) { /** Generate a key for authentication. */ MPMarshallFormatNone, /** Generate a key for authentication. */ @@ -36,7 +36,7 @@ typedef enum( unsigned int, MPMarshallFormat ) { MPMarshallFormatDefault = MPMarshallFormatJSON, }; -typedef enum( unsigned int, MPMarshallErrorType ) { +typedef mpw_enum( unsigned int, MPMarshallErrorType ) { /** The marshalling operation completed successfully. */ MPMarshallSuccess, /** An error in the structure of the marshall file interrupted marshalling. */ diff --git a/core/c/mpw-types.c b/core/c/mpw-types.c index a6cdc218..5eec4e78 100644 --- a/core/c/mpw-types.c +++ b/core/c/mpw-types.c @@ -16,16 +16,9 @@ // LICENSE file. Alternatively, see . //============================================================================== -#include -#include #include #include -#ifdef COLOR -#include -#include -#endif - #include "mpw-types.h" #include "mpw-util.h" diff --git a/core/c/mpw-types.h b/core/c/mpw-types.h index c19cadad..0318b3a7 100644 --- a/core/c/mpw-types.h +++ b/core/c/mpw-types.h @@ -24,9 +24,9 @@ #include #ifdef NS_ENUM -#define enum(_type, _name) NS_ENUM(_type, _name) +#define mpw_enum(_type, _name) NS_ENUM(_type, _name) #else -#define enum(_type, _name) _type _name; enum +#define mpw_enum(_type, _name) _type _name; enum #endif //// Types. @@ -37,7 +37,7 @@ typedef const uint8_t *MPMasterKey; typedef const uint8_t *MPSiteKey; typedef const char *MPKeyID; -typedef enum( uint8_t, MPKeyPurpose ) { +typedef mpw_enum( uint8_t, MPKeyPurpose ) { /** Generate a key for authentication. */ MPKeyPurposeAuthentication, /** Generate a name for identification. */ @@ -47,7 +47,7 @@ typedef enum( uint8_t, MPKeyPurpose ) { }; // 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. */ MPResultTypeClassTemplate = 1 << 4, /** Use the site key to encrypt and decrypt a stateful entity. */ @@ -57,7 +57,7 @@ typedef enum( uint16_t, MPResultTypeClass ) { }; // bit 10 - 15 -typedef enum( uint16_t, MPSiteFeature ) { +typedef mpw_enum( uint16_t, MPSiteFeature ) { /** Export the key-protected content data. */ MPSiteFeatureExportContent = 1 << 10, /** Never export content. */ @@ -67,7 +67,7 @@ typedef enum( uint16_t, MPSiteFeature ) { }; // bit 0-3 | MPResultTypeClass | MPSiteFeature -typedef enum( uint32_t, MPResultType ) { +typedef mpw_enum( uint32_t, MPResultType ) { /** pg^VMAUBk5x3p%HP%i4= */ MPResultTypeTemplateMaximum = 0x0 | MPResultTypeClassTemplate | 0x0, /** BiroYena8:Kixa */ @@ -96,7 +96,7 @@ typedef enum( uint32_t, MPResultType ) { MPResultTypeDefault = MPResultTypeTemplateLong, }; -typedef enum ( uint32_t, MPCounterValue ) { +typedef mpw_enum ( uint32_t, MPCounterValue ) { /** Use a time-based counter value, resulting in a TOTP generator. */ MPCounterValueTOTP = 0, /** The initial value for a site's counter. */ diff --git a/platform-independent/cli-c/cli/bcrypt.h b/platform-independent/cli-c/cli/bcrypt.h index d8bdb8b5..d9cc2591 100644 --- a/platform-independent/cli-c/cli/bcrypt.h +++ b/platform-independent/cli-c/cli/bcrypt.h @@ -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]; diff --git a/platform-independent/cli-c/cli/blowfish.h b/platform-independent/cli-c/cli/blowfish.h index 57a01275..86f780bd 100644 --- a/platform-independent/cli-c/cli/blowfish.h +++ b/platform-independent/cli-c/cli/blowfish.h @@ -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