SE050: NIST Key Wrapping using secure element

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SE050: NIST Key Wrapping using secure element

830 Views
Zarein94
Contributor II

Hi,

I am trying to replicate a software-crypto module to use the secure element (SE050). The way the design works is that, the crypto module is initialized with a dmk key and three other keys as (dck, dkek, cpk) are derived from this key. After deriving these keys, they are transient keys in host krypto and I store them in the SE key store to use the dck for aead encryption and decryption. (Till here works fine)(If you see any problem or have any point about these steps please share with me)! 

Now, A new wrapped key is received which has to be unwrapped using the dkek(kek) key ( I can retrieve the key object of the dkek which I derived and stored beforehand). After unwrapping the crpyto-module is initialized with this new unwrapped key and the other keys are derived again. I am not able to find my on how to implement this nist unwrapping using secure element. Here's the mbedTLS code version which I want to implement it using the secure element. Could you give me some hints or is there an example? 

kek_ is the dkek key. 

 

nist_unwrap(AES128Key *&key, octet *wrapped_key, size_t len_wrapped_key) {
   mbedtls_nist_kw_context ctx;

    //Initialise key-wrap context
    mbedtls_nist_kw_init(&ctx);
    //Set up the context
    int res = mbedtls_nist_kw_setkey(&ctx, MBEDTLS_CIPHER_ID_AES, kek_->key_, kek_->length_, KWMODE_UNWRAP);
    if (res) {
        mbedtls_nist_kw_free(&ctx);
        return res;
    }

    auto output = new octet[len_wrapped_key];
    size_t len_output;
    res = mbedtls_nist_kw_unwrap(&ctx, MBEDTLS_KW_MODE_KW,
                                 wrapped_key,
                                 len_wrapped_key, /* here the length is NOT!!!! in the number of semiblocks, doc is wrong*/
                                 output, &len_output,
                                 len_wrapped_key);

    mbedtls_nist_kw_free(&ctx);
    if (res) {
        if (res == MBEDTLS_ERR_CIPHER_AUTH_FAILED) {
            return -2;
        } else {
            return res;
        }
    }

    // set the key with the found.
    return deserializeKeyHeader(key, output, len_output);

}

 



0 Kudos
Reply
1 Reply

771 Views
Kan_Li
NXP TechSupport
NXP TechSupport

Hi @Zarein94 ,

 

Actually neither MW nor SDK has a separate NIST KW demo.

But there is a self-test, placed in  middleware\mbedtls\library\nist_kw.c in the mbedtls_nist_kw_self_test() function. It can be used as a demo example.

The NIST KW API is very clear https://mbed-tls.readthedocs.io/projects/api/en/development/api/file/nist__kw_8h/

And AES is HW accelerated on all platforms.

 

Hope that helps,

 

Have a great day,
Kan


-------------------------------------------------------------------------------
Note:
- If this post answers your question, please click the "Mark Correct" button. Thank you!
- We are following threads for 7 weeks after the last post, later replies are ignored
Please open a new thread and refer to the closed one, if you have a related question at a later point in time.
-------------------------------------------------------------------------------

0 Kudos
Reply