Skip to content

Commit

Permalink
Apply review suggestions IV
Browse files Browse the repository at this point in the history
  • Loading branch information
FAlbertDev committed Sep 20, 2024
1 parent 16a9a13 commit 11ce0c7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/lib/pubkey/sphincsplus/sphincsplus_common/sp_fors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ std::vector<TreeNodeIndex> fors_message_to_indices(std::span<const uint8_t> mess

// This is one of the few places where the logic of SPHINCS+ round 3.1 and SLH-DSA differs
auto update_idx = [&]() -> std::function<void(TreeNodeIndex&, uint32_t)> {
#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) or defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
if(params.is_slh_dsa()) {
return [&](TreeNodeIndex& idx, uint32_t i) {
idx ^= (((message[offset >> 3] >> (~offset & 0x7)) & 0x1) << (params.a() - 1 - i));
};
}
#endif
#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) or defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) || defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
if(!params.is_slh_dsa()) {
return [&](TreeNodeIndex& idx, uint32_t i) { idx ^= (((message[offset >> 3] >> (offset & 0x7)) & 0x1) << i); };
}
Expand Down
14 changes: 7 additions & 7 deletions src/lib/pubkey/sphincsplus/sphincsplus_common/sphincsplus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,20 @@ SphincsMessageInternal prepare_message(SphincsInputMessage msg,
const Sphincs_Parameters& params,
StrongSpan<const SphincsContext> context) {
BOTAN_ARG_CHECK(params.is_slh_dsa() || context.empty(), "Context is not supported for SPHINCS+");
[[maybe_unused]] SphincsMessageInternal msg_internal{.prefix = SphincsMessagePrefix(), .message = std::move(msg)};
#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) or defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
#if defined(BOTAN_HAS_SLH_DSA_WITH_SHA2) || defined(BOTAN_HAS_SLH_DSA_WITH_SHAKE)
if(params.is_slh_dsa()) {
// prefix (no pre-hash mode): input mode byte + |ctx| + ctx
const uint8_t input_mode_byte = 0x00; // Pure (TODO: pre-hash mode: 0x01)
msg_internal.prefix = concat<SphincsMessagePrefix>(
store_be(input_mode_byte), store_be(checked_cast_to<uint8_t>(context.size())), context);
return msg_internal;
return {.prefix = concat<SphincsMessagePrefix>(
store_be(input_mode_byte), store_be(checked_cast_to<uint8_t>(context.size())), context),
.message = std::move(msg)};
}
#endif
#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) or defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
#if defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHA2) || defined(BOTAN_HAS_SPHINCS_PLUS_WITH_SHAKE)
if(!params.is_slh_dsa()) {
// SPHINCS+ Round 3.1 uses the message without any prefix
return msg_internal;
return {.prefix = {}, // SPHINCS+ has no prefix
.message = std::move(msg)};
}
#endif
throw Internal_Error("Missing message preparation logic for SLH-DSA or SPHINCS+");
Expand Down

0 comments on commit 11ce0c7

Please sign in to comment.