summaryrefslogtreecommitdiff
path: root/crypto/rsa_helper.c
blob: efc78fe7ae2e3e5f971a69f0e2fd9a76967b11c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
/*
 * RSA key extract helper
 *
 * Copyright (c) 2015, Intel Corporation
 * Authors: Tadeusz Struk <tadeusz.struk@intel.com>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the Free
 * Software Foundation; either version 2 of the License, or (at your option)
 * any later version.
 *
 */
#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/err.h>
#include <linux/fips.h>
#include <crypto/internal/rsa.h>
#include "rsapubkey.asn1.h"
#include "rsaprivkey.asn1.h"

int rsa_get_n(void *context, size_t hdrlen, unsigned char tag,
	      const void *value, size_t vlen)
{
	struct rsa_key *key = context;
	const u8 *ptr = value;
	size_t n_sz = vlen;

	/* invalid key provided */
	if (!value || !vlen)
		return -EINVAL;

	if (fips_enabled) {
		while (n_sz && !*ptr) {
			ptr++;
			n_sz--;
		}

		/* In FIPS mode only allow key size 2K and higher */
		if (n_sz < 256) {
			pr_err("RSA: key size not allowed in FIPS mode\n");
			return -EINVAL;
		}
	}

	key->n = value;
	key->n_sz = vlen;

	return 0;
}

int rsa_get_e(void *context, size_t hdrlen, unsigned char tag,
	      const void *value, size_t vlen)
{
	struct rsa_key *key = context;

	/* invalid key provided */
	if (!value || !key->n_sz || !vlen || vlen > key->n_sz)
		return -EINVAL;

	key->e = value;
	key->e_sz = vlen;

	return 0;
}

int rsa_get_d(void *context, size_t hdrlen, unsigned char tag,
	      const void *value, size_t vlen)
{
	struct rsa_key *key = context;

	/* invalid key provided */
	if (!value || !key->n_sz || !vlen || vlen > key->n_sz)
		return -EINVAL;

	key->d = value;
	key->d_sz = vlen;

	return 0;
}

int rsa_get_p(void *context, size_t hdrlen, unsigned char tag,
	      const void *value, size_t vlen)
{
	struct rsa_key *key = context;

	/* invalid key provided */
	if (!value || !vlen || vlen > key->n_sz)
		return -EINVAL;

	key->p = value;
	key->p_sz = vlen;

	return 0;
}

int rsa_get_q(void *context, size_t hdrlen, unsigned char tag,
	      const void *value, size_t vlen)
{
	struct rsa_key *key = context;

	/* invalid key provided */
	if (!value || !vlen || vlen > key->n_sz)
		return -EINVAL;

	key->q = value;
	key->q_sz = vlen;

	return 0;
}

int rsa_get_dp(void *context, size_t hdrlen, unsigned char tag,
	       const void *value, size_t vlen)
{
	struct rsa_key *key = context;

	/* invalid key provided */
	if (!value || !vlen || vlen > key->n_sz)
		return -EINVAL;

	key->dp = value;
	key->dp_sz = vlen;

	return 0;
}

int rsa_get_dq(void *context, size_t hdrlen, unsigned char tag,
	       const void *value, size_t vlen)
{
	struct rsa_key *key = context;

	/* invalid key provided */
	if (!value || !vlen || vlen > key->n_sz)
		return -EINVAL;

	key->dq = value;
	key->dq_sz = vlen;

	return 0;
}

int rsa_get_qinv(void *context, size_t hdrlen, unsigned char tag,
		 const void *value, size_t vlen)
{
	struct rsa_key *key = context;

	/* invalid key provided */
	if (!value || !vlen || vlen > key->n_sz)
		return -EINVAL;

	key->qinv = value;
	key->qinv_sz = vlen;

	return 0;
}

/**
 * rsa_parse_pub_key() - decodes the BER encoded buffer and stores in the
 *                       provided struct rsa_key, pointers to the raw key as is,
 *                       so that the caller can copy it or MPI parse it, etc.
 *
 * @rsa_key:	struct rsa_key key representation
 * @key:	key in BER format
 * @key_len:	length of key
 *
 * Return:	0 on success or error code in case of error
 */
int rsa_parse_pub_key(struct rsa_key *rsa_key, const void *key,
		      unsigned int key_len)
{
	return asn1_ber_decoder(&rsapubkey_decoder, rsa_key, key, key_len);
}
EXPORT_SYMBOL_GPL(rsa_parse_pub_key);

/**
 * rsa_parse_priv_key() - decodes the BER encoded buffer and stores in the
 *                        provided struct rsa_key, pointers to the raw key
 *                        as is, so that the caller can copy it or MPI parse it,
 *                        etc.
 *
 * @rsa_key:	struct rsa_key key representation
 * @key:	key in BER format
 * @key_len:	length of key
 *
 * Return:	0 on success or error code in case of error
 */
