Wander Nauta Wander Nauta - 1 month ago 7
C Question

How do I correctly use libsodium so that it is compatible between versions?

I'm planning on storing a bunch of records in a file, where each record is then signed with libsodium. However, I would like future versions of my program to be able to check signatures the current version has made, and ideally vice-versa.

For the current version of Sodium, signatures are made using the Ed25519 algorithm. I imagine that the default primitive can change in new versions of Sodium (otherwise libsodium wouldn't expose a way to choose a particular one, I think).

Should I...


  1. Always use the default primitive (i.e.
    crypto_sign
    )

  2. Use a specific primitive (i.e.
    crypto_sign_ed25519
    )

  3. Do (1), but store the value of
    sodium_library_version_major()
    in the file (either in a dedicated 'sodium version' field or a general 'file format revision' field) and quit if the currently running version is lower

  4. Do (3), but also store
    crypto_sign_primitive()

  5. Do (4), but also store
    crypto_sign_bytes()
    and friends



...or should I do something else entirely?

My program will be written in C.

Answer

Just use the high-level API.

Functions from the high-level API are not going to use a different algorithm without the major version of the library being bumped.

The only breaking change one can expect in libsodium 1.x.y is the removal of deprecated/undocumented functions (that don't even exist in current releases compiled with the --enable-minimal switch). Everything else will remain backward compatible.

New algorithms might be introduced in 1.x.y versions without high-level wrappers, and will be stabilized and exposed via a new high-level API in libsodium 2.

Therefore, do not bother calling crypto_sign_ed25519(). Just use crypto_sign().

Comments