blob: 436a1ee1ee647fe08adaf6b18e6de252593f3159 [file] [log] [blame]
AKASHI Takahirocbb10072019-11-13 09:44:58 +09001/* SPDX-License-Identifier: GPL-2.0-or-later */
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)
8 */
9
10#ifndef _LINUX_PUBLIC_KEY_H
11#define _LINUX_PUBLIC_KEY_H
12
13#ifdef __UBOOT__
14#include <linux/types.h>
15#else
16#include <linux/keyctl.h>
17#endif
18#include <linux/oid_registry.h>
19
20/*
21 * Cryptographic data for the public-key subtype of the asymmetric key type.
22 *
23 * Note that this may include private part of the key as well as the public
24 * part.
25 */
26struct public_key {
27 void *key;
28 u32 keylen;
29 enum OID algo;
30 void *params;
31 u32 paramlen;
32 bool key_is_private;
33 const char *id_type;
34 const char *pkey_algo;
35};
36
37extern void public_key_free(struct public_key *key);
38
39/*
40 * Public key cryptography signature data
41 */
42struct public_key_signature {
43 struct asymmetric_key_id *auth_ids[2];
44 u8 *s; /* Signature */
45 u32 s_size; /* Number of bytes in signature */
46 u8 *digest;
47 u8 digest_size; /* Number of bytes in digest */
48 const char *pkey_algo;
49 const char *hash_algo;
50 const char *encoding;
51};
52
53extern void public_key_signature_free(struct public_key_signature *sig);
54
55#ifndef __UBOOT__
56extern struct asymmetric_key_subtype public_key_subtype;
57
58struct key;
59struct key_type;
60union key_payload;
61
62extern int restrict_link_by_signature(struct key *dest_keyring,
63 const struct key_type *type,
64 const union key_payload *payload,
65 struct key *trust_keyring);
66
67extern int restrict_link_by_key_or_keyring(struct key *dest_keyring,
68 const struct key_type *type,
69 const union key_payload *payload,
70 struct key *trusted);
71
72extern int restrict_link_by_key_or_keyring_chain(struct key *trust_keyring,
73 const struct key_type *type,
74 const union key_payload *payload,
75 struct key *trusted);
76
77extern int query_asymmetric_key(const struct kernel_pkey_params *,
78 struct kernel_pkey_query *);
79
80extern int encrypt_blob(struct kernel_pkey_params *, const void *, void *);
81extern int decrypt_blob(struct kernel_pkey_params *, const void *, void *);
82extern int create_signature(struct kernel_pkey_params *, const void *, void *);
83extern int verify_signature(const struct key *,
84 const struct public_key_signature *);
85
86int public_key_verify_signature(const struct public_key *pkey,
87 const struct public_key_signature *sig);
88#endif /* !__UBOOT__ */
89
90#endif /* _LINUX_PUBLIC_KEY_H */