sm.c (7a2e63879d57860d229c0f7788838f28e611a3b9) sm.c (4b8c611fad8a61a6dc6beab3a7a10f746bfd7c41)
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

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

195
196// configuration
197static uint8_t sm_accepted_stk_generation_methods;
198static uint8_t sm_max_encryption_key_size;
199static uint8_t sm_min_encryption_key_size;
200static uint8_t sm_auth_req = 0;
201static uint8_t sm_io_capabilities = IO_CAPABILITY_NO_INPUT_NO_OUTPUT;
202static uint8_t sm_slave_request_security;
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

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

195
196// configuration
197static uint8_t sm_accepted_stk_generation_methods;
198static uint8_t sm_max_encryption_key_size;
199static uint8_t sm_min_encryption_key_size;
200static uint8_t sm_auth_req = 0;
201static uint8_t sm_io_capabilities = IO_CAPABILITY_NO_INPUT_NO_OUTPUT;
202static uint8_t sm_slave_request_security;
203static uint32_t sm_fixed_legacy_pairing_passkey_in_display_role;
203static uint32_t sm_fixed_passkey_in_display_role;
204static uint8_t sm_reconstruct_ltk_without_le_device_db_entry;
205#ifdef ENABLE_LE_SECURE_CONNECTIONS
206static uint8_t sm_have_ec_keypair;
207#endif
208
209// Security Manager Master Keys, please use sm_set_er(er) and sm_set_ir(ir) with your own 128 bit random values
210static sm_key_t sm_persistent_er;
211static sm_key_t sm_persistent_ir;

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

