- Timestamp:
- Nov 29, 2023 9:47:41 AM (15 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/shacrypt.cpp
r102361 r102372 69 69 AssertReturn (cRounds, VERR_INVALID_PARAMETER); 70 70 71 size_t const c bKey = strlen(pszKey);72 AssertReturn(c bKey, VERR_INVALID_PARAMETER);73 size_t const c bSalt = strlen(pszSalt);74 AssertMsgReturn(c bSalt >= RT_SHACRYPT_MIN_SALT_LEN && cbSalt <= RT_SHACRYPT_MAX_SALT_LEN, ("len=%zu\n", cbSalt),71 size_t const cchKey = strlen(pszKey); 72 AssertReturn(cchKey, VERR_INVALID_PARAMETER); 73 size_t const cchSalt = strlen(pszSalt); 74 AssertMsgReturn(cchSalt >= RT_SHACRYPT_MIN_SALT_LEN && cchSalt <= RT_SHACRYPT_MAX_SALT_LEN, ("len=%zu\n", cchSalt), 75 75 VERR_INVALID_PARAMETER); 76 76 … … 80 80 RTSHA256CONTEXT Ctx; 81 81 RTSha256Init(&Ctx); /* Step 1. */ 82 RTSha256Update(&Ctx, pszKey, c bKey);/* Step 2. */83 RTSha256Update(&Ctx, pszSalt, c bSalt);/* Step 3. */82 RTSha256Update(&Ctx, pszKey, cchKey); /* Step 2. */ 83 RTSha256Update(&Ctx, pszSalt, cchSalt); /* Step 3. */ 84 84 85 85 RTSHA256CONTEXT CtxAlt; 86 86 RTSha256Init(&CtxAlt); /* Step 4. */ 87 RTSha256Update(&CtxAlt, pszKey, c bKey);/* Step 5. */88 RTSha256Update(&CtxAlt, pszSalt, c bSalt);/* Step 6. */89 RTSha256Update(&CtxAlt, pszKey, c bKey);/* Step 7. */87 RTSha256Update(&CtxAlt, pszKey, cchKey); /* Step 5. */ 88 RTSha256Update(&CtxAlt, pszSalt, cchSalt); /* Step 6. */ 89 RTSha256Update(&CtxAlt, pszKey, cchKey); /* Step 7. */ 90 90 RTSha256Final(&CtxAlt, abDigest); /* Step 8. */ 91 91 92 size_t i = c bKey;92 size_t i = cchKey; 93 93 for (; i > RTSHA256_HASH_SIZE; i -= RTSHA256_HASH_SIZE) /* Step 9. */ 94 94 RTSha256Update(&Ctx, abDigest, sizeof(abDigest)); 95 95 RTSha256Update(&Ctx, abDigest, i); /* Step 10. */ 96 96 97 size_t keyBits = c bKey;97 size_t keyBits = cchKey; 98 98 while (keyBits) /* Step 11. */ 99 99 { … … 101 101 RTSha256Update(&Ctx, abDigest, sizeof(abDigest)); /* a) */ 102 102 else 103 RTSha256Update(&Ctx, pszKey, c bKey);/* b) */103 RTSha256Update(&Ctx, pszKey, cchKey); /* b) */ 104 104 keyBits >>= 1; 105 105 } … … 108 108 109 109 RTSha256Init(&CtxAlt); /* Step 13. */ 110 for (i = 0; i < c bKey; i++)/* Step 14. */111 RTSha256Update(&CtxAlt, pszKey, c bKey);110 for (i = 0; i < cchKey; i++) /* Step 14. */ 111 RTSha256Update(&CtxAlt, pszKey, cchKey); 112 112 RTSha256Final(&CtxAlt, abDigestTemp); /* Step 15. */ 113 113 … … 115 115 * Byte sequence P (= password). 116 116 */ 117 size_t const cbSeqP = c bKey;117 size_t const cbSeqP = cchKey; 118 118 uint8_t *pabSeqP = (uint8_t *)RTMemDup(pszKey, cbSeqP); 119 119 uint8_t *p = pabSeqP; … … 130 130 131 131 for (i = 0; i < 16 + (unsigned)abDigest[0]; i++) /* Step 18. */ 132 RTSha256Update(&CtxAlt, pszSalt, c bSalt);132 RTSha256Update(&CtxAlt, pszSalt, cchSalt); 133 133 134 134 RTSha256Final(&CtxAlt, abDigestTemp); /* Step 19. */ … … 137 137 * Byte sequence S (= salt). 138 138 */ 139 size_t const cbSeqS = c bSalt;139 size_t const cbSeqS = cchSalt; 140 140 uint8_t *pabSeqS = (uint8_t *)RTMemDup(pszSalt, cbSeqS); 141 141 p = pabSeqS; … … 255 255 AssertReturn (cRounds, VERR_INVALID_PARAMETER); 256 256 257 size_t const c bKey = strlen(pszKey);258 AssertReturn(c bKey, VERR_INVALID_PARAMETER);259 size_t const c bSalt = strlen(pszSalt);260 AssertMsgReturn(c bSalt >= RT_SHACRYPT_MIN_SALT_LEN && cbSalt <= RT_SHACRYPT_MAX_SALT_LEN, ("len=%zu\n", cbSalt),257 size_t const cchKey = strlen(pszKey); 258 AssertReturn(cchKey, VERR_INVALID_PARAMETER); 259 size_t const cchSalt = strlen(pszSalt); 260 AssertMsgReturn(cchSalt >= RT_SHACRYPT_MIN_SALT_LEN && cchSalt <= RT_SHACRYPT_MAX_SALT_LEN, ("len=%zu\n", cchSalt), 261 261 VERR_INVALID_PARAMETER); 262 262 … … 266 266 RTSHA512CONTEXT Ctx; 267 267 RTSha512Init(&Ctx); /* Step 1. */ 268 RTSha512Update(&Ctx, pszKey, c bKey);/* Step 2. */269 RTSha512Update(&Ctx, pszSalt, c bSalt);/* Step 3. */268 RTSha512Update(&Ctx, pszKey, cchKey); /* Step 2. */ 269 RTSha512Update(&Ctx, pszSalt, cchSalt); /* Step 3. */ 270 270 271 271 RTSHA512CONTEXT CtxAlt; 272 272 RTSha512Init(&CtxAlt); /* Step 4. */ 273 RTSha512Update(&CtxAlt, pszKey, c bKey);/* Step 5. */274 RTSha512Update(&CtxAlt, pszSalt, c bSalt);/* Step 6. */275 RTSha512Update(&CtxAlt, pszKey, c bKey);/* Step 7. */273 RTSha512Update(&CtxAlt, pszKey, cchKey); /* Step 5. */ 274 RTSha512Update(&CtxAlt, pszSalt, cchSalt); /* Step 6. */ 275 RTSha512Update(&CtxAlt, pszKey, cchKey); /* Step 7. */ 276 276 RTSha512Final(&CtxAlt, abDigest); /* Step 8. */ 277 277 278 size_t i = c bKey;278 size_t i = cchKey; 279 279 for (; i > RTSHA512_HASH_SIZE; i -= RTSHA512_HASH_SIZE) /* Step 9. */ 280 280 RTSha512Update(&Ctx, abDigest, sizeof(abDigest)); 281 281 RTSha512Update(&Ctx, abDigest, i); /* Step 10. */ 282 282 283 size_t keyBits = c bKey;283 size_t keyBits = cchKey; 284 284 while (keyBits) /* Step 11. */ 285 285 { … … 287 287 RTSha512Update(&Ctx, abDigest, sizeof(abDigest)); /* a) */ 288 288 else 289 RTSha512Update(&Ctx, pszKey, c bKey);/* b) */289 RTSha512Update(&Ctx, pszKey, cchKey); /* b) */ 290 290 keyBits >>= 1; 291 291 } … … 294 294 295 295 RTSha512Init(&CtxAlt); /* Step 13. */ 296 for (i = 0; i < c bKey; i++)/* Step 14. */297 RTSha512Update(&CtxAlt, pszKey, c bKey);296 for (i = 0; i < cchKey; i++) /* Step 14. */ 297 RTSha512Update(&CtxAlt, pszKey, cchKey); 298 298 RTSha512Final(&CtxAlt, abDigestTemp); /* Step 15. */ 299 299 … … 301 301 * Byte sequence P (= password). 302 302 */ 303 size_t const cbSeqP = c bKey;303 size_t const cbSeqP = cchKey; 304 304 uint8_t *pabSeqP = (uint8_t *)RTMemDup(pszKey, cbSeqP); 305 305 uint8_t *p = pabSeqP; … … 316 316 317 317 for (i = 0; i < 16 + (unsigned)abDigest[0]; i++) /* Step 18. */ 318 RTSha512Update(&CtxAlt, pszSalt, c bSalt);318 RTSha512Update(&CtxAlt, pszSalt, cchSalt); 319 319 320 320 RTSha512Final(&CtxAlt, abDigestTemp); /* Step 19. */ … … 323 323 * Byte sequence S (= salt). 324 324 */ 325 size_t const cbSeqS = c bSalt;325 size_t const cbSeqS = cchSalt; 326 326 uint8_t *pabSeqS = (uint8_t *)RTMemDup(pszSalt, cbSeqS); 327 327 p = pabSeqS;
Note:
See TracChangeset
for help on using the changeset viewer.