sm.c (a756d52b3209d76e772137ef6e58ae0423f8a456) sm.c (1046568c8fed82922390eaa81b0675f1224490aa)
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 2903 unchanged lines hidden (view full) ---

2912 if (connection == NULL) return;
2913
2914 log_info_key("ltk", setup->sm_ltk);
2915 // calc CSRK next
2916 sm_d1_d_prime(setup->sm_local_div, 1, sm_aes128_plaintext);
2917 sm_aes128_state = SM_AES128_ACTIVE;
2918 btstack_crypto_aes128_encrypt(&sm_crypto_aes128_request, sm_persistent_er, sm_aes128_plaintext, setup->sm_local_csrk, sm_handle_encryption_result_enc_csrk, (void *)(uintptr_t) connection->sm_handle);
2919}
1/*
2 * Copyright (C) 2014 BlueKitchen GmbH
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1. Redistributions of source code must retain the above copyright

--- 2903 unchanged lines hidden (view full) ---

2912 if (connection == NULL) return;
2913
2914 log_info_key("ltk", setup->sm_ltk);
2915 // calc CSRK next
2916 sm_d1_d_prime(setup->sm_local_div, 1, sm_aes128_plaintext);
2917 sm_aes128_state = SM_AES128_ACTIVE;
2918 btstack_crypto_aes128_encrypt(&sm_crypto_aes128_request, sm_persistent_er, sm_aes128_plaintext, setup->sm_local_csrk, sm_handle_encryption_result_enc_csrk, (void *)(uintptr_t) connection->sm_handle);
2919}
2920static bool sm_ctkd_from_le(void){
2921#ifdef ENABLE_CROSS_TRANSPORT_KEY_DERIVATION
2922 bool bonding_enabled = (sm_pairing_packet_get_auth_req(setup->sm_m_preq) & sm_pairing_packet_get_auth_req(setup->sm_s_pres) & SM_AUTHREQ_BONDING ) != 0u;
2923 bool have_identity_address_info = ((setup->sm_key_distribution_received_set & SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION) != 0);
2924 return bonding_enabled && setup->sm_use_secure_connections && have_identity_address_info;
2925#else
2926 return false;
2927#endif
2928}
2920
2921static void sm_handle_encryption_result_enc_csrk(void *arg){
2922 hci_con_handle_t con_handle = (hci_con_handle_t) (uintptr_t) arg;
2923 sm_aes128_state = SM_AES128_IDLE;
2924
2925 sm_connection_t * connection = sm_get_connection_for_handle(con_handle);
2926 if (connection == NULL) return;
2927
2928 sm_aes128_state = SM_AES128_IDLE;
2929 log_info_key("csrk", setup->sm_local_csrk);
2930 if (setup->sm_key_distribution_send_set){
2931 connection->sm_engine_state = SM_PH3_DISTRIBUTE_KEYS;
2932 } else {
2933 // no keys to send, just continue
2934 if (IS_RESPONDER(connection->sm_role)){
2935 // slave -> receive master keys
2936 connection->sm_engine_state = SM_PH3_RECEIVE_KEYS;
2937 } else {
2938#ifdef ENABLE_CLASSIC
2929
2930static void sm_handle_encryption_result_enc_csrk(void *arg){
2931 hci_con_handle_t con_handle = (hci_con_handle_t) (uintptr_t) arg;
2932 sm_aes128_state = SM_AES128_IDLE;
2933
2934 sm_connection_t * connection = sm_get_connection_for_handle(con_handle);
2935 if (connection == NULL) return;
2936
2937 sm_aes128_state = SM_AES128_IDLE;
2938 log_info_key("csrk", setup->sm_local_csrk);
2939 if (setup->sm_key_distribution_send_set){
2940 connection->sm_engine_state = SM_PH3_DISTRIBUTE_KEYS;
2941 } else {
2942 // no keys to send, just continue
2943 if (IS_RESPONDER(connection->sm_role)){
2944 // slave -> receive master keys
2945 connection->sm_engine_state = SM_PH3_RECEIVE_KEYS;
2946 } else {
2947#ifdef ENABLE_CLASSIC
2939 if (setup->sm_use_secure_connections && (setup->sm_key_distribution_received_set & SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION)){
2948 if (sm_ctkd_from_le()){
2940 connection->sm_engine_state = SM_SC_W2_CALCULATE_H6_ILK;
2941 } else
2942#endif
2943 {
2944 sm_master_pairing_success(connection);
2945 }
2946 }
2947 }

--- 1039 unchanged lines hidden (view full) ---

3987 }
3988 // done with key distribution?
3989 if (sm_key_distribution_all_received(sm_conn)){
3990
3991 sm_key_distribution_handle_all_received(sm_conn);
3992
3993 if (IS_RESPONDER(sm_conn->sm_role)){
3994#ifdef ENABLE_CLASSIC
2949 connection->sm_engine_state = SM_SC_W2_CALCULATE_H6_ILK;
2950 } else
2951#endif
2952 {
2953 sm_master_pairing_success(connection);
2954 }
2955 }
2956 }

--- 1039 unchanged lines hidden (view full) ---

3996 }
3997 // done with key distribution?
3998 if (sm_key_distribution_all_received(sm_conn)){
3999
4000 sm_key_distribution_handle_all_received(sm_conn);
4001
4002 if (IS_RESPONDER(sm_conn->sm_role)){
4003#ifdef ENABLE_CLASSIC
3995 if (setup->sm_use_secure_connections && (setup->sm_key_distribution_received_set & SM_KEYDIST_FLAG_IDENTITY_ADDRESS_INFORMATION)){
4004 if (sm_ctkd_from_le()){
3996 sm_conn->sm_engine_state = SM_SC_W2_CALCULATE_H6_ILK;
3997 } else
3998#endif
3999 {
4000 sm_conn->sm_engine_state = SM_RESPONDER_IDLE;
4001 sm_notify_client_status_reason(sm_conn, ERROR_CODE_SUCCESS, 0);
4002 sm_done_for_handle(sm_conn->sm_handle);
4003 }

--- 514 unchanged lines hidden ---
4005 sm_conn->sm_engine_state = SM_SC_W2_CALCULATE_H6_ILK;
4006 } else
4007#endif
4008 {
4009 sm_conn->sm_engine_state = SM_RESPONDER_IDLE;
4010 sm_notify_client_status_reason(sm_conn, ERROR_CODE_SUCCESS, 0);
4011 sm_done_for_handle(sm_conn->sm_handle);
4012 }

--- 514 unchanged lines hidden ---