diff --git a/core/c/mpw-algorithm_v0.c b/core/c/mpw-algorithm_v0.c index 5893c674..ca293ffc 100644 --- a/core/c/mpw-algorithm_v0.c +++ b/core/c/mpw-algorithm_v0.c @@ -156,6 +156,9 @@ static const char *mpw_sitePassword_v0( const char *mpw_encrypt_v0( MPMasterKey masterKey, const char *plainText) { + trc( "-- mpw_encrypt_v0\n" ); + trc( "plainText: %s = %s\n", plainText, mpw_hex( plainText, sizeof( plainText ) ) ); + // Encrypt size_t bufSize = strlen( plainText ); const uint8_t *cipherBuf = mpw_aes_encrypt( masterKey, MPMasterKeySize, (const uint8_t *)plainText, bufSize ); @@ -163,6 +166,7 @@ const char *mpw_encrypt_v0( err( "AES encryption error: %s\n", strerror( errno ) ); return NULL; } + trc( "cipherBuf: %lu bytes = %s\n", bufSize, mpw_hex( cipherBuf, bufSize ) ); // Base64-encode @@ -173,6 +177,7 @@ const char *mpw_encrypt_v0( mpw_free_string( cipherText ); cipherText = NULL; } + trc( "b64 encoded -> cipherText: %s = %s\n", cipherText, mpw_hex( cipherText, sizeof( cipherText ) ) ); mpw_free( cipherBuf, bufSize ); return cipherText; @@ -181,6 +186,9 @@ const char *mpw_encrypt_v0( const char *mpw_decrypt_v0( MPMasterKey masterKey, const char *cipherText) { + trc( "-- mpw_decrypt_v0\n" ); + trc( "cipherText: %s = %s\n", cipherText, mpw_hex( cipherText, sizeof( cipherText ) ) ); + // Base64-decode size_t bufSize = mpw_base64_decode_max( cipherText ); uint8_t *cipherBuf = calloc( 1, bufSize ); @@ -189,12 +197,15 @@ const char *mpw_decrypt_v0( mpw_free( cipherBuf, mpw_base64_decode_max( cipherText ) ); return NULL; } - + trc( "b64 decoded: %lu bytes = %s\n", bufSize, mpw_hex( cipherBuf, bufSize ) ); // Decrypt - const char *plainText = (const char *)mpw_aes_decrypt( masterKey, MPMasterKeySize, cipherBuf, bufSize ); + const uint8_t *plainBytes = mpw_aes_decrypt( masterKey, MPMasterKeySize, cipherBuf, bufSize ); + const char *plainText = strndup( (char *)plainBytes, bufSize ); + mpw_free( plainBytes, bufSize ); if (!plainText) err( "AES decryption error: %s\n", strerror( errno ) ); + trc( "decrypted -> plainText: %s = %s\n", plainText, mpw_hex( plainText, sizeof( plainText ) ) ); mpw_free( cipherBuf, bufSize ); return plainText; diff --git a/core/c/mpw-util.c b/core/c/mpw-util.c index 8b5c8bde..b0b8f184 100644 --- a/core/c/mpw-util.c +++ b/core/c/mpw-util.c @@ -391,10 +391,3 @@ const size_t mpw_utf8_strlen(const char *utf8String) { return charlen; } - -void printb(const void *p, size_t size) { - - for (int i = 0; i < size; ++i) - dbg( "%02hhX ", ((const uint8_t *)p)[i] ); - dbg( "\n" ); -} diff --git a/core/c/mpw-util.h b/core/c/mpw-util.h index 09a3c517..6059a8d8 100644 --- a/core/c/mpw-util.h +++ b/core/c/mpw-util.h @@ -174,6 +174,4 @@ const char *mpw_identicon(const char *fullName, const char *masterPassword); /** @return The amount of display characters in the given UTF-8 string. */ const size_t mpw_utf8_strlen(const char *utf8String); -void printb(const void *p, size_t size); - #endif // _MPW_UTIL_H