Changeset 102491 in vbox for trunk/src/VBox/Runtime/common
- Timestamp:
- Dec 6, 2023 12:48:47 AM (14 months ago)
- Location:
- trunk/src/VBox/Runtime/common/crypto
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/common/crypto/shacrypt-256.cpp.h
r102490 r102491 82 82 RTSha256Final(&CtxB, abDigest); /* Step 8. */ 83 83 84 size_t i = cchPhrase; 85 for (; i > RTSHA256_HASH_SIZE; i -= RTSHA256_HASH_SIZE) /* Step 9. */ 84 size_t cbLeft = cchPhrase; 85 while (cbLeft > RTSHA256_HASH_SIZE) /* Step 9. */ 86 { 86 87 RTSha256Update(&CtxA, abDigest, sizeof(abDigest)); 87 RTSha256Update(&CtxA, abDigest, i); /* Step 10. */ 88 cbLeft -= RTSHA256_HASH_SIZE; 89 } 90 RTSha256Update(&CtxA, abDigest, cbLeft); /* Step 10. */ 88 91 89 92 size_t iPhraseBit = cchPhrase; … … 100 103 101 104 RTSha256Init(&CtxB); /* Step 13. */ 102 for ( i = 0; i < cchPhrase; i++)/* Step 14. */105 for (size_t i = 0; i < cchPhrase; i++) /* Step 14. */ 103 106 RTSha256Update(&CtxB, pszPhrase, cchPhrase); 104 107 … … 109 112 * Byte sequence P (= password). 110 113 */ 114 /* Step 16. */ 111 115 size_t const cbSeqP = cchPhrase; 112 116 uint8_t *pabSeqP = (uint8_t *)RTMemTmpAllocZ(cbSeqP + 1); /* +1 because the password may be empty */ 113 117 uint8_t *pb = pabSeqP; 114 118 AssertPtrReturn(pabSeqP, VERR_NO_MEMORY); 115 116 for (i = cbSeqP; i > RTSHA256_HASH_SIZE; i -= RTSHA256_HASH_SIZE) /* Step 16. */119 cbLeft = cbSeqP; 120 while (cbLeft > RTSHA256_HASH_SIZE) 117 121 { 118 122 memcpy(pb, abDigestTemp, sizeof(abDigestTemp)); /* a) */ 119 pb += RTSHA256_HASH_SIZE; 120 } 121 memcpy(pb, abDigestTemp, i); /* b) */ 123 pb += RTSHA256_HASH_SIZE; 124 cbLeft -= RTSHA256_HASH_SIZE; 125 } 126 memcpy(pb, abDigestTemp, cbLeft); /* b) */ 122 127 123 128 RTSha256Init(&CtxB); /* Step 17. */ 124 129 125 for ( i = 0; i < 16 + (unsigned)abDigest[0]; i++)/* Step 18. */130 for (size_t i = 0; i < 16 + (unsigned)abDigest[0]; i++) /* Step 18. */ 126 131 RTSha256Update(&CtxB, pszSalt, cchSalt); 127 132 … … 141 146 AssertPtrReturn(pabSeqS, VERR_NO_MEMORY); 142 147 143 pb = pabSeqS; 144 for (i = cbSeqS; i > RTSHA256_HASH_SIZE; i -= RTSHA256_HASH_SIZE) 148 pb = pabSeqS; 149 cbLeft = cbSeqS; 150 while (cbLeft > RTSHA256_HASH_SIZE) 145 151 { 146 152 memcpy(pb, (void *)abDigestTemp, sizeof(abDigestTemp)); /* a) */ 147 pb += RTSHA256_HASH_SIZE; 148 } 149 memcpy(pb, abDigestTemp, i); /* b) */ 153 pb += RTSHA256_HASH_SIZE; 154 cbLeft -= RTSHA256_HASH_SIZE 155 } 156 memcpy(pb, abDigestTemp, cbLeft); /* b) */ 150 157 #else 151 158 AssertCompile(RT_SHACRYPT_SALT_MAX_LEN < RTSHA256_HASH_SIZE); -
trunk/src/VBox/Runtime/common/crypto/shacrypt-512.cpp.h
r102490 r102491 83 83 RTSha512Final(&CtxB, abDigest); /* Step 8. */ 84 84 85 size_t i = cchPhrase; 86 for (; i > RTSHA512_HASH_SIZE; i -= RTSHA512_HASH_SIZE) /* Step 9. */ 85 size_t cbLeft = cchPhrase; 86 while (cbLeft > RTSHA512_HASH_SIZE) /* Step 9. */ 87 { 87 88 RTSha512Update(&CtxA, abDigest, sizeof(abDigest)); 88 RTSha512Update(&CtxA, abDigest, i); /* Step 10. */ 89 cbLeft -= RTSHA512_HASH_SIZE; 90 } 91 RTSha512Update(&CtxA, abDigest, cbLeft); /* Step 10. */ 89 92 90 93 size_t iPhraseBit = cchPhrase; … … 101 104 102 105 RTSha512Init(&CtxB); /* Step 13. */ 103 for ( i = 0; i < cchPhrase; i++)/* Step 14. */106 for (size_t i = 0; i < cchPhrase; i++) /* Step 14. */ 104 107 RTSha512Update(&CtxB, pszPhrase, cchPhrase); 105 108 … … 110 113 * Byte sequence P (= password). 111 114 */ 115 /* Step 16. */ 112 116 size_t const cbSeqP = cchPhrase; 113 117 uint8_t *pabSeqP = (uint8_t *)RTMemTmpAllocZ(cbSeqP + 1); /* +1 because the password may be empty */ 114 118 uint8_t *pb = pabSeqP; 115 119 AssertPtrReturn(pabSeqP, VERR_NO_MEMORY); 116 117 for (i = cbSeqP; i > RTSHA512_HASH_SIZE; i -= RTSHA512_HASH_SIZE) /* Step 16. */120 cbLeft = cbSeqP; 121 while (cbLeft > RTSHA512_HASH_SIZE) 118 122 { 119 123 memcpy(pb, abDigestTemp, sizeof(abDigestTemp)); /* a) */ 120 pb += RTSHA512_HASH_SIZE; 121 } 122 memcpy(pb, abDigestTemp, i); /* b) */ 124 pb += RTSHA512_HASH_SIZE; 125 cbLeft -= RTSHA512_HASH_SIZE; 126 } 127 memcpy(pb, abDigestTemp, cbLeft); /* b) */ 123 128 124 129 RTSha512Init(&CtxB); /* Step 17. */ 125 130 126 for ( i = 0; i < 16 + (unsigned)abDigest[0]; i++)/* Step 18. */131 for (size_t i = 0; i < 16 + (unsigned)abDigest[0]; i++) /* Step 18. */ 127 132 RTSha512Update(&CtxB, pszSalt, cchSalt); 128 133 … … 142 147 AssertPtrReturn(pabSeqS, VERR_NO_MEMORY); 143 148 144 pb = pabSeqS; 145 for (i = cbSeqS; i > RTSHA512_HASH_SIZE; i -= RTSHA512_HASH_SIZE) 149 pb = pabSeqS; 150 cbLeft = cbSeqS; 151 while (cbLeft > RTSHA512_HASH_SIZE) 146 152 { 147 153 memcpy(pb, (void *)abDigestTemp, sizeof(abDigestTemp)); /* a) */ 148 pb += RTSHA512_HASH_SIZE; 149 } 150 memcpy(pb, abDigestTemp, i); /* b) */ 154 pb += RTSHA512_HASH_SIZE; 155 cbLeft -= RTSHA512_HASH_SIZE 156 } 157 memcpy(pb, abDigestTemp, cbLeft); /* b) */ 151 158 #else 152 159 AssertCompile(RT_SHACRYPT_SALT_MAX_LEN < RTSHA512_HASH_SIZE);
Note:
See TracChangeset
for help on using the changeset viewer.