This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] CC2745R10-Q1:关于 PSA API

Guru**** 2535150 points
Other Parts Discussed in Thread: CC2745R10-Q1

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/wireless-connectivity/bluetooth-group/bluetooth/f/bluetooth-forum/1566039/cc2745r10-q1-about-the-psa-api

器件型号:CC2745R10-Q1


工具/软件:

您好:

我的环境如下:
板:CC2745R10-Q1
调试器:XDS110
SDK:SimpleLink Lowpower f3 ver.9.10.00.83
IDE:IAR Embedded Workbench for ARM 9.60.3.7274

PSA API 基本上被识别为同步 API、但如果您要使用异步处理或回调、该怎么办?

是否可以使用 PSA API 实现以下示例代码示例[在回调返回模式下使用明文加密密钥的单调用 CBC 解密]?
TI/simplelink_lowpower_f3_SDK_9_10_00_83/docs/secure_drivers/doxygen/html/_a_e_s_c_b_c_8h.html

#include <ti/drivers/AESCBC.h>
#include <ti/drivers/cryptoutils/cryptokey/CryptoKeyPlaintext.h>
...
// Test vector 0 from NIST CAPV set CBCMMT256
uint8_t iv[16] =                {0xdd, 0xbb, 0xb0, 0x17, 0x3f, 0x1e, 0x2d, 0xeb,
                                 0x23, 0x94, 0xa6, 0x2a, 0xa2, 0xa0, 0x24, 0x0e};
uint8_t ciphertext[16] =        {0xd5, 0x1d, 0x19, 0xde, 0xd5, 0xca, 0x4a, 0xe1,
                                 0x4b, 0x2b, 0x20, 0xb0, 0x27, 0xff, 0xb0, 0x20};
uint8_t keyingMaterial[32] =    {0x43, 0xe9, 0x53, 0xb2, 0xae, 0xa0, 0x8a, 0x3a,
                                 0xd5, 0x2d, 0x18, 0x2f, 0x58, 0xc7, 0x2b, 0x9c,
                                 0x60, 0xfb, 0xe4, 0xa9, 0xca, 0x46, 0xa3, 0xcb,
                                 0x89, 0xe3, 0x86, 0x38, 0x45, 0xe2, 0x2c, 0x9e};
uint8_t plaintext[sizeof(ciphertext)];
// The plaintext should be the following after the decryption operation:
//  0x07, 0x27, 0x0d, 0x0e, 0x63, 0xaa, 0x36, 0xda
//  0xed, 0x8c, 0x6a, 0xde, 0x13, 0xac, 0x1a, 0xf1
void cbcCallback(AESCBC_Handle handle,
                 int_fast16_t returnValue,
                 AESCBC_OperationUnion *operation,
                 AESCBC_OperationType operationType) {
    if (returnValue != AESCBC_STATUS_SUCCESS) {
        // handle error
    }
    if (operationType == AESCBC_OPERATION_TYPE_DECRYPT ||
        operationType == AESCBC_OPERATION_TYPE_ENCRYPT) {
        // do something with operation->oneStepOperation
    } else {
        // do something with operation->segmentedOperation
    }
}
AESCBC_OneStepOperation operation;
void cbcStartFunction(void) {
    AESCBC_Handle handle;
    AESCBC_Params params;
    CryptoKey cryptoKey;
    int_fast16_t decryptionResult;
    AESCBC_Params_init(&params);
    params.returnBehavior = AESCBC_RETURN_BEHAVIOR_CALLBACK;
    params.callbackFxn = cbcCallback;
    handle = AESCBC_open(0, &params);
    if (handle == NULL) {
        // handle error
    }
    CryptoKeyPlaintext_initKey(&cryptoKey, keyingMaterial, sizeof(keyingMaterial));
    AESCBC_OneStepOperation_init(&operation);
    operation.key               = &cryptoKey;
    operation.input             = ciphertext;
    operation.output            = plaintext;
    operation.inputLength       = sizeof(ciphertext);
    operation.iv                = iv;
    decryptionResult = AESCBC_oneStepDecrypt(handle, &operation);
    if (decryptionResult != AESCBC_STATUS_SUCCESS) {
        // handle error
    }
    // do other things while CBC operation completes in the background
}

此致、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    您可以阅读 F3 SDK 的 PSA 安全驱动程序的 API 和文档、它将指导您创建 CryptoKey 对象。 该对象可以是纯文本(如您共享的示例中)、也可以是从 PSA API 生成的加密密钥。

    拥有加密密钥后、就可以 像通常一样将其与 AESCBC 函数一起使用。

    此致、
    Maxence

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    实际上、有关 PSA 的用户指南有一个 Simplelink API 到 PSA API 映射表、这应该非常有用。

    例如、在您的用例中、  PSA_密码 解密  函数等效于调用  KEYSTORAGE_PSA_initKey 和  AESCBC_oneStepDecrypt  根据表。

    此致、
    Lea

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好:

    在另一个问答中、我收到了如下建议使用 PSA API 的答案、因此我正在考虑仅使用 PSA API 来实现它。
    我想使用异步处理和回调处理、但这是否可行?
    如果是、请告诉我如何实现这一点。

     CC2745R10-Q1:请确认使用 ECDH_generatePublicKey 

    “您只能使用 PSA、而不能使用 SimpleLink API。 它们不兼容。

    如果要使用 SimpleLink API、则不能使用 PSA 或 Keystore。

    未来将弃用 SimpleLink 加密驱动程序。“

    此致、

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    您好!

    如果您查看 C:\ti\simplelink_lowpower_f3_SDK_9_11_00_18\source\third_party\PSA_crypto\PSA_crypto_wrapper.c 中的代码、您将看到 PSA_crypto_Decuty 当前正在使用  KEYSTORAGE_PSA_initKey  和  AESCBC_oneStepDecrypt  就功能而言。

    在您链接的线程中、NIMA 是正确的:我们的 PSA 实施方案是围绕我们当前用于加密的 SimpleLink 安全驱动程序 API 的包装器。 将来、此 SimpleLink API 可能会发生变化、因此 仅使用 PSA 函数将使您的软件更符合未来 SDK 更新的要求 。  

    至于同步、我们的 PSA 实现是同步的、并且所有操作都是阻塞的。 具体而言,您可以在 PSA_CRrypto_init 函数中看到 AESCBC 是在阻塞模式下设置的:  
      

    我们的 PSA 实现严格遵循 PSA API 规范、该规范是同步的。 如果我们的 PSA 实现是异步的、那么我们偏离了 PSA 规范。 有些人提出了与您一样的担忧、但这 目前不在 PSA 或 mbed-TLS的范围内。

    打开了 目前、无法在非阻塞模式下仅使用 PSA 函数来调用 AESCBC 等加密函数

    使用非阻塞模式的唯一选项是使用 SimpleLink API 加密功能、该功能不应与 PSA 函数结合使用。 我会要求 NIMA 同时使用 KeyStorage 和 SimpleLink API。

    此致、
    Maxence