Commit | Line | Data |
---|---|---|
a9681bf3 DH |
1 | /* Asymmetric public-key algorithm definitions |
2 | * | |
3 | * See Documentation/crypto/asymmetric-keys.txt | |
4 | * | |
5 | * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved. | |
6 | * Written by David Howells (dhowells@redhat.com) | |
7 | * | |
8 | * This program is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU General Public Licence | |
10 | * as published by the Free Software Foundation; either version | |
11 | * 2 of the Licence, or (at your option) any later version. | |
12 | */ | |
13 | ||
14 | #ifndef _LINUX_PUBLIC_KEY_H | |
15 | #define _LINUX_PUBLIC_KEY_H | |
16 | ||
17 | #include <linux/mpi.h> | |
3fe78ca2 | 18 | #include <crypto/hash_info.h> |
a9681bf3 DH |
19 | |
20 | enum pkey_algo { | |
21 | PKEY_ALGO_DSA, | |
22 | PKEY_ALGO_RSA, | |
23 | PKEY_ALGO__LAST | |
24 | }; | |
25 | ||
9abc4e66 | 26 | extern const char *const pkey_algo_name[PKEY_ALGO__LAST]; |
a9681bf3 | 27 | |
3fe78ca2 DK |
28 | /* asymmetric key implementation supports only up to SHA224 */ |
29 | #define PKEY_HASH__LAST (HASH_ALGO_SHA224 + 1) | |
a9681bf3 DH |
30 | |
31 | enum pkey_id_type { | |
32 | PKEY_ID_PGP, /* OpenPGP generated key ID */ | |
33 | PKEY_ID_X509, /* X.509 arbitrary subjectKeyIdentifier */ | |
bc1c373d | 34 | PKEY_ID_PKCS7, /* Signature in PKCS#7 message */ |
a9681bf3 DH |
35 | PKEY_ID_TYPE__LAST |
36 | }; | |
37 | ||
9abc4e66 | 38 | extern const char *const pkey_id_type_name[PKEY_ID_TYPE__LAST]; |
a9681bf3 | 39 | |
99db4435 DH |
40 | /* |
41 | * The use to which an asymmetric key is being put. | |
42 | */ | |
43 | enum key_being_used_for { | |
44 | VERIFYING_MODULE_SIGNATURE, | |
45 | VERIFYING_FIRMWARE_SIGNATURE, | |
46 | VERIFYING_KEXEC_PE_SIGNATURE, | |
47 | VERIFYING_KEY_SIGNATURE, | |
48 | VERIFYING_KEY_SELF_SIGNATURE, | |
49 | VERIFYING_UNSPECIFIED_SIGNATURE, | |
50 | NR__KEY_BEING_USED_FOR | |
51 | }; | |
52 | extern const char *const key_being_used_for[NR__KEY_BEING_USED_FOR]; | |
53 | ||
a9681bf3 DH |
54 | /* |
55 | * Cryptographic data for the public-key subtype of the asymmetric key type. | |
56 | * | |
57 | * Note that this may include private part of the key as well as the public | |
58 | * part. | |
59 | */ | |
60 | struct public_key { | |
db6c43bd TS |
61 | void *key; |
62 | u32 keylen; | |
67f7d60b | 63 | enum pkey_algo pkey_algo : 8; |
a9681bf3 | 64 | enum pkey_id_type id_type : 8; |
a9681bf3 DH |
65 | }; |
66 | ||
67 | extern void public_key_destroy(void *payload); | |
68 | ||
69 | /* | |
70 | * Public key cryptography signature data | |
71 | */ | |
72 | struct public_key_signature { | |
db6c43bd TS |
73 | u8 *s; /* Signature */ |
74 | u32 s_size; /* Number of bytes in signature */ | |
a9681bf3 DH |
75 | u8 *digest; |
76 | u8 digest_size; /* Number of bytes in digest */ | |
77 | u8 nr_mpi; /* Occupancy of mpi[] */ | |
1573801f | 78 | enum pkey_algo pkey_algo : 8; |
3fe78ca2 | 79 | enum hash_algo pkey_hash_algo : 8; |
a9681bf3 DH |
80 | union { |
81 | MPI mpi[2]; | |
82 | struct { | |
83 | MPI s; /* m^d mod n */ | |
84 | } rsa; | |
85 | struct { | |
86 | MPI r; | |
87 | MPI s; | |
88 | } dsa; | |
89 | }; | |
90 | }; | |
91 | ||
db6c43bd | 92 | extern struct asymmetric_key_subtype public_key_subtype; |
4ae71c1d DH |
93 | struct key; |
94 | extern int verify_signature(const struct key *key, | |
95 | const struct public_key_signature *sig); | |
96 | ||
46963b77 | 97 | struct asymmetric_key_id; |
5ce43ad2 | 98 | extern struct key *x509_request_asymmetric_key(struct key *keyring, |
4573b64a DH |
99 | const struct asymmetric_key_id *id, |
100 | const struct asymmetric_key_id *skid, | |
f1b731db | 101 | bool partial); |
5ce43ad2 | 102 | |
db6c43bd TS |
103 | int public_key_verify_signature(const struct public_key *pkey, |
104 | const struct public_key_signature *sig); | |
105 | ||
106 | int rsa_verify_signature(const struct public_key *pkey, | |
107 | const struct public_key_signature *sig); | |
a9681bf3 | 108 | #endif /* _LINUX_PUBLIC_KEY_H */ |