Skip to content

Commit 96bc9e9

Browse files
committed
slow_hash_plug.c as used for Monero: Free OAES context on failure
1 parent 28fb2aa commit 96bc9e9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/slow_hash_plug.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ int cn_slow_hash(const void *data, size_t length, char *hash, void *memory)
182182
memcpy(text, state.init, INIT_SIZE_BYTE);
183183

184184
if (!aes_ctx || oaes_key_import_data(aes_ctx, state.hs.b, AES_KEY_SIZE))
185-
return -1;
185+
goto fail;
186186
#if MBEDTLS_AESNI_HAVE_CODE == 2
187187
const uint8_t *aes_exp_data = oaes_get_exp_data(aes_ctx);
188188
if (have_aesni)
@@ -254,7 +254,7 @@ int cn_slow_hash(const void *data, size_t length, char *hash, void *memory)
254254

255255
memcpy(text, state.init, INIT_SIZE_BYTE);
256256
if (oaes_key_import_data(aes_ctx, &state.hs.b[32], AES_KEY_SIZE))
257-
return -1;
257+
goto fail;
258258
#if MBEDTLS_AESNI_HAVE_CODE == 2
259259
aes_exp_data = oaes_get_exp_data(aes_ctx);
260260
if (have_aesni)
@@ -277,6 +277,9 @@ int cn_slow_hash(const void *data, size_t length, char *hash, void *memory)
277277
extra_hashes[state.hs.b[0] & 3](&state, 200, hash);
278278
oaes_free(&aes_ctx);
279279
return 0;
280+
fail:
281+
oaes_free(&aes_ctx);
282+
return -1;
280283
}
281284

282285
int cn_slow_hash_aesni(void)

0 commit comments

Comments
 (0)