]>
git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blob - crypto/rsa_helper.c
2 * RSA key extract helper
4 * Copyright (c) 2015, Intel Corporation
5 * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the Free
9 * Software Foundation; either version 2 of the License, or (at your option)
13 #include <linux/kernel.h>
14 #include <linux/export.h>
15 #include <linux/err.h>
16 #include <linux/fips.h>
17 #include <crypto/internal/rsa.h>
18 #include "rsakey-asn1.h"
20 int rsa_get_n(void *context
, size_t hdrlen
, unsigned char tag
,
21 const void *value
, size_t vlen
)
23 struct rsa_key
*key
= context
;
25 key
->n
= mpi_read_raw_data(value
, vlen
);
30 /* In FIPS mode only allow key size 2K & 3K */
31 if (fips_enabled
&& (mpi_get_size(key
->n
) != 256 &&
32 mpi_get_size(key
->n
) != 384)) {
33 pr_err("RSA: key size not allowed in FIPS mode\n");
41 int rsa_get_e(void *context
, size_t hdrlen
, unsigned char tag
,
42 const void *value
, size_t vlen
)
44 struct rsa_key
*key
= context
;
46 key
->e
= mpi_read_raw_data(value
, vlen
);
54 int rsa_get_d(void *context
, size_t hdrlen
, unsigned char tag
,
55 const void *value
, size_t vlen
)
57 struct rsa_key
*key
= context
;
59 key
->d
= mpi_read_raw_data(value
, vlen
);
64 /* In FIPS mode only allow key size 2K & 3K */
65 if (fips_enabled
&& (mpi_get_size(key
->d
) != 256 &&
66 mpi_get_size(key
->d
) != 384)) {
67 pr_err("RSA: key size not allowed in FIPS mode\n");
75 static void free_mpis(struct rsa_key
*key
)
86 * rsa_free_key() - frees rsa key allocated by rsa_parse_key()
88 * @rsa_key: struct rsa_key key representation
90 void rsa_free_key(struct rsa_key
*key
)
94 EXPORT_SYMBOL_GPL(rsa_free_key
);
97 * rsa_parse_key() - extracts an rsa key from BER encoded buffer
98 * and stores it in the provided struct rsa_key
100 * @rsa_key: struct rsa_key key representation
101 * @key: key in BER format
102 * @key_len: length of key
104 * Return: 0 on success or error code in case of error
106 int rsa_parse_key(struct rsa_key
*rsa_key
, const void *key
,
107 unsigned int key_len
)
112 ret
= asn1_ber_decoder(&rsakey_decoder
, rsa_key
, key
, key_len
);
121 EXPORT_SYMBOL_GPL(rsa_parse_key
);