blob: 0588ef3bc6ff6bf10352d52476d7c201dc1d9e46 [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 *
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 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>
David Howells5a307712018-10-09 17:47:07 +010015
David Howellsa9681bf2012-09-21 23:24:55 +010016/*
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 */
22struct public_key {
Tadeusz Strukdb6c43b2016-02-02 10:08:53 -080023 void *key;
24 u32 keylen;
Vitaly Chikunovf1774cb2019-04-11 18:51:17 +030025 enum OID algo;
26 void *params;
27 u32 paramlen;
David Howellsf7c4e062018-10-09 17:47:31 +010028 bool key_is_private;
David Howells4e8ae722016-03-03 21:49:27 +000029 const char *id_type;
30 const char *pkey_algo;
David Howellsa9681bf2012-09-21 23:24:55 +010031};
32
David Howells3b764562016-04-06 16:13:33 +010033extern void public_key_free(struct public_key *key);
David Howellsa9681bf2012-09-21 23:24:55 +010034
35/*
36 * Public key cryptography signature data
37 */
38struct public_key_signature {
David Howellsa022ec02016-04-06 16:13:33 +010039 struct asymmetric_key_id *auth_ids[2];
Tadeusz Strukdb6c43b2016-02-02 10:08:53 -080040 u8 *s; /* Signature */
41 u32 s_size; /* Number of bytes in signature */
David Howellsa9681bf2012-09-21 23:24:55 +010042 u8 *digest;
Tadeusz Strukd846e782016-02-02 10:09:03 -080043 u8 digest_size; /* Number of bytes in digest */
David Howells4e8ae722016-03-03 21:49:27 +000044 const char *pkey_algo;
45 const char *hash_algo;
David Howells5a307712018-10-09 17:47:07 +010046 const char *encoding;
David Howellsa9681bf2012-09-21 23:24:55 +010047};
48
David Howells3b764562016-04-06 16:13:33 +010049extern void public_key_signature_free(struct public_key_signature *sig);
50
Tadeusz Strukdb6c43b2016-02-02 10:08:53 -080051extern struct asymmetric_key_subtype public_key_subtype;
David Howells3b764562016-04-06 16:13:33 +010052
David Howells4ae71c12012-09-21 23:25:04 +010053struct key;
David Howellsa511e1a2016-04-06 16:14:26 +010054struct key_type;
55union key_payload;
56
Mat Martineauaaf66c82016-08-30 11:33:13 -070057extern int restrict_link_by_signature(struct key *dest_keyring,
David Howellsa511e1a2016-04-06 16:14:26 +010058 const struct key_type *type,
Mat Martineauaaf66c82016-08-30 11:33:13 -070059 const union key_payload *payload,
60 struct key *trust_keyring);
David Howellsa511e1a2016-04-06 16:14:26 +010061
Mat Martineau7e3c4d22016-06-27 16:45:16 -070062extern 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 Martineau8e323a02016-10-04 16:42:45 -070067extern 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 Howells5a307712018-10-09 17:47:07 +010072extern int query_asymmetric_key(const struct kernel_pkey_params *,
73 struct kernel_pkey_query *);
74
75extern int encrypt_blob(struct kernel_pkey_params *, const void *, void *);
76extern int decrypt_blob(struct kernel_pkey_params *, const void *, void *);
77extern int create_signature(struct kernel_pkey_params *, const void *, void *);
78extern int verify_signature(const struct key *,
79 const struct public_key_signature *);
David Howells4ae71c12012-09-21 23:25:04 +010080
Tadeusz Strukdb6c43b2016-02-02 10:08:53 -080081int public_key_verify_signature(const struct public_key *pkey,
82 const struct public_key_signature *sig);
83
David Howellsa9681bf2012-09-21 23:24:55 +010084#endif /* _LINUX_PUBLIC_KEY_H */