Previously, no timeout or an arbitrary timeout (500ms) was used. This
usually works but causes some issues when operations take longer: for
example, during `mifare_desfire_format_picc`.
This changes increases the previous default timeout to two seconds and
adds a new function that allows setting custom timeouts.
This commit fixes issue #91.
[AN10922][] specifies the key diversification algorithms used by the
MIFARE SAM AV3. Support for these algorithms was added to
`libfreefare` via pull-request #79.
However, while every attempt was made to write a faithful
implementation, the implemented code did not properly handle cases
where the diversification data was less than or equal to the block
size of the cipher: 16 bytes for AES, and 8 bytes for DES. This
bug was identified in issue #91.
This commit addresses this problem while providing a way to revert to
the previous behavior in cases where it is necessary to maintain
previous deployments. This was accomplished by introducing a new
`flags` parameter to the `mifare_key_deriver_new_an10922` method.
Normally, `flags` should simply be set to `AN10922_FLAG_DEFAULT`.
However, if the previous behavior is required, it should be set to
`AN10922_FLAG_EMULATE_ISSUE_91`.
[AN10922][] does not include any test vectors that might have helped to
identify this problem earlier. However, [AN10957][] (pages 13-14) was
found to have a suitable example usage of [AN10922][] with an
appropriately short value for *M* that we are using as a test vector
to verify correct behavior.
Note that the issue being addressed here is not a security issue:
using the `AN10922_FLAG_EMULATE_ISSUE_91` should not be any less
secure than using `AN10922_FLAG_DEFAULT`.
[AN10922]: https://www.nxp.com/docs/en/application-note/AN10922.pdf
[AN10957]: https://www.nxp.com/docs/en/application-note/AN10957.pdf
Fix build issue:
```
/tmp/libfreefare/libfreefare/ntag21x.c:718:5: error: array index 1 is past the end of the array
(which contains 1 element) [-Werror,-Warray-bounds]
cmd_step1[1] = 0x00;
^ ~
/tmp/libfreefare/libfreefare/ntag21x.c:715:5: note: array 'cmd_step1' declared here
uint8_t cmd_step1[1];
^
1 error generated.
```
Fix build issue:
```
/tmp/libfreefare/libfreefare/felica.c:50:16: error: implicitly declaring library
function 'malloc' with type 'void *(unsigned long)'
[-Werror,-Wimplicit-function-declaration]
if ((tag = malloc(sizeof(struct felica_tag)))) {
^
/tmp/libfreefare/libfreefare/felica.c:50:16: note: include the header <stdlib.h>
or explicitly provide a declaration for 'malloc'
/tmp/libfreefare/libfreefare/felica.c:64:5: error: implicit declaration of
function 'free' is invalid in C99
[-Werror,-Wimplicit-function-declaration]
free(tag);
^
2 errors generated.
```
There are a few reasons why an NFC operation may timeout, including
the pn533 USB toggle bit bug. In that case it helps to report the
problem to calling process so that it can retry operation, instead
of hanging forever.
For instance, mifare_desfire_format_picc() may make the chip
unresponsive (see commit 91d3ff9cc4),
but if calling process gets ETIMEDOUT, it can select_application,
authenticate and format_picc again, with some success.
- Change default tag from NTAG_213 to NTAG_UNKNOWN so unknown tags can
be detected. ntag_get_info() MUST be called after connect;
- Fix reuse function which used to reset all tag info;
- Introduce ntag21x error reporting through freefare_error(3);
In addition to adding tests for the bugs addressed via #70,
this commit also addresses a key corruption bug that would
occur on 3DES keys when `mifare_desfire_key_set_version()`
was called.
No objection for a year, I guess anyone is fine with the `COPYING` file in the repository root directory and relying on git to determine who wrote what piece of code.