smp.c (98817a84ff1c755c347ac633ff017a623a631fad) | smp.c (19186c7b45c134820ea6fde3165a2cf30c1ace47) |
---|---|
1/* 2 BlueZ - Bluetooth protocol stack for Linux 3 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License version 2 as 7 published by the Free Software Foundation; 8 --- 156 unchanged lines hidden (view full) --- 165/* The following functions map to the LE SC SMP crypto functions 166 * AES-CMAC, f4, f5, f6, g2 and h6. 167 */ 168 169static int aes_cmac(struct crypto_shash *tfm, const u8 k[16], const u8 *m, 170 size_t len, u8 mac[16]) 171{ 172 uint8_t tmp[16], mac_msb[16], msg_msb[CMAC_MSG_MAX]; | 1/* 2 BlueZ - Bluetooth protocol stack for Linux 3 Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License version 2 as 7 published by the Free Software Foundation; 8 --- 156 unchanged lines hidden (view full) --- 165/* The following functions map to the LE SC SMP crypto functions 166 * AES-CMAC, f4, f5, f6, g2 and h6. 167 */ 168 169static int aes_cmac(struct crypto_shash *tfm, const u8 k[16], const u8 *m, 170 size_t len, u8 mac[16]) 171{ 172 uint8_t tmp[16], mac_msb[16], msg_msb[CMAC_MSG_MAX]; |
173 SHASH_DESC_ON_STACK(desc, tfm); |
|
173 int err; 174 175 if (len > CMAC_MSG_MAX) 176 return -EFBIG; 177 178 if (!tfm) { 179 BT_ERR("tfm %p", tfm); 180 return -EINVAL; 181 } 182 | 174 int err; 175 176 if (len > CMAC_MSG_MAX) 177 return -EFBIG; 178 179 if (!tfm) { 180 BT_ERR("tfm %p", tfm); 181 return -EINVAL; 182 } 183 |
184 desc->tfm = tfm; 185 |
|
183 /* Swap key and message from LSB to MSB */ 184 swap_buf(k, tmp, 16); 185 swap_buf(m, msg_msb, len); 186 187 SMP_DBG("msg (len %zu) %*phN", len, (int) len, m); 188 SMP_DBG("key %16phN", k); 189 190 err = crypto_shash_setkey(tfm, tmp, 16); 191 if (err) { 192 BT_ERR("cipher setkey failed: %d", err); 193 return err; 194 } 195 | 186 /* Swap key and message from LSB to MSB */ 187 swap_buf(k, tmp, 16); 188 swap_buf(m, msg_msb, len); 189 190 SMP_DBG("msg (len %zu) %*phN", len, (int) len, m); 191 SMP_DBG("key %16phN", k); 192 193 err = crypto_shash_setkey(tfm, tmp, 16); 194 if (err) { 195 BT_ERR("cipher setkey failed: %d", err); 196 return err; 197 } 198 |
196 err = crypto_shash_tfm_digest(tfm, msg_msb, len, mac_msb); | 199 err = crypto_shash_digest(desc, msg_msb, len, mac_msb); 200 shash_desc_zero(desc); |
197 if (err) { 198 BT_ERR("Hash computation error %d", err); 199 return err; 200 } 201 202 swap_buf(mac_msb, mac, 16); 203 204 SMP_DBG("mac %16phN", mac); --- 1444 unchanged lines hidden (view full) --- 1649 } 1650 1651 switch (mgmt_op) { 1652 case MGMT_OP_USER_PASSKEY_REPLY: 1653 value = le32_to_cpu(passkey); 1654 memset(smp->tk, 0, sizeof(smp->tk)); 1655 BT_DBG("PassKey: %d", value); 1656 put_unaligned_le32(value, smp->tk); | 201 if (err) { 202 BT_ERR("Hash computation error %d", err); 203 return err; 204 } 205 206 swap_buf(mac_msb, mac, 16); 207 208 SMP_DBG("mac %16phN", mac); --- 1444 unchanged lines hidden (view full) --- 1653 } 1654 1655 switch (mgmt_op) { 1656 case MGMT_OP_USER_PASSKEY_REPLY: 1657 value = le32_to_cpu(passkey); 1658 memset(smp->tk, 0, sizeof(smp->tk)); 1659 BT_DBG("PassKey: %d", value); 1660 put_unaligned_le32(value, smp->tk); |
1657 /* Fall Through */ | 1661 fallthrough; |
1658 case MGMT_OP_USER_CONFIRM_REPLY: 1659 set_bit(SMP_FLAG_TK_VALID, &smp->flags); 1660 break; 1661 case MGMT_OP_USER_PASSKEY_NEG_REPLY: 1662 case MGMT_OP_USER_CONFIRM_NEG_REPLY: 1663 smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED); 1664 err = 0; 1665 goto unlock; --- 2200 unchanged lines hidden --- | 1662 case MGMT_OP_USER_CONFIRM_REPLY: 1663 set_bit(SMP_FLAG_TK_VALID, &smp->flags); 1664 break; 1665 case MGMT_OP_USER_PASSKEY_NEG_REPLY: 1666 case MGMT_OP_USER_CONFIRM_NEG_REPLY: 1667 smp_failure(conn, SMP_PASSKEY_ENTRY_FAILED); 1668 err = 0; 1669 goto unlock; --- 2200 unchanged lines hidden --- |