Skip to content

Commit

Permalink
revert back to abort() for checked cases
Browse files Browse the repository at this point in the history
Signed-off-by: Songling Han <[email protected]>
  • Loading branch information
songlingatpan committed Oct 14, 2024
1 parent 6032349 commit 1e4201b
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/common/sha2/sha2_armv8.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void oqs_sha2_sha256_inc_finalize_armv8(uint8_t *out, sha256ctx *state, const ui
// Combine incremental data with final input
tmp_in = OQS_MEM_malloc(tmp_len);
if (!tmp_in) {
return;
abort();
}
memcpy(tmp_in, state->data, state->data_len);
if (in && inlen) {
Expand Down Expand Up @@ -258,7 +258,7 @@ void oqs_sha2_sha256_inc_blocks_armv8(sha256ctx *state, const uint8_t *in, size_
if (state->data_len) {
tmp_in = OQS_MEM_malloc(buf_len);
if (!tmp_in) {
return;
abort();
}
memcpy(tmp_in, state->data, state->data_len);
memcpy(tmp_in + state->data_len, in, buf_len - state->data_len);
Expand Down
20 changes: 10 additions & 10 deletions src/common/sha2/sha2_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ static const uint8_t iv_512[64] = {
void oqs_sha2_sha224_inc_init_c(sha224ctx *state) {
state->ctx = OQS_MEM_malloc(PQC_SHA256CTX_BYTES);
if (!state->ctx) {
return;
abort();
}
for (size_t i = 0; i < 32; ++i) {
state->ctx[i] = iv_224[i];
Expand All @@ -520,7 +520,7 @@ void oqs_sha2_sha256_inc_init_c(sha256ctx *state) {
state->data_len = 0;
state->ctx = OQS_MEM_malloc(PQC_SHA256CTX_BYTES);
if (!state->ctx) {
return;
abort();
}
for (size_t i = 0; i < 32; ++i) {
state->ctx[i] = iv_256[i];
Expand All @@ -535,7 +535,7 @@ void oqs_sha2_sha256_inc_init_c(sha256ctx *state) {
void oqs_sha2_sha384_inc_init_c(sha384ctx *state) {
state->ctx = OQS_MEM_malloc(PQC_SHA512CTX_BYTES);
if (!state->ctx) {
return;
abort();
}
for (size_t i = 0; i < 64; ++i) {
state->ctx[i] = iv_384[i];
Expand All @@ -550,7 +550,7 @@ void oqs_sha2_sha384_inc_init_c(sha384ctx *state) {
void oqs_sha2_sha512_inc_init_c(sha512ctx *state) {
state->ctx = OQS_MEM_malloc(PQC_SHA512CTX_BYTES);
if (!state->ctx) {
return;
abort();
}
for (size_t i = 0; i < 64; ++i) {
state->ctx[i] = iv_512[i];
Expand All @@ -565,7 +565,7 @@ void oqs_sha2_sha512_inc_init_c(sha512ctx *state) {
void oqs_sha2_sha224_inc_ctx_clone_c(sha224ctx *stateout, const sha224ctx *statein) {
stateout->ctx = OQS_MEM_malloc(PQC_SHA256CTX_BYTES);
if (!stateout->ctx) {
return;
abort();
}
stateout->data_len = statein->data_len;
memcpy(stateout->data, statein->data, 128);
Expand All @@ -575,7 +575,7 @@ void oqs_sha2_sha224_inc_ctx_clone_c(sha224ctx *stateout, const sha224ctx *state
void oqs_sha2_sha256_inc_ctx_clone_c(sha256ctx *stateout, const sha256ctx *statein) {
stateout->ctx = OQS_MEM_malloc(PQC_SHA256CTX_BYTES);
if (!stateout->ctx) {
return;
abort();
}
stateout->data_len = statein->data_len;
memcpy(stateout->data, statein->data, 128);
Expand All @@ -585,7 +585,7 @@ void oqs_sha2_sha256_inc_ctx_clone_c(sha256ctx *stateout, const sha256ctx *state
void oqs_sha2_sha384_inc_ctx_clone_c(sha384ctx *stateout, const sha384ctx *statein) {
stateout->ctx = OQS_MEM_malloc(PQC_SHA512CTX_BYTES);
if (!stateout->ctx) {
return;
abort();
}
stateout->data_len = statein->data_len;
memcpy(stateout->data, statein->data, 128);
Expand All @@ -595,7 +595,7 @@ void oqs_sha2_sha384_inc_ctx_clone_c(sha384ctx *stateout, const sha384ctx *state
void oqs_sha2_sha512_inc_ctx_clone_c(sha512ctx *stateout, const sha512ctx *statein) {
stateout->ctx = OQS_MEM_malloc(PQC_SHA512CTX_BYTES);
if (!stateout->ctx) {
return;
abort();
}
stateout->data_len = statein->data_len;
memcpy(stateout->data, statein->data, 128);
Expand Down Expand Up @@ -632,7 +632,7 @@ void oqs_sha2_sha256_inc_blocks_c(sha256ctx *state, const uint8_t *in, size_t in
if (state->data_len) {
tmp_in = OQS_MEM_malloc(tmp_buflen);
if (!tmp_in) {
return;
abort();
}
memcpy(tmp_in, state->data, state->data_len);
memcpy(tmp_in + state->data_len, in, tmp_buflen - state->data_len);
Expand Down Expand Up @@ -711,7 +711,7 @@ void oqs_sha2_sha256_inc_finalize_c(uint8_t *out, sha256ctx *state, const uint8_
} else { //Combine incremental data with final input
tmp_in = OQS_MEM_malloc(tmp_len);
if (!tmp_in) {
return;
abort();
}
memcpy(tmp_in, state->data, state->data_len);
if (in && inlen) {
Expand Down
4 changes: 2 additions & 2 deletions src/common/sha3/ossl_sha3.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static void SHA3_shake128_inc_squeeze(uint8_t *output, size_t outlen, OQS_SHA3_s
} else {
uint8_t *tmp = OQS_MEM_malloc(s->n_out + outlen);
if (!tmp) {
return;
abort();
}
OSSL_FUNC(EVP_DigestFinalXOF)(clone, tmp, s->n_out + outlen);
memcpy(output, tmp + s->n_out, outlen);
Expand Down Expand Up @@ -277,7 +277,7 @@ static void SHA3_shake256_inc_squeeze(uint8_t *output, size_t outlen, OQS_SHA3_s
} else {
uint8_t *tmp = OQS_MEM_malloc(s->n_out + outlen);
if (!tmp) {
return;
abort();
}
OSSL_FUNC(EVP_DigestFinalXOF)(clone, tmp, s->n_out + outlen);
memcpy(output, tmp + s->n_out, outlen);
Expand Down
4 changes: 2 additions & 2 deletions src/common/sha3/ossl_sha3x4.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static void SHA3_shake128_x4_inc_squeeze(uint8_t *out0, uint8_t *out1, uint8_t *
} else {
uint8_t *tmp = OQS_MEM_malloc(s->n_out + outlen);
if (!tmp) {
return;
abort();
}
OSSL_FUNC(EVP_MD_CTX_copy_ex)(clone, s->mdctx0);
OSSL_FUNC(EVP_DigestFinalXOF)(clone, tmp, s->n_out + outlen);
Expand Down Expand Up @@ -207,7 +207,7 @@ static void SHA3_shake256_x4_inc_squeeze(uint8_t *out0, uint8_t *out1, uint8_t *
} else {
uint8_t *tmp = OQS_MEM_malloc(s->n_out + outlen);
if (!tmp) {
return;
abort();
}
OSSL_FUNC(EVP_MD_CTX_copy_ex)(clone, s->mdctx0);
OSSL_FUNC(EVP_DigestFinalXOF)(clone, tmp, s->n_out + outlen);
Expand Down
23 changes: 14 additions & 9 deletions src/common/sha3/xkcp_sha3.c
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,11 @@ static void SHA3_sha3_256(uint8_t *output, const uint8_t *input, size_t inlen) {

static void SHA3_sha3_256_inc_init(OQS_SHA3_sha3_256_inc_ctx *state) {
state->ctx = OQS_MEM_aligned_alloc(KECCAK_CTX_ALIGNMENT, KECCAK_CTX_BYTES);
if (state->ctx != NULL) {
keccak_inc_reset((uint64_t *)state->ctx);

if (state->ctx == NULL) {
abort();
}
keccak_inc_reset((uint64_t *)state->ctx);
}

static void SHA3_sha3_256_inc_absorb(OQS_SHA3_sha3_256_inc_ctx *state, const uint8_t *input, size_t inlen) {
Expand Down Expand Up @@ -238,9 +240,10 @@ static void SHA3_sha3_384(uint8_t *output, const uint8_t *input, size_t inlen) {

static void SHA3_sha3_384_inc_init(OQS_SHA3_sha3_384_inc_ctx *state) {
state->ctx = OQS_MEM_aligned_alloc(KECCAK_CTX_ALIGNMENT, KECCAK_CTX_BYTES);
if (state->ctx != NULL) {
keccak_inc_reset((uint64_t *)state->ctx);
if (state->ctx == NULL) {
abort();
}
keccak_inc_reset((uint64_t *)state->ctx);
}
static void SHA3_sha3_384_inc_absorb(OQS_SHA3_sha3_384_inc_ctx *state, const uint8_t *input, size_t inlen) {
keccak_inc_absorb((uint64_t *)state->ctx, OQS_SHA3_SHA3_384_RATE, input, inlen);
Expand Down Expand Up @@ -275,9 +278,10 @@ static void SHA3_sha3_512(uint8_t *output, const uint8_t *input, size_t inlen) {

static void SHA3_sha3_512_inc_init(OQS_SHA3_sha3_512_inc_ctx *state) {
state->ctx = OQS_MEM_aligned_alloc(KECCAK_CTX_ALIGNMENT, KECCAK_CTX_BYTES);
if (state->ctx != NULL) {
keccak_inc_reset((uint64_t *)state->ctx);
if (state->ctx == NULL) {
abort();
}
keccak_inc_reset((uint64_t *)state->ctx);
}

static void SHA3_sha3_512_inc_absorb(OQS_SHA3_sha3_512_inc_ctx *state, const uint8_t *input, size_t inlen) {
Expand Down Expand Up @@ -320,7 +324,7 @@ static void SHA3_shake128_inc_init(OQS_SHA3_shake128_inc_ctx *state) {
}
state->ctx = OQS_MEM_aligned_alloc(KECCAK_CTX_ALIGNMENT, KECCAK_CTX_BYTES);
if (state->ctx == NULL) {
return;
abort();
}
keccak_inc_reset((uint64_t *)state->ctx);
}
Expand Down Expand Up @@ -364,9 +368,10 @@ static void SHA3_shake256(uint8_t *output, size_t outlen, const uint8_t *input,

static void SHA3_shake256_inc_init(OQS_SHA3_shake256_inc_ctx *state) {
state->ctx = OQS_MEM_aligned_alloc(KECCAK_CTX_ALIGNMENT, KECCAK_CTX_BYTES);
if (state->ctx != NULL) {
keccak_inc_reset((uint64_t *)state->ctx);
if (state->ctx == NULL) {
abort();
}
keccak_inc_reset((uint64_t *)state->ctx);
}

static void SHA3_shake256_inc_absorb(OQS_SHA3_shake256_inc_ctx *state, const uint8_t *input, size_t inlen) {
Expand Down
4 changes: 2 additions & 2 deletions src/common/sha3/xkcp_sha3x4.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static void SHA3_shake128_x4(uint8_t *out0, uint8_t *out1, uint8_t *out2, uint8_
static void SHA3_shake128_x4_inc_init(OQS_SHA3_shake128_x4_inc_ctx *state) {
state->ctx = OQS_MEM_aligned_alloc(KECCAK_X4_CTX_ALIGNMENT, KECCAK_X4_CTX_BYTES);
if (state->ctx == NULL) {
return;
abort();
}
keccak_x4_inc_reset((uint64_t *)state->ctx);
}
Expand Down Expand Up @@ -213,7 +213,7 @@ static void SHA3_shake256_x4(uint8_t *out0, uint8_t *out1, uint8_t *out2, uint8_
static void SHA3_shake256_x4_inc_init(OQS_SHA3_shake256_x4_inc_ctx *state) {
state->ctx = OQS_MEM_aligned_alloc(KECCAK_X4_CTX_ALIGNMENT, KECCAK_X4_CTX_BYTES);
if (state->ctx == NULL) {
return;
abort();
}
keccak_x4_inc_reset((uint64_t *)state->ctx);
}
Expand Down

0 comments on commit 1e4201b

Please sign in to comment.