11 #include RUBY_EXTCONF_H
13 #if defined(HAVE_OPENSSL_ENGINE_H) && defined(HAVE_ST_ENGINE)
14 # include <openssl/engine.h>
16 #include <openssl/x509_vfy.h>
18 #if !defined(OPENSSL_NO_HMAC)
20 #include <openssl/hmac.h>
24 #if !defined(HAVE_HMAC_CTX_COPY)
28 if (!out || !in)
return;
29 memcpy(out, in,
sizeof(HMAC_CTX));
31 EVP_MD_CTX_copy(&out->md_ctx, &in->md_ctx);
32 EVP_MD_CTX_copy(&out->i_ctx, &in->i_ctx);
33 EVP_MD_CTX_copy(&out->o_ctx, &in->o_ctx);
38 #if !defined(HAVE_X509_STORE_SET_EX_DATA)
41 return CRYPTO_set_ex_data(&str->ex_data, idx, data);
45 #if !defined(HAVE_X509_STORE_GET_EX_DATA)
48 return CRYPTO_get_ex_data(&str->ex_data, idx);
52 #if !defined(HAVE_EVP_MD_CTX_CREATE)
56 EVP_MD_CTX *ctx = OPENSSL_malloc(
sizeof(EVP_MD_CTX));
57 if (!ctx)
return NULL;
59 memset(ctx, 0,
sizeof(EVP_MD_CTX));
65 #if !defined(HAVE_EVP_MD_CTX_CLEANUP)
70 memset(ctx, 0,
sizeof(EVP_MD_CTX));
76 #if !defined(HAVE_EVP_MD_CTX_DESTROY)
85 #if !defined(HAVE_EVP_MD_CTX_INIT)
89 memset(ctx, 0,
sizeof(EVP_MD_CTX));
93 #if !defined(HAVE_HMAC_CTX_INIT)
103 #if !defined(HAVE_HMAC_CTX_CLEANUP)
110 memset(ctx, 0,
sizeof(HMAC_CTX));
114 #if !defined(HAVE_EVP_CIPHER_CTX_COPY)
123 memcpy(out, in,
sizeof(EVP_CIPHER_CTX));
125 #if defined(HAVE_ENGINE_ADD) && defined(HAVE_ST_ENGINE)
126 if (in->engine) ENGINE_add(out->engine);
127 if (in->cipher_data) {
128 out->cipher_data = OPENSSL_malloc(in->cipher->ctx_size);
129 memcpy(out->cipher_data, in->cipher_data, in->cipher->ctx_size);
137 #if !defined(HAVE_X509_CRL_SET_VERSION)
141 if (x ==
NULL || x->crl ==
NULL)
return 0;
142 if (x->crl->version ==
NULL) {
143 x->crl->version = M_ASN1_INTEGER_new();
144 if (x->crl->version ==
NULL)
return 0;
146 return ASN1_INTEGER_set(x->crl->version, version);
150 #if !defined(HAVE_X509_CRL_SET_ISSUER_NAME)
154 if (x ==
NULL || x->crl ==
NULL)
return 0;
155 return X509_NAME_set(&x->crl->issuer, name);
159 #if !defined(HAVE_X509_CRL_SORT)
167 sk_X509_REVOKED_sort(c->crl->revoked);
168 for (i=0; i<sk_X509_REVOKED_num(c->crl->revoked); i++) {
169 r=sk_X509_REVOKED_value(c->crl->revoked, i);
176 #if !defined(HAVE_X509_CRL_ADD0_REVOKED)
180 return(ASN1_STRING_cmp(
181 (ASN1_STRING *)(*a)->serialNumber,
182 (ASN1_STRING *)(*b)->serialNumber));
193 if (!inf->revoked || !sk_X509_REVOKED_push(inf->revoked, rev))
199 #if !defined(HAVE_BN_MOD_SQR)
203 if (!BN_sqr(r, (BIGNUM*)a, ctx))
return 0;
204 return BN_mod(r, r, m, ctx);
208 #if !defined(HAVE_BN_MOD_ADD) || !defined(HAVE_BN_MOD_SUB)
209 int BN_nnmod(BIGNUM *
r,
const BIGNUM *
m,
const BIGNUM *
d, BN_CTX *ctx)
211 if (!BN_mod(r,m,d,ctx))
return 0;
212 if (!r->neg)
return 1;
213 return (d->neg ? BN_sub : BN_add)(
r,
r,
d);
217 #if !defined(HAVE_BN_MOD_ADD)
219 BN_mod_add(BIGNUM *
r,
const BIGNUM *
a,
const BIGNUM *
b,
const BIGNUM *
m, BN_CTX *ctx)
221 if (!BN_add(r, a, b))
return 0;
226 #if !defined(HAVE_BN_MOD_SUB)
228 BN_mod_sub(BIGNUM *
r,
const BIGNUM *
a,
const BIGNUM *
b,
const BIGNUM *
m, BN_CTX *ctx)
230 if (!BN_sub(r, a, b))
return 0;
235 #if !defined(HAVE_BN_RAND_RANGE) || !defined(HAVE_BN_PSEUDO_RAND_RANGE)
239 int (*bn_rand)(BIGNUM *,
int,
int,
int) = pseudo ? BN_pseudo_rand : BN_rand;
242 if (range->neg || BN_is_zero(range))
return 0;
244 n = BN_num_bits(range);
247 if (!BN_zero(r))
return 0;
248 }
else if (!BN_is_bit_set(range, n - 2) && !BN_is_bit_set(range, n - 3)) {
250 if (!bn_rand(r, n + 1, -1, 0))
return 0;
251 if (BN_cmp(r ,range) >= 0) {
252 if (!BN_sub(r, r, range))
return 0;
253 if (BN_cmp(r, range) >= 0)
254 if (!BN_sub(r, r, range))
return 0;
256 }
while (BN_cmp(r, range) >= 0);
259 if (!bn_rand(r, n, -1, 0))
return 0;
260 }
while (BN_cmp(r, range) >= 0);
267 #if !defined(HAVE_BN_RAND_RANGE)
275 #if !defined(HAVE_BN_PSEUDO_RAND_RANGE)
283 #if !defined(HAVE_CONF_GET1_DEFAULT_CONFIG_FILE)
284 #define OPENSSL_CONF "openssl.cnf"
291 file =
getenv(
"OPENSSL_CONF");
292 if (file)
return BUF_strdup(file);
293 len =
strlen(X509_get_default_cert_area());
294 #ifndef OPENSSL_SYS_VMS
298 file = OPENSSL_malloc(len + 1);
299 if (!file)
return NULL;
300 strcpy(file,X509_get_default_cert_area());
301 #ifndef OPENSSL_SYS_VMS
310 #if !defined(HAVE_PEM_DEF_CALLBACK)
311 #define OSSL_PASS_MIN_LENGTH 4
320 i = (i > num) ? num : i;
325 prompt = EVP_get_pw_prompt();
326 if (prompt ==
NULL) prompt =
"Enter PEM pass phrase:";
328 i = EVP_read_pw_string(buf, num, prompt, w);
330 memset(buf, 0, (
unsigned int)num);
336 "phrase is too short, needs to be at least %d chars\n",
345 #if !defined(HAVE_ASN1_PUT_EOC)
349 unsigned char *
p = *pp;
int BN_rand_range(BIGNUM *r, BIGNUM *range)
size_t strlen(const char *)
static int OSSL_X509_REVOKED_cmp(const X509_REVOKED *const *a, const X509_REVOKED *const *b)
void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
void HMAC_CTX_copy(HMAC_CTX *out, HMAC_CTX *in)
void * X509_STORE_get_ex_data(X509_STORE *str, int idx)
int BN_mod_add(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
int X509_CRL_sort(X509_CRL *c)
memset(y->frac+ix+1, 0,(y->Prec-(ix+1))*sizeof(BDIGIT))
#define range(low, item, hi)
unsigned char buf[MIME_BUF_SIZE]
int X509_CRL_set_issuer_name(X509_CRL *x, X509_NAME *name)
int PEM_def_callback(char *buf, int num, int w, void *key)
EVP_MD_CTX * EVP_MD_CTX_create(void)
int BN_pseudo_rand_range(BIGNUM *r, BIGNUM *range)
int X509_STORE_set_ex_data(X509_STORE *str, int idx, void *data)
#define OSSL_PASS_MIN_LENGTH
void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
static int bn_rand_range(int pseudo, BIGNUM *r, BIGNUM *range)
void HMAC_CTX_init(HMAC_CTX *ctx)
int X509_CRL_add0_revoked(X509_CRL *crl, X509_REVOKED *rev)
int ASN1_put_eoc(unsigned char **pp)
int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
int BN_mod_sub(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m, BN_CTX *ctx)
char * CONF_get1_default_config_file(void)
static void version(void)
int EVP_CIPHER_CTX_copy(EVP_CIPHER_CTX *out, EVP_CIPHER_CTX *in)
int X509_CRL_set_version(X509_CRL *x, long version)
void HMAC_CTX_cleanup(HMAC_CTX *ctx)
int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)