Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perform serialization of KES and DSIGN sign keys in MLocked memory #276

Closed
wants to merge 28 commits into from

Conversation

tdammers
Copy link
Contributor

We will need this for a KES Agent: in order to send and receive keys over a secure network connection, we have to serialize and deserialize them. The serialized format is still just as confidential as the deserialized form, so we need to treat them with the same care, and that involves storing them in mlocked memory.

We also need to make sure no intermediate values ever reach unprotected memory, so we cannot use the usual Haskell serialization primitives, as these may store intermediates on the Haskell heap. At the same time, mlocked memory is a scarce resource, and we don't want to allocate excessive amounts of it, so in the case of staged KES algorithms (SumKES / CompactSumKES), we cannot create a new temporary variable for each sub-key at each stage - ideally, we want to allocate a single block of mlocked memory for the final key, and perform all operations on it, in-place.

Hence, we use the following approach:

  • We extend the MLockedSizedBytes API with a function mlsbMemcpy, which, just like the memcpy C function, takes two pointers (MLockedSizedBytes) and a length, and copies this many bytes from one MLockedSizedBytes to the other. However, this function has two additional offset parameters, which allow us to address memory locations within the MLockedSizedBytes, and, unlike memcpy, we add bounds checking to prevent buffer overruns.
  • The DSIGNM and KESSignAlgorithm classes expose two methods for serializing and deserializing their SignKeys; these methods accept a target MLockedSizedBytes value that they write to, and an offset into it. This is a slightly awkward signature for user code, but it allows us to delegate the serialization of sub-keys recursively.
  • To deal with the awkwardness, then, we provide a pair of convenience wrappers that have more palatable signatures (SignKey -> IO MLockedSizedBytes for serialization, and MLockedSizedBytes -> IO (Maybe SignKey) for deserialization). These can't be used for recursive ser/deser of composite keys, but they are perfect for user code.

tdammers and others added 28 commits April 7, 2022 11:42
WIP - trace debugging statements still left in
Converting to hex prior to decoding ensures correct symbol range.
This commit adds a function which can extend an `EpochInfo` linearly
given a starting point. This is needed to put in place a patch for a bug
that arose in the Alonzo era, where the `EpochInfo` was too generous in
translating slots.

In order to support this, this adds an additional function
`epochInfoSlotLength`, which returns the 'SlotLength' for the given
slot.
@iquerejeta
Copy link
Collaborator

closing in favour of #255 and #317

@iquerejeta iquerejeta closed this Oct 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants