libpqcrypto

The C API follows the principles of the NaCl/TweetNaCl/SUPERCOP/libsodium API, and in particular supports the previously defined crypto_sign and crypto_kem interfaces. However, to avoid namespace conflicts with NaCl, libpqcrypto uses pqcrypto_* names instead of crypto_* names. For example, put the following code into testsign.c:

    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include "pqcrypto_sign_mqdss64.h"

    unsigned char pk[pqcrypto_sign_mqdss64_PUBLICKEYBYTES];
    unsigned char sk[pqcrypto_sign_mqdss64_SECRETKEYBYTES];

    #define mlen 7
    unsigned char m[mlen] = "hello\n";
    unsigned char sm[pqcrypto_sign_mqdss64_BYTES + mlen];
    unsigned long long smlen;
    unsigned char t[sizeof sm];
    unsigned long long tlen;

    int main()
    {
      if (pqcrypto_sign_mqdss64_keypair(pk,sk)) abort();
      if (pqcrypto_sign_mqdss64(sm,&smlen,m,mlen,sk)) abort();
      if (pqcrypto_sign_mqdss64_open(t,&tlen,sm,smlen,pk)) abort();
      if (tlen != mlen) abort();
      if (memcmp(t,m,mlen)) abort();
      return 0;
    }

Compile and run as follows:

    gcc -o testsign testsign.c \
      -I /home/libpqcrypto/include \
      -L /home/libpqcrypto/lib -Wl,-rpath=/home/libpqcrypto/lib \
      -lpqcrypto
    ./testsign && echo ok

The output will be ok.

If you have also compiled x86 libraries on an amd64 machine, you can compile in 32-bit mode as follows:

    gcc -m32 -o testsign testsign.c \
      -I /home/libpqcrypto/include \
      -L /home/libpqcrypto/lib-x86 -Wl,-rpath=/home/libpqcrypto/lib-x86 \
      -lpqcrypto

libpqcrypto does not include NaCl-type selection of default primitives. The caller needs to select which pqcrypto_sign function to use and which pqcrypto_kem function to use.

Some of the software included in libpqcrypto uses malloc and is not suitable for environments that control memory usage statically.


Version: This is version 2018.03.14 of the "C API" web page.