Skip to content

Commit 15796be

Browse files
committed
Additional minor tweaks to reduce Windows XP issues
Some internal (non-security!) hash functions were using a variety of crypto providers without any thought for what the functions were actually doing. These have all been condensed to a single provider, which should improve reliability on Windows XP. (Some XP installs were reporting provider-related crashes, likely from running SP2 instead of SP3 - this should solve that, although no promises are made for 3rd-party library behavior under old XP versions!)
1 parent 4ae1d6e commit 15796be

6 files changed

Lines changed: 17 additions & 12 deletions

File tree

Classes/pdCrypto.cls

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -108,25 +108,30 @@ Private m_CryptoProviderHandle As Long, m_CryptoProviderID As PD_CRYPT_PROVIDERS
108108
Private m_HashHandle As Long
109109

110110
'PD's default string hash function. PD uses hashed strings for a lot of random things - session IDs, temp files, etc.
111-
' By default, the first 16 characters of an SHA-256 hash is used for these purposes.
112-
Friend Function QuickHashString(ByRef srcString As String, Optional ByVal strLength As Long = 16) As String
111+
' By default, the first 16 characters of the hash is used for these purposes.
112+
'
113+
'(NOTE: this function is not guaranteed to return identical results between sessions, so do not use it for
114+
' anything persistent.)
115+
'
116+
'(NOTE: using default settings, do not ask for a length > 16 as MD5 is used.)
117+
Friend Function QuickHashString(ByRef srcString As String, Optional ByVal dstStrLength As Long = 16) As String
113118

114119
If (LenB(srcString) <> 0) Then
115120

116121
Dim i As Long
117122

118123
'Perform a quick hash of the input string
119-
If QuickHash(PDCA_SHA_256, StrPtr(srcString), LenB(srcString)) Then
124+
If QuickHash(PDCA_MD5, StrPtr(srcString), LenB(srcString)) Then
120125

121126
'Retrieve the hashed data
122127
Dim hashBytes() As Byte, hashLength As Long
123128
If RetrieveHashedData(hashBytes, hashLength) Then
124129

125130
'Translate the first (strLength) bytes into a human-readable string, then return it.
126131
' (Thank you to vbForums user "dilettante" for this translation technique.)
127-
QuickHashString = String$(strLength, "0")
132+
QuickHashString = String$(dstStrLength, "0")
128133

129-
For i = 0 To (strLength \ 2) - 1
134+
For i = 0 To (dstStrLength \ 2) - 1
130135
If (hashBytes(i) < &H10) Then
131136
Mid$(QuickHashString, i * 2 + 2, 1) = Hex$(hashBytes(i))
132137
Else
@@ -147,8 +152,8 @@ Friend Function QuickHashString(ByRef srcString As String, Optional ByVal strLen
147152
End Function
148153

149154
'Same as QuickHashString(), above, but operates on arbitrary binary data. The first (n) chars of the result are
150-
' returned as a hex string.
151-
Friend Function QuickHash_AsString(ByVal ptrData As Long, ByVal dataLen As Long, Optional ByVal strLength As Long = 16, Optional ByVal cryptoMethod As PD_CRYPT_ALGOS = PDCA_SHA_256) As String
155+
' returned as a hex string. (Using default settings, do not ask for a length > 16.)
156+
Friend Function QuickHash_AsString(ByVal ptrData As Long, ByVal dataLen As Long, Optional ByVal strLength As Long = 16, Optional ByVal cryptoMethod As PD_CRYPT_ALGOS = PDCA_MD5) As String
152157

153158
'Perform a quick hash of the input string
154159
If QuickHash(cryptoMethod, ptrData, dataLen) Then

Classes/pdImage.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ Friend Function GetUniqueID() As String
295295
Dim tmpString As String
296296
tmpString = OS.GetArbitraryGUID()
297297
m_uniqueHash = cCrypto.QuickHashString(tmpString, Len(tmpString))
298-
If (Len(m_uniqueHash) > 12) Then m_uniqueHash = Left$(m_uniqueHash, 12)
298+
If (Len(m_uniqueHash) > 16) Then m_uniqueHash = Left$(m_uniqueHash, 16)
299299
End If
300300

301301
GetUniqueID = m_uniqueHash

Classes/pdTranslate.cls

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ Private Function GetLangFileChecksum(ByRef srcFile As String) As String
504504
strHashSource = srcFile & "|" & CStr(Files.FileLenW(srcFile)) & "|" & CStr(Files.FileGetTimeAsCurrency(srcFile, PDFT_WriteTime))
505505

506506
'A dedicated crypto class handles the actual hashing
507-
GetLangFileChecksum = m_Crypto.QuickHashString(strHashSource, 64)
507+
GetLangFileChecksum = m_Crypto.QuickHashString(strHashSource)
508508

509509
End Function
510510

Modules/ColorManagement_ICM.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ Public Function AddProfileToCache(ByRef srcProfile As pdICCProfile, Optional ByV
344344
'Profiles are quickly hashed; subsequent profile requests rely on this hash to return correct data
345345
If (m_Hasher Is Nothing) Then Set m_Hasher = New pdCrypto
346346
Dim profHash As String
347-
profHash = m_Hasher.QuickHash_AsString(srcProfile.GetICCDataPointer, srcProfile.GetICCDataSize, , PDCA_MD5)
347+
profHash = m_Hasher.QuickHash_AsString(srcProfile.GetICCDataPointer, srcProfile.GetICCDataSize, 16, PDCA_MD5)
348348

349349
'Regardless of whether this profile already exists in our cache, we will return its hash value. (This gives the
350350
' caller a unique way to retrieve the profile in the future.)

Modules/OS.bas

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1171,7 +1171,7 @@ Public Function UniqueSessionID() As String
11711171
Dim tmpString As String
11721172
tmpString = GetArbitraryGUID()
11731173
m_SessionID = cCrypto.QuickHashString(tmpString, Len(tmpString))
1174-
If (Len(m_SessionID) > 12) Then m_SessionID = Left$(m_SessionID, 12)
1174+
If (Len(m_SessionID) > 16) Then m_SessionID = Left$(m_SessionID, 16)
11751175
End If
11761176

11771177
UniqueSessionID = m_SessionID

PhotoDemon.vbp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -534,7 +534,7 @@ Description="PhotoDemon Photo Editor"
534534
CompatibleMode="0"
535535
MajorVer=2024
536536
MinorVer=8
537-
RevisionVer=110
537+
RevisionVer=111
538538
AutoIncrementVer=1
539539
ServerSupportFiles=0
540540
VersionComments="Copyright 2000-2024 Tanner Helland - photodemon.org"

0 commit comments

Comments
 (0)