diff --git a/src/shared/crypto.c b/src/shared/crypto.c
index d4c4cc7..ad89174 100644
--- a/src/shared/crypto.c
+++ b/src/shared/crypto.c
return true;
}
-static inline void swap128(const uint8_t src[16], uint8_t dst[16])
+static inline void swap_buf(const uint8_t *src, uint8_t *dst, uint16_t len)
{
int i;
- for (i = 0; i < 16; i++)
- dst[15 - i] = src[i];
+ for (i = 0; i < len; i++)
+ dst[len - 1 - i] = src[i];
}
bool bt_crypto_sign_att(struct bt_crypto *crypto, const uint8_t key[16],
put_le32(sign_cnt, msg + m_len);
/* The most significant octet of key corresponds to key[0] */
- swap128(key, tmp);
+ swap_buf(key, tmp, 16);
memcpy(signature, tmp + 4, 12);
fd = alg_new(crypto->cmac_aes, tmp, 16);
* Then truncate in most significant bit first order to a length of
* 12 octets
*/
- swap128(out, tmp);
+ swap_buf(out, tmp, 16);
memcpy(signature, tmp + 4, 12);
return true;
return false;
/* The most significant octet of key corresponds to key[0] */
- swap128(key, tmp);
+ swap_buf(key, tmp, 16);
fd = alg_new(crypto->ecb_aes, tmp, 16);
if (fd < 0)
/* Most significant octet of plaintextData corresponds to in[0] */
- swap128(plaintext, in);
+ swap_buf(plaintext, in, 16);
if (!alg_encrypt(fd, in, 16, out, 16)) {
close(fd);
}
/* Most significant octet of encryptedData corresponds to out[0] */
- swap128(out, encrypted);
+ swap_buf(out, encrypted, 16);
close(fd);