Skip to content

Commit dc5ec77

Browse files
propagating errors
1 parent f59d4ed commit dc5ec77

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

crypto/sha2-hacl.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ int hacl_sha256_update(struct shash_desc *desc, const u8 *data,
1919
st.block_state = sctx->state;
2020
st.buf = sctx->buf;
2121
st.total_len = sctx->count;
22-
Hacl_Streaming_SHA2_update_256(&st, (u8 *)data, len);
22+
uint8_t res = Hacl_Streaming_SHA2_update_256(&st, (u8 *)data, len);
2323
sctx->count = st.total_len;
24-
return 0;
24+
return res;
2525
}
2626
EXPORT_SYMBOL(hacl_sha256_update);
2727

@@ -64,9 +64,9 @@ int hacl_sha512_update(struct shash_desc *desc, const u8 *data,
6464
st.block_state = sctx->state;
6565
st.buf = sctx->buf;
6666
st.total_len = sctx->count[0];
67-
Hacl_Streaming_SHA2_update_512(&st, (u8 *)data, len);
67+
uint8_t res = Hacl_Streaming_SHA2_update_512(&st, (u8 *)data, len);
6868
sctx->count[0] = st.total_len;
69-
return 0;
69+
return res;
7070
}
7171
EXPORT_SYMBOL(hacl_sha512_update);
7272

@@ -92,12 +92,15 @@ int hacl_sha512_finup(struct shash_desc *desc, const u8 *data, unsigned int len,
9292
st.block_state = sctx->state;
9393
st.buf = sctx->buf;
9494
st.total_len = sctx->count[0];
95-
Hacl_Streaming_SHA2_update_512(&st, (u8 *)data, len);
96-
if (crypto_shash_digestsize(desc->tfm) == SHA384_DIGEST_SIZE)
97-
Hacl_Streaming_SHA2_finish_384(&st, hash);
98-
else
99-
Hacl_Streaming_SHA2_finish_512(&st, hash);
100-
return 0;
95+
uint8_t res = Hacl_Streaming_SHA2_update_512(&st, (u8 *)data, len);
96+
if (res == 0) {
97+
if (crypto_shash_digestsize(desc->tfm) == SHA384_DIGEST_SIZE)
98+
Hacl_Streaming_SHA2_finish_384(&st, hash);
99+
else
100+
Hacl_Streaming_SHA2_finish_512(&st, hash);
101+
return 0;
102+
} else
103+
return res;
101104
}
102105
EXPORT_SYMBOL(hacl_sha512_finup);
103106

0 commit comments

Comments
 (0)