Skip to content

Define some cryptographic functions in sel as pure#189

Merged
Kleidukos merged 11 commits intohaskell-cryptography:mainfrom
intricate:pure-functions
May 19, 2025
Merged

Define some cryptographic functions in sel as pure#189
Kleidukos merged 11 commits intohaskell-cryptography:mainfrom
intricate:pure-functions

Conversation

@intricate
Copy link
Copy Markdown
Contributor

@intricate intricate commented May 18, 2025

Closes #187

Defines the following functions as pure:

  • Sel.Hashing.hashByteString
  • Sel.Hashing.SHA256.hashByteString
  • Sel.Hashing.SHA512.hashByteString
  • Sel.Hashing.Short.hashByteString
  • Sel.Hashing.Password.hashByteStringWithParams
  • Sel.HMAC.SHA256.authenticate
  • Sel.HMAC.SHA512.authenticate
  • Sel.HMAC.SHA512_256.authenticate
  • Sel.SecretKey.Authentication.authenticate

@Kleidukos
Copy link
Copy Markdown
Member

@intricate I'll merge when CI is green, good job!

Comment on lines +165 to +173
-- Note that, if @libsodium@ is compiled with the @ED25519_NONDETERMINISTIC@
-- macro defined, this function will produce non-deterministic (but also
-- non-standard) Ed25519 signatures. If @libsodium@ hasn't been compiled with
-- the @ED25519_NONDETERMINISTIC@ macro defined, it's safe to call this
-- function in a pure context with 'unsafeDupablePerformIO'.
--
-- For more information, see the
-- [@libsodium@ docs](https://doc.libsodium.org/public-key_cryptography/public-key_signatures#notes).
--
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Kleidukos: how do you feel about this comment?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent.

@intricate
Copy link
Copy Markdown
Contributor Author

Deleted my previous comment to avoid muddying the waters with a non-issue that I brought up 😁


Outside of Sel.PublicKey.Signature.signMessage, it seems safe to define all of these functions as pure.

As we know, libsodium makes heavy use of "out" parameters, so technically none of this stuff is truly pure. However, apart from mutating buffers and whatnot (of course, not mutating any of the "in" parameters), there doesn't appear to be anything else that's secretly stateful. So I think it's probably safe to just call these functions pure.

@Kleidukos Kleidukos merged commit a6e7938 into haskell-cryptography:main May 19, 2025
15 checks passed
@Kleidukos
Copy link
Copy Markdown
Member

@intricate Thank you very much for you recent contributions. I believe this was the last PR needed to release a new major version of sel. :)

@intricate intricate deleted the pure-functions branch May 19, 2025 13:51
Kleidukos added a commit that referenced this pull request May 20, 2025
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.

Pure cryptographic functions in sel

2 participants