// SPDX-License-Identifier: GPL-2.0-or-later /* Large capacity key type * * Copyright (C) 2017-2020 Jason A. Donenfeld <[email protected]>. All Rights Reserved. * Copyright (C) 2013 Red Hat, Inc. All Rights Reserved. * Written by David Howells ([email protected]) */ #define pr_fmt(fmt) … #include <linux/init.h> #include <linux/seq_file.h> #include <linux/file.h> #include <linux/shmem_fs.h> #include <linux/err.h> #include <linux/random.h> #include <keys/user-type.h> #include <keys/big_key-type.h> #include <crypto/chacha20poly1305.h> /* * Layout of key payload words. */ struct big_key_payload { … }; #define to_big_key_payload(payload) … /* * If the data is under this limit, there's no point creating a shm file to * hold it as the permanently resident metadata for the shmem fs will be at * least as large as the data. */ #define BIG_KEY_FILE_THRESHOLD … /* * big_key defined keys take an arbitrary string as the description and an * arbitrary blob of data as the payload */ struct key_type key_type_big_key = …; /* * Preparse a big key */ int big_key_preparse(struct key_preparsed_payload *prep) { … } /* * Clear preparsement. */ void big_key_free_preparse(struct key_preparsed_payload *prep) { … } /* * dispose of the links from a revoked keyring * - called with the key sem write-locked */ void big_key_revoke(struct key *key) { … } /* * dispose of the data dangling from the corpse of a big_key key */ void big_key_destroy(struct key *key) { … } /* * Update a big key */ int big_key_update(struct key *key, struct key_preparsed_payload *prep) { … } /* * describe the big_key key */ void big_key_describe(const struct key *key, struct seq_file *m) { … } /* * read the key data * - the key's semaphore is read-locked */ long big_key_read(const struct key *key, char *buffer, size_t buflen) { … } /* * Register key type */ static int __init big_key_init(void) { … } late_initcall(big_key_init);