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 | * |
| 4 | * See Documentation/crypto/asymmetric-keys.txt |
| 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> |
David Howells | 5a30771 | 2018-10-09 17:47:07 +0100 | [diff] [blame] | 15 | |
David Howells | a9681bf | 2012-09-21 23:24:55 +0100 | [diff] [blame] | 16 | /* |
| 17 | * Cryptographic data for the public-key subtype of the asymmetric key type. |
| 18 | * |
| 19 | * Note that this may include private part of the key as well as the public |
| 20 | * part. |
| 21 | */ |
| 22 | struct public_key { |
Tadeusz Struk | db6c43b | 2016-02-02 10:08:53 -0800 | [diff] [blame] | 23 | void *key; |
| 24 | u32 keylen; |
Vitaly Chikunov | f1774cb | 2019-04-11 18:51:17 +0300 | [diff] [blame] | 25 | enum OID algo; |
| 26 | void *params; |
| 27 | u32 paramlen; |
David Howells | f7c4e06 | 2018-10-09 17:47:31 +0100 | [diff] [blame] | 28 | bool key_is_private; |
David Howells | 4e8ae72 | 2016-03-03 21:49:27 +0000 | [diff] [blame] | 29 | const char *id_type; |
| 30 | const char *pkey_algo; |
David Howells | a9681bf | 2012-09-21 23:24:55 +0100 | [diff] [blame] | 31 | }; |
| 32 | |
David Howells | 3b76456 | 2016-04-06 16:13:33 +0100 | [diff] [blame] | 33 | extern void public_key_free(struct public_key *key); |
David Howells | a9681bf | 2012-09-21 23:24:55 +0100 | [diff] [blame] | 34 | |
| 35 | /* |
| 36 | * Public key cryptography signature data |
| 37 | */ |
| 38 | struct public_key_signature { |
David Howells | a022ec0 | 2016-04-06 16:13:33 +0100 | [diff] [blame] | 39 | struct asymmetric_key_id *auth_ids[2]; |
Tadeusz Struk | db6c43b | 2016-02-02 10:08:53 -0800 | [diff] [blame] | 40 | u8 *s; /* Signature */ |
| 41 | u32 s_size; /* Number of bytes in signature */ |
David Howells | a9681bf | 2012-09-21 23:24:55 +0100 | [diff] [blame] | 42 | u8 *digest; |
Tadeusz Struk | d846e78 | 2016-02-02 10:09:03 -0800 | [diff] [blame] | 43 | u8 digest_size; /* Number of bytes in digest */ |
David Howells | 4e8ae72 | 2016-03-03 21:49:27 +0000 | [diff] [blame] | 44 | const char *pkey_algo; |
| 45 | const char *hash_algo; |
David Howells | 5a30771 | 2018-10-09 17:47:07 +0100 | [diff] [blame] | 46 | const char *encoding; |
David Howells | a9681bf | 2012-09-21 23:24:55 +0100 | [diff] [blame] | 47 | }; |
| 48 | |
David Howells | 3b76456 | 2016-04-06 16:13:33 +0100 | [diff] [blame] | 49 | extern void public_key_signature_free(struct public_key_signature *sig); |
| 50 | |
Tadeusz Struk | db6c43b | 2016-02-02 10:08:53 -0800 | [diff] [blame] | 51 | extern struct asymmetric_key_subtype public_key_subtype; |
David Howells | 3b76456 | 2016-04-06 16:13:33 +0100 | [diff] [blame] | 52 | |
David Howells | 4ae71c1 | 2012-09-21 23:25:04 +0100 | [diff] [blame] | 53 | struct key; |
David Howells | a511e1a | 2016-04-06 16:14:26 +0100 | [diff] [blame] | 54 | struct key_type; |
| 55 | union key_payload; |
| 56 | |
Mat Martineau | aaf66c8 | 2016-08-30 11:33:13 -0700 | [diff] [blame] | 57 | extern int restrict_link_by_signature(struct key *dest_keyring, |
David Howells | a511e1a | 2016-04-06 16:14:26 +0100 | [diff] [blame] | 58 | const struct key_type *type, |
Mat Martineau | aaf66c8 | 2016-08-30 11:33:13 -0700 | [diff] [blame] | 59 | const union key_payload *payload, |
| 60 | struct key *trust_keyring); |
David Howells | a511e1a | 2016-04-06 16:14:26 +0100 | [diff] [blame] | 61 | |
Mat Martineau | 7e3c4d2 | 2016-06-27 16:45:16 -0700 | [diff] [blame] | 62 | extern int restrict_link_by_key_or_keyring(struct key *dest_keyring, |
| 63 | const struct key_type *type, |
| 64 | const union key_payload *payload, |
| 65 | struct key *trusted); |
| 66 | |
Mat Martineau | 8e323a0 | 2016-10-04 16:42:45 -0700 | [diff] [blame] | 67 | extern int restrict_link_by_key_or_keyring_chain(struct key *trust_keyring, |
| 68 | const struct key_type *type, |
| 69 | const union key_payload *payload, |
| 70 | struct key *trusted); |
| 71 | |
David Howells | 5a30771 | 2018-10-09 17:47:07 +0100 | [diff] [blame] | 72 | extern int query_asymmetric_key(const struct kernel_pkey_params *, |
| 73 | struct kernel_pkey_query *); |
| 74 | |
| 75 | extern int encrypt_blob(struct kernel_pkey_params *, const void *, void *); |
| 76 | extern int decrypt_blob(struct kernel_pkey_params *, const void *, void *); |
| 77 | extern int create_signature(struct kernel_pkey_params *, const void *, void *); |
| 78 | extern int verify_signature(const struct key *, |
| 79 | const struct public_key_signature *); |
David Howells | 4ae71c1 | 2012-09-21 23:25:04 +0100 | [diff] [blame] | 80 | |
Tadeusz Struk | db6c43b | 2016-02-02 10:08:53 -0800 | [diff] [blame] | 81 | int public_key_verify_signature(const struct public_key *pkey, |
| 82 | const struct public_key_signature *sig); |
| 83 | |
David Howells | a9681bf | 2012-09-21 23:24:55 +0100 | [diff] [blame] | 84 | #endif /* _LINUX_PUBLIC_KEY_H */ |