Changeset 102335 in vbox
- Timestamp:
- Nov 27, 2023 5:01:59 PM (12 months ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/include/iprt/crypto/shacrypt.h
r102298 r102335 59 59 60 60 /** 61 * Creates a randomized salt for the RTCrShaCryptXXX functions. 62 * 63 * @returns IPRT status code. 64 * @param szSalt Where to store the generated salt. 65 * @param cchSalt Number of characters the generated salt should use. 66 * Must be >= RT_SHACRYPT_MIN_SALT_LEN and <= RT_SHACRYPT_MAX_SALT_LEN. 67 */ 68 RTR3DECL(int) RTCrShaCryptGenerateSalt(char szSalt[RT_SHACRYPT_MAX_SALT_LEN + 1], size_t cchSalt); 69 70 71 /** 61 72 * Calculates a SHAcrypt (SHA-256) digest. 62 73 * 63 * @returns VBoxstatus code.74 * @returns IPRT status code. 64 75 * @param pszKey Key (password) to use. 65 76 * @param pszSalt Salt to use. … … 76 87 * Returns a SHAcrypt (SHA-256) digest as a printable scheme. 77 88 * 78 * @returns VBoxstatus code.89 * @returns IPRT status code. 79 90 * @param abHash SHAcrypt (SHA-256) digest to return printable scheme for. 80 91 * @param pszSalt Salt to use. Must match the salt used when generating \a pabHash via RTSha256Crypt(). … … 92 103 * Calculates a SHAcrypt (SHA-512) digest. 93 104 * 94 * @returns VBoxstatus code.105 * @returns IPRT status code. 95 106 * @param pszKey Key (password) to use. 96 107 * @param pszSalt Salt to use. … … 107 118 * Returns a SHAcrypt (SHA-512) digest as a printable scheme. 108 119 * 109 * @returns VBoxstatus code.120 * @returns IPRT status code. 110 121 * @param abHash SHAcrypt (SHA-512) digest to return printable scheme for. 111 122 * @param pszSalt Salt to use. Must match the salt used when generating \a pabHash via RTSha512Crypt(). -
trunk/include/iprt/mangling.h
r102296 r102335 3734 3734 # define RTCrPkixCanCertHandleDigestType RT_MANGLER(RTCrPkixCanCertHandleDigestType) 3735 3735 # define RTCrRandBytes RT_MANGLER(RTCrRandBytes) 3736 # define RTCrShaCryptGenerateSalt RT_MANGLER(RTCrShaCryptGenerateSalt) 3736 3737 # define RTCrShaCrypt256 RT_MANGLER(RTCrShaCrypt256) 3737 3738 # define RTCrShaCrypt256ToString RT_MANGLER(RTCrShaCrypt256ToString) -
trunk/src/VBox/Runtime/common/crypto/shacrypt.cpp
r102297 r102335 43 43 #include <iprt/types.h> 44 44 #include <iprt/mem.h> 45 #include <iprt/rand.h> 45 46 #include <iprt/sha.h> 46 47 #include <iprt/string.h> 47 48 49 50 51 RTR3DECL(int) RTCrShaCryptGenerateSalt(char szSalt[RT_SHACRYPT_MAX_SALT_LEN + 1], size_t cchSalt) 52 { 53 AssertMsgReturn(cchSalt >= RT_SHACRYPT_MIN_SALT_LEN && cchSalt <= RT_SHACRYPT_MAX_SALT_LEN, ("len=%zu\n", cchSalt), 54 VERR_INVALID_PARAMETER); 55 56 static const char aRange[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890./"; 57 for (size_t i = 0; i < cchSalt; i++) 58 szSalt[i] = aRange[RTRandU32Ex(0, sizeof(aRange) - 2)]; 59 60 szSalt[RT_SHACRYPT_MAX_SALT_LEN] = '\0'; 61 return VINF_SUCCESS; 62 } 48 63 49 64 -
trunk/src/VBox/Runtime/testcase/tstRTShaCrypt.cpp
r102297 r102335 191 191 else 192 192 { 193 static const char aRange[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!?+\"%&/()[]{}=#"; 194 for (unsigned s = 0; s < RT_SHACRYPT_MAX_SALT_LEN; s++) /* Always go with a strong salt by default. */ 195 szSalt[s] = aRange[RTRandU32Ex(0, sizeof(aRange) - 2)]; 193 rc = RTCrShaCryptGenerateSalt(szSalt, RT_SHACRYPT_MAX_SALT_LEN); 194 RTTEST_CHECK_RC_OK(hTest, rc); 196 195 pszSalt = szSalt; 197 196 } -
trunk/src/VBox/Runtime/tools/RTMkPasswd.cpp
r102297 r102335 164 164 if (!pszSalt) 165 165 { 166 static const char aRange[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!?+\"%&/()[]{}=#"; 167 for (unsigned i = 0; i < RT_SHACRYPT_MAX_SALT_LEN; i++) /* Always go with a strong salt by default. */ 168 szSalt[i] = aRange[RTRandU32Ex(0, sizeof(aRange) - 2)]; 166 int vrc2 = RTCrShaCryptGenerateSalt(szSalt, RT_SHACRYPT_MAX_SALT_LEN); 167 AssertRCReturn(vrc2, RTEXITCODE_FAILURE); 169 168 pszSalt = szSalt; 170 169 }
Note:
See TracChangeset
for help on using the changeset viewer.