18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */ 28c2ecf20Sopenharmony_ci/* Asymmetric public-key algorithm definitions 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * See Documentation/crypto/asymmetric-keys.rst 58c2ecf20Sopenharmony_ci * 68c2ecf20Sopenharmony_ci * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. 78c2ecf20Sopenharmony_ci * Written by David Howells (dhowells@redhat.com) 88c2ecf20Sopenharmony_ci */ 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_ci#ifndef _LINUX_PUBLIC_KEY_H 118c2ecf20Sopenharmony_ci#define _LINUX_PUBLIC_KEY_H 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/keyctl.h> 148c2ecf20Sopenharmony_ci#include <linux/oid_registry.h> 158c2ecf20Sopenharmony_ci#include <crypto/akcipher.h> 168c2ecf20Sopenharmony_ci 178c2ecf20Sopenharmony_ci/* 188c2ecf20Sopenharmony_ci * Cryptographic data for the public-key subtype of the asymmetric key type. 198c2ecf20Sopenharmony_ci * 208c2ecf20Sopenharmony_ci * Note that this may include private part of the key as well as the public 218c2ecf20Sopenharmony_ci * part. 228c2ecf20Sopenharmony_ci */ 238c2ecf20Sopenharmony_cistruct public_key { 248c2ecf20Sopenharmony_ci void *key; 258c2ecf20Sopenharmony_ci u32 keylen; 268c2ecf20Sopenharmony_ci enum OID algo; 278c2ecf20Sopenharmony_ci void *params; 288c2ecf20Sopenharmony_ci u32 paramlen; 298c2ecf20Sopenharmony_ci bool key_is_private; 308c2ecf20Sopenharmony_ci const char *id_type; 318c2ecf20Sopenharmony_ci const char *pkey_algo; 328c2ecf20Sopenharmony_ci}; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ciextern void public_key_free(struct public_key *key); 358c2ecf20Sopenharmony_ci 368c2ecf20Sopenharmony_ci/* 378c2ecf20Sopenharmony_ci * Public key cryptography signature data 388c2ecf20Sopenharmony_ci */ 398c2ecf20Sopenharmony_cistruct public_key_signature { 408c2ecf20Sopenharmony_ci struct asymmetric_key_id *auth_ids[2]; 418c2ecf20Sopenharmony_ci u8 *s; /* Signature */ 428c2ecf20Sopenharmony_ci u8 *digest; 438c2ecf20Sopenharmony_ci u32 s_size; /* Number of bytes in signature */ 448c2ecf20Sopenharmony_ci u32 digest_size; /* Number of bytes in digest */ 458c2ecf20Sopenharmony_ci const char *pkey_algo; 468c2ecf20Sopenharmony_ci const char *hash_algo; 478c2ecf20Sopenharmony_ci const char *encoding; 488c2ecf20Sopenharmony_ci const void *data; 498c2ecf20Sopenharmony_ci unsigned int data_size; 508c2ecf20Sopenharmony_ci}; 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ciextern void public_key_signature_free(struct public_key_signature *sig); 538c2ecf20Sopenharmony_ci 548c2ecf20Sopenharmony_ciextern struct asymmetric_key_subtype public_key_subtype; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_cistruct key; 578c2ecf20Sopenharmony_cistruct key_type; 588c2ecf20Sopenharmony_ciunion key_payload; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ciextern int restrict_link_by_signature(struct key *dest_keyring, 618c2ecf20Sopenharmony_ci const struct key_type *type, 628c2ecf20Sopenharmony_ci const union key_payload *payload, 638c2ecf20Sopenharmony_ci struct key *trust_keyring); 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ciextern int restrict_link_by_key_or_keyring(struct key *dest_keyring, 668c2ecf20Sopenharmony_ci const struct key_type *type, 678c2ecf20Sopenharmony_ci const union key_payload *payload, 688c2ecf20Sopenharmony_ci struct key *trusted); 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ciextern int restrict_link_by_key_or_keyring_chain(struct key *trust_keyring, 718c2ecf20Sopenharmony_ci const struct key_type *type, 728c2ecf20Sopenharmony_ci const union key_payload *payload, 738c2ecf20Sopenharmony_ci struct key *trusted); 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ciextern int query_asymmetric_key(const struct kernel_pkey_params *, 768c2ecf20Sopenharmony_ci struct kernel_pkey_query *); 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_ciextern int encrypt_blob(struct kernel_pkey_params *, const void *, void *); 798c2ecf20Sopenharmony_ciextern int decrypt_blob(struct kernel_pkey_params *, const void *, void *); 808c2ecf20Sopenharmony_ciextern int create_signature(struct kernel_pkey_params *, const void *, void *); 818c2ecf20Sopenharmony_ciextern int verify_signature(const struct key *, 828c2ecf20Sopenharmony_ci const struct public_key_signature *); 838c2ecf20Sopenharmony_ci 848c2ecf20Sopenharmony_ciint public_key_verify_signature(const struct public_key *pkey, 858c2ecf20Sopenharmony_ci const struct public_key_signature *sig); 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_ci#endif /* _LINUX_PUBLIC_KEY_H */ 88