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