Changeset 102297 in vbox
- Timestamp:
- Nov 24, 2023 4:32:03 PM (10 months ago)
- Location:
- trunk
- Files:
-
- 4 edited
-
include/iprt/crypto/shacrypt.h (modified) (2 diffs)
-
src/VBox/Runtime/common/crypto/shacrypt.cpp (modified) (2 diffs)
-
src/VBox/Runtime/testcase/tstRTShaCrypt.cpp (modified) (1 diff)
-
src/VBox/Runtime/tools/RTMkPasswd.cpp (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/crypto/shacrypt.h
r102296 r102297 81 81 * @param cRounds Number of rounds used for generating \a pabHash. 82 82 * @param pszString Where to store the printable string on success. 83 * @param cbString Size (in bytes) of \a pszString. 83 * @param cchString Size of \a pszString. 84 * Should be at least RTSHA256_DIGEST_LEN + 1 bytes. 84 85 * 85 86 * @note This implements step 22 of SHA-crypt.txt Version: 0.6 2016-8-31. 86 87 */ 87 RTR3DECL(int) RTCrShaCrypt256ToString(uint8_t abHash[RTSHA256_HASH_SIZE], const char *pszSalt, uint32_t cRounds, char *pszString, size_t c bString);88 RTR3DECL(int) RTCrShaCrypt256ToString(uint8_t abHash[RTSHA256_HASH_SIZE], const char *pszSalt, uint32_t cRounds, char *pszString, size_t cchString); 88 89 89 90 … … 111 112 * @param cRounds Number of rounds used for generating \a pabHash. 112 113 * @param pszString Where to store the printable string on success. 113 * @param cbString Size (in bytes) of \a pszString. 114 * @param cchString Size of \a pszString. 115 * Should be at least RTSHA512_DIGEST_LEN + 1 bytes. 114 116 * 115 117 * @note This implements step 22 of SHA-crypt.txt Version: 0.6 2016-8-31. 116 118 */ 117 RTR3DECL(int) RTCrShaCrypt512ToString(uint8_t abHash[RTSHA512_HASH_SIZE], const char *pszSalt, uint32_t cRounds, char *pszString, size_t c bString);119 RTR3DECL(int) RTCrShaCrypt512ToString(uint8_t abHash[RTSHA512_HASH_SIZE], const char *pszSalt, uint32_t cRounds, char *pszString, size_t cchString); 118 120 119 121 /** @} */ -
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] = -
trunk/src/VBox/Runtime/testcase/tstRTShaCrypt.cpp
r102296 r102297 227 227 && g_aTests[i].pszResultStr) 228 228 { 229 char szResult[RTSHA512_DIGEST_LEN ];229 char szResult[RTSHA512_DIGEST_LEN + 1]; 230 230 231 231 switch (enmType) -
trunk/src/VBox/Runtime/tools/RTMkPasswd.cpp
r102296 r102297 177 177 178 178 uint8_t abDigest[RTSHA512_HASH_SIZE]; 179 char szResult[RTSHA512_DIGEST_LEN ];179 char szResult[RTSHA512_DIGEST_LEN + 1]; 180 180 181 181 switch (enmMethod)
Note:
See TracChangeset
for help on using the changeset viewer.

