Changeset 102297 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Nov 24, 2023 4:32:03 PM (13 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/shacrypt.cpp
r102296 r102297 173 173 174 174 RTR3DECL(int) RTCrShaCrypt256ToString(uint8_t abHash[RTSHA256_HASH_SIZE], const char *pszSalt, uint32_t cRounds, 175 char *pszString, size_t c bString)175 char *pszString, size_t cchString) 176 176 { 177 177 AssertPtrReturn(pszSalt, VERR_INVALID_POINTER); 178 178 AssertReturn (cRounds, VERR_INVALID_PARAMETER); 179 AssertReturn (c bString,VERR_INVALID_PARAMETER);179 AssertReturn (cchString >= RTSHA256_DIGEST_LEN + 1, VERR_INVALID_PARAMETER); 180 180 AssertPtrReturn(pszString, VERR_INVALID_POINTER); 181 181 182 182 char *psz = pszString; 183 size_t cch = c bString;183 size_t cch = cchString; 184 184 185 185 *psz = '\0'; 186 187 size_t cchPrefix; 186 188 if (cRounds == RT_SHACRYPT_DEFAULT_ROUNDS) 187 psz += RTStrPrintf2(psz, cch, "$5$%s$", pszSalt);189 cchPrefix = RTStrPrintf2(psz, cchString, "$5$%s$", pszSalt); 188 190 else 189 psz += RTStrPrintf2(psz, cch, "$5$rounds=%RU32$%s$", cRounds, pszSalt); 191 cchPrefix = RTStrPrintf2(psz, cchString, "$5$rounds=%RU32$%s$", cRounds, pszSalt); 192 AssertReturn(cchPrefix > 0, VERR_BUFFER_OVERFLOW); 193 AssertReturn(cch >= cchPrefix, VERR_BUFFER_OVERFLOW); 194 cch -= cchPrefix; 195 psz += cchPrefix; 196 197 /* Make sure that there is enough room to store the base64-encoded hash. */ 198 AssertReturn(cch >= ((RTSHA256_HASH_SIZE / 3) * 4) + 1, VERR_BUFFER_OVERFLOW); 190 199 191 200 static const char acBase64[64 + 1] = … … 347 356 348 357 RTR3DECL(int) RTCrShaCrypt512ToString(uint8_t abHash[RTSHA512_HASH_SIZE], const char *pszSalt, uint32_t cRounds, 349 char *pszString, size_t c bString)358 char *pszString, size_t cchString) 350 359 { 351 360 AssertPtrReturn(pszSalt, VERR_INVALID_POINTER); 352 361 AssertReturn (cRounds, VERR_INVALID_PARAMETER); 353 AssertReturn (c bString,VERR_INVALID_PARAMETER);362 AssertReturn (cchString >= RTSHA512_DIGEST_LEN + 1, VERR_INVALID_PARAMETER); 354 363 AssertPtrReturn(pszString, VERR_INVALID_POINTER); 355 364 356 365 char *psz = pszString; 357 size_t cch = c bString;358 359 *psz = '\0';366 size_t cch = cchString; 367 368 size_t cchPrefix; 360 369 if (cRounds == RT_SHACRYPT_DEFAULT_ROUNDS) 361 psz += RTStrPrintf2(psz, cch, "$6$%s$", pszSalt);370 cchPrefix = RTStrPrintf2(psz, cchString, "$6$%s$", pszSalt); 362 371 else 363 psz += RTStrPrintf2(psz, cch, "$6$rounds=%RU32$%s$", cRounds, pszSalt); 372 cchPrefix = RTStrPrintf2(psz, cchString, "$6$rounds=%RU32$%s$", cRounds, pszSalt); 373 AssertReturn(cchPrefix > 0, VERR_BUFFER_OVERFLOW); 374 AssertReturn(cch >= cchPrefix, VERR_BUFFER_OVERFLOW); 375 cch -= cchPrefix; 376 psz += cchPrefix; 377 378 /* Make sure that there is enough room to store the base64-encoded hash. */ 379 AssertReturn(cch >= ((RTSHA512_HASH_SIZE / 3) * 4) + 1, VERR_BUFFER_OVERFLOW); 364 380 365 381 static const char acBase64[64 + 1] =
Note:
See TracChangeset
for help on using the changeset viewer.