| 1 |
SealedBox reference vectors |
| 2 |
^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
| 3 |
|
| 4 |
Since libsodium's tests do not provide reference data for the SealedBox |
| 5 |
construction, the implementation is verified with a ``sealbox_test_vectors`` |
| 6 |
utility program that produces and checks custom test vectors |
| 7 |
by making specific calls to libsodium API. |
| 8 |
|
| 9 |
To build the ``sealbox_test_vectors`` you need a ``C`` language compiler, |
| 10 |
a prebuilt libsodium library more recent than version 1.0.3 and the |
| 11 |
corresponding include headers. |
| 12 |
|
| 13 |
In a UNIX-like programming environment you should then execute: |
| 14 |
|
| 15 |
.. code-block:: bash |
| 16 |
|
| 17 |
$ cc -o sealbox_test_vectors sealbox_test_vectors.c -lsodium -lc |
| 18 |
|
| 19 |
If you prefer using a locally compiled installation of the bundled sources, |
| 20 |
refer to :ref:`building-a-local-library` and then run: |
| 21 |
|
| 22 |
.. code-block:: bash |
| 23 |
|
| 24 |
$ cc -o sealbox_test_vectors sealbox_test_vectors.c \ |
| 25 |
${SODIUMINCL} ${SODIUMLIB} -lsodium -lc |
| 26 |
|
| 27 |
Vector generation |
| 28 |
""""""""""""""""" |
| 29 |
|
| 30 |
When called with one or more command line arguments, ``sealbox_test_vectors`` |
| 31 |
will generate the number of hex-encoded vectors requested as first argument, |
| 32 |
with the optional second and third arguments influencing the length of the |
| 33 |
randomly generated messages: |
| 34 |
|
| 35 |
.. code-block:: bash |
| 36 |
|
| 37 |
$ ./sealbox_test_vectors 1 |
| 38 |
XXXX... XXXX... <len>:XXXX... <len>:XXXX... |
| 39 |
|
| 40 |
The second argument, if present, sets both a minimum and a maximum length |
| 41 |
on generated messages, overriding the default 128 bytes values |
| 42 |
respectively with the supplied value and with twice the supplied value. |
| 43 |
|
| 44 |
The third argument, if present, sets the maximum length of generated |
| 45 |
messages. |
| 46 |
|
| 47 |
Vector test |
| 48 |
""""""""""" |
| 49 |
|
| 50 |
When called without command line arguments, ``sealbox_test_vectors`` |
| 51 |
will parse and hex-decode the lines given as standard input and |
| 52 |
check if decoding the encrypted message will return the original |
| 53 |
message. A "OK"/"FAIL" tag will be appended to the input line to |
| 54 |
signify success/failure of the test. |
| 55 |
|
| 56 |
To check correct "round-trip" behavior, you can run ``sealbox_test_vectors`` |
| 57 |
as a test vector generator against itself: |
| 58 |
|
| 59 |
.. code-block:: bash |
| 60 |
|
| 61 |
$ ./sealbox_test_vectors 1 | ./sealbox_test_vectors |
| 62 |
XXXX... XXXX... <len>:XXXX... <len>:XXXX... OK |
| 63 |
|
| 64 |
If you want to check the vectors distributed with PyNaCl's sources, |
| 65 |
after setting the environment variable ``PYNACL_BASE`` to the directory |
| 66 |
where the unpacked source for PyNaCl has been extracted/cloned, |
| 67 |
you could run: |
| 68 |
|
| 69 |
.. code-block:: bash |
| 70 |
|
| 71 |
$ ./sealbox_test_vectors < ${PYNACL_BASE}/tests/data/sealed_box_ref.txt |
| 72 |
77076d ... 8c86 OK |
| 73 |
|
| 74 |
|
| 75 |
Source code for the vector checker utility |
| 76 |
"""""""""""""""""""""""""""""""""""""""""" |
| 77 |
|
| 78 |
The source code for ``sealbox_test_vectors`` is available inside |
| 79 |
the ``docs/vectors/c-source`` directory of PyNaCl distribution |
| 80 |
and can also be directly downloaded from |
| 81 |
:download:`sealbox_test_vectors.c <./c-source/sealbox_test_vectors.c>`. |
| 82 |
|
| 83 |
.. |
| 84 |
put the and... sentence under a ..only:: builder_html |
| 85 |
when readthedocs begins to correctly support the directive |
| 86 |
|
| 87 |
.. literalinclude:: c-source/sealbox_test_vectors.c |
| 88 |
:language: c |
| 89 |
:caption: sealbox_test_vectors.c |