Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

crypto: KEYS: convert public key and digsig asym to the akcipher api

This patch converts the module verification code to the new akcipher API.

Signed-off-by: Tadeusz Struk <tadeusz.struk@intel.com>
Acked-by: Herbert Xu <herbert@gondor.apana.org.au>
Signed-off-by: David Howells <dhowells@redhat.com>

authored by

Tadeusz Struk and committed by
David Howells
db6c43bd 50d35015

+141 -302
+1 -1
crypto/asymmetric_keys/Kconfig
··· 22 22 23 23 config PUBLIC_KEY_ALGO_RSA 24 24 tristate "RSA public-key algorithm" 25 - select MPILIB 25 + select CRYPTO_RSA 26 26 help 27 27 This option enables support for the RSA algorithm (PKCS#1, RFC3447). 28 28
+2 -5
crypto/asymmetric_keys/Makefile
··· 16 16 x509_key_parser-y := \ 17 17 x509-asn1.o \ 18 18 x509_akid-asn1.o \ 19 - x509_rsakey-asn1.o \ 20 19 x509_cert_parser.o \ 21 20 x509_public_key.o 22 21 23 22 $(obj)/x509_cert_parser.o: \ 24 23 $(obj)/x509-asn1.h \ 25 - $(obj)/x509_akid-asn1.h \ 26 - $(obj)/x509_rsakey-asn1.h 24 + $(obj)/x509_akid-asn1.h 25 + 27 26 $(obj)/x509-asn1.o: $(obj)/x509-asn1.c $(obj)/x509-asn1.h 28 27 $(obj)/x509_akid-asn1.o: $(obj)/x509_akid-asn1.c $(obj)/x509_akid-asn1.h 29 - $(obj)/x509_rsakey-asn1.o: $(obj)/x509_rsakey-asn1.c $(obj)/x509_rsakey-asn1.h 30 28 31 29 clean-files += x509-asn1.c x509-asn1.h 32 30 clean-files += x509_akid-asn1.c x509_akid-asn1.h 33 - clean-files += x509_rsakey-asn1.c x509_rsakey-asn1.h 34 31 35 32 # 36 33 # PKCS#7 message handling
+5 -7
crypto/asymmetric_keys/pkcs7_parser.c
··· 15 15 #include <linux/slab.h> 16 16 #include <linux/err.h> 17 17 #include <linux/oid_registry.h> 18 - #include "public_key.h" 18 + #include <crypto/public_key.h> 19 19 #include "pkcs7_parser.h" 20 20 #include "pkcs7-asn1.h" 21 21 ··· 44 44 static void pkcs7_free_signed_info(struct pkcs7_signed_info *sinfo) 45 45 { 46 46 if (sinfo) { 47 - mpi_free(sinfo->sig.mpi[0]); 47 + kfree(sinfo->sig.s); 48 48 kfree(sinfo->sig.digest); 49 49 kfree(sinfo->signing_cert_id); 50 50 kfree(sinfo); ··· 614 614 const void *value, size_t vlen) 615 615 { 616 616 struct pkcs7_parse_context *ctx = context; 617 - MPI mpi; 618 617 619 618 BUG_ON(ctx->sinfo->sig.pkey_algo != PKEY_ALGO_RSA); 620 619 621 - mpi = mpi_read_raw_data(value, vlen); 622 - if (!mpi) 620 + ctx->sinfo->sig.s = kmemdup(value, vlen, GFP_KERNEL); 621 + if (!ctx->sinfo->sig.s) 623 622 return -ENOMEM; 624 623 625 - ctx->sinfo->sig.mpi[0] = mpi; 626 - ctx->sinfo->sig.nr_mpi = 1; 624 + ctx->sinfo->sig.s_size = vlen; 627 625 return 0; 628 626 } 629 627
+1 -1
crypto/asymmetric_keys/pkcs7_trust.c
··· 17 17 #include <linux/asn1.h> 18 18 #include <linux/key.h> 19 19 #include <keys/asymmetric-type.h> 20 - #include "public_key.h" 20 + #include <crypto/public_key.h> 21 21 #include "pkcs7_parser.h" 22 22 23 23 /**
+1 -1
crypto/asymmetric_keys/pkcs7_verify.c
··· 16 16 #include <linux/err.h> 17 17 #include <linux/asn1.h> 18 18 #include <crypto/hash.h> 19 - #include "public_key.h" 19 + #include <crypto/public_key.h> 20 20 #include "pkcs7_parser.h" 21 21 22 22 /*
+22 -42
crypto/asymmetric_keys/public_key.c
··· 18 18 #include <linux/slab.h> 19 19 #include <linux/seq_file.h> 20 20 #include <keys/asymmetric-subtype.h> 21 - #include "public_key.h" 21 + #include <crypto/public_key.h> 22 22 23 23 MODULE_LICENSE("GPL"); 24 24 25 25 const char *const pkey_algo_name[PKEY_ALGO__LAST] = { 26 - [PKEY_ALGO_DSA] = "DSA", 27 - [PKEY_ALGO_RSA] = "RSA", 26 + [PKEY_ALGO_DSA] = "dsa", 27 + [PKEY_ALGO_RSA] = "rsa", 28 28 }; 29 29 EXPORT_SYMBOL_GPL(pkey_algo_name); 30 - 31 - const struct public_key_algorithm *pkey_algo[PKEY_ALGO__LAST] = { 32 - #if defined(CONFIG_PUBLIC_KEY_ALGO_RSA) || \ 33 - defined(CONFIG_PUBLIC_KEY_ALGO_RSA_MODULE) 34 - [PKEY_ALGO_RSA] = &RSA_public_key_algorithm, 35 - #endif 36 - }; 37 - EXPORT_SYMBOL_GPL(pkey_algo); 38 30 39 31 const char *const pkey_id_type_name[PKEY_ID_TYPE__LAST] = { 40 32 [PKEY_ID_PGP] = "PGP", ··· 34 42 [PKEY_ID_PKCS7] = "PKCS#7", 35 43 }; 36 44 EXPORT_SYMBOL_GPL(pkey_id_type_name); 45 + 46 + static int (*alg_verify[PKEY_ALGO__LAST])(const struct public_key *pkey, 47 + const struct public_key_signature *sig) = { 48 + NULL, 49 + rsa_verify_signature 50 + }; 37 51 38 52 /* 39 53 * Provide a part of a description of the key for /proc/keys. ··· 51 53 52 54 if (key) 53 55 seq_printf(m, "%s.%s", 54 - pkey_id_type_name[key->id_type], key->algo->name); 56 + pkey_id_type_name[key->id_type], 57 + pkey_algo_name[key->pkey_algo]); 55 58 } 56 59 57 60 /* ··· 61 62 void public_key_destroy(void *payload) 62 63 { 63 64 struct public_key *key = payload; 64 - int i; 65 65 66 - if (key) { 67 - for (i = 0; i < ARRAY_SIZE(key->mpi); i++) 68 - mpi_free(key->mpi[i]); 69 - kfree(key); 70 - } 66 + if (key) 67 + kfree(key->key); 68 + kfree(key); 71 69 } 72 70 EXPORT_SYMBOL_GPL(public_key_destroy); 73 71 74 72 /* 75 73 * Verify a signature using a public key. 76 74 */ 77 - int public_key_verify_signature(const struct public_key *pk, 75 + int public_key_verify_signature(const struct public_key *pkey, 78 76 const struct public_key_signature *sig) 79 77 { 80 - const struct public_key_algorithm *algo; 81 - 82 - BUG_ON(!pk); 83 - BUG_ON(!pk->mpi[0]); 84 - BUG_ON(!pk->mpi[1]); 78 + BUG_ON(!pkey); 85 79 BUG_ON(!sig); 86 80 BUG_ON(!sig->digest); 87 - BUG_ON(!sig->mpi[0]); 81 + BUG_ON(!sig->s); 88 82 89 - algo = pk->algo; 90 - if (!algo) { 91 - if (pk->pkey_algo >= PKEY_ALGO__LAST) 92 - return -ENOPKG; 93 - algo = pkey_algo[pk->pkey_algo]; 94 - if (!algo) 95 - return -ENOPKG; 96 - } 83 + if (pkey->pkey_algo >= PKEY_ALGO__LAST) 84 + return -ENOPKG; 97 85 98 - if (!algo->verify_signature) 99 - return -ENOTSUPP; 86 + if (!alg_verify[pkey->pkey_algo]) 87 + return -ENOPKG; 100 88 101 - if (sig->nr_mpi != algo->n_sig_mpi) { 102 - pr_debug("Signature has %u MPI not %u\n", 103 - sig->nr_mpi, algo->n_sig_mpi); 104 - return -EINVAL; 105 - } 106 - 107 - return algo->verify_signature(pk, sig); 89 + return alg_verify[pkey->pkey_algo](pkey, sig); 108 90 } 109 91 EXPORT_SYMBOL_GPL(public_key_verify_signature); 110 92
-36
crypto/asymmetric_keys/public_key.h
··· 1 - /* Public key algorithm internals 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 - #include <crypto/public_key.h> 15 - 16 - extern struct asymmetric_key_subtype public_key_subtype; 17 - 18 - /* 19 - * Public key algorithm definition. 20 - */ 21 - struct public_key_algorithm { 22 - const char *name; 23 - u8 n_pub_mpi; /* Number of MPIs in public key */ 24 - u8 n_sec_mpi; /* Number of MPIs in secret key */ 25 - u8 n_sig_mpi; /* Number of MPIs in a signature */ 26 - int (*verify_signature)(const struct public_key *key, 27 - const struct public_key_signature *sig); 28 - }; 29 - 30 - extern const struct public_key_algorithm RSA_public_key_algorithm; 31 - 32 - /* 33 - * public_key.c 34 - */ 35 - extern int public_key_verify_signature(const struct public_key *pk, 36 - const struct public_key_signature *sig);
+86 -140
crypto/asymmetric_keys/rsa.c
··· 11 11 12 12 #define pr_fmt(fmt) "RSA: "fmt 13 13 #include <linux/module.h> 14 - #include <linux/kernel.h> 15 14 #include <linux/slab.h> 15 + #include <crypto/akcipher.h> 16 + #include <crypto/public_key.h> 16 17 #include <crypto/algapi.h> 17 - #include "public_key.h" 18 18 19 19 MODULE_LICENSE("GPL"); 20 20 MODULE_DESCRIPTION("RSA Public Key Algorithm"); ··· 84 84 #undef _ 85 85 }; 86 86 87 - /* 88 - * RSAVP1() function [RFC3447 sec 5.2.2] 89 - */ 90 - static int RSAVP1(const struct public_key *key, MPI s, MPI *_m) 91 - { 92 - MPI m; 93 - int ret; 94 - 95 - /* (1) Validate 0 <= s < n */ 96 - if (mpi_cmp_ui(s, 0) < 0) { 97 - kleave(" = -EBADMSG [s < 0]"); 98 - return -EBADMSG; 99 - } 100 - if (mpi_cmp(s, key->rsa.n) >= 0) { 101 - kleave(" = -EBADMSG [s >= n]"); 102 - return -EBADMSG; 103 - } 104 - 105 - m = mpi_alloc(0); 106 - if (!m) 107 - return -ENOMEM; 108 - 109 - /* (2) m = s^e mod n */ 110 - ret = mpi_powm(m, s, key->rsa.e, key->rsa.n); 111 - if (ret < 0) { 112 - mpi_free(m); 113 - return ret; 114 - } 115 - 116 - *_m = m; 117 - return 0; 118 - } 119 - 120 - /* 121 - * Integer to Octet String conversion [RFC3447 sec 4.1] 122 - */ 123 - static int RSA_I2OSP(MPI x, size_t xLen, u8 **pX) 124 - { 125 - unsigned X_size, x_size; 126 - int X_sign; 127 - u8 *X; 128 - 129 - /* Make sure the string is the right length. The number should begin 130 - * with { 0x00, 0x01, ... } so we have to account for 15 leading zero 131 - * bits not being reported by MPI. 132 - */ 133 - x_size = mpi_get_nbits(x); 134 - pr_devel("size(x)=%u xLen*8=%zu\n", x_size, xLen * 8); 135 - if (x_size != xLen * 8 - 15) 136 - return -ERANGE; 137 - 138 - X = mpi_get_buffer(x, &X_size, &X_sign); 139 - if (!X) 140 - return -ENOMEM; 141 - if (X_sign < 0) { 142 - kfree(X); 143 - return -EBADMSG; 144 - } 145 - if (X_size != xLen - 1) { 146 - kfree(X); 147 - return -EBADMSG; 148 - } 149 - 150 - *pX = X; 151 - return 0; 152 - } 87 + struct rsa_completion { 88 + struct completion completion; 89 + int err; 90 + }; 153 91 154 92 /* 155 93 * Perform the RSA signature verification. ··· 98 160 * @asn1_template: The DigestInfo ASN.1 template 99 161 * @asn1_size: Size of asm1_template[] 100 162 */ 101 - static int RSA_verify(const u8 *H, const u8 *EM, size_t k, size_t hash_size, 163 + static int rsa_verify(const u8 *H, const u8 *EM, size_t k, size_t hash_size, 102 164 const u8 *asn1_template, size_t asn1_size) 103 165 { 104 166 unsigned PS_end, T_offset, i; ··· 108 170 if (k < 2 + 1 + asn1_size + hash_size) 109 171 return -EBADMSG; 110 172 111 - /* Decode the EMSA-PKCS1-v1_5 */ 112 - if (EM[1] != 0x01) { 113 - kleave(" = -EBADMSG [EM[1] == %02u]", EM[1]); 173 + /* Decode the EMSA-PKCS1-v1_5 174 + * note: leading zeros are stripped by the RSA implementation 175 + */ 176 + if (EM[0] != 0x01) { 177 + kleave(" = -EBADMSG [EM[0] == %02u]", EM[0]); 114 178 return -EBADMSG; 115 179 } 116 180 ··· 123 183 return -EBADMSG; 124 184 } 125 185 126 - for (i = 2; i < PS_end; i++) { 186 + for (i = 1; i < PS_end; i++) { 127 187 if (EM[i] != 0xff) { 128 188 kleave(" = -EBADMSG [EM[PS%x] == %02u]", i - 2, EM[i]); 129 189 return -EBADMSG; ··· 144 204 return 0; 145 205 } 146 206 147 - /* 148 - * Perform the verification step [RFC3447 sec 8.2.2]. 149 - */ 150 - static int RSA_verify_signature(const struct public_key *key, 151 - const struct public_key_signature *sig) 207 + static void public_key_verify_done(struct crypto_async_request *req, int err) 152 208 { 153 - size_t tsize; 154 - int ret; 209 + struct rsa_completion *compl = req->data; 155 210 156 - /* Variables as per RFC3447 sec 8.2.2 */ 157 - const u8 *H = sig->digest; 158 - u8 *EM = NULL; 159 - MPI m = NULL; 160 - size_t k; 211 + if (err == -EINPROGRESS) 212 + return; 161 213 162 - kenter(""); 163 - 164 - if (!RSA_ASN1_templates[sig->pkey_hash_algo].data) 165 - return -ENOTSUPP; 166 - 167 - /* (1) Check the signature size against the public key modulus size */ 168 - k = mpi_get_nbits(key->rsa.n); 169 - tsize = mpi_get_nbits(sig->rsa.s); 170 - 171 - /* According to RFC 4880 sec 3.2, length of MPI is computed starting 172 - * from most significant bit. So the RFC 3447 sec 8.2.2 size check 173 - * must be relaxed to conform with shorter signatures - so we fail here 174 - * only if signature length is longer than modulus size. 175 - */ 176 - pr_devel("step 1: k=%zu size(S)=%zu\n", k, tsize); 177 - if (k < tsize) { 178 - ret = -EBADMSG; 179 - goto error; 180 - } 181 - 182 - /* Round up and convert to octets */ 183 - k = (k + 7) / 8; 184 - 185 - /* (2b) Apply the RSAVP1 verification primitive to the public key */ 186 - ret = RSAVP1(key, sig->rsa.s, &m); 187 - if (ret < 0) 188 - goto error; 189 - 190 - /* (2c) Convert the message representative (m) to an encoded message 191 - * (EM) of length k octets. 192 - * 193 - * NOTE! The leading zero byte is suppressed by MPI, so we pass a 194 - * pointer to the _preceding_ byte to RSA_verify()! 195 - */ 196 - ret = RSA_I2OSP(m, k, &EM); 197 - if (ret < 0) 198 - goto error; 199 - 200 - ret = RSA_verify(H, EM - 1, k, sig->digest_size, 201 - RSA_ASN1_templates[sig->pkey_hash_algo].data, 202 - RSA_ASN1_templates[sig->pkey_hash_algo].size); 203 - 204 - error: 205 - kfree(EM); 206 - mpi_free(m); 207 - kleave(" = %d", ret); 208 - return ret; 214 + compl->err = err; 215 + complete(&compl->completion); 209 216 } 210 217 211 - const struct public_key_algorithm RSA_public_key_algorithm = { 212 - .name = "RSA", 213 - .n_pub_mpi = 2, 214 - .n_sec_mpi = 3, 215 - .n_sig_mpi = 1, 216 - .verify_signature = RSA_verify_signature, 217 - }; 218 - EXPORT_SYMBOL_GPL(RSA_public_key_algorithm); 218 + int rsa_verify_signature(const struct public_key *pkey, 219 + const struct public_key_signature *sig) 220 + { 221 + struct crypto_akcipher *tfm; 222 + struct akcipher_request *req; 223 + struct rsa_completion compl; 224 + struct scatterlist sig_sg, sg_out; 225 + void *outbuf = NULL; 226 + unsigned int outlen = 0; 227 + int ret = -ENOMEM; 228 + 229 + tfm = crypto_alloc_akcipher("rsa", 0, 0); 230 + if (IS_ERR(tfm)) 231 + goto error_out; 232 + 233 + req = akcipher_request_alloc(tfm, GFP_KERNEL); 234 + if (!req) 235 + goto error_free_tfm; 236 + 237 + ret = crypto_akcipher_set_pub_key(tfm, pkey->key, pkey->keylen); 238 + if (ret) 239 + goto error_free_req; 240 + 241 + ret = -EINVAL; 242 + outlen = crypto_akcipher_maxsize(tfm); 243 + if (!outlen) 244 + goto error_free_req; 245 + 246 + /* Initialize the output buffer */ 247 + ret = -ENOMEM; 248 + outbuf = kmalloc(outlen, GFP_KERNEL); 249 + if (!outbuf) 250 + goto error_free_req; 251 + 252 + sg_init_one(&sig_sg, sig->s, sig->s_size); 253 + sg_init_one(&sg_out, outbuf, outlen); 254 + akcipher_request_set_crypt(req, &sig_sg, &sg_out, sig->s_size, outlen); 255 + init_completion(&compl.completion); 256 + akcipher_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG | 257 + CRYPTO_TFM_REQ_MAY_SLEEP, 258 + public_key_verify_done, &compl); 259 + 260 + ret = crypto_akcipher_verify(req); 261 + if (ret == -EINPROGRESS) { 262 + wait_for_completion(&compl.completion); 263 + ret = compl.err; 264 + } 265 + 266 + if (ret) 267 + goto error_free_req; 268 + 269 + /* Output from the operation is an encoded message (EM) of 270 + * length k octets. 271 + */ 272 + outlen = req->dst_len; 273 + ret = rsa_verify(sig->digest, outbuf, outlen, sig->digest_size, 274 + RSA_ASN1_templates[sig->pkey_hash_algo].data, 275 + RSA_ASN1_templates[sig->pkey_hash_algo].size); 276 + error_free_req: 277 + akcipher_request_free(req); 278 + error_free_tfm: 279 + crypto_free_akcipher(tfm); 280 + error_out: 281 + kfree(outbuf); 282 + return ret; 283 + } 284 + EXPORT_SYMBOL_GPL(rsa_verify_signature);
+7 -30
crypto/asymmetric_keys/x509_cert_parser.c
··· 15 15 #include <linux/slab.h> 16 16 #include <linux/err.h> 17 17 #include <linux/oid_registry.h> 18 - #include "public_key.h" 18 + #include <crypto/public_key.h> 19 19 #include "x509_parser.h" 20 20 #include "x509-asn1.h" 21 21 #include "x509_akid-asn1.h" 22 - #include "x509_rsakey-asn1.h" 23 22 24 23 struct x509_parse_context { 25 24 struct x509_certificate *cert; /* Certificate being constructed */ ··· 55 56 kfree(cert->akid_id); 56 57 kfree(cert->akid_skid); 57 58 kfree(cert->sig.digest); 58 - mpi_free(cert->sig.rsa.s); 59 + kfree(cert->sig.s); 59 60 kfree(cert); 60 61 } 61 62 } ··· 102 103 } 103 104 } 104 105 105 - /* Decode the public key */ 106 - ret = asn1_ber_decoder(&x509_rsakey_decoder, ctx, 107 - ctx->key, ctx->key_size); 108 - if (ret < 0) 106 + cert->pub->key = kmemdup(ctx->key, ctx->key_size, GFP_KERNEL); 107 + if (!cert->pub->key) 109 108 goto error_decode; 109 + 110 + cert->pub->keylen = ctx->key_size; 110 111 111 112 /* Generate cert issuer + serial number key ID */ 112 113 kid = asymmetric_key_generate_id(cert->raw_serial, ··· 123 124 return cert; 124 125 125 126 error_decode: 127 + kfree(cert->pub->key); 126 128 kfree(ctx); 127 129 error_no_ctx: 128 130 x509_free_certificate(cert); ··· 401 401 /* Discard the BIT STRING metadata */ 402 402 ctx->key = value + 1; 403 403 ctx->key_size = vlen - 1; 404 - return 0; 405 - } 406 - 407 - /* 408 - * Extract a RSA public key value 409 - */ 410 - int rsa_extract_mpi(void *context, size_t hdrlen, 411 - unsigned char tag, 412 - const void *value, size_t vlen) 413 - { 414 - struct x509_parse_context *ctx = context; 415 - MPI mpi; 416 - 417 - if (ctx->nr_mpi >= ARRAY_SIZE(ctx->cert->pub->mpi)) { 418 - pr_err("Too many public key MPIs in certificate\n"); 419 - return -EBADMSG; 420 - } 421 - 422 - mpi = mpi_read_raw_data(value, vlen); 423 - if (!mpi) 424 - return -ENOMEM; 425 - 426 - ctx->cert->pub->mpi[ctx->nr_mpi++] = mpi; 427 404 return 0; 428 405 } 429 406
+6 -11
crypto/asymmetric_keys/x509_public_key.c
··· 13 13 #include <linux/module.h> 14 14 #include <linux/kernel.h> 15 15 #include <linux/slab.h> 16 - #include <linux/err.h> 17 - #include <linux/mpi.h> 18 - #include <linux/asn1_decoder.h> 19 16 #include <keys/asymmetric-subtype.h> 20 17 #include <keys/asymmetric-parser.h> 21 18 #include <keys/system_keyring.h> 22 19 #include <crypto/hash.h> 23 20 #include "asymmetric_keys.h" 24 - #include "public_key.h" 25 21 #include "x509_parser.h" 26 22 27 23 static bool use_builtin_keys; ··· 163 167 164 168 if (cert->unsupported_crypto) 165 169 return -ENOPKG; 166 - if (cert->sig.rsa.s) 170 + if (cert->sig.s) 167 171 return 0; 168 172 169 - cert->sig.rsa.s = mpi_read_raw_data(cert->raw_sig, cert->raw_sig_size); 170 - if (!cert->sig.rsa.s) 173 + cert->sig.s = kmemdup(cert->raw_sig, cert->raw_sig_size, 174 + GFP_KERNEL); 175 + if (!cert->sig.s) 171 176 return -ENOMEM; 172 - cert->sig.nr_mpi = 1; 177 + 178 + cert->sig.s_size = cert->raw_sig_size; 173 179 174 180 /* Allocate the hashing algorithm we're going to need and find out how 175 181 * big the hash operational data will be. ··· 294 296 if (cert->pub->pkey_algo >= PKEY_ALGO__LAST || 295 297 cert->sig.pkey_algo >= PKEY_ALGO__LAST || 296 298 cert->sig.pkey_hash_algo >= PKEY_HASH__LAST || 297 - !pkey_algo[cert->pub->pkey_algo] || 298 - !pkey_algo[cert->sig.pkey_algo] || 299 299 !hash_algo_name[cert->sig.pkey_hash_algo]) { 300 300 ret = -ENOPKG; 301 301 goto error_free_cert; ··· 305 309 pkey_algo_name[cert->sig.pkey_algo], 306 310 hash_algo_name[cert->sig.pkey_hash_algo]); 307 311 308 - cert->pub->algo = pkey_algo[cert->pub->pkey_algo]; 309 312 cert->pub->id_type = PKEY_ID_X509; 310 313 311 314 /* Check the signature on the key if it appears to be self-signed */
-4
crypto/asymmetric_keys/x509_rsakey.asn1
··· 1 - RSAPublicKey ::= SEQUENCE { 2 - modulus INTEGER ({ rsa_extract_mpi }), -- n 3 - publicExponent INTEGER ({ rsa_extract_mpi }) -- e 4 - }
+10 -24
include/crypto/public_key.h
··· 24 24 }; 25 25 26 26 extern const char *const pkey_algo_name[PKEY_ALGO__LAST]; 27 - extern const struct public_key_algorithm *pkey_algo[PKEY_ALGO__LAST]; 28 27 29 28 /* asymmetric key implementation supports only up to SHA224 */ 30 29 #define PKEY_HASH__LAST (HASH_ALGO_SHA224 + 1) ··· 58 59 * part. 59 60 */ 60 61 struct public_key { 61 - const struct public_key_algorithm *algo; 62 - u8 capabilities; 63 - #define PKEY_CAN_ENCRYPT 0x01 64 - #define PKEY_CAN_DECRYPT 0x02 65 - #define PKEY_CAN_SIGN 0x04 66 - #define PKEY_CAN_VERIFY 0x08 62 + void *key; 63 + u32 keylen; 67 64 enum pkey_algo pkey_algo : 8; 68 65 enum pkey_id_type id_type : 8; 69 - union { 70 - MPI mpi[5]; 71 - struct { 72 - MPI p; /* DSA prime */ 73 - MPI q; /* DSA group order */ 74 - MPI g; /* DSA group generator */ 75 - MPI y; /* DSA public-key value = g^x mod p */ 76 - MPI x; /* DSA secret exponent (if present) */ 77 - } dsa; 78 - struct { 79 - MPI n; /* RSA public modulus */ 80 - MPI e; /* RSA public encryption exponent */ 81 - MPI d; /* RSA secret encryption exponent (if present) */ 82 - MPI p; /* RSA secret prime (if present) */ 83 - MPI q; /* RSA secret prime (if present) */ 84 - } rsa; 85 - }; 86 66 }; 87 67 88 68 extern void public_key_destroy(void *payload); ··· 70 92 * Public key cryptography signature data 71 93 */ 72 94 struct public_key_signature { 95 + u8 *s; /* Signature */ 96 + u32 s_size; /* Number of bytes in signature */ 73 97 u8 *digest; 74 98 u8 digest_size; /* Number of bytes in digest */ 75 99 u8 nr_mpi; /* Occupancy of mpi[] */ ··· 89 109 }; 90 110 }; 91 111 112 + extern struct asymmetric_key_subtype public_key_subtype; 92 113 struct key; 93 114 extern int verify_signature(const struct key *key, 94 115 const struct public_key_signature *sig); ··· 100 119 const struct asymmetric_key_id *skid, 101 120 bool partial); 102 121 122 + int public_key_verify_signature(const struct public_key *pkey, 123 + const struct public_key_signature *sig); 124 + 125 + int rsa_verify_signature(const struct public_key *pkey, 126 + const struct public_key_signature *sig); 103 127 #endif /* _LINUX_PUBLIC_KEY_H */