Skip to content

Commit 80c5d5f

Browse files
committed
bcrypt: Use Win32 API directly when computing checksum without a context
instead of creating a context on stack. It's more convenient and it feels wrong to use our "public" API with additional custom manipulations here. * subversion/libsvn_subr/checksum_bcrypt.c (bcrypt_checksum): Replace bcrypt_ctx_t with a plain BCRYPT_HANDLE, use BCryptHashData() and BCryptFinishHash() instead of bcrypt_ctx_update() and bcrypt_ctx_final(). git-svn-id: https://svn.apache.org/repos/asf/subversion/trunk@1931095 13f79535-47bb-0310-9956-ffa450edef68
1 parent 15e05d4 commit 80c5d5f

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

subversion/libsvn_subr/checksum_bcrypt.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -165,27 +165,33 @@ bcrypt_checksum(algorithm_state_t *algorithm,
165165
const void *data,
166166
apr_size_t len)
167167
{
168-
bcrypt_ctx_t bcrypt_ctx = { 0 };
168+
BCRYPT_HANDLE handle;
169169
void *object_buf;
170170

171+
SVN_ERR_ASSERT(len <= ULONG_MAX);
172+
171173
SVN_ERR(svn_atomic__init_once(&algorithm->initialized, algorithm_init,
172174
algorithm, NULL));
173175

174176
SVN_ERR_ASSERT(algorithm->object_length < 4096);
175177
object_buf = alloca(algorithm->object_length);
176178

177179
SVN_ERR(handle_error(BCryptCreateHash(algorithm->alg_handle,
178-
&bcrypt_ctx.handle,
180+
&handle,
179181
object_buf, algorithm->object_length,
180182
/* pbSecret */ NULL,
181183
/* cbSecret */ 0,
182184
/* dwFlags */ 0)));
183185

184-
SVN_ERR(bcrypt_ctx_update(algorithm, &bcrypt_ctx,
185-
data, len));
186+
SVN_ERR(handle_error(BCryptHashData(handle,
187+
(PUCHAR) data,
188+
(ULONG) len,
189+
/* dwFlags */ 0)));
186190

187-
SVN_ERR(bcrypt_ctx_final(algorithm, &bcrypt_ctx,
188-
digest));
191+
SVN_ERR(handle_error(BCryptFinishHash(handle,
192+
(PUCHAR) digest,
193+
algorithm->hash_length,
194+
/* dwFlags */ 0)));
189195

190196
return SVN_NO_ERROR;
191197
}

0 commit comments

Comments
 (0)