On 3 March 2018 at 02:22, Hernán Morales Durand <hernan.mora...@gmail.com>
wrote:

> Hi
>
> 2018-03-02 11:24 GMT-03:00 Esteban A. Maringolo <emaring...@gmail.com>:
> > 2018-03-02 8:54 GMT-03:00 Ben Coman <b...@openinworld.com>:
> >
> >> On 2 March 2018 at 10:43, Esteban A. Maringolo <emaring...@gmail.com>
> wrote:
> >
> >>> So after all this what's the recommended way to use HMAC-SHA512 in
> Pharo
> >>> 6?
> >
> >> Libsodium installation instructions...
> >> https://github.com/Traadh/bittrex
> >
> > Why did you create  BittrexLibsodium library wrapper instead of a
> > plain Libsodium wrapper like the one at
> > http://smalltalkhub.com/#!/~tonyg/Crypto-Nacl/ ?
>

If that is the one available from the Pharo Catalog, when I tried it, it
used a different api than the libsodium library supplied by Ubuntu 16.04.

It makes this call out...
   crypto_hash_sha512_ref()
but Ubuntu libsodium library did not export that, but instead...
  crypto_hash_sha512()

I failed to track down the implications of the "_ref",
and at that time Crypto-Nacl did not supply a 64-bit library,
so a single FFI matching the system supplied libsodium library was easier.
Also as a minor policy, I prefer to use the system library than one
compiled by a third-party.

cheers -ben




>
> >
>
> I inspected the Nacl library and it provides the functions:
>
> crypto_auth_hmacsha256
> crypto_auth_hmacsha256_bytes
> crypto_auth_hmacsha256_keybytes
> crypto_auth_hmacsha256_primitive
> crypto_auth_hmacsha256_ref
> crypto_auth_hmacsha256_ref_verify
> crypto_auth_hmacsha256_verify
> crypto_auth_hmacsha512256
> crypto_auth_hmacsha512256_bytes
> crypto_auth_hmacsha512256_keybytes
> crypto_auth_hmacsha512256_primitive
> crypto_auth_hmacsha512256_ref
> crypto_auth_hmacsha512256_ref_verify
> crypto_auth_hmacsha512256_verify
>
> I've also followed the Ben's example in Nacl but the output is truncated
>
> | data message output key expected |
> data := 'Hi There' .
> key := (ByteArray readHexFrom:
>                 '0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b',
>                 '0b0b0b0b') extendedToSize: 32.
> expected := ByteArray readHexFrom:
>                     '87aa7cdea5ef619d4ff0b4241a1d6cb0',
>                     '2379f4e2ce4ec2787ad0b30545e17cde',
>                     'daa833b7d6b8a702038b274eaea3f4e4',
>                     'be9d914eeb61f1702e696c203a126854'.
> output := ByteArray new: 64.
> Nacl apiCryptoAuthHMAC512: output
>         message: data
>         messageLength: data size
>         key: key.
> output
>
>

Just off the top of my head, should the following method properly be named
apiCryptoAuthHMAC512256:message:messageLength:key:
to match the library function its calling?


> Nacl class>>apiCryptoAuthHMAC512: c message: m messageLength: mlen key:
> key


>     ^ self
>         ffiCall: #(long crypto_auth_hmacsha512256(byte * c, byte * m,
> ulonglong mlen, byte * key))
>         module: 'libsodium'.
>
> Ben do you know what could be happening here?
>
>
By how much is it truncated? Perhaps half?
https://dirvine.github.io/data_chain/master///rust_sodium_sys/constant.crypto_auth_hmacsha512_BYTES.html
https://dirvine.github.io/data_chain/master///rust_sodium_sys/constant.crypto_auth_hmacsha512256_BYTES.html


cheers -ben

Reply via email to