csec的key更新

在对csec的使用中(其他遵循hsm key update协议的芯片也适用),kdf的运算过程中遇到的数据都是128bit。不需要考虑padding的问题。
目前并没有找到对padding的一致性的处理方式。

对于Miyaguchi-Preneel compression的具体计算过程,Wikipedia中存在相应的算法解释。

https://en.wikipedia.org/wiki/One-way_compression_function

AES的CBC模式:

    mbedtls_aes_context aes;
    mbedtls_aes_init( &aes );
    ret = mbedtls_aes_setkey_enc( &aes, k1, 128u );
    ret = mbedtls_aes_crypt_cbc( &aes, MBEDTLS_AES_ENCRYPT, ATOMIC_BUFSIZE*2, IV_zero, data_connected, pM2); /*  */
    mbedtls_aes_free( &aes );

AES的ECB模式:

    mbedtls_aes_context aes;
    mbedtls_aes_init( &aes );
    ret = mbedtls_aes_setkey_enc( &aes, tempIV, 128u );
    ret = mbedtls_aes_crypt_ecb( &aes, MBEDTLS_AES_ENCRYPT, key, tempENC_Text);
    mbedtls_aes_free( &aes );

CMAC算法:

    const mbedtls_cipher_info_t *cipher_info;

    cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_AES_128_ECB );
    ret = mbedtls_cipher_cmac( cipher_info, k2, 128u, data_connected, M1_SIZE + M2_SIZE, pM3);

注意,CMAC的计算模式也是CBC模式,由于CBC模式的初始化向量必然要用到,相关的NIST公开规范中规定初始化向量为全零值。

/* The Fid can be considered as always 6bits. no matter the SFE is 0x00 or 0x01.
* Align the Fid to the leftest postion.
*
* */

 

posted @ 2022-09-13 14:35  panrui  阅读(324)  评论(0)    收藏  举报