net: l2: ieee802154: consistently name authtag length
The naming of variables and arguments containing the authentication tag length was inconsistent: * Naming inconsistency between header "length" vs. authtag "size" in the same API calls * "Tag" rather than "Auth[orization ]Tag" in external API calls which is too generic from a compliance and readability viewpoint. This is in preparation to zero-copy authentication support. Almost all call sites will be subject to required structural changes later on so no relevant git blame noise/history loss will be introduced by this naming change in the long run. Signed-off-by: Florian Grandel <fgrandel@code-for-humans.de>
This commit is contained in:
parent
681e2145b8
commit
315394eb53
|
@ -343,7 +343,7 @@ static int ieee802154_send(struct net_if *iface, struct net_pkt *pkt)
|
|||
}
|
||||
|
||||
if (!send_raw) {
|
||||
ll_hdr_len = ieee802154_compute_header_and_authtag_size(
|
||||
ll_hdr_len = ieee802154_compute_header_and_authtag_len(
|
||||
iface, net_pkt_lladdr_dst(pkt), net_pkt_lladdr_src(pkt));
|
||||
|
||||
#ifdef CONFIG_NET_6LO
|
||||
|
|
|
@ -32,9 +32,9 @@ LOG_MODULE_REGISTER(net_ieee802154_frame, CONFIG_NET_L2_IEEE802154_LOG_LEVEL);
|
|||
#define BUF_TIMEOUT K_MSEC(50)
|
||||
|
||||
#ifdef CONFIG_NET_L2_IEEE802154_SECURITY
|
||||
const uint8_t level_2_tag_size[4] = {0, IEEE8021254_AUTH_TAG_LENGTH_32,
|
||||
IEEE8021254_AUTH_TAG_LENGTH_64,
|
||||
IEEE8021254_AUTH_TAG_LENGTH_128};
|
||||
const uint8_t level_2_authtag_len[4] = {0, IEEE8021254_AUTH_TAG_LENGTH_32,
|
||||
IEEE8021254_AUTH_TAG_LENGTH_64,
|
||||
IEEE8021254_AUTH_TAG_LENGTH_128};
|
||||
#endif
|
||||
|
||||
struct ieee802154_fcf_seq *ieee802154_validate_fc_seq(uint8_t *buf, uint8_t **p_buf,
|
||||
|
@ -445,8 +445,8 @@ bool ieee802154_validate_frame(uint8_t *buf, uint8_t length, struct ieee802154_m
|
|||
return validate_payload_and_mfr(mpdu, buf, p_buf, length);
|
||||
}
|
||||
|
||||
uint8_t ieee802154_compute_header_and_authtag_size(struct net_if *iface, struct net_linkaddr *dst,
|
||||
struct net_linkaddr *src)
|
||||
uint8_t ieee802154_compute_header_and_authtag_len(struct net_if *iface, struct net_linkaddr *dst,
|
||||
struct net_linkaddr *src)
|
||||
{
|
||||
bool broadcast = !dst->addr;
|
||||
uint8_t hdr_len = sizeof(struct ieee802154_fcf_seq);
|
||||
|
@ -504,9 +504,9 @@ uint8_t ieee802154_compute_header_and_authtag_size(struct net_if *iface, struct
|
|||
* which will fill the tag space in the end.
|
||||
*/
|
||||
if (sec_ctx->level < IEEE802154_SECURITY_LEVEL_ENC) {
|
||||
hdr_len += level_2_tag_size[sec_ctx->level];
|
||||
hdr_len += level_2_authtag_len[sec_ctx->level];
|
||||
} else {
|
||||
hdr_len += level_2_tag_size[sec_ctx->level - 4U];
|
||||
hdr_len += level_2_authtag_len[sec_ctx->level - 4U];
|
||||
}
|
||||
|
||||
release:
|
||||
|
@ -740,19 +740,19 @@ bool ieee802154_create_data_frame(struct ieee802154_context *ctx, struct net_lin
|
|||
level -= 4U;
|
||||
}
|
||||
|
||||
uint8_t tag_size = level_2_tag_size[level];
|
||||
uint8_t authtag_len = level_2_authtag_len[level];
|
||||
|
||||
if (tag_size > 0) {
|
||||
if (authtag_len > 0) {
|
||||
/* If tagged, let's create tailroom for the tag by moving the payload left,
|
||||
*see comment in ieee802154_compute_header_and_authtag_size().
|
||||
*see comment in ieee802154_compute_header_and_authtag_len().
|
||||
*/
|
||||
memmove(p_buf, buf_start + hdr_len, payload_len);
|
||||
hdr_len -= tag_size;
|
||||
hdr_len -= authtag_len;
|
||||
}
|
||||
|
||||
/* Let's encrypt/auth only in the end, if needed */
|
||||
if (!ieee802154_encrypt_auth(&ctx->sec_ctx, buf_start, hdr_len,
|
||||
payload_len, tag_size, ctx->ext_addr)) {
|
||||
payload_len, authtag_len, ctx->ext_addr)) {
|
||||
goto out;
|
||||
};
|
||||
|
||||
|
@ -972,9 +972,9 @@ bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_pkt *pkt,
|
|||
level -= 4U;
|
||||
}
|
||||
|
||||
uint8_t tag_size = level_2_tag_size[level];
|
||||
uint8_t authtag_len = level_2_authtag_len[level];
|
||||
uint8_t hdr_len = (uint8_t *)mpdu->payload - net_pkt_data(pkt);
|
||||
uint8_t payload_len = net_pkt_get_len(pkt) - hdr_len - tag_size;
|
||||
uint8_t payload_len = net_pkt_get_len(pkt) - hdr_len - authtag_len;
|
||||
uint8_t ext_addr_le[IEEE802154_EXT_ADDR_LENGTH];
|
||||
|
||||
/* TODO: Handle src short address.
|
||||
|
@ -988,14 +988,14 @@ bool ieee802154_decipher_data_frame(struct net_if *iface, struct net_pkt *pkt,
|
|||
|
||||
sys_memcpy_swap(ext_addr_le, net_pkt_lladdr_src(pkt)->addr, net_pkt_lladdr_src(pkt)->len);
|
||||
if (!ieee802154_decrypt_auth(&ctx->sec_ctx, net_pkt_data(pkt), hdr_len, payload_len,
|
||||
tag_size, ext_addr_le,
|
||||
authtag_len, ext_addr_le,
|
||||
sys_le32_to_cpu(mpdu->mhr.aux_sec->frame_counter))) {
|
||||
NET_ERR("Could not decipher the frame");
|
||||
goto out;
|
||||
}
|
||||
|
||||
/* We remove tag size from buf's length, it is now useless. */
|
||||
pkt->buffer->len -= tag_size;
|
||||
pkt->buffer->len -= authtag_len;
|
||||
|
||||
ret = true;
|
||||
|
||||
|
|
|
@ -475,8 +475,8 @@ struct ieee802154_fcf_seq *ieee802154_validate_fc_seq(uint8_t *buf, uint8_t **p_
|
|||
|
||||
bool ieee802154_validate_frame(uint8_t *buf, uint8_t length, struct ieee802154_mpdu *mpdu);
|
||||
|
||||
uint8_t ieee802154_compute_header_and_authtag_size(struct net_if *iface, struct net_linkaddr *dst,
|
||||
struct net_linkaddr *src);
|
||||
uint8_t ieee802154_compute_header_and_authtag_len(struct net_if *iface, struct net_linkaddr *dst,
|
||||
struct net_linkaddr *src);
|
||||
|
||||
bool ieee802154_create_data_frame(struct ieee802154_context *ctx, struct net_linkaddr *dst,
|
||||
struct net_linkaddr *src, struct net_buf *buf, uint8_t hdr_len);
|
||||
|
|
|
@ -20,12 +20,12 @@ LOG_MODULE_REGISTER(net_ieee802154_security, CONFIG_NET_L2_IEEE802154_LOG_LEVEL)
|
|||
#include <zephyr/crypto/crypto.h>
|
||||
#include <zephyr/net/net_core.h>
|
||||
|
||||
extern const uint8_t level_2_tag_size[4];
|
||||
extern const uint8_t level_2_authtag_len[4];
|
||||
|
||||
int ieee802154_security_setup_session(struct ieee802154_security_ctx *sec_ctx, uint8_t level,
|
||||
uint8_t key_mode, uint8_t *key, uint8_t key_len)
|
||||
{
|
||||
uint8_t tag_size;
|
||||
uint8_t authtag_len;
|
||||
int ret;
|
||||
|
||||
if (level > IEEE802154_SECURITY_LEVEL_ENC_MIC_128 ||
|
||||
|
@ -47,12 +47,12 @@ int ieee802154_security_setup_session(struct ieee802154_security_ctx *sec_ctx, u
|
|||
}
|
||||
|
||||
if (level >= IEEE802154_SECURITY_LEVEL_ENC) {
|
||||
tag_size = level_2_tag_size[level - 4];
|
||||
authtag_len = level_2_authtag_len[level - 4];
|
||||
} else {
|
||||
tag_size = level_2_tag_size[level];
|
||||
authtag_len = level_2_authtag_len[level];
|
||||
}
|
||||
sec_ctx->enc.mode_params.ccm_info.tag_len = tag_size;
|
||||
sec_ctx->dec.mode_params.ccm_info.tag_len = tag_size;
|
||||
sec_ctx->enc.mode_params.ccm_info.tag_len = authtag_len;
|
||||
sec_ctx->dec.mode_params.ccm_info.tag_len = authtag_len;
|
||||
|
||||
memcpy(sec_ctx->key, key, key_len);
|
||||
sec_ctx->key_len = key_len;
|
||||
|
@ -96,7 +96,7 @@ void ieee802154_security_teardown_session(struct ieee802154_security_ctx *sec_ct
|
|||
}
|
||||
|
||||
static void prepare_cipher_aead_pkt(uint8_t *frame, uint8_t level, uint8_t hdr_len,
|
||||
uint8_t payload_len, uint8_t tag_size,
|
||||
uint8_t payload_len, uint8_t authtag_len,
|
||||
struct cipher_aead_pkt *apkt, struct cipher_pkt *pkt)
|
||||
{
|
||||
bool is_encrypted = level >= IEEE802154_SECURITY_LEVEL_ENC;
|
||||
|
@ -112,7 +112,7 @@ static void prepare_cipher_aead_pkt(uint8_t *frame, uint8_t level, uint8_t hdr_l
|
|||
uint8_t auth_len = is_authenticated ? out_buf_offset : 0;
|
||||
|
||||
pkt->out_buf = frame + out_buf_offset;
|
||||
pkt->out_buf_max = (is_encrypted ? payload_len : 0) + tag_size;
|
||||
pkt->out_buf_max = (is_encrypted ? payload_len : 0) + authtag_len;
|
||||
|
||||
apkt->ad = is_authenticated ? frame : NULL;
|
||||
apkt->ad_len = auth_len;
|
||||
|
@ -121,7 +121,7 @@ static void prepare_cipher_aead_pkt(uint8_t *frame, uint8_t level, uint8_t hdr_l
|
|||
}
|
||||
|
||||
bool ieee802154_decrypt_auth(struct ieee802154_security_ctx *sec_ctx, uint8_t *frame,
|
||||
uint8_t hdr_len, uint8_t payload_len, uint8_t tag_size,
|
||||
uint8_t hdr_len, uint8_t payload_len, uint8_t authtag_len,
|
||||
uint8_t *src_ext_addr, uint32_t frame_counter)
|
||||
{
|
||||
struct cipher_aead_pkt apkt;
|
||||
|
@ -147,7 +147,7 @@ bool ieee802154_decrypt_auth(struct ieee802154_security_ctx *sec_ctx, uint8_t *f
|
|||
sys_put_be32(frame_counter, &nonce[8]);
|
||||
nonce[12] = level;
|
||||
|
||||
prepare_cipher_aead_pkt(frame, level, hdr_len, payload_len, tag_size, &apkt, &pkt);
|
||||
prepare_cipher_aead_pkt(frame, level, hdr_len, payload_len, authtag_len, &apkt, &pkt);
|
||||
|
||||
ret = cipher_ccm_op(&sec_ctx->dec, &apkt, nonce);
|
||||
if (ret) {
|
||||
|
@ -160,7 +160,7 @@ bool ieee802154_decrypt_auth(struct ieee802154_security_ctx *sec_ctx, uint8_t *f
|
|||
}
|
||||
|
||||
bool ieee802154_encrypt_auth(struct ieee802154_security_ctx *sec_ctx, uint8_t *frame,
|
||||
uint8_t hdr_len, uint8_t payload_len, uint8_t tag_size,
|
||||
uint8_t hdr_len, uint8_t payload_len, uint8_t authtag_len,
|
||||
uint8_t *src_ext_addr)
|
||||
{
|
||||
struct cipher_aead_pkt apkt;
|
||||
|
@ -195,7 +195,7 @@ bool ieee802154_encrypt_auth(struct ieee802154_security_ctx *sec_ctx, uint8_t *f
|
|||
sys_put_be32(sec_ctx->frame_counter, &nonce[8]);
|
||||
nonce[12] = level;
|
||||
|
||||
prepare_cipher_aead_pkt(frame, level, hdr_len, payload_len, tag_size, &apkt, &pkt);
|
||||
prepare_cipher_aead_pkt(frame, level, hdr_len, payload_len, authtag_len, &apkt, &pkt);
|
||||
|
||||
ret = cipher_ccm_op(&sec_ctx->enc, &apkt, nonce);
|
||||
if (ret) {
|
||||
|
|
|
@ -27,13 +27,13 @@ void ieee802154_security_teardown_session(struct ieee802154_security_ctx *sec_ct
|
|||
* @param frame Pointer to the frame data in original (little endian) byte order.
|
||||
* @param hdr_len Length of the MHR.
|
||||
* @param payload_len Length of the MAC payload.
|
||||
* @param tag_size Length of the authentication tag.
|
||||
* @param authtag_len Length of the authentication tag.
|
||||
* @param src_ext_addr Pointer to the extended source address of the frame (in little endian byte
|
||||
* order).
|
||||
* @param frame_counter Frame counter in CPU byte order.
|
||||
*/
|
||||
bool ieee802154_decrypt_auth(struct ieee802154_security_ctx *sec_ctx, uint8_t *frame,
|
||||
uint8_t hdr_len, uint8_t payload_len, uint8_t tag_size,
|
||||
uint8_t hdr_len, uint8_t payload_len, uint8_t authtag_len,
|
||||
uint8_t *src_ext_addr, uint32_t frame_counter);
|
||||
|
||||
/**
|
||||
|
@ -43,13 +43,13 @@ bool ieee802154_decrypt_auth(struct ieee802154_security_ctx *sec_ctx, uint8_t *f
|
|||
* @param frame Pointer to the frame data in original (little endian) byte order.
|
||||
* @param hdr_len Length of the MHR.
|
||||
* @param payload_len Length of the MAC payload.
|
||||
* @param tag_size Length of the authentication tag.
|
||||
* @param authtag_len Length of the authentication tag.
|
||||
* @param src_ext_addr Pointer to the extended source address of the frame (in little endian byte
|
||||
* order).
|
||||
*/
|
||||
bool ieee802154_encrypt_auth(struct ieee802154_security_ctx *sec_ctx, uint8_t *frame,
|
||||
uint8_t hdr_len, uint8_t payload_len,
|
||||
uint8_t tag_size, uint8_t *src_ext_addr);
|
||||
uint8_t authtag_len, uint8_t *src_ext_addr);
|
||||
|
||||
int ieee802154_security_init(struct ieee802154_security_ctx *sec_ctx);
|
||||
|
||||
|
|
|
@ -690,8 +690,8 @@ static bool test_dgram_packet_reception(void *src_ll_addr, uint8_t src_ll_addr_l
|
|||
goto release_pkt;
|
||||
}
|
||||
|
||||
ll_hdr_len = ieee802154_compute_header_and_authtag_size(iface, net_pkt_lladdr_dst(pkt),
|
||||
net_pkt_lladdr_src(pkt));
|
||||
ll_hdr_len = ieee802154_compute_header_and_authtag_len(iface, net_pkt_lladdr_dst(pkt),
|
||||
net_pkt_lladdr_src(pkt));
|
||||
|
||||
net_buf_add(frame_buf, ll_hdr_len);
|
||||
net_buf_add_mem(frame_buf, payload, sizeof(payload));
|
||||
|
|
Loading…
Reference in a new issue