File tree Expand file tree Collapse file tree 3 files changed +56
-4
lines changed Expand file tree Collapse file tree 3 files changed +56
-4
lines changed Original file line number Diff line number Diff line change @@ -114,16 +114,29 @@ rsource "../mesh/Kconfig"
114
114
rsource "../audio/Kconfig"
115
115
116
116
config BT_HOST_CRYPTO
117
- # Hidden option that compiles in random number generation and AES
118
- # encryption support using TinyCrypt library if this is not provided
119
- # by the controller implementation.
117
+ # Hidden option that compiles in AES encryption support using TinyCrypt
118
+ # library if this is not provided by the controller implementation.
120
119
bool
121
120
default y if !BT_CTLR_CRYPTO
122
121
select TINYCRYPT
123
122
select TINYCRYPT_AES
123
+
124
+ config BT_HOST_CRYPTO_PRNG
125
+ bool "Use Tinycrypt library for random number generation"
126
+ default y
124
127
select TINYCRYPT_SHA256
125
128
select TINYCRYPT_SHA256_HMAC
126
129
select TINYCRYPT_SHA256_HMAC_PRNG
130
+ depends on BT_HOST_CRYPTO
131
+ help
132
+ When selected, will use tinycrypt library for random number generation.
133
+ This will consume additional ram, but may speed up the generation of random
134
+ numbers.
135
+
136
+ Otherwise, random numbers will be generated through multiple HCI calls,
137
+ which will not consume additional resources, but may take a long time,
138
+ depending on the length of the random data.
139
+ This method is generally recommended within 16 bytes.
127
140
128
141
config BT_SETTINGS
129
142
bool "Store Bluetooth state and configuration persistently"
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ int prng_init(void)
94
94
return prng_reseed (& prng );
95
95
}
96
96
97
+ #if defined(CONFIG_BT_HOST_CRYPTO_PRNG )
97
98
int bt_rand (void * buf , size_t len )
98
99
{
99
100
int ret ;
@@ -114,6 +115,44 @@ int bt_rand(void *buf, size_t len)
114
115
115
116
return - EIO ;
116
117
}
118
+ #else /* !CONFIG_BT_HOST_CRYPTO_PRNG */
119
+ int bt_rand (void * buf , size_t len )
120
+ {
121
+ int ret , size ;
122
+ size_t i = 0 ;
123
+
124
+ /* Check first that HCI_LE_Rand is supported */
125
+ if (!BT_CMD_TEST (bt_dev .supported_commands , 27 , 7 )) {
126
+ return - ENOTSUP ;
127
+ }
128
+
129
+ while (len ) {
130
+ struct bt_hci_rp_le_rand * rp ;
131
+ struct net_buf * rsp ;
132
+
133
+ ret = bt_hci_cmd_send_sync (BT_HCI_OP_LE_RAND , NULL , & rsp );
134
+ if (ret ) {
135
+ return ret ;
136
+ }
137
+
138
+ rp = (void * )rsp -> data ;
139
+ if (rp -> status ) {
140
+ return - EIO ;
141
+ }
142
+
143
+ size = MIN (len , sizeof (rp -> rand ));
144
+
145
+ (void )memcpy ((uint8_t * )buf + i , rp -> rand , size );
146
+
147
+ net_buf_unref (rsp );
148
+
149
+ i += size ;
150
+ len -= size ;
151
+ }
152
+
153
+ return 0 ;
154
+ }
155
+ #endif /* CONFIG_BT_HOST_CRYPTO_PRNG */
117
156
118
157
int bt_encrypt_le (const uint8_t key [16 ], const uint8_t plaintext [16 ],
119
158
uint8_t enc_data [16 ])
Original file line number Diff line number Diff line change @@ -2655,7 +2655,7 @@ static int common_init(void)
2655
2655
read_supported_commands_complete (rsp );
2656
2656
net_buf_unref (rsp );
2657
2657
2658
- if (IS_ENABLED (CONFIG_BT_HOST_CRYPTO )) {
2658
+ if (IS_ENABLED (CONFIG_BT_HOST_CRYPTO_PRNG )) {
2659
2659
/* Initialize the PRNG so that it is safe to use it later
2660
2660
* on in the initialization process.
2661
2661
*/
You can’t perform that action at this time.
0 commit comments