int rsa_parse_priv_key(struct rsa_key *rsa_key, const void *key,
		       unsigned int key_len)
{
	return asn1_ber_decoder(&rsaprivkey_decoder, rsa_key, key, key_len);
}
EXPORT_SYMBOL_GPL(rsa_parse_priv_key);
feature/coretext main, development code repositoryroot
summaryrefslogtreecommitdiff
path: root/io
AgeCommit message (Expand)AuthorFilesLines
2018-08-01add operator+=(OUStringBuffer) method to OUStringNoel Grandin2-2/+2
2018-07-30Add missing sal/log.hxx headersGabor Kelemen1-0/+1
2018-07-23Fix typosAndrea Gelmini1-1/+1
2018-07-18Fix typosAndrea Gelmini1-1/+1
2018-07-08tdf#84323 - sal - add sane sleep interface: cleanup osl_waitThreadKevin Dubrulle2-7/+4
2018-03-18Use for-range loops in hwpfilter, i18n*, idl* and ioJulien Nabet1-10/+14
2018-01-24Fix typosAndrea Gelmini1-1/+1
2018-01-19SAL_W32 is just an alias for _WIN32Stephan Bergmann1-1/+1
2018-01-15remove local copies of std::min,std::maxNoel Grandin4-9/+6
2018-01-12More loplugin:cstylecast: ioStephan Bergmann1-22/+22
2018-01-11loplugin:useuniqueptr cppu,idlc,io,ucbhelperNoel Grandin1-11/+9
2017-12-19inline use-once typedefsNoel Grandin1-3/+1
2017-12-11loplugin:salcall fix functionsNoel Grandin10-25/+25
2017-11-23loplugin:simplifybool for negation of comparison operatorNoel Grandin1-3/+3
2017-10-30loplugin:constmethod in vcl and stocNoel Grandin2-3/+3
2017-10-23loplugin:includeform: ioStephan Bergmann11-24/+24
2017-10-04add << operator for css::uno::ExceptionNoel Grandin1-5/+5
2017-09-29loplugin:flatten check for throw in then clauseNoel Grandin1-15/+6
2017-09-22loplugin:flatten in framework..packageNoel Grandin5-219/+161
2017-09-04loplugin:unnecessaryparen include c++ castsNoel Grandin3-15/+15
2017-07-31loplugin:oncevarNoel Grandin2-12/+4
2017-07-22loplugin:unusedfields in ioNoel Grandin1-2/+3
2017-07-17RTL_UNICODETOTEXT_INFO_{DEST|SCR}BUFFERTOSMALL should use TOO, not TOChris Sherlock1-2/+2
2017-07-13loplugin:oncevar: empty strings: ioStephan Bergmann1-4/+2
2017-07-07loplugin:unnecessaryparen handle parens inside call exprNoel Grandin1-1/+1
2017-07-05new loplugin unnecessaryparenNoel Grandin1-2/+2
2017-06-27loplugin:useuniqueptr in variousNoel Grandin1-31/+12
2017-06-25loplugin:oncevar in helpcompiler..jvmfwkNoel Grandin2-6/+3
2017-06-18remove unused osl/mutex.hxx includesJochen Nitschke4-4/+0
2017-06-12clang-tidy readability-delete-null-pointerNoel Grandin2-20/+5
2017-05-31clang-tidy readability-redundant-control-flowNoel Grandin1-3/+0
2017-05-09cleanup osl/diagnose.h includesJochen Nitschke4-4/+0
2017-05-07revert OSL_ASSERT changesChris Sherlock5-22/+22
2017-05-07tdf#43157: convert cppuhelper and io from OSL_ASSERT to assertChris Sherlock5-22/+22
2017-04-21gbuild: Remove MSVC 2013 legacy codeDavid Ostrovsky1-1/+0
2017-03-30remove type decorations on char literalsJochen Nitschke1-1/+1
2017-03-23loplugins:redundantcast teach it about c-style typedef castsNoel Grandin2-4/+4
2017-03-16Fix typosAndrea Gelmini2-2/+2
2017-03-03Remove redundant 'inline' keywordStephan Bergmann1-1/+1
2017-02-10io: warn if OConnector can't connect to pipeMichael Stahl1-5/+4
2017-02-06Add missing #includesStephan Bergmann12-2/+22
2017-02-02unnecessary use of OUStringBuffer in throwing exceptionsNoel Grandin2-46/+29
2017-01-26Remove dynamic exception specificationsStephan Bergmann17-724/+330
2017-01-19New loplugin:dynexcspec: Add @throws documentation, ioStephan Bergmann6-1/+23
2017-01-17new loplugin: useuniqueptr: helpcompiler..ioNoel Grandin2-23/+10
2016-12-13OSL_TRACE->SAL in framework..salNoel Grandin2-20/+1
2016-12-05loplugin:unnecessaryoverride (dtors) in ioStephan Bergmann4-35/+1