Ignore:
Timestamp:
Jun 22, 2021, 9:00:19 PM (3 years ago)
Author:
coas-nagasima
Message:

WolfSSLとAzure IoT SDKを更新

Location:
azure_iot_hub_f767zi/trunk/wolfssl-4.7.0
Files:
1 edited
1 moved

Legend:

Unmodified
Added
Removed
  • azure_iot_hub_f767zi/trunk/wolfssl-4.7.0/src/keys.c

    r457 r464  
    10751075        ssl->specs.pad_size              = PAD_SHA;
    10761076        ssl->specs.static_ecdh           = 0;
    1077         ssl->specs.key_size              = WC_SHA256_DIGEST_SIZE / 2;
     1077        ssl->specs.key_size              = WC_SHA256_DIGEST_SIZE;
    10781078        ssl->specs.block_size            = 0;
    10791079        ssl->specs.iv_size               = HMAC_NONCE_SZ;
     
    10931093        ssl->specs.pad_size              = PAD_SHA;
    10941094        ssl->specs.static_ecdh           = 0;
    1095         ssl->specs.key_size              = WC_SHA384_DIGEST_SIZE / 2;
     1095        ssl->specs.key_size              = WC_SHA384_DIGEST_SIZE;
    10961096        ssl->specs.block_size            = 0;
    10971097        ssl->specs.iv_size               = HMAC_NONCE_SZ;
     
    29102910            }
    29112911
     2912            if (enc) {
     2913                if (wc_HmacInit(enc->hmac, heap, devId) != 0) {
     2914                    WOLFSSL_MSG("HmacInit failed in SetKeys");
     2915                    XFREE(enc->hmac, heap, DYNAMIC_TYPE_CIPHER);
     2916                    enc->hmac = NULL;
     2917                    return ASYNC_INIT_E;
     2918                }
     2919            }
     2920
    29122921            if (dec && dec->hmac == NULL) {
    29132922                dec->hmac = (Hmac*)XMALLOC(sizeof(Hmac), heap,
     
    29172926            }
    29182927
    2919             if (enc) {
    2920                 if (wc_HmacInit(enc->hmac, heap, devId) != 0) {
    2921                     WOLFSSL_MSG("HmacInit failed in SetKeys");
    2922                     return ASYNC_INIT_E;
    2923                 }
    2924             }
    29252928            if (dec) {
    29262929                if (wc_HmacInit(dec->hmac, heap, devId) != 0) {
    29272930                    WOLFSSL_MSG("HmacInit failed in SetKeys");
     2931                    XFREE(dec->hmac, heap, DYNAMIC_TYPE_CIPHER);
     2932                    dec->hmac = NULL;
    29282933                    return ASYNC_INIT_E;
    29292934                }
     
    29322937            if (side == WOLFSSL_CLIENT_END) {
    29332938                if (enc) {
     2939                    XMEMCPY(keys->aead_enc_imp_IV, keys->client_write_IV,
     2940                            HMAC_NONCE_SZ);
    29342941                    hmacRet = wc_HmacSetKey(enc->hmac, hashType,
    29352942                                       keys->client_write_key, specs->key_size);
     
    29372944                }
    29382945                if (dec) {
     2946                    XMEMCPY(keys->aead_dec_imp_IV, keys->server_write_IV,
     2947                            HMAC_NONCE_SZ);
    29392948                    hmacRet = wc_HmacSetKey(dec->hmac, hashType,
    29402949                                       keys->server_write_key, specs->key_size);
     
    29442953            else {
    29452954                if (enc) {
     2955                    XMEMCPY(keys->aead_enc_imp_IV, keys->server_write_IV,
     2956                            HMAC_NONCE_SZ);
    29462957                    hmacRet = wc_HmacSetKey(enc->hmac, hashType,
    29472958                                       keys->server_write_key, specs->key_size);
     
    29492960                }
    29502961                if (dec) {
     2962                    XMEMCPY(keys->aead_dec_imp_IV, keys->client_write_IV,
     2963                            HMAC_NONCE_SZ);
    29512964                    hmacRet = wc_HmacSetKey(dec->hmac, hashType,
    29522965                                       keys->client_write_key, specs->key_size);
     
    30593072    if (ssl->secure_renegotiation && ssl->secure_renegotiation->cache_status) {
    30603073        keys = &ssl->secure_renegotiation->tmp_keys;
    3061         copy = 1;
     3074#ifdef WOLFSSL_DTLS
     3075        /* For DTLS, copy is done in StoreKeys */
     3076        if (!ssl->options.dtls)
     3077#endif
     3078            copy = 1;
    30623079    }
    30633080#endif /* HAVE_SECURE_RENEGOTIATION */
     
    31343151
    31353152#ifdef HAVE_SECURE_RENEGOTIATION
     3153#ifdef WOLFSSL_DTLS
     3154    if (ret == 0 && ssl->options.dtls) {
     3155        if (wc_encrypt)
     3156            wc_encrypt->src = keys == &ssl->keys ? KEYS : SCR;
     3157        if (wc_decrypt)
     3158            wc_decrypt->src = keys == &ssl->keys ? KEYS : SCR;
     3159    }
     3160#endif
     3161
    31363162    if (copy) {
    31373163        int clientCopy = 0;
     
    32103236    int sz, i = 0;
    32113237    Keys* keys = &ssl->keys;
     3238#ifdef WOLFSSL_DTLS
     3239    /* In case of DTLS, ssl->keys is updated here */
     3240    int scr_copy = 0;
     3241#endif
    32123242
    32133243#ifdef HAVE_SECURE_RENEGOTIATION
    3214     if (ssl->secure_renegotiation && ssl->secure_renegotiation->cache_status ==
    3215                                                             SCR_CACHE_NEEDED) {
     3244    if (ssl->secure_renegotiation &&
     3245            ssl->secure_renegotiation->cache_status == SCR_CACHE_NEEDED) {
    32163246        keys = &ssl->secure_renegotiation->tmp_keys;
     3247#ifdef WOLFSSL_DTLS
     3248        if (ssl->options.dtls) {
     3249            /* epoch is incremented after StoreKeys is called */
     3250            ssl->secure_renegotiation->tmp_keys.dtls_epoch = ssl->keys.dtls_epoch + 1;
     3251            /* we only need to copy keys on second and future renegotiations */
     3252            if (ssl->keys.dtls_epoch > 1)
     3253                scr_copy = 1;
     3254            ssl->encrypt.src = KEYS_NOT_SET;
     3255            ssl->decrypt.src = KEYS_NOT_SET;
     3256        }
     3257#endif
    32173258        CacheStatusPP(ssl->secure_renegotiation);
    32183259    }
     
    32253266            sz = ssl->specs.hash_size;
    32263267    #ifndef WOLFSSL_AEAD_ONLY
     3268
     3269    #ifdef WOLFSSL_DTLS
     3270            if (scr_copy) {
     3271                XMEMCPY(ssl->keys.client_write_MAC_secret,
     3272                        keys->client_write_MAC_secret, sz);
     3273                XMEMCPY(ssl->keys.server_write_MAC_secret,
     3274                        keys->server_write_MAC_secret, sz);
     3275            }
     3276    #endif
    32273277            XMEMCPY(keys->client_write_MAC_secret,&keyData[i], sz);
    32283278            XMEMCPY(keys->server_write_MAC_secret,&keyData[i], sz);
     
    32313281        }
    32323282        sz = ssl->specs.key_size;
     3283    #ifdef WOLFSSL_DTLS
     3284        if (scr_copy) {
     3285            XMEMCPY(ssl->keys.client_write_key,
     3286                    keys->client_write_key, sz);
     3287            XMEMCPY(ssl->keys.server_write_key,
     3288                    keys->server_write_key, sz);
     3289        }
     3290    #endif
    32333291        XMEMCPY(keys->client_write_key, &keyData[i], sz);
    32343292        XMEMCPY(keys->server_write_key, &keyData[i], sz);
     
    32363294
    32373295        sz = ssl->specs.iv_size;
     3296    #ifdef WOLFSSL_DTLS
     3297        if (scr_copy) {
     3298            XMEMCPY(ssl->keys.client_write_IV,
     3299                    keys->client_write_IV, sz);
     3300            XMEMCPY(ssl->keys.server_write_IV,
     3301                    keys->server_write_IV, sz);
     3302        }
     3303    #endif
    32383304        XMEMCPY(keys->client_write_IV, &keyData[i], sz);
    32393305        XMEMCPY(keys->server_write_IV, &keyData[i], sz);
     
    32423308        if (ssl->specs.cipher_type == aead) {
    32433309            /* Initialize the AES-GCM/CCM explicit IV to a zero. */
     3310        #ifdef WOLFSSL_DTLS
     3311            if (scr_copy) {
     3312                XMEMCPY(ssl->keys.aead_exp_IV,
     3313                        keys->aead_exp_IV, AEAD_MAX_EXP_SZ);
     3314            }
     3315        #endif
    32443316            XMEMSET(keys->aead_exp_IV, 0, AEAD_MAX_EXP_SZ);
    32453317        }
     
    32543326        if (side & PROVISION_CLIENT) {
    32553327    #ifndef WOLFSSL_AEAD_ONLY
     3328        #ifdef WOLFSSL_DTLS
     3329            if (scr_copy)
     3330                XMEMCPY(ssl->keys.client_write_MAC_secret,
     3331                        keys->client_write_MAC_secret, sz);
     3332        #endif
    32563333            XMEMCPY(keys->client_write_MAC_secret,&keyData[i], sz);
    32573334    #endif
     
    32603337        if (side & PROVISION_SERVER) {
    32613338    #ifndef WOLFSSL_AEAD_ONLY
     3339        #ifdef WOLFSSL_DTLS
     3340            if (scr_copy)
     3341                XMEMCPY(ssl->keys.server_write_MAC_secret,
     3342                        keys->server_write_MAC_secret, sz);
     3343        #endif
    32623344            XMEMCPY(keys->server_write_MAC_secret,&keyData[i], sz);
    32633345    #endif
     
    32673349    sz = ssl->specs.key_size;
    32683350    if (side & PROVISION_CLIENT) {
     3351    #ifdef WOLFSSL_DTLS
     3352        if (scr_copy)
     3353            XMEMCPY(ssl->keys.client_write_key,
     3354                    keys->client_write_key, sz);
     3355    #endif
    32693356        XMEMCPY(keys->client_write_key, &keyData[i], sz);
    32703357        i += sz;
    32713358    }
    32723359    if (side & PROVISION_SERVER) {
     3360    #ifdef WOLFSSL_DTLS
     3361        if (scr_copy)
     3362            XMEMCPY(ssl->keys.server_write_key,
     3363                    keys->server_write_key, sz);
     3364    #endif
    32733365        XMEMCPY(keys->server_write_key, &keyData[i], sz);
    32743366        i += sz;
     
    32773369    sz = ssl->specs.iv_size;
    32783370    if (side & PROVISION_CLIENT) {
     3371    #ifdef WOLFSSL_DTLS
     3372        if (scr_copy)
     3373            XMEMCPY(ssl->keys.client_write_IV,
     3374                    keys->client_write_IV, sz);
     3375    #endif
    32793376        XMEMCPY(keys->client_write_IV, &keyData[i], sz);
    32803377        i += sz;
    32813378    }
    3282     if (side & PROVISION_SERVER)
     3379    if (side & PROVISION_SERVER) {
     3380    #ifdef WOLFSSL_DTLS
     3381        if (scr_copy)
     3382            XMEMCPY(ssl->keys.server_write_IV,
     3383                    keys->server_write_IV, sz);
     3384    #endif
    32833385        XMEMCPY(keys->server_write_IV, &keyData[i], sz);
     3386    }
    32843387
    32853388#ifdef HAVE_AEAD
    32863389    if (ssl->specs.cipher_type == aead) {
    32873390        /* Initialize the AES-GCM/CCM explicit IV to a zero. */
     3391    #ifdef WOLFSSL_DTLS
     3392        if (scr_copy)
     3393            XMEMMOVE(ssl->keys.aead_exp_IV,
     3394                    keys->aead_exp_IV, AEAD_MAX_EXP_SZ);
     3395    #endif
    32883396        XMEMSET(keys->aead_exp_IV, 0, AEAD_MAX_EXP_SZ);
    32893397    }
     
    33423450    }
    33433451#endif
    3344 
     3452    XMEMSET(shaOutput, 0, WC_SHA_DIGEST_SIZE);
    33453453    ret = wc_InitMd5(md5);
    33463454    if (ret == 0) {
     
    34723580    }
    34733581#endif
     3582    XMEMSET(shaOutput, 0, WC_SHA_DIGEST_SIZE);
    34743583
    34753584    ret = wc_InitMd5(md5);
Note: See TracChangeset for help on using the changeset viewer.