Skip to content

Commit

Permalink
Apply some review suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
FAlbertDev committed Oct 6, 2023
1 parent b60515a commit b8663c1
Show file tree
Hide file tree
Showing 11 changed files with 39 additions and 21 deletions.
2 changes: 2 additions & 0 deletions doc/dev_ref/oids.rst
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ Values currently assigned are::
SphincsPlus-haraka-256s-r3.1 OBJECT IDENTIFIER ::= { SphincsPlus-haraka 5 }
SphincsPlus-haraka-256f-r3.1 OBJECT IDENTIFIER ::= { SphincsPlus-haraka 6 }

HSS-LMS-Private-Key OBJECT IDENTIFIER ::= { publicKey 13 }

symmetricKey OBJECT IDENTIFIER ::= { randombit 3 }

ocbModes OBJECT IDENTIFIER ::= { symmetricKey 2 }
Expand Down
4 changes: 4 additions & 0 deletions src/lib/pubkey/hss_lms/hss_lms_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,13 @@ class PseudorandomKeyGeneration {
void gen(std::span<uint8_t> out, HashFunction& hash, std::span<const uint8_t> seed) const;

private:
/// Input buffer containing the prefix: 'identifier || u32str(q) || u16str(i) || u8str(j)'
std::vector<uint8_t> m_input_buffer;
/// Subspan of m_input_buffer representing 'u32str(q)'
std::span<uint8_t> m_q;
/// Subspan of m_input_buffer representing 'u26str(i)'
std::span<uint8_t> m_i;
/// Pointer to m_input_buffer at 'u8str(j)'
uint8_t* m_j;
};

Expand Down
1 change: 1 addition & 0 deletions src/lib/pubkey/hss_lms/info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ rng
sha2_32
shake
trunc_hash
tree_hash
</requires>
5 changes: 4 additions & 1 deletion src/lib/pubkey/hss_lms/lm_ots.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ using LMS_Message = Strong<std::vector<uint8_t>, struct LMS_Message_>;
/**
* @brief Enum of available LM-OTS algorithm types.
*
* See RFC 8554 Section 4.1.
* The supported parameter sets are defined in RFC 8554 Section 4.1. and
* draft-fluhrer-lms-more-parm-sets-11 Section 4. HSS/LMS typecodes are
* introduced in RFC 8554 Section 3.2. and their format specified in
* Section 3.3.
*/
enum class LMOTS_Algorithm_Type : uint32_t {
// --- RFC 8554 ---
Expand Down
5 changes: 4 additions & 1 deletion src/lib/pubkey/hss_lms/lms.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ namespace Botan {
/**
* @brief Enum of available LMS algorithm types.
*
* See RFC 8554 Section 5.1.
* The supported parameter sets are defined in RFC 8554 Section 5.1. and
* draft-fluhrer-lms-more-parm-sets-11 Section 5. HSS/LMS typecodes are
* introduced in RFC 8554 Section 3.2. and their format specified in
* Section 3.3.
*/
enum class LMS_Algorithm_Type : uint32_t {
// --- RFC 8554 ---
Expand Down
17 changes: 2 additions & 15 deletions src/lib/utils/concepts.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,6 @@ struct is_strong_type<Strong<Ts...>> : std::true_type {};
template <typename... Ts>
constexpr bool is_strong_type_v = is_strong_type<std::remove_const_t<Ts>...>::value;

/**
* Checks whether a strong type has the @p Capability included in its @p Tags type pack.
*/
template <typename Capability, typename T, typename... Tags>
constexpr auto strong_type_has_capability(Strong<T, Tags...>) {
if constexpr((std::is_same_v<Capability, Tags> || ...)) {
return std::true_type();
} else {
return std::false_type();
}
}

namespace concepts {

// TODO: C++20 use std::convertible_to<> that was not available in Android NDK
Expand Down Expand Up @@ -130,9 +118,8 @@ template <class T>
concept contiguous_strong_type = strong_type<T> && contiguous_container<T>;

template <typename T, typename Capability>
concept strong_type_with_capability = requires(T a) {
{ strong_type_has_capability<Capability>(a) } -> std::same_as<std::true_type>;
};
concept strong_type_with_capability = T::template
has_capability<Capability>();

// std::integral is a concept that is shipped with C++20 but Android NDK is not
// yet there.
Expand Down
1 change: 0 additions & 1 deletion src/lib/utils/info.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ safeint.h
scan_name.h
stl_util.h
timer.h
tree_hash.h
</header:internal>

<requires>
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utils/stl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ class BufferSlicer final {
return load_be<T>(take(sizeof(T)).data(), 0);
}

template <typename T>
auto copy_le() {
return load_le<T>(take(sizeof(T)).data(), 0);
}

void skip(const size_t count) { take(count); }

size_t remaining() const { return m_remaining.size(); }
Expand Down
5 changes: 5 additions & 0 deletions src/lib/utils/strong_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,11 @@ class Strong : public detail::Strong_Adapter<T> {
public:
using detail::Strong_Adapter<T>::Strong_Adapter;

template <typename CapabilityT>
constexpr static bool has_capability() {
return (std::is_same_v<CapabilityT, Capabilities> || ...);
}

private:
using Tag = TagTypeT;
};
Expand Down
12 changes: 12 additions & 0 deletions src/lib/utils/tree_hash/info.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<defines>
TREE_HASH -> 20231006
</defines>

<module_info>
name -> "Tree Hash"
</module_info>

<header:internal>
tree_hash.h
</header:internal>

Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ concept tree_node_index = strong_type_with_capability<T, EnableArithmeticWithPla
template <typename T>
concept tree_layer_index = strong_type_with_capability<T, EnableArithmeticWithPlainNumber>;

template <strong_type S>
struct strong_span_type {};

/**
* @brief An adress in a Tree.
*/
Expand Down

0 comments on commit b8663c1

Please sign in to comment.