drivers/net/ovpn/crypto_aead.c
Source file repositories/reference/linux-study-clean/drivers/net/ovpn/crypto_aead.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/net/ovpn/crypto_aead.c- Extension
.c- Size
- 13959 bytes
- Lines
- 476
- Domain
- Driver Families
- Bucket
- drivers/net
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
crypto/aead.hlinux/skbuff.hnet/ip.hnet/ipv6.hnet/udp.hovpnpriv.hmain.hio.hpktid.hcrypto_aead.hcrypto.hpeer.hproto.hskb.h
Detected Declarations
function Copyrightfunction vectorfunction vectorfunction ovpn_aead_encryptfunction ovpn_aead_decryptfunction ovpn_aead_crypto_key_slot_destroyfunction ovpn_aead_crypto_key_slot_newfunction ovpn_aead_crypto_alg
Annotated Snippet
// SPDX-License-Identifier: GPL-2.0
/* OpenVPN data channel offload
*
* Copyright (C) 2020-2025 OpenVPN, Inc.
*
* Author: James Yonan <james@openvpn.net>
* Antonio Quartulli <antonio@openvpn.net>
*/
#include <crypto/aead.h>
#include <linux/skbuff.h>
#include <net/ip.h>
#include <net/ipv6.h>
#include <net/udp.h>
#include "ovpnpriv.h"
#include "main.h"
#include "io.h"
#include "pktid.h"
#include "crypto_aead.h"
#include "crypto.h"
#include "peer.h"
#include "proto.h"
#include "skb.h"
#define OVPN_AUTH_TAG_SIZE 16
#define OVPN_AAD_SIZE (OVPN_OPCODE_SIZE + OVPN_NONCE_WIRE_SIZE)
#define ALG_NAME_AES "gcm(aes)"
#define ALG_NAME_CHACHAPOLY "rfc7539(chacha20,poly1305)"
static int ovpn_aead_encap_overhead(const struct ovpn_crypto_key_slot *ks)
{
return OVPN_OPCODE_SIZE + /* OP header size */
sizeof(u32) + /* Packet ID */
crypto_aead_authsize(ks->encrypt); /* Auth Tag */
}
/**
* ovpn_aead_crypto_tmp_size - compute the size of a temporary object containing
* an AEAD request structure with extra space for SG
* and IV.
* @tfm: the AEAD cipher handle
* @nfrags: the number of fragments in the skb
*
* This function calculates the size of a contiguous memory block that includes
* the initialization vector (IV), the AEAD request, and an array of scatterlist
* entries. For alignment considerations, the IV is placed first, followed by
* the request, and then the scatterlist.
* Additional alignment is applied according to the requirements of the
* underlying structures.
*
* Return: the size of the temporary memory that needs to be allocated
*/
static unsigned int ovpn_aead_crypto_tmp_size(struct crypto_aead *tfm,
const unsigned int nfrags)
{
unsigned int len = OVPN_NONCE_SIZE;
DEBUG_NET_WARN_ON_ONCE(crypto_aead_ivsize(tfm) != OVPN_NONCE_SIZE);
/* min size for a buffer of ivsize, aligned to alignmask */
len += crypto_aead_alignmask(tfm) & ~(crypto_tfm_ctx_alignment() - 1);
/* round up to the next multiple of the crypto ctx alignment */
len = ALIGN(len, crypto_tfm_ctx_alignment());
/* reserve space for the AEAD request */
len += sizeof(struct aead_request) + crypto_aead_reqsize(tfm);
/* round up to the next multiple of the scatterlist alignment */
len = ALIGN(len, __alignof__(struct scatterlist));
/* add enough space for nfrags + 2 scatterlist entries */
len += array_size(sizeof(struct scatterlist), nfrags + 2);
return len;
}
/**
* ovpn_aead_crypto_tmp_iv - retrieve the pointer to the IV within a temporary
* buffer allocated using ovpn_aead_crypto_tmp_size
* @aead: the AEAD cipher handle
* @tmp: a pointer to the beginning of the temporary buffer
*
* This function retrieves a pointer to the initialization vector (IV) in the
* temporary buffer. If the AEAD cipher specifies an IV size, the pointer is
* adjusted using the AEAD's alignment mask to ensure proper alignment.
*
* Returns: a pointer to the IV within the temporary buffer
*/
static u8 *ovpn_aead_crypto_tmp_iv(struct crypto_aead *aead, void *tmp)
{
Annotation
- Immediate include surface: `crypto/aead.h`, `linux/skbuff.h`, `net/ip.h`, `net/ipv6.h`, `net/udp.h`, `ovpnpriv.h`, `main.h`, `io.h`.
- Detected declarations: `function Copyright`, `function vector`, `function vector`, `function ovpn_aead_encrypt`, `function ovpn_aead_decrypt`, `function ovpn_aead_crypto_key_slot_destroy`, `function ovpn_aead_crypto_key_slot_new`, `function ovpn_aead_crypto_alg`.
- Atlas domain: Driver Families / drivers/net.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.