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