Debian Codegraph @

lib_pypy/_cffi_ssl/_cffi_src/openssl/rsa.py

raw symbols SCIP
1 # This file is dual licensed under the terms of the Apache License, Version
2 # 2.0, and the BSD License. See the LICENSE file in the root of this repository
3 # for complete details.
4
5 from __future__ import absolute_import, division, print_function
6
7 INCLUDES = """
8 #include <openssl/rsa.h>
9 """
10
11 TYPES = """
12 typedef ... RSA;
13 typedef ... BN_GENCB;
14 static const int RSA_PKCS1_PADDING;
15 static const int RSA_NO_PADDING;
16 static const int RSA_PKCS1_OAEP_PADDING;
17 static const int RSA_PKCS1_PSS_PADDING;
18 static const int RSA_F4;
19
20 static const int Cryptography_HAS_PSS_PADDING;
21 static const int Cryptography_HAS_RSA_OAEP_MD;
22 static const int Cryptography_HAS_RSA_OAEP_LABEL;
23 """
24
25 FUNCTIONS = """
26 RSA *RSA_new(void);
27 void RSA_free(RSA *);
28 int RSA_size(const RSA *);
29 int RSA_generate_key_ex(RSA *, int, BIGNUM *, BN_GENCB *);
30 int RSA_check_key(const RSA *);
31 RSA *RSAPublicKey_dup(RSA *);
32 int RSA_blinding_on(RSA *, BN_CTX *);
33 int RSA_public_encrypt(int, const unsigned char *, unsigned char *,
34 RSA *, int);
35 int RSA_private_encrypt(int, const unsigned char *, unsigned char *,
36 RSA *, int);
37 int RSA_public_decrypt(int, const unsigned char *, unsigned char *,
38 RSA *, int);
39 int RSA_private_decrypt(int, const unsigned char *, unsigned char *,
40 RSA *, int);
41 int RSA_print(BIO *, const RSA *, int);
42
43 /* added in 1.1.0 when the RSA struct was opaqued */
44 int RSA_set0_key(RSA *, BIGNUM *, BIGNUM *, BIGNUM *);
45 int RSA_set0_factors(RSA *, BIGNUM *, BIGNUM *);
46 int RSA_set0_crt_params(RSA *, BIGNUM *, BIGNUM *, BIGNUM *);
47 void RSA_get0_key(const RSA *, const BIGNUM **, const BIGNUM **,
48 const BIGNUM **);
49 void RSA_get0_factors(const RSA *, const BIGNUM **, const BIGNUM **);
50 void RSA_get0_crt_params(const RSA *, const BIGNUM **, const BIGNUM **,
51 const BIGNUM **);
52 // int EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *, int);
53 //int EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *, int);
54 int EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *, EVP_MD *);
55 int EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *, unsigned char *, int);
56
57 int EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *, EVP_MD *);
58 """
59
60 CUSTOMIZATIONS = """
61 static const long Cryptography_HAS_PSS_PADDING = 1;
62
63 #if !CRYPTOGRAPHY_IS_LIBRESSL
64 static const long Cryptography_HAS_RSA_OAEP_MD = 1;
65 static const long Cryptography_HAS_RSA_OAEP_LABEL = 1;
66 #else
67 static const long Cryptography_HAS_RSA_OAEP_MD = 0;
68 static const long Cryptography_HAS_RSA_OAEP_LABEL = 0;
69 int (*EVP_PKEY_CTX_set_rsa_oaep_md)(EVP_PKEY_CTX *, EVP_MD *) = NULL;
70 int (*EVP_PKEY_CTX_set0_rsa_oaep_label)(EVP_PKEY_CTX *, unsigned char *,
71 int) = NULL;
72 #endif
73
74 /* These functions were added in OpenSSL 1.1.0 */
75 #if CRYPTOGRAPHY_OPENSSL_LESS_THAN_110 && !CRYPTOGRAPHY_LIBRESSL_27_OR_GREATER
76 int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
77 {
78 /* If the fields n and e in r are NULL, the corresponding input
79 * parameters MUST be non-NULL for n and e. d may be
80 * left NULL (in case only the public key is used).
81 */
82 if ((r->n == NULL && n == NULL)
83 || (r->e == NULL && e == NULL))
84 return 0;
85
86 if (n != NULL) {
87 BN_free(r->n);
88 r->n = n;
89 }
90 if (e != NULL) {
91 BN_free(r->e);
92 r->e = e;
93 }
94 if (d != NULL) {
95 BN_free(r->d);
96 r->d = d;
97 }
98
99 return 1;
100 }
101
102 int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
103 {
104 /* If the fields p and q in r are NULL, the corresponding input
105 * parameters MUST be non-NULL.
106 */
107 if ((r->p == NULL && p == NULL)
108 || (r->q == NULL && q == NULL))
109 return 0;
110
111 if (p != NULL) {
112 BN_free(r->p);
113 r->p = p;
114 }
115 if (q != NULL) {
116 BN_free(r->q);
117 r->q = q;
118 }
119
120 return 1;
121 }
122
123 int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
124 {
125 /* If the fields dmp1, dmq1 and iqmp in r are NULL, the corresponding input
126 * parameters MUST be non-NULL.
127 */
128 if ((r->dmp1 == NULL && dmp1 == NULL)
129 || (r->dmq1 == NULL && dmq1 == NULL)
130 || (r->iqmp == NULL && iqmp == NULL))
131 return 0;
132
133 if (dmp1 != NULL) {
134 BN_free(r->dmp1);
135 r->dmp1 = dmp1;
136 }
137 if (dmq1 != NULL) {
138 BN_free(r->dmq1);
139 r->dmq1 = dmq1;
140 }
141 if (iqmp != NULL) {
142 BN_free(r->iqmp);
143 r->iqmp = iqmp;
144 }
145
146 return 1;
147 }
148
149 void RSA_get0_key(const RSA *r,
150 const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
151 {
152 if (n != NULL)
153 *n = r->n;
154 if (e != NULL)
155 *e = r->e;
156 if (d != NULL)
157 *d = r->d;
158 }
159
160 void RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
161 {
162 if (p != NULL)
163 *p = r->p;
164 if (q != NULL)
165 *q = r->q;
166 }
167
168 void RSA_get0_crt_params(const RSA *r,
169 const BIGNUM **dmp1, const BIGNUM **dmq1,
170 const BIGNUM **iqmp)
171 {
172 if (dmp1 != NULL)
173 *dmp1 = r->dmp1;
174 if (dmq1 != NULL)
175 *dmq1 = r->dmq1;
176 if (iqmp != NULL)
177 *iqmp = r->iqmp;
178 }
179 #endif
180 """