-
Notifications
You must be signed in to change notification settings - Fork 41
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
UnsoundPureKES and DirectSerialise API #504
Conversation
dee6ddf
to
5d87496
Compare
Is that a replacement for #317 or an extension of it? Before I waste time on reviewing both I'd like to know what the actual plan is. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My apologies for taking so long to review this work.
It looks great! I only had a few suggestions, but nothing critical.
I just noticed that instance KESAlgorithm v => Arbitrary (VerKeyKES v) where
arbitrary = deriveVerKeyKES <$> arbitrary
instance (KESAlgorithm v, ContextKES v ~ (), Signable v ~ SignableRepresentation)
=> Arbitrary (SigKES v) where
arbitrary = do
a <- arbitrary :: Gen Message
sk <- arbitrary
let sig = signKES () 0 a sk
return sig FYI. These arbitrary instances do not need to All they need is to generate concrete types that contain random data with the expected length. So it would be sufficient to generate random bytestring and deserialize it into |
Here are the missing instance KESAlgorithm v => Arbitrary (VerKeyKES v) where
arbitrary = do
bs <- genByteString (fromInteger (natVal (Proxy @(SizeVerKeyKES v))))
case rawDeserialiseVerKeyKES bs of
Nothing -> error "Impossible: the size of VerKeyKES is specified statically"
Just vk -> pure vk
instance KESAlgorithm v => Arbitrary (SigKES v) where
arbitrary = do
bs <- genByteString (fromInteger (natVal (Proxy @(SizeSigKES v))))
case rawDeserialiseSigKES bs of
Nothing -> error "Impossible: the size of SigKES is specified statically"
Just vk -> pure vk
instance UnsoundPureKESAlgorithm v => Arbitrary (UnsoundPureSignKeyKES v) where
arbitrary = unsoundPureGenKeyKES <$> arbitrarySeedOfSize seedSize
where
seedSize = seedSizeKES (Proxy :: Proxy v) |
This hinges on the assumption that raw serialization works the way it currently does, i.e., just pack the raw key data into the buffer in binary form. But this is not part of the In fact, the assumption does not hold for We can, however, generate a random seed and then go through |
We can provide Arbitrary instance through serialization for individual KES algorithms, it doesn't have to be catch all for all algorithms. So, we can still use serialization to provide instances. However, if you have better ideas on how to reinstate Arbitrary instances, then by all means, it doesn't really matter how as long as we can still use it for testing things like serialization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good. Few more comments with respect to recent changes
IMO the simplest way would be to generate an arbitrary seed, use the unsound KES API to generate a sign key from that, and then derive a verkey and/or signature. This will work for any KES algorithm, and it's completely agnostic of the serialization format. Note however that we already have machinery in place for testing ser/deser. I could of course rewrite all that to use I'll provide the |
Whatever route you think is the easiest way, go for it. We just to make sure we don't loose those |
12c4077
to
a182417
Compare
Description
This introduces two changes that are needed for introducing mlocked KES into ouroboros-consensus and implementing a KES agent:
DirectSerialise
API, an abstraction that allows us to send key data over a socket connection directly from mlocked memory, without using any intermediate variables on the GHC heap that might leak secrets to diskUnsoundPureKES
; this is necessary for a minimally disruptive migration path in ouroboros-consensus. We will use this API to keep the existing code, loading KES keys from disk, available, while adding KES agent connectivity (which will use mlocked memory throughout) as an alternative. Until all non-mlocked KES usage has been phased out, we will need to keep theUnsoundPureKES
API around.Checklist
CHANGELOG.md
for the affected packages.New section is never added with the code changes. (See RELEASING.md)
.cabal
andCHANGELOG.md
files according to theversioning process.
.cabal
files for all affected packages are updated.If you change the bounds in a cabal file, that package itself must have a version increase. (See RELEASING.md)