NaCl/libsodium binding for Pharo and Squeak

I’ve just written Pharo/Squeak bindings to libsodium, which is a portable shared-library version of the NaCl cryptography library. A good description of the motivation of the library is this PDF.

Installing the software

To use the bindings, you will need to install the Monticello package Crypto-Nacl from http://smalltalkhub.com/mc/tonyg/Crypto-Nacl/main. The bindings depend on the FFI, so that must be installed.

From within Squeak:

(Installer repository: 'http://source.squeak.org/FFI')
   install: 'FFI-Pools';
   install: 'FFI-Kernel';
   install: 'FFI-Tests'.

(Installer repository: 'http://smalltalkhub.com/mc/tonyg/Crypto-Nacl/main')
   install: 'Crypto-Nacl'.

Most importantly, you will need a version of libsodium for your Smalltalk VM. Because most Squeak/Pharo VMs are 32-bit, you will need to get hold of a 32-bit libsodium. I’ve prebuilt some:

  • OS X, 32-bit VMs: libsodium.dylib.gz
    • decompress and put this in either
      • Squeak.app/Contents/Resources/libsodium (note: no extension!) for the Squeak VM, or
      • Pharo.app/Contents/MacOS/Plugins/libsodium (note: no extension!) for the Pharo VM.
  • Linux, 32-bit VMs: libsodium.so.gz
    • decompress and place the libsodium.so file in the same directory as vm-display-X11 and friends.
Compiling your own libsodium (optional)

Compiling libsodium to work with Squeak/Pharo can be tricky:

  • On OS X, configure libsodium with ./configure CFLAGS=-m32 to build a 32-bit version.

  • On 32-bit linux, ordinary ./configure works just fine, but I haven’t yet managed to get things working on a 64-bit linux. If anyone tries 64-bit and manages to get it to work, please let me know!

  • I haven’t tried it on Windows at all. Please let me know if you try this, and how it goes, either success or failure.

Running the tests

On the Smalltalk side, once you’ve loaded the .mcz, open a Test Runner and select the Crypto-Nacl tests. With Crypto-Nacl-tonyg.4, there should be 12 tests, and they should all pass if the shared library can be found in the right place.

You can also try it out in a Workspace: a printIt of Nacl sodiumVersionString will yield '0.3' or '0.4.1', depending on which version of libsodium you have.

Enjoy!

Comments (closed)
Ken Dickey 18:37, 11 Aug 2013

Ported to Cuis Smalltalk 4.2 < https://github.com/Cuis-Smallt... >

https://github.com/KenDickey/C...

Thanks a bunch!!

-KenD < Ken [dot] Dickey [at] whidbey [dot] com >

Tony Garnock-Jones 18:56, 11 Aug 2013 (in reply to this comment)

Thanks, Ken! That's great.