^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-or-later */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /* Asymmetric public-key algorithm definitions
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * See Documentation/crypto/asymmetric-keys.rst
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #ifndef _LINUX_PUBLIC_KEY_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #define _LINUX_PUBLIC_KEY_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/keyctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/oid_registry.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <crypto/akcipher.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) * Cryptographic data for the public-key subtype of the asymmetric key type.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) * Note that this may include private part of the key as well as the public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * part.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) struct public_key {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) void *key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) u32 keylen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) enum OID algo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) void *params;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) u32 paramlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) bool key_is_private;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) const char *id_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) const char *pkey_algo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) extern void public_key_free(struct public_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) * Public key cryptography signature data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct public_key_signature {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct asymmetric_key_id *auth_ids[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) u8 *s; /* Signature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) u32 s_size; /* Number of bytes in signature */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) u8 *digest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) u8 digest_size; /* Number of bytes in digest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) const char *pkey_algo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) const char *hash_algo;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) const char *encoding;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) const void *data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) unsigned int data_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) extern void public_key_signature_free(struct public_key_signature *sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) extern struct asymmetric_key_subtype public_key_subtype;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) struct key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) struct key_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) union key_payload;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) extern int restrict_link_by_signature(struct key *dest_keyring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) const struct key_type *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) const union key_payload *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) struct key *trust_keyring);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) extern int restrict_link_by_key_or_keyring(struct key *dest_keyring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) const struct key_type *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) const union key_payload *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) struct key *trusted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) extern int restrict_link_by_key_or_keyring_chain(struct key *trust_keyring,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) const struct key_type *type,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) const union key_payload *payload,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct key *trusted);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) extern int query_asymmetric_key(const struct kernel_pkey_params *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct kernel_pkey_query *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) extern int encrypt_blob(struct kernel_pkey_params *, const void *, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) extern int decrypt_blob(struct kernel_pkey_params *, const void *, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) extern int create_signature(struct kernel_pkey_params *, const void *, void *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) extern int verify_signature(const struct key *,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) const struct public_key_signature *);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) int public_key_verify_signature(const struct public_key *pkey,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) const struct public_key_signature *sig);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) #endif /* _LINUX_PUBLIC_KEY_H */