|
Lines 21-26
Link Here
|
| 21 |
#ifndef OPENSSL_RSA_PUBLIC_KEY_H_ |
21 |
#ifndef OPENSSL_RSA_PUBLIC_KEY_H_ |
| 22 |
#define OPENSSL_RSA_PUBLIC_KEY_H_ |
22 |
#define OPENSSL_RSA_PUBLIC_KEY_H_ |
| 23 |
|
23 |
|
|
|
24 |
#if OPENSSL_VERSION_NUMBER < 0x10100000L |
| 25 |
/** |
| 26 |
* OpenSSL compat functions |
| 27 |
* From https://wiki.openssl.org/index.php/OpenSSL_1.1.0_Changes |
| 28 |
*/ |
| 29 |
|
| 30 |
/* See src/libstrongswan/plugins/openssl/openssl_util.c #define OBJ_get0_data(o) ((o)->data) |
| 31 |
#define OBJ_length(o) ((o)->length) /* |
| 32 |
|
| 33 |
#include <string.h> |
| 34 |
#include <openssl/engine.h> |
| 35 |
|
| 36 |
int RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d) |
| 37 |
{ |
| 38 |
/* If the fields n and e in r are NULL, the corresponding input |
| 39 |
* parameters MUST be non-NULL for n and e. d may be |
| 40 |
* left NULL (in case only the public key is used). |
| 41 |
*/ |
| 42 |
if ((r->n == NULL && n == NULL) |
| 43 |
|| (r->e == NULL && e == NULL)) |
| 44 |
return 0; |
| 45 |
|
| 46 |
if (n != NULL) { |
| 47 |
BN_free(r->n); |
| 48 |
r->n = n; |
| 49 |
} |
| 50 |
if (e != NULL) { |
| 51 |
BN_free(r->e); |
| 52 |
r->e = e; |
| 53 |
} |
| 54 |
if (d != NULL) { |
| 55 |
BN_free(r->d); |
| 56 |
r->d = d; |
| 57 |
} |
| 58 |
|
| 59 |
return 1; |
| 60 |
} |
| 61 |
|
| 62 |
int RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q) |
| 63 |
{ |
| 64 |
/* If the fields p and q in r are NULL, the corresponding input |
| 65 |
* parameters MUST be non-NULL. |
| 66 |
*/ |
| 67 |
if ((r->p == NULL && p == NULL) |
| 68 |
|| (r->q == NULL && q == NULL)) |
| 69 |
return 0; |
| 70 |
|
| 71 |
if (p != NULL) { |
| 72 |
BN_free(r->p); |
| 73 |
r->p = p; |
| 74 |
} |
| 75 |
if (q != NULL) { |
| 76 |
BN_free(r->q); |
| 77 |
r->q = q; |
| 78 |
} |
| 79 |
|
| 80 |
return 1; |
| 81 |
} |
| 82 |
|
| 83 |
int RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp) |
| 84 |
{ |
| 85 |
/* If the fields dmp1, dmq1 and iqmp in r are NULL, the corresponding input |
| 86 |
* parameters MUST be non-NULL. |
| 87 |
*/ |
| 88 |
if ((r->dmp1 == NULL && dmp1 == NULL) |
| 89 |
|| (r->dmq1 == NULL && dmq1 == NULL) |
| 90 |
|| (r->iqmp == NULL && iqmp == NULL)) |
| 91 |
return 0; |
| 92 |
|
| 93 |
if (dmp1 != NULL) { |
| 94 |
BN_free(r->dmp1); |
| 95 |
r->dmp1 = dmp1; |
| 96 |
} |
| 97 |
if (dmq1 != NULL) { |
| 98 |
BN_free(r->dmq1); |
| 99 |
r->dmq1 = dmq1; |
| 100 |
} |
| 101 |
if (iqmp != NULL) { |
| 102 |
BN_free(r->iqmp); |
| 103 |
r->iqmp = iqmp; |
| 104 |
} |
| 105 |
|
| 106 |
return 1; |
| 107 |
} |
| 108 |
|
| 109 |
void RSA_get0_key(const RSA *r, |
| 110 |
const BIGNUM **n, const BIGNUM **e, const BIGNUM **d) |
| 111 |
{ |
| 112 |
if (n != NULL) |
| 113 |
*n = r->n; |
| 114 |
if (e != NULL) |
| 115 |
*e = r->e; |
| 116 |
if (d != NULL) |
| 117 |
*d = r->d; |
| 118 |
} |
| 119 |
|
| 120 |
void DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key) |
| 121 |
{ |
| 122 |
if (pub_key != NULL) |
| 123 |
*pub_key = dh->pub_key; |
| 124 |
if (priv_key != NULL) |
| 125 |
*priv_key = dh->priv_key; |
| 126 |
} |
| 127 |
|
| 128 |
int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key) |
| 129 |
{ |
| 130 |
/* If the field pub_key in dh is NULL, the corresponding input |
| 131 |
* parameters MUST be non-NULL. The priv_key field may |
| 132 |
* be left NULL. |
| 133 |
*/ |
| 134 |
if (dh->pub_key == NULL && pub_key == NULL) |
| 135 |
return 0; |
| 136 |
|
| 137 |
if (pub_key != NULL) { |
| 138 |
BN_free(dh->pub_key); |
| 139 |
dh->pub_key = pub_key; |
| 140 |
} |
| 141 |
if (priv_key != NULL) { |
| 142 |
BN_free(dh->priv_key); |
| 143 |
dh->priv_key = priv_key; |
| 144 |
} |
| 145 |
|
| 146 |
return 1; |
| 147 |
} |
| 148 |
|
| 149 |
int DH_set_length(DH *dh, long length) |
| 150 |
{ |
| 151 |
dh->length = length; |
| 152 |
return 1; |
| 153 |
} |
| 154 |
|
| 155 |
#endif |
| 156 |
|
| 24 |
typedef struct openssl_rsa_public_key_t openssl_rsa_public_key_t; |
157 |
typedef struct openssl_rsa_public_key_t openssl_rsa_public_key_t; |
| 25 |
|
158 |
|
| 26 |
#include <credentials/keys/public_key.h> |
159 |
#include <credentials/keys/public_key.h> |