blob: 948c5203ca9c671ee94c1e05dc84034f2fe381ef [file] [log] [blame]
Thomas Gleixnerb4d0d232019-05-20 19:08:01 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
David Howellsa9681bf2012-09-21 23:24:55 +01002/* Asymmetric public-key algorithm definitions
3 *
Mauro Carvalho Chehab0efaaa82020-06-15 08:50:08 +02004 * See Documentation/crypto/asymmetric-keys.rst
David Howellsa9681bf2012-09-21 23:24:55 +01005 *
6 * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
7 * Written by David Howells (dhowells@redhat.com)
David Howellsa9681bf2012-09-21 23:24:55 +01008 */
9
10#ifndef _LINUX_PUBLIC_KEY_H
11#define _LINUX_PUBLIC_KEY_H
12
David Howells5a307712018-10-09 17:47:07 +010013#include <linux/keyctl.h>
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +030014#include <linux/oid_registry.h>
Tianjia Zhang21552562020-09-21 00:21:02 +080015#include <crypto/akcipher.h>
David Howells5a307712018-10-09 17:47:07 +010016
David Howellsa9681bf2012-09-21 23:24:55 +010017/*
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 */
23struct public_key {
Tadeusz Strukdb6c43b2016-02-02 10:08:53 -080024 void *key;
25 u32 keylen;
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +030026 enum OID algo;
27 void *params;
28 u32 paramlen;
David Howellsf7c4e062018-10-09 17:47:31 +010029 bool key_is_private;
David Howells4e8ae722016-03-03 21:49:27 +000030 const char *id_type;
31 const char *pkey_algo;
David Howellsa9681bf2012-09-21 23:24:55 +010032};
33
David Howells3b764562016-04-06 16:13:33 +010034extern void public_key_free(struct public_key *key);
David Howellsa9681bf2012-09-21 23:24:55 +010035
36/*
37 * Public key cryptography signature data
38 */
39struct public_key_signature {
David Howellsa022ec02016-04-06 16:13:33 +010040 struct asymmetric_key_id *auth_ids[2];
Tadeusz Strukdb6c43b2016-02-02 10:08:53 -080041 u8 *s; /* Signature */
42 u32 s_size; /* Number of bytes in signature */
David Howellsa9681bf2012-09-21 23:24:55 +010043 u8 *digest;
Tadeusz Strukd846e782016-02-02 10:09:03 -080044 u8 digest_size; /* Number of bytes in digest */
David Howells4e8ae722016-03-03 21:49:27 +000045 const char *pkey_algo;
46 const char *hash_algo;
David Howells5a307712018-10-09 17:47:07 +010047 const char *encoding;
Tianjia Zhang21552562020-09-21 00:21:02 +080048 const void *data;
49 unsigned int data_size;
David Howellsa9681bf2012-09-21 23:24:55 +010050};
51
David Howells3b764562016-04-06 16:13:33 +010052extern void public_key_signature_free(struct public_key_signature *sig);
53
Tadeusz Strukdb6c43b2016-02-02 10:08:53 -080054extern struct asymmetric_key_subtype public_key_subtype;
David Howells3b764562016-04-06 16:13:33 +010055
David Howells4ae71c12012-09-21 23:25:04 +010056struct key;
David Howellsa511e1a2016-04-06 16:14:26 +010057struct key_type;
58union key_payload;
59
Mat Martineauaaf66c82016-08-30 11:33:13 -070060extern int restrict_link_by_signature(struct key *dest_keyring,
David Howellsa511e1a2016-04-06 16:14:26 +010061 const struct key_type *type,
Mat Martineauaaf66c82016-08-30 11:33:13 -070062 const union key_payload *payload,
63 struct key *trust_keyring);
David Howellsa511e1a2016-04-06 16:14:26 +010064
Mat Martineau7e3c4d22016-06-27 16:45:16 -070065extern 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 Martineau8e323a02016-10-04 16:42:45 -070070extern 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 Howells5a307712018-10-09 17:47:07 +010075extern int query_asymmetric_key(const struct kernel_pkey_params *,
76 struct kernel_pkey_query *);
77
78extern int encrypt_blob(struct kernel_pkey_params *, const void *, void *);
79extern int decrypt_blob(struct kernel_pkey_params *, const void *, void *);
80extern int create_signature(struct kernel_pkey_params *, const void *, void *);
81extern int verify_signature(const struct key *,
82 const struct public_key_signature *);
David Howells4ae71c12012-09-21 23:25:04 +010083
Tadeusz Strukdb6c43b2016-02-02 10:08:53 -080084int public_key_verify_signature(const struct public_key *pkey,
85 const struct public_key_signature *sig);
86
David Howellsa9681bf2012-09-21 23:24:55 +010087#endif /* _LINUX_PUBLIC_KEY_H */