3016 }
3017 break;
3018#endif
3019
3020 case SM_PH2_W4_RANDOM_TK:
3021 {
3022 sm_reset_tk();
3023 uint32_t tk;
204static uint8_t sm_reconstruct_ltk_without_le_device_db_entry;
205#ifdef ENABLE_LE_SECURE_CONNECTIONS
206static uint8_t sm_have_ec_keypair;
207#endif
208
209// Security Manager Master Keys, please use sm_set_er(er) and sm_set_ir(ir) with your own 128 bit random values
210static sm_key_t sm_persistent_er;
211static sm_key_t sm_persistent_ir;

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

3016 }
3017 break;
3018#endif
3019
3020 case SM_PH2_W4_RANDOM_TK:
3021 {
3022 sm_reset_tk();
3023 uint32_t tk;
3024 if (sm_fixed_legacy_pairing_passkey_in_display_role == 0xffffffff){
3024 if (sm_fixed_passkey_in_display_role == 0xffffffff){
3025 // map random to 0-999999 without speding much cycles on a modulus operation
3026 tk = little_endian_read_32(data,0);
3027 tk = tk & 0xfffff; // 1048575
3028 if (tk >= 999999){
3029 tk = tk - 999999;
3030 }
3031 } else {
3032 // override with pre-defined passkey
3025 // map random to 0-999999 without speding much cycles on a modulus operation
3026 tk = little_endian_read_32(data,0);
3027 tk = tk & 0xfffff; // 1048575
3028 if (tk >= 999999){
3029 tk = tk - 999999;
3030 }
3031 } else {
3032 // override with pre-defined passkey
3033 tk = sm_fixed_legacy_pairing_passkey_in_display_role;
3033 tk = sm_fixed_passkey_in_display_role;
3034 }
3035 big_endian_store_32(setup->sm_tk, 12, tk);
3036 if (IS_RESPONDER(connection->sm_role)){
3037 connection->sm_engine_state = SM_RESPONDER_PH1_SEND_PAIRING_RESPONSE;
3038 } else {
3039 if (setup->sm_use_secure_connections){
3040 connection->sm_engine_state = SM_SC_SEND_PUBLIC_KEY_COMMAND;
3041 } else {

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

3926 sm_accepted_stk_generation_methods = SM_STK_GENERATION_METHOD_JUST_WORKS
3927 | SM_STK_GENERATION_METHOD_OOB
3928 | SM_STK_GENERATION_METHOD_PASSKEY
3929 | SM_STK_GENERATION_METHOD_NUMERIC_COMPARISON;
3930
3931 sm_max_encryption_key_size = 16;
3932 sm_min_encryption_key_size = 7;
3933
3034 }
3035 big_endian_store_32(setup->sm_tk, 12, tk);
3036 if (IS_RESPONDER(connection->sm_role)){
3037 connection->sm_engine_state = SM_RESPONDER_PH1_SEND_PAIRING_RESPONSE;
3038 } else {
3039 if (setup->sm_use_secure_connections){
3040 connection->sm_engine_state = SM_SC_SEND_PUBLIC_KEY_COMMAND;
3041 } else {

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

3926 sm_accepted_stk_generation_methods = SM_STK_GENERATION_METHOD_JUST_WORKS
3927 | SM_STK_GENERATION_METHOD_OOB
3928 | SM_STK_GENERATION_METHOD_PASSKEY
3929 | SM_STK_GENERATION_METHOD_NUMERIC_COMPARISON;
3930
3931 sm_max_encryption_key_size = 16;
3932 sm_min_encryption_key_size = 7;
3933
3934 sm_fixed_legacy_pairing_passkey_in_display_role = 0xffffffff;
3934 sm_fixed_passkey_in_display_role = 0xffffffff;
3935 sm_reconstruct_ltk_without_le_device_db_entry = 1;
3936
3937#ifdef ENABLE_CMAC_ENGINE
3938 sm_cmac_state = CMAC_IDLE;
3939#endif
3940 dkg_state = DKG_W4_WORKING;
3941 rau_state = RAU_W4_WORKING;
3942 sm_aes128_state = SM_AES128_IDLE;

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

3999 parse_hex(ec_d, ec_d_string);
4000 parse_hex(&ec_q[0], ec_qx_string);
4001 parse_hex(&ec_q[32], ec_qy_string);
4002 sm_have_ec_keypair = 1;
4003 ec_key_generation_state = EC_KEY_GENERATION_DONE;
4004#endif
4005}
4006
3935 sm_reconstruct_ltk_without_le_device_db_entry = 1;
3936
3937#ifdef ENABLE_CMAC_ENGINE
3938 sm_cmac_state = CMAC_IDLE;
3939#endif
3940 dkg_state = DKG_W4_WORKING;
3941 rau_state = RAU_W4_WORKING;
3942 sm_aes128_state = SM_AES128_IDLE;

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

3999 parse_hex(ec_d, ec_d_string);
4000 parse_hex(&ec_q[0], ec_qx_string);
4001 parse_hex(&ec_q[32], ec_qy_string);
4002 sm_have_ec_keypair = 1;
4003 ec_key_generation_state = EC_KEY_GENERATION_DONE;
4004#endif
4005}
4006
4007void sm_use_fixed_legacy_pairing_passkey_in_display_role(uint32_t passkey){
4008 sm_fixed_legacy_pairing_passkey_in_display_role = passkey;
4007void sm_use_fixed_passkey_in_display_role(uint32_t passkey){
4008 sm_fixed_passkey_in_display_role = passkey;
4009}
4010
4011void sm_allow_ltk_reconstruction_without_le_device_db_entry(int allow){
4012 sm_reconstruct_ltk_without_le_device_db_entry = allow;
4013}
4014
4015static sm_connection_t * sm_get_connection_for_handle(hci_con_handle_t con_handle){
4016 hci_connection_t * hci_con = hci_connection_for_handle(con_handle);

--- 253 unchanged lines hidden ---
4009}
4010
4011void sm_allow_ltk_reconstruction_without_le_device_db_entry(int allow){
4012 sm_reconstruct_ltk_without_le_device_db_entry = allow;
4013}
4014
4015static sm_connection_t * sm_get_connection_for_handle(hci_con_handle_t con_handle){
4016 hci_connection_t * hci_con = hci_connection_for_handle(con_handle);

--- 253 unchanged lines hidden ---