sm.c (fcae305fb22a6740cf3bf82a590eac260422f5b3) sm.c (d1ba1a576919a3b0b4558f205cc4d10d32f9a3a1)
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

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

75#if HCI_ACL_PAYLOAD_SIZE < 69
76#error "HCI_ACL_PAYLOAD_SIZE must be at least 69 bytes when using LE Secure Conection. Please increase HCI_ACL_PAYLOAD_SIZE or disable ENABLE_LE_SECURE_CONNECTIONS"
77#endif
78
79// Software ECDH implementation provided by micro-ecc
80#ifdef ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS
81#include "uECC.h"
82#endif
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

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

75#if HCI_ACL_PAYLOAD_SIZE < 69
76#error "HCI_ACL_PAYLOAD_SIZE must be at least 69 bytes when using LE Secure Conection. Please increase HCI_ACL_PAYLOAD_SIZE or disable ENABLE_LE_SECURE_CONNECTIONS"
77#endif
78
79// Software ECDH implementation provided by micro-ecc
80#ifdef ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS
81#include "uECC.h"
82#endif
83#endif
83
84#if defined(ENABLE_LE_SIGNED_WRITE) || defined(ENABLE_LE_SECURE_CONNECTIONS)
85#define ENABLE_CMAC_ENGINE
86#endif
87
88//
89// SM internal types and globals
90//

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

2144 if (sm_active_connection_handle == HCI_CON_HANDLE_INVALID) return;
2145
2146 sm_connection_t * connection = sm_get_connection_for_handle(sm_active_connection_handle);
2147 if (!connection) {
2148 log_info("no connection for handle 0x%04x", sm_active_connection_handle);
2149 return;
2150 }
2151
84
85#if defined(ENABLE_LE_SIGNED_WRITE) || defined(ENABLE_LE_SECURE_CONNECTIONS)
86#define ENABLE_CMAC_ENGINE
87#endif
88
89//
90// SM internal types and globals
91//

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

2145 if (sm_active_connection_handle == HCI_CON_HANDLE_INVALID) return;
2146
2147 sm_connection_t * connection = sm_get_connection_for_handle(sm_active_connection_handle);
2148 if (!connection) {
2149 log_info("no connection for handle 0x%04x", sm_active_connection_handle);
2150 return;
2151 }
2152
2152#if defined(ENABLE_LE_SECURE_CONNECTIONS) || !defined(ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS)
2153#if defined(ENABLE_LE_SECURE_CONNECTIONS) && !defined(ENABLE_MICRO_ECC_FOR_LE_SECURE_CONNECTIONS)
2153 if (setup->sm_state_vars & SM_STATE_VAR_DHKEY_NEEDED){
2154 setup->sm_state_vars &= ~SM_STATE_VAR_DHKEY_NEEDED;
2155 hci_send_cmd(&hci_le_generate_dhkey, &setup->sm_peer_q[0], &setup->sm_peer_q[32]);
2156 return;
2157 }
2158#endif
2159
2160 // assert that we could send a SM PDU - not needed for all of the following

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

2875
2876 ec_key_generation_state = EC_KEY_GENERATION_DONE;
2877 log_info("Elliptic curve: d");
2878 log_info_hexdump(ec_d,32);
2879 sm_log_ec_keypair();
2880 }
2881 }
2882#endif
2154 if (setup->sm_state_vars & SM_STATE_VAR_DHKEY_NEEDED){
2155 setup->sm_state_vars &= ~SM_STATE_VAR_DHKEY_NEEDED;
2156 hci_send_cmd(&hci_le_generate_dhkey, &setup->sm_peer_q[0], &setup->sm_peer_q[32]);
2157 return;
2158 }
2159#endif
2160
2161 // assert that we could send a SM PDU - not needed for all of the following

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

2876
2877 ec_key_generation_state = EC_KEY_GENERATION_DONE;
2878 log_info("Elliptic curve: d");
2879 log_info_hexdump(ec_d,32);
2880 sm_log_ec_keypair();
2881 }
2882 }
2883#endif
2883#endif
2884
2885 switch (rau_state){
2886 case RAU_W4_RANDOM:
2887 // non-resolvable vs. resolvable
2888 switch (gap_random_adress_type){
2889 case GAP_RANDOM_ADDRESS_RESOLVABLE:
2890 // resolvable: use random as prand and calc address hash
2891 // "The two most significant bits of prand shall be equal to ‘0’ and ‘1"

--- 1209 unchanged lines hidden ---
2884
2885 switch (rau_state){
2886 case RAU_W4_RANDOM:
2887 // non-resolvable vs. resolvable
2888 switch (gap_random_adress_type){
2889 case GAP_RANDOM_ADDRESS_RESOLVABLE:
2890 // resolvable: use random as prand and calc address hash
2891 // "The two most significant bits of prand shall be equal to ‘0’ and ‘1"

--- 1209 unchanged lines hidden ---