summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortb <>2022-01-14 08:34:39 +0000
committertb <>2022-01-14 08:34:39 +0000
commit385790bbe258a0de5b6842a60a07a834e590fe1a (patch)
treed1055b55981f9ad17a7c3eba698619cd0ce84aed
parent57442b0028fb09287793f279ee57ebb38e9ab954 (diff)
downloadopenbsd-385790bbe258a0de5b6842a60a07a834e590fe1a.tar.gz
openbsd-385790bbe258a0de5b6842a60a07a834e590fe1a.tar.bz2
openbsd-385790bbe258a0de5b6842a60a07a834e590fe1a.zip
Make RSA, RSA_PSS_PARAMS and RSA_METHOD opaque
Move the struct internals to rsa_locl.h and provide a missing typedef in ossl_typ.h. ok inoguchi jsing
-rw-r--r--src/lib/libcrypto/ossl_typ.h3
-rw-r--r--src/lib/libcrypto/rsa/rsa.h84
-rw-r--r--src/lib/libcrypto/rsa/rsa_locl.h76
3 files changed, 80 insertions, 83 deletions
diff --git a/src/lib/libcrypto/ossl_typ.h b/src/lib/libcrypto/ossl_typ.h
index 161bf86a3e..4f94c4032e 100644
--- a/src/lib/libcrypto/ossl_typ.h
+++ b/src/lib/libcrypto/ossl_typ.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: ossl_typ.h,v 1.19 2022/01/14 08:21:12 tb Exp $ */ 1/* $OpenBSD: ossl_typ.h,v 1.20 2022/01/14 08:34:39 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2001 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -121,6 +121,7 @@ typedef struct dsa_method DSA_METHOD;
121 121
122typedef struct rsa_st RSA; 122typedef struct rsa_st RSA;
123typedef struct rsa_meth_st RSA_METHOD; 123typedef struct rsa_meth_st RSA_METHOD;
124typedef struct rsa_pss_params_st RSA_PSS_PARAMS;
124 125
125typedef struct rand_meth_st RAND_METHOD; 126typedef struct rand_meth_st RAND_METHOD;
126 127
diff --git a/src/lib/libcrypto/rsa/rsa.h b/src/lib/libcrypto/rsa/rsa.h
index e01e6ba553..d59fd03f76 100644
--- a/src/lib/libcrypto/rsa/rsa.h
+++ b/src/lib/libcrypto/rsa/rsa.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa.h,v 1.54 2022/01/14 08:12:31 tb Exp $ */ 1/* $OpenBSD: rsa.h,v 1.55 2022/01/14 08:34:39 tb Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -80,11 +80,7 @@
80extern "C" { 80extern "C" {
81#endif 81#endif
82 82
83/* Declared already in ossl_typ.h */ 83struct rsa_pss_params_st {
84/* typedef struct rsa_st RSA; */
85/* typedef struct rsa_meth_st RSA_METHOD; */
86
87typedef struct rsa_pss_params_st {
88 X509_ALGOR *hashAlgorithm; 84 X509_ALGOR *hashAlgorithm;
89 X509_ALGOR *maskGenAlgorithm; 85 X509_ALGOR *maskGenAlgorithm;
90 ASN1_INTEGER *saltLength; 86 ASN1_INTEGER *saltLength;
@@ -92,7 +88,7 @@ typedef struct rsa_pss_params_st {
92 88
93 /* Hash algorithm decoded from maskGenAlgorithm. */ 89 /* Hash algorithm decoded from maskGenAlgorithm. */
94 X509_ALGOR *maskHash; 90 X509_ALGOR *maskHash;
95} RSA_PSS_PARAMS; 91} /* RSA_PSS_PARAMS */;
96 92
97typedef struct rsa_oaep_params_st { 93typedef struct rsa_oaep_params_st {
98 X509_ALGOR *hashFunc; 94 X509_ALGOR *hashFunc;
@@ -103,80 +99,6 @@ typedef struct rsa_oaep_params_st {
103 X509_ALGOR *maskHash; 99 X509_ALGOR *maskHash;
104} RSA_OAEP_PARAMS; 100} RSA_OAEP_PARAMS;
105 101
106struct rsa_meth_st {
107 const char *name;
108 int (*rsa_pub_enc)(int flen, const unsigned char *from,
109 unsigned char *to, RSA *rsa, int padding);
110 int (*rsa_pub_dec)(int flen, const unsigned char *from,
111 unsigned char *to, RSA *rsa, int padding);
112 int (*rsa_priv_enc)(int flen, const unsigned char *from,
113 unsigned char *to, RSA *rsa, int padding);
114 int (*rsa_priv_dec)(int flen, const unsigned char *from,
115 unsigned char *to, RSA *rsa, int padding);
116 int (*rsa_mod_exp)(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
117 BN_CTX *ctx); /* Can be null */
118 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
119 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); /* Can be null */
120 int (*init)(RSA *rsa); /* called at new */
121 int (*finish)(RSA *rsa); /* called at free */
122 int flags; /* RSA_METHOD_FLAG_* things */
123 char *app_data; /* may be needed! */
124/* New sign and verify functions: some libraries don't allow arbitrary data
125 * to be signed/verified: this allows them to be used. Note: for this to work
126 * the RSA_public_decrypt() and RSA_private_encrypt() should *NOT* be used
127 * RSA_sign(), RSA_verify() should be used instead. Note: for backwards
128 * compatibility this functionality is only enabled if the RSA_FLAG_SIGN_VER
129 * option is set in 'flags'.
130 */
131 int (*rsa_sign)(int type, const unsigned char *m, unsigned int m_length,
132 unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
133 int (*rsa_verify)(int dtype, const unsigned char *m,
134 unsigned int m_length, const unsigned char *sigbuf,
135 unsigned int siglen, const RSA *rsa);
136/* If this callback is NULL, the builtin software RSA key-gen will be used. This
137 * is for behavioural compatibility whilst the code gets rewired, but one day
138 * it would be nice to assume there are no such things as "builtin software"
139 * implementations. */
140 int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
141};
142
143struct rsa_st {
144 /* The first parameter is used to pickup errors where
145 * this is passed instead of aEVP_PKEY, it is set to 0 */
146 int pad;
147 long version;
148 const RSA_METHOD *meth;
149
150 /* functional reference if 'meth' is ENGINE-provided */
151 ENGINE *engine;
152 BIGNUM *n;
153 BIGNUM *e;
154 BIGNUM *d;
155 BIGNUM *p;
156 BIGNUM *q;
157 BIGNUM *dmp1;
158 BIGNUM *dmq1;
159 BIGNUM *iqmp;
160
161 /* Parameter restrictions for PSS only keys. */
162 RSA_PSS_PARAMS *pss;
163
164 /* be careful using this if the RSA structure is shared */
165 CRYPTO_EX_DATA ex_data;
166 int references;
167 int flags;
168
169 /* Used to cache montgomery values */
170 BN_MONT_CTX *_method_mod_n;
171 BN_MONT_CTX *_method_mod_p;
172 BN_MONT_CTX *_method_mod_q;
173
174 /* all BIGNUM values are actually in the following data, if it is not
175 * NULL */
176 BN_BLINDING *blinding;
177 BN_BLINDING *mt_blinding;
178};
179
180#ifndef OPENSSL_RSA_MAX_MODULUS_BITS 102#ifndef OPENSSL_RSA_MAX_MODULUS_BITS
181# define OPENSSL_RSA_MAX_MODULUS_BITS 16384 103# define OPENSSL_RSA_MAX_MODULUS_BITS 16384
182#endif 104#endif
diff --git a/src/lib/libcrypto/rsa/rsa_locl.h b/src/lib/libcrypto/rsa/rsa_locl.h
index 7036449c36..9eae2b3a24 100644
--- a/src/lib/libcrypto/rsa/rsa_locl.h
+++ b/src/lib/libcrypto/rsa/rsa_locl.h
@@ -1,4 +1,4 @@
1/* $OpenBSD: rsa_locl.h,v 1.11 2019/11/02 13:47:41 jsing Exp $ */ 1/* $OpenBSD: rsa_locl.h,v 1.12 2022/01/14 08:34:39 tb Exp $ */
2 2
3__BEGIN_HIDDEN_DECLS 3__BEGIN_HIDDEN_DECLS
4 4
@@ -8,6 +8,80 @@ __BEGIN_HIDDEN_DECLS
8#define pkey_is_pss(pkey) (pkey->ameth->pkey_id == EVP_PKEY_RSA_PSS) 8#define pkey_is_pss(pkey) (pkey->ameth->pkey_id == EVP_PKEY_RSA_PSS)
9#define pkey_ctx_is_pss(ctx) (ctx->pmeth->pkey_id == EVP_PKEY_RSA_PSS) 9#define pkey_ctx_is_pss(ctx) (ctx->pmeth->pkey_id == EVP_PKEY_RSA_PSS)
10 10
11struct rsa_meth_st {
12 const char *name;
13 int (*rsa_pub_enc)(int flen, const unsigned char *from,
14 unsigned char *to, RSA *rsa, int padding);
15 int (*rsa_pub_dec)(int flen, const unsigned char *from,
16 unsigned char *to, RSA *rsa, int padding);
17 int (*rsa_priv_enc)(int flen, const unsigned char *from,
18 unsigned char *to, RSA *rsa, int padding);
19 int (*rsa_priv_dec)(int flen, const unsigned char *from,
20 unsigned char *to, RSA *rsa, int padding);
21 int (*rsa_mod_exp)(BIGNUM *r0, const BIGNUM *I, RSA *rsa,
22 BN_CTX *ctx); /* Can be null */
23 int (*bn_mod_exp)(BIGNUM *r, const BIGNUM *a, const BIGNUM *p,
24 const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx); /* Can be null */
25 int (*init)(RSA *rsa); /* called at new */
26 int (*finish)(RSA *rsa); /* called at free */
27 int flags; /* RSA_METHOD_FLAG_* things */
28 char *app_data; /* may be needed! */
29/* New sign and verify functions: some libraries don't allow arbitrary data
30 * to be signed/verified: this allows them to be used. Note: for this to work
31 * the RSA_public_decrypt() and RSA_private_encrypt() should *NOT* be used
32 * RSA_sign(), RSA_verify() should be used instead. Note: for backwards
33 * compatibility this functionality is only enabled if the RSA_FLAG_SIGN_VER
34 * option is set in 'flags'.
35 */
36 int (*rsa_sign)(int type, const unsigned char *m, unsigned int m_length,
37 unsigned char *sigret, unsigned int *siglen, const RSA *rsa);
38 int (*rsa_verify)(int dtype, const unsigned char *m,
39 unsigned int m_length, const unsigned char *sigbuf,
40 unsigned int siglen, const RSA *rsa);
41/* If this callback is NULL, the builtin software RSA key-gen will be used. This
42 * is for behavioural compatibility whilst the code gets rewired, but one day
43 * it would be nice to assume there are no such things as "builtin software"
44 * implementations. */
45 int (*rsa_keygen)(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb);
46};
47
48struct rsa_st {
49 /* The first parameter is used to pickup errors where
50 * this is passed instead of aEVP_PKEY, it is set to 0 */
51 int pad;
52 long version;
53 const RSA_METHOD *meth;
54
55 /* functional reference if 'meth' is ENGINE-provided */
56 ENGINE *engine;
57 BIGNUM *n;
58 BIGNUM *e;
59 BIGNUM *d;
60 BIGNUM *p;
61 BIGNUM *q;
62 BIGNUM *dmp1;
63 BIGNUM *dmq1;
64 BIGNUM *iqmp;
65
66 /* Parameter restrictions for PSS only keys. */
67 RSA_PSS_PARAMS *pss;
68
69 /* be careful using this if the RSA structure is shared */
70 CRYPTO_EX_DATA ex_data;
71 int references;
72 int flags;
73
74 /* Used to cache montgomery values */
75 BN_MONT_CTX *_method_mod_n;
76 BN_MONT_CTX *_method_mod_p;
77 BN_MONT_CTX *_method_mod_q;
78
79 /* all BIGNUM values are actually in the following data, if it is not
80 * NULL */
81 BN_BLINDING *blinding;
82 BN_BLINDING *mt_blinding;
83};
84
11RSA_PSS_PARAMS *rsa_pss_params_create(const EVP_MD *sigmd, const EVP_MD *mgf1md, 85RSA_PSS_PARAMS *rsa_pss_params_create(const EVP_MD *sigmd, const EVP_MD *mgf1md,
12 int saltlen); 86 int saltlen);
13int rsa_pss_get_param(const RSA_PSS_PARAMS *pss, const EVP_MD **pmd, 87int rsa_pss_get_param(const RSA_PSS_PARAMS *pss, const EVP_MD **pmd,