Closed JanAhrens closed 10 years ago
The Nonce
interface was a little experimental. The thought was that it's
broadly really important to ensure uniqueness, so the use of nonces would
somehow drive that.
But I wouldn't mind relaxing that, at least with a warning. Perhaps it
should just be that the type constructors are exported in an Internal
module.
If you'd like to experiment with this, please feel free to send pull requests.
On Sat, Jun 28, 2014 at 8:34 AM, JanAhrens notifications@github.com wrote:
I'm trying to implement a NaCl based protocol. It requires to use nonces that are generated by concatenating a nonce-prefix and a counter. For example:
noncePrefix = "abcdefghijklmnop"counter = 1nonce = generateNonce noncePrefix counter # => "abcdefghijklmnop00000001"
My problem is that I'm unable to use my own nonces with the secretbox function, because I can't create the Nonce type. Internally Nonce is implemented https://github.com/tel/saltine/blob/master/src/Crypto/Saltine/Core/SecretBox.hs#L71 as a newtype for ByteString, but the constructor can only be used inside the Crypto.Saltine.Core.SecretBox package.
If you agree that this is a valid use case, I'd like to send a pull-request that exposes the Nonce type constructor for the Nonce types in Crypto.Saltine.Core.SecretBox, Crypto.Saltine.Core.Box and Crypto.Saltine.Core.Stream.
— Reply to this email directly or view it on GitHub https://github.com/tel/saltine/issues/16.
Thanks for your quick response!
The
Nonce
interface was a little experimental. The thought was that it's broadly really important to ensure uniqueness, so the use of nonces would somehow drive that.
That makes sense. I'll try to make that clear when I change the API.
I also saw that in the message
branch the internal implementation of Nonce
was changed from ByteString
to Vector Word8
. To make sure that this change can happen in a compatible manner, I'll probably write and export a ByteString -> Nonce
function.
Message was an old experiment. I don't think it's worth spending effort to be compatible with it.
It actually works already. I don't need to send a pull-request :smiley:
While reading through the tests I learned about the Cypto.Saltine.Class.decode
function from the IsEncoding
typeclass. Using this I can implement my use-case:
noncePrefix = "abcdefghijklmnop"
counter = 1
nonce = fromJust (encode $ generateNonce noncePrefix counter :: Maybe Nonce)
I'm closing this issue myself.
Alright, excellent!
If you feel like it'd be helpful, feel free to patch the documentation as well.
I'm trying to implement a NaCl based protocol. It requires to use nonces that are generated by concatenating a nonce-prefix and a counter. For example:
My problem is that I'm unable to use my own nonces with the
secretbox
function, because I can't create theNonce
type. InternallyNonce
is implemented as anewtype
for ByteString, but the constructor can only be used inside theCrypto.Saltine.Core.SecretBox
package.If you agree that this is a valid use case, I'd like to send a pull-request that exposes the
Nonce
type constructor for the Nonce types inCrypto.Saltine.Core.SecretBox
,Crypto.Saltine.Core.Box
andCrypto.Saltine.Core.Stream
.