MBED_TLS 返回错误 0xFFFFBC80

MBED_TLS returning an error of 0xFFFFBC80

使用 mbded_tls 库,我收到从 0xFFFFBC80 设备返回的错误代码。我假设前导 F 是无关紧要的,但我在文档中找不到 BC80(或其倒数,4380)的任何错误代码。我可以看到文档中提到了高级代码和低级代码的总和,但要精确定位并不容易。该错误几乎可以肯定与使用私钥签名的签名文件的验证有关,并由设备使用 public 密钥进行检查,但没有更具体的细节,我无法确定我的错误所在。

此致,

0xFFFFBC80

来自mbed_tls/error.h

 * Currently we try to keep all error codes within the negative space of 16
 * bits signed integers to support all platforms (-0x0001 - -0x7FFF). In
 * addition we'd like to give two layers of information on the error if
 * possible.
 *
 * For that purpose the error codes are segmented in the following manner:
 *
 * 16 bit error code bit-segmentation
 *
 * 1 bit  - Unused (sign bit)
 * 3 bits - High level module ID
 * 5 bits - Module-dependent error code
 * 7 bits - Low level module errors

0xFFFFBC80-0x4380 也就是二进制 0100 0011 1000 0000

这给了我们:

 - 1 bit unused - 0
 - 3 bits high level module id - 0b100
 - 5 bits module dependent error code - 0b00111
 - 7 bits low level module errors  - 0b0000000

现在我们可以专注于查找和解释单个位并阅读 mbed_tls 来源...或者只是做个聪明人并在 mbed_tls 来源上做 grep -r 4380,这将产生rsa.h 中的行:

 #define MBEDTLS_ERR_RSA_VERIFY_FAILED                     -0x4380  /**< The PKCS#1 verification failed. */

因此您的代码中的 PKCS#1 验证失败。

但是,说真的,为什么要手工做呢?您可以只使用 mbedtls_strerror 函数:

char buf[1024];
mbedtls_strerror(0xFFFFBC80, buf, sizeof(buf));
printf("result: %s\n", buf);