-
Notifications
You must be signed in to change notification settings - Fork 42
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
Add Cardano.Crypto.Libsodium with basic secure memory stubs #118
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dcoutts
approved these changes
Jun 2, 2020
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.
LGTM. We'll need to fix the nix config for libsodium.
CI Green. |
bors merge |
iohk-bors bot
added a commit
that referenced
this pull request
Jun 9, 2020
118: Add Cardano.Crypto.Libsodium with basic secure memory stubs r=dcoutts a=phadej The allocSecureForeignPtr is as secure as `libsodium` makes it. To allocate the single `GHC.Fingerprint` (used for 128bit MD5 hash), on my machine it reserves four memory pages. With provided `memory-example`, it is possible to investigate what (and if) happens. Execute with cabal run test-memory-example -- Then, using information in /proc we can see how pages come and go. The pages around the payload page (`rw-p` one) are protection trap pages by libsodium, explained in https://libsodium.gitbook.io/doc/memory_management#guarded-heap-allocations ```diff --- before.txt 2020-06-01 00:46:35.947953980 +0300 +++ after.txt 2020-06-01 00:46:42.003877057 +0300 @@ -46,10 +46,6 @@ 7f3538e01000-7f3538e02000 rw-p 0019d000 103:05 399924 /lib/x86_64-linux-gnu/libm-2.27.so 7f3538e02000-7f3538e29000 r-xp 00000000 103:05 397952 /lib/x86_64-linux-gnu/ld-2.27.so 7f3538fff000-7f3539005000 rw-p 00000000 00:00 0 -7f3539025000-7f3539026000 r--p 00000000 00:00 0 -7f3539026000-7f3539027000 ---p 00000000 00:00 0 -7f3539027000-7f3539028000 rw-p 00000000 00:00 0 -7f3539028000-7f3539029000 ---p 00000000 00:00 0 7f3539029000-7f353902a000 r--p 00027000 103:05 397952 /lib/x86_64-linux-gnu/ld-2.27.so 7f353902a000-7f353902b000 rw-p 00028000 103:05 397952 /lib/x86_64-linux-gnu/ld-2.27.so 7f353902b000-7f353902c000 rw-p 00000000 00:00 0 ``` I think that for development this is very good option. The less memory hungry variant can be easily added later. Yet, in it we'd still like to use `libsodium`'s `mlock` and `munlock` primitives, so having this in place sooner is beneficial. Co-authored-by: Oleg Grenrus <oleg@well-typed.com>
Build failed |
Can fix the stack error by adding
|
The allocSecureForeignPtr is as secure as `libsodium` makes it. To allocate the single `GHC.Fingerprint` (used for 128bit MD5 hash), on my machine it reserves four memory pages. With provided `memory-example`, it is possible to investigate what (and if) happens. Execute with cabal run test-memory-example -- Then, using information in /proc we can see how pages come and go. The pages around the payload page (`rw-p` one) are protection trap pages by libsodium, explained in https://libsodium.gitbook.io/doc/memory_management#guarded-heap-allocations ```diff --- before.txt 2020-06-01 00:46:35.947953980 +0300 +++ after.txt 2020-06-01 00:46:42.003877057 +0300 @@ -46,10 +46,6 @@ 7f3538e01000-7f3538e02000 rw-p 0019d000 103:05 399924 /lib/x86_64-linux-gnu/libm-2.27.so 7f3538e02000-7f3538e29000 r-xp 00000000 103:05 397952 /lib/x86_64-linux-gnu/ld-2.27.so 7f3538fff000-7f3539005000 rw-p 00000000 00:00 0 -7f3539025000-7f3539026000 r--p 00000000 00:00 0 -7f3539026000-7f3539027000 ---p 00000000 00:00 0 -7f3539027000-7f3539028000 rw-p 00000000 00:00 0 -7f3539028000-7f3539029000 ---p 00000000 00:00 0 7f3539029000-7f353902a000 r--p 00027000 103:05 397952 /lib/x86_64-linux-gnu/ld-2.27.so 7f353902a000-7f353902b000 rw-p 00028000 103:05 397952 /lib/x86_64-linux-gnu/ld-2.27.so 7f353902b000-7f353902c000 rw-p 00000000 00:00 0 ``` I think that for development this is very good option. The less memory hungry variant can be easily added later. Yet, in it we'd still like to use `libsodium`'s `mlock` and `munlock` primitives, so having this in place sooner is beneficial.
@nc6 added |
bors merge |
Build succeeded |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The allocSecureForeignPtr is as secure as
libsodium
makes it.To allocate the single
GHC.Fingerprint
(used for 128bit MD5 hash),on my machine it reserves four memory pages.
With provided
memory-example
, it is possible to investigatewhat (and if) happens. Execute with
Then, using information in /proc we can see how pages come and go.
The pages around the payload page (
rw-p
one) areprotection trap pages by libsodium, explained in
https://libsodium.gitbook.io/doc/memory_management#guarded-heap-allocations
I think that for development this is very good option.
The less memory hungry variant can be easily added later.
Yet, in it we'd still like to use
libsodium
'smlock
andmunlock
primitives, so having this in place sooner is beneficial.