sm.c (9ad0dd7c756f8c8a57f6fab8a770efeb7a604ddb) sm.c (c61cfe5aa7af72adcb3a84d25ad26efcf721d86d)
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

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

2551 hci_send_cmd(&hci_le_long_term_key_request_reply, connection->sm_handle, ltk_flipped);
2552 sm_done_for_handle(connection->sm_handle);
2553 return;
2554 }
2555 case SM_RESPONDER_PH4_Y_GET_ENC:
2556 // already busy?
2557 if (sm_aes128_state == SM_AES128_ACTIVE) break;
2558 log_info("LTK Request: recalculating with ediv 0x%04x", setup->sm_local_ediv);
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

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

2551 hci_send_cmd(&hci_le_long_term_key_request_reply, connection->sm_handle, ltk_flipped);
2552 sm_done_for_handle(connection->sm_handle);
2553 return;
2554 }
2555 case SM_RESPONDER_PH4_Y_GET_ENC:
2556 // already busy?
2557 if (sm_aes128_state == SM_AES128_ACTIVE) break;
2558 log_info("LTK Request: recalculating with ediv 0x%04x", setup->sm_local_ediv);
2559
2560 // dm helper (was sm_dm_r_prime)
2561 // r' = padding || r
2562 // r - 64 bit value
2563 memset(&sm_aes128_plaintext[0], 0, 8);
2564 memcpy(&sm_aes128_plaintext[8], setup->sm_local_rand, 8);
2565
2559 // Y = dm(DHK, Rand)
2566 // Y = dm(DHK, Rand)
2560 sm_dm_r_prime(setup->sm_local_rand, sm_aes128_plaintext);
2561 connection->sm_engine_state = SM_RESPONDER_PH4_Y_W4_ENC;
2562 sm_aes128_state = SM_AES128_ACTIVE;
2563 btstack_crypto_aes128_encrypt(&sm_crypto_aes128_request, sm_persistent_dhk, sm_aes128_plaintext, sm_aes128_ciphertext, sm_handle_encryption_result_enc_ph4_y, (void *)(uintptr_t) connection->sm_handle);
2564 return;
2565#endif
2566#ifdef ENABLE_LE_CENTRAL
2567 case SM_INITIATOR_PH3_SEND_START_ENCRYPTION: {
2568 sm_key_t stk_flipped;

--- 1808 unchanged lines hidden ---
2567 connection->sm_engine_state = SM_RESPONDER_PH4_Y_W4_ENC;
2568 sm_aes128_state = SM_AES128_ACTIVE;
2569 btstack_crypto_aes128_encrypt(&sm_crypto_aes128_request, sm_persistent_dhk, sm_aes128_plaintext, sm_aes128_ciphertext, sm_handle_encryption_result_enc_ph4_y, (void *)(uintptr_t) connection->sm_handle);
2570 return;
2571#endif
2572#ifdef ENABLE_LE_CENTRAL
2573 case SM_INITIATOR_PH3_SEND_START_ENCRYPTION: {
2574 sm_key_t stk_flipped;

--- 1808 unchanged lines hidden ---