AKASHI Takahiro | c4e961e | 2019-11-13 09:44:58 +0900 | [diff] [blame] | 1 | /* 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 Mao | f758647 | 2024-10-03 14:50:29 -0700 | [diff] [blame] | 15 | #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 Takahiro | c4e961e | 2019-11-13 09:44:58 +0900 | [diff] [blame] | 21 | #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 | */ |
| 32 | struct 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 | |
| 43 | extern void public_key_free(struct public_key *key); |
| 44 | |
| 45 | /* |
| 46 | * Public key cryptography signature data |
| 47 | */ |
| 48 | struct 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 | |
| 59 | extern void public_key_signature_free(struct public_key_signature *sig); |
| 60 | |
| 61 | #ifndef __UBOOT__ |
| 62 | extern struct asymmetric_key_subtype public_key_subtype; |
| 63 | |
| 64 | struct key; |
| 65 | struct key_type; |
| 66 | union key_payload; |
| 67 | |
| 68 | extern 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 | |
| 73 | extern 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 | |
| 78 | extern 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 | |
| 83 | extern int query_asymmetric_key(const struct kernel_pkey_params *, |
| 84 | struct kernel_pkey_query *); |
| 85 | |
| 86 | extern int encrypt_blob(struct kernel_pkey_params *, const void *, void *); |
| 87 | extern int decrypt_blob(struct kernel_pkey_params *, const void *, void *); |
| 88 | extern int create_signature(struct kernel_pkey_params *, const void *, void *); |
| 89 | extern int verify_signature(const struct key *, |
| 90 | const struct public_key_signature *); |
AKASHI Takahiro | b2a1049 | 2020-07-21 19:35:17 +0900 | [diff] [blame] | 91 | #endif /* __UBOOT__ */ |
AKASHI Takahiro | c4e961e | 2019-11-13 09:44:58 +0900 | [diff] [blame] | 92 | |
| 93 | int public_key_verify_signature(const struct public_key *pkey, |
| 94 | const struct public_key_signature *sig); |
AKASHI Takahiro | c4e961e | 2019-11-13 09:44:58 +0900 | [diff] [blame] | 95 | |
| 96 | #endif /* _LINUX_PUBLIC_KEY_H */ |