xref: /openbmc/linux/include/crypto/public_key.h (revision 2208f39c)
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* Asymmetric public-key algorithm definitions
3  *
4  * See Documentation/crypto/asymmetric-keys.rst
5  *
6  * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
7  * Written by David Howells (dhowells@redhat.com)
8  */
9 
10 #ifndef _LINUX_PUBLIC_KEY_H
11 #define _LINUX_PUBLIC_KEY_H
12 
13 #include <linux/keyctl.h>
14 #include <linux/oid_registry.h>
15 #include <crypto/akcipher.h>
16 
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 {
24 	void *key;
25 	u32 keylen;
26 	enum OID algo;
27 	void *params;
28 	u32 paramlen;
29 	bool key_is_private;
30 	const char *id_type;
31 	const char *pkey_algo;
32 };
33 
34 extern void public_key_free(struct public_key *key);
35 
36 /*
37  * Public key cryptography signature data
38  */
39 struct public_key_signature {
40 	struct asymmetric_key_id *auth_ids[2];
41 	u8 *s;			/* Signature */
42 	u32 s_size;		/* Number of bytes in signature */
43 	u8 *digest;
44 	u8 digest_size;		/* Number of bytes in digest */
45 	const char *pkey_algo;
46 	const char *hash_algo;
47 	const char *encoding;
48 	const void *data;
49 	unsigned int data_size;
50 };
51 
52 extern void public_key_signature_free(struct public_key_signature *sig);
53 
54 extern struct asymmetric_key_subtype public_key_subtype;
55 
56 struct key;
57 struct key_type;
58 union key_payload;
59 
60 extern int restrict_link_by_signature(struct key *dest_keyring,
61 				      const struct key_type *type,
62 				      const union key_payload *payload,
63 				      struct key *trust_keyring);
64 
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 
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 
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 *);
83 
84 int public_key_verify_signature(const struct public_key *pkey,
85 				const struct public_key_signature *sig);
86 
87 #endif /* _LINUX_PUBLIC_KEY_H */
88