summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjsing <>2019-10-24 16:26:13 +0000
committerjsing <>2019-10-24 16:26:13 +0000
commite76162e1394c75ce7b2d71cffbe5483c0725825d (patch)
tree7c02664411d33f6459e1dc8e6a3768f67a0cdfe1 /src
parentabc6e23413236ede23b95beac5c9e9e9ba8866e2 (diff)
downloadopenbsd-e76162e1394c75ce7b2d71cffbe5483c0725825d.tar.gz
openbsd-e76162e1394c75ce7b2d71cffbe5483c0725825d.tar.bz2
openbsd-e76162e1394c75ce7b2d71cffbe5483c0725825d.zip
Provide RSA_OAEP_PARAMS along with ASN.1 encoding/decoding.
For now these are internal only. From OpenSSL 1.1.1d. ok inoguchi@
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/rsa/rsa_asn1.c82
-rw-r--r--src/lib/libcrypto/rsa/rsa_locl.h17
2 files changed, 97 insertions, 2 deletions
diff --git a/src/lib/libcrypto/rsa/rsa_asn1.c b/src/lib/libcrypto/rsa/rsa_asn1.c
index f931a93e85..fa340a26d2 100644
--- a/src/lib/libcrypto/rsa/rsa_asn1.c
+++ b/src/lib/libcrypto/rsa/rsa_asn1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_asn1.c,v 1.13 2016/12/30 15:47:07 jsing Exp $ */ 1/* $OpenBSD: rsa_asn1.c,v 1.14 2019/10/24 16:26:13 jsing Exp $ */
2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL 2/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
3 * project 2000. 3 * project 2000.
4 */ 4 */
@@ -63,6 +63,8 @@
63#include <openssl/rsa.h> 63#include <openssl/rsa.h>
64#include <openssl/x509.h> 64#include <openssl/x509.h>
65 65
66#include "rsa_locl.h"
67
66/* Override the default free and new methods */ 68/* Override the default free and new methods */
67static int 69static int
68rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg) 70rsa_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
@@ -267,6 +269,84 @@ RSA_PSS_PARAMS_free(RSA_PSS_PARAMS *a)
267 ASN1_item_free((ASN1_VALUE *)a, &RSA_PSS_PARAMS_it); 269 ASN1_item_free((ASN1_VALUE *)a, &RSA_PSS_PARAMS_it);
268} 270}
269 271
272static int
273rsa_oaep_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
274{
275 /* Free up maskHash */
276 if (operation == ASN1_OP_FREE_PRE) {
277 RSA_OAEP_PARAMS *oaep = (RSA_OAEP_PARAMS *)*pval;
278 X509_ALGOR_free(oaep->maskHash);
279 }
280 return 1;
281}
282
283static const ASN1_AUX RSA_OAEP_PARAMS_aux = {
284 .app_data = NULL,
285 .flags = 0,
286 .ref_offset = 0,
287 .ref_lock = 0,
288 .asn1_cb = rsa_oaep_cb,
289 .enc_offset = 0,
290};
291static const ASN1_TEMPLATE RSA_OAEP_PARAMS_seq_tt[] = {
292 {
293 .flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL,
294 .tag = 0,
295 .offset = offsetof(RSA_OAEP_PARAMS, hashFunc),
296 .field_name = "hashFunc",
297 .item = &X509_ALGOR_it,
298 },
299 {
300 .flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL,
301 .tag = 1,
302 .offset = offsetof(RSA_OAEP_PARAMS, maskGenFunc),
303 .field_name = "maskGenFunc",
304 .item = &X509_ALGOR_it,
305 },
306 {
307 .flags = ASN1_TFLG_EXPLICIT | ASN1_TFLG_OPTIONAL,
308 .tag = 2,
309 .offset = offsetof(RSA_OAEP_PARAMS, pSourceFunc),
310 .field_name = "pSourceFunc",
311 .item = &X509_ALGOR_it,
312 },
313};
314
315const ASN1_ITEM RSA_OAEP_PARAMS_it = {
316 .itype = ASN1_ITYPE_SEQUENCE,
317 .utype = V_ASN1_SEQUENCE,
318 .templates = RSA_OAEP_PARAMS_seq_tt,
319 .tcount = sizeof(RSA_OAEP_PARAMS_seq_tt) / sizeof(ASN1_TEMPLATE),
320 .funcs = &RSA_OAEP_PARAMS_aux,
321 .size = sizeof(RSA_OAEP_PARAMS),
322 .sname = "RSA_OAEP_PARAMS",
323};
324
325
326RSA_OAEP_PARAMS *
327d2i_RSA_OAEP_PARAMS(RSA_OAEP_PARAMS **a, const unsigned char **in, long len)
328{
329 return (RSA_OAEP_PARAMS *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
330 &RSA_OAEP_PARAMS_it);
331}
332
333int
334i2d_RSA_OAEP_PARAMS(RSA_OAEP_PARAMS *a, unsigned char **out)
335{
336 return ASN1_item_i2d((ASN1_VALUE *)a, out, &RSA_OAEP_PARAMS_it);
337}
338
339RSA_OAEP_PARAMS *
340RSA_OAEP_PARAMS_new(void)
341{
342 return (RSA_OAEP_PARAMS *)ASN1_item_new(&RSA_OAEP_PARAMS_it);
343}
344
345void
346RSA_OAEP_PARAMS_free(RSA_OAEP_PARAMS *a)
347{
348 ASN1_item_free((ASN1_VALUE *)a, &RSA_OAEP_PARAMS_it);
349}
270 350
271RSA * 351RSA *
272d2i_RSAPrivateKey(RSA **a, const unsigned char **in, long len) 352d2i_RSAPrivateKey(RSA **a, const unsigned char **in, long len)
diff --git a/src/lib/libcrypto/rsa/rsa_locl.h b/src/lib/libcrypto/rsa/rsa_locl.h
index 28bf4110c2..0d86799777 100644
--- a/src/lib/libcrypto/rsa/rsa_locl.h
+++ b/src/lib/libcrypto/rsa/rsa_locl.h
@@ -1,7 +1,22 @@
1/* $OpenBSD: rsa_locl.h,v 1.5 2019/10/04 16:51:31 jsing Exp $ */ 1/* $OpenBSD: rsa_locl.h,v 1.6 2019/10/24 16:26:13 jsing Exp $ */
2 2
3__BEGIN_HIDDEN_DECLS 3__BEGIN_HIDDEN_DECLS
4 4
5typedef struct rsa_oaep_params_st {
6 X509_ALGOR *hashFunc;
7 X509_ALGOR *maskGenFunc;
8 X509_ALGOR *pSourceFunc;
9
10 /* Hash algorithm decoded from maskGenFunc. */
11 X509_ALGOR *maskHash;
12} RSA_OAEP_PARAMS;
13
14RSA_OAEP_PARAMS *RSA_OAEP_PARAMS_new(void);
15void RSA_OAEP_PARAMS_free(RSA_OAEP_PARAMS *a);
16RSA_OAEP_PARAMS *d2i_RSA_OAEP_PARAMS(RSA_OAEP_PARAMS **a, const unsigned char **in, long len);
17int i2d_RSA_OAEP_PARAMS(RSA_OAEP_PARAMS *a, unsigned char **out);
18extern const ASN1_ITEM RSA_OAEP_PARAMS_it;
19
5extern int int_rsa_verify(int dtype, const unsigned char *m, 20extern int int_rsa_verify(int dtype, const unsigned char *m,
6 unsigned int m_len, unsigned char *rm, size_t *prm_len, 21 unsigned int m_len, unsigned char *rm, size_t *prm_len,
7 const unsigned char *sigbuf, size_t siglen, RSA *rsa); 22 const unsigned char *sigbuf, size_t siglen, RSA *rsa);