net/ceph/crypto.c
Source file repositories/reference/linux-study-clean/net/ceph/crypto.c
File Facts
- System
- Linux kernel
- Corpus path
net/ceph/crypto.c- Extension
.c- Size
- 12046 bytes
- Lines
- 521
- Domain
- Networking Core
- Bucket
- Sockets, Protocols, Packet Path, And Network Policy
- Inferred role
- Networking Core: implementation source
- Status
- source implementation candidate
Why This File Exists
Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- Networking stack implementation surface: socket APIs, protocol dispatch, packet flow, routing, filtering, and network namespaces.
- 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
linux/ceph/ceph_debug.hlinux/err.hlinux/scatterlist.hlinux/sched.hlinux/slab.hcrypto/aes.hcrypto/krb5.hcrypto/skcipher.hlinux/key-type.hlinux/sched/mm.hkeys/ceph-type.hkeys/user-type.hlinux/ceph/decode.hcrypto.h
Detected Declarations
function set_aes_tfmfunction set_krb5_tfmsfunction ceph_crypto_key_preparefunction ceph_crypto_key_clonefunction ceph_crypto_key_decodefunction ceph_crypto_key_unarmorfunction ceph_crypto_key_destroyfunction kvmallocfunction for_each_sgfunction teardown_sgtablefunction ceph_aes_cryptfunction ceph_krb5_encryptfunction ceph_krb5_decryptfunction ceph_cryptfunction ceph_crypt_data_offsetfunction ceph_crypt_buflenfunction ceph_hmac_sha256function ceph_key_preparsefunction ceph_key_free_preparsefunction ceph_key_destroyfunction ceph_crypto_initfunction ceph_crypto_shutdown
Annotated Snippet
if (IS_ERR(key->krb5_tfms[i])) {
ret = PTR_ERR(key->krb5_tfms[i]);
key->krb5_tfms[i] = NULL;
goto out_flag;
}
}
out_flag:
memalloc_noio_restore(noio_flag);
return ret;
}
int ceph_crypto_key_prepare(struct ceph_crypto_key *key,
const u32 *key_usages, int key_usage_cnt)
{
switch (key->type) {
case CEPH_CRYPTO_NONE:
return 0; /* nothing to do */
case CEPH_CRYPTO_AES:
return set_aes_tfm(key);
case CEPH_CRYPTO_AES256KRB5:
hmac_sha256_preparekey(&key->hmac_key, key->key, key->len);
return set_krb5_tfms(key, key_usages, key_usage_cnt);
default:
return -ENOTSUPP;
}
}
/*
* @dst should be zeroed before this function is called.
*/
int ceph_crypto_key_clone(struct ceph_crypto_key *dst,
const struct ceph_crypto_key *src)
{
dst->type = src->type;
dst->created = src->created;
dst->len = src->len;
dst->key = kmemdup(src->key, src->len, GFP_NOIO);
if (!dst->key)
return -ENOMEM;
return 0;
}
/*
* @key should be zeroed before this function is called.
*/
int ceph_crypto_key_decode(struct ceph_crypto_key *key, void **p, void *end)
{
ceph_decode_need(p, end, 2*sizeof(u16) + sizeof(key->created), bad);
key->type = ceph_decode_16(p);
ceph_decode_copy(p, &key->created, sizeof(key->created));
key->len = ceph_decode_16(p);
ceph_decode_need(p, end, key->len, bad);
if (key->len > CEPH_MAX_KEY_LEN) {
pr_err("secret too big %d\n", key->len);
return -EINVAL;
}
key->key = kmemdup(*p, key->len, GFP_NOIO);
if (!key->key)
return -ENOMEM;
memzero_explicit(*p, key->len);
*p += key->len;
return 0;
bad:
dout("failed to decode crypto key\n");
return -EINVAL;
}
int ceph_crypto_key_unarmor(struct ceph_crypto_key *key, const char *inkey)
{
int inlen = strlen(inkey);
int blen = inlen * 3 / 4;
void *buf, *p;
int ret;
dout("crypto_key_unarmor %s\n", inkey);
buf = kmalloc(blen, GFP_NOFS);
if (!buf)
return -ENOMEM;
blen = ceph_unarmor(buf, inkey, inkey+inlen);
if (blen < 0) {
kfree(buf);
return blen;
}
Annotation
- Immediate include surface: `linux/ceph/ceph_debug.h`, `linux/err.h`, `linux/scatterlist.h`, `linux/sched.h`, `linux/slab.h`, `crypto/aes.h`, `crypto/krb5.h`, `crypto/skcipher.h`.
- Detected declarations: `function set_aes_tfm`, `function set_krb5_tfms`, `function ceph_crypto_key_prepare`, `function ceph_crypto_key_clone`, `function ceph_crypto_key_decode`, `function ceph_crypto_key_unarmor`, `function ceph_crypto_key_destroy`, `function kvmalloc`, `function for_each_sg`, `function teardown_sgtable`.
- Atlas domain: Networking Core / Sockets, Protocols, Packet Path, And Network Policy.
- 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.