1 use std
::sync
::{Mutex, MutexGuard}
;
2 use std
::sync
::{Once, ONCE_INIT}
;
7 pub use libressl
::v250
::*;
8 #[cfg(not(libressl250))]
9 pub use libressl
::v25x
::*;
11 use libc
::{c_int, c_char, c_void, c_long, c_uchar, size_t, c_uint, c_ulong}
;
15 #[cfg(not(libressl250))]
19 pub struct stack_st_ASN1_OBJECT
{
24 pub struct stack_st_X509
{
29 pub struct stack_st_X509_NAME
{
34 pub struct stack_st_X509_ATTRIBUTE
{
39 pub struct stack_st_X509_EXTENSION
{
44 pub struct stack_st_GENERAL_NAME
{
49 pub struct stack_st_void
{
54 pub struct stack_st_SSL_CIPHER
{
59 pub struct stack_st_OPENSSL_STRING
{
66 pub data
: *mut *mut c_char
,
69 pub comp
: Option
<unsafe extern fn(*const c_void
, *const c_void
) -> c_int
>,
73 pub struct BIO_METHOD
{
75 pub name
: *const c_char
,
76 pub bwrite
: Option
<unsafe extern fn(*mut ::BIO
, *const c_char
, c_int
) -> c_int
>,
77 pub bread
: Option
<unsafe extern fn(*mut ::BIO
, *mut c_char
, c_int
) -> c_int
>,
78 pub bputs
: Option
<unsafe extern fn(*mut ::BIO
, *const c_char
) -> c_int
>,
79 pub bgets
: Option
<unsafe extern fn(*mut ::BIO
, *mut c_char
, c_int
) -> c_int
>,
80 pub ctrl
: Option
<unsafe extern fn(*mut ::BIO
, c_int
, c_long
, *mut c_void
) -> c_long
>,
81 pub create
: Option
<unsafe extern fn(*mut ::BIO
) -> c_int
>,
82 pub destroy
: Option
<unsafe extern fn(*mut ::BIO
) -> c_int
>,
83 pub callback_ctrl
: Option
<unsafe extern fn(*mut ::BIO
, c_int
, ::bio_info_cb
) -> c_long
>,
90 pub meth
: *const ::RSA_METHOD
,
92 pub engine
: *mut ::ENGINE
,
98 pub dmp1
: *mut ::BIGNUM
,
99 pub dmq1
: *mut ::BIGNUM
,
100 pub iqmp
: *mut ::BIGNUM
,
102 pub ex_data
: ::CRYPTO_EX_DATA
,
103 pub references
: c_int
,
106 pub _method_mod_n
: *mut ::BN_MONT_CTX
,
107 pub _method_mod_p
: *mut ::BN_MONT_CTX
,
108 pub _method_mod_q
: *mut ::BN_MONT_CTX
,
110 pub blinding
: *mut ::BN_BLINDING
,
111 pub mt_blinding
: *mut ::BN_BLINDING
,
118 pub write_params
: c_int
,
120 pub p
: *mut ::BIGNUM
,
121 pub q
: *mut ::BIGNUM
,
122 pub g
: *mut ::BIGNUM
,
123 pub pub_key
: *mut ::BIGNUM
,
124 pub priv_key
: *mut ::BIGNUM
,
125 pub kinv
: *mut ::BIGNUM
,
126 pub r
: *mut ::BIGNUM
,
129 pub method_mont_p
: *mut ::BN_MONT_CTX
,
130 pub references
: c_int
,
131 pub ex_data
: ::CRYPTO_EX_DATA
,
132 pub meth
: *const ::DSA_METHOD
,
133 pub engine
: *mut ::ENGINE
,
137 pub struct EVP_PKEY
{
139 pub save_type
: c_int
,
140 pub references
: c_int
,
141 pub ameth
: *const ::EVP_PKEY_ASN1_METHOD
,
142 pub engine
: *mut ::ENGINE
,
143 pub pkey
: *mut c_void
,
144 pub save_parameters
: c_int
,
145 pub attributes
: *mut stack_st_X509_ATTRIBUTE
,
150 pub method
: *mut ::BIO_METHOD
,
151 pub callback
: Option
<unsafe extern fn(*mut ::BIO
,
158 pub cb_arg
: *mut c_char
,
162 pub retry_reason
: c_int
,
164 pub ptr
: *mut c_void
,
165 pub next_bio
: *mut ::BIO
,
166 pub prev_bio
: *mut ::BIO
,
167 pub references
: c_int
,
168 pub num_read
: c_ulong
,
169 pub num_write
: c_ulong
,
170 pub ex_data
: ::CRYPTO_EX_DATA
,
174 pub struct CRYPTO_EX_DATA
{
175 pub sk
: *mut ::stack_st_void
,
179 pub struct EVP_MD_CTX
{
180 digest
: *mut ::EVP_MD
,
181 engine
: *mut ::ENGINE
,
183 md_data
: *mut c_void
,
184 pctx
: *mut ::EVP_PKEY_CTX
,
189 pub struct EVP_CIPHER
{
191 pub block_size
: c_int
,
195 pub init
: Option
<unsafe extern fn(*mut ::EVP_CIPHER_CTX
,
199 pub do_cipher
: Option
<unsafe extern fn(*mut ::EVP_CIPHER_CTX
,
203 pub cleanup
: Option
<unsafe extern fn(*mut ::EVP_CIPHER_CTX
) -> c_int
>,
205 pub set_asn1_parameters
: Option
<unsafe extern fn(*mut ::EVP_CIPHER_CTX
,
206 *mut ::ASN1_TYPE
) -> c_int
>,
207 pub get_asn1_parameters
: Option
<unsafe extern fn(*mut ::EVP_CIPHER_CTX
,
208 *mut ::ASN1_TYPE
) -> c_int
>,
209 pub ctrl
: Option
<unsafe extern fn(*mut ::EVP_CIPHER_CTX
,
212 *mut c_void
) -> c_int
>,
213 pub app_data
: *mut c_void
,
217 pub struct HMAC_CTX
{
219 md_ctx
: ::EVP_MD_CTX
,
228 pub d
: *mut ::BN_ULONG
,
239 pub p
: *mut ::BIGNUM
,
240 pub g
: *mut ::BIGNUM
,
242 pub pub_key
: *mut ::BIGNUM
,
243 pub priv_key
: *mut ::BIGNUM
,
245 pub method_mont_p
: *mut ::BN_MONT_CTX
,
246 pub q
: *mut ::BIGNUM
,
247 pub j
: *mut ::BIGNUM
,
248 pub seed
: *mut c_uchar
,
250 pub counter
: *mut ::BIGNUM
,
251 pub references
: c_int
,
252 pub ex_data
: ::CRYPTO_EX_DATA
,
253 pub meth
: *const ::DH_METHOD
,
254 pub engine
: *mut ::ENGINE
,
259 pub cert_info
: *mut X509_CINF
,
260 pub sig_alg
: *mut ::X509_ALGOR
,
261 pub signature
: *mut ::ASN1_BIT_STRING
,
263 pub references
: c_int
,
264 pub name
: *mut c_char
,
265 pub ex_data
: ::CRYPTO_EX_DATA
,
266 pub ex_pathlen
: c_long
,
267 pub ex_pcpathlen
: c_long
,
268 pub ex_flags
: c_ulong
,
269 pub ex_kusage
: c_ulong
,
270 pub ex_xkusage
: c_ulong
,
271 pub ex_nscert
: c_ulong
,
274 policy_cache
: *mut c_void
,
276 altname
: *mut c_void
,
278 #[cfg(not(osslconf = "OPENSSL_NO_SHA"))]
279 sha1_hash
: [c_uchar
; 20],
284 pub struct X509_CINF
{
285 version
: *mut c_void
,
286 serialNumber
: *mut c_void
,
287 signature
: *mut c_void
,
289 pub validity
: *mut X509_VAL
,
290 subject
: *mut c_void
,
292 issuerUID
: *mut c_void
,
293 subjectUID
: *mut c_void
,
294 pub extensions
: *mut stack_st_X509_EXTENSION
,
299 pub struct X509_ALGOR
{
300 pub algorithm
: *mut ::ASN1_OBJECT
,
301 parameter
: *mut c_void
,
305 pub struct ASN1_ENCODING
{
306 pub enc
: *mut c_uchar
,
312 pub struct X509_VAL
{
313 pub notBefore
: *mut ::ASN1_TIME
,
314 pub notAfter
: *mut ::ASN1_TIME
,
318 pub struct X509_REQ_INFO
{
319 pub enc
: ASN1_ENCODING
,
320 pub version
: *mut ::ASN1_INTEGER
,
321 pub subject
: *mut ::X509_NAME
,
323 pub attributes
: *mut stack_st_X509_ATTRIBUTE
327 pub struct X509_REQ
{
328 pub req_info
: *mut X509_REQ_INFO
,
329 sig_alg
: *mut c_void
,
330 signature
: *mut c_void
,
334 pub enum X509_VERIFY_PARAM_ID {}
337 pub const SSL_CTRL_GET_SESSION_REUSED
: c_int
= 8;
338 pub const SSL_CTRL_OPTIONS
: c_int
= 32;
339 pub const SSL_CTRL_CLEAR_OPTIONS
: c_int
= 77;
340 pub const SSL_CTRL_SET_ECDH_AUTO
: c_int
= 94;
342 pub const SSL_OP_ALL
: c_ulong
= 0x80000014;
343 pub const SSL_OP_CISCO_ANYCONNECT
: c_ulong
= 0x0;
344 pub const SSL_OP_NO_COMPRESSION
: c_ulong
= 0x0;
345 pub const SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION
: c_ulong
= 0x0;
346 pub const SSL_OP_NO_SSLv3
: c_ulong
= 0x0;
347 pub const SSL_OP_MICROSOFT_SESS_ID_BUG
: c_ulong
= 0x0;
348 pub const SSL_OP_NETSCAPE_CHALLENGE_BUG
: c_ulong
= 0x0;
349 pub const SSL_OP_NETSCAPE_REUSE_CIPHER_CHANGE_BUG
: c_ulong
= 0x0;
350 pub const SSL_OP_MICROSOFT_BIG_SSLV3_BUFFER
: c_ulong
= 0x0;
351 pub const SSL_OP_SSLEAY_080_CLIENT_DH_BUG
: c_ulong
= 0x0;
352 pub const SSL_OP_TLS_D5_BUG
: c_ulong
= 0x0;
353 pub const SSL_OP_TLS_BLOCK_PADDING_BUG
: c_ulong
= 0x0;
354 pub const SSL_OP_SINGLE_ECDH_USE
: c_ulong
= 0x00080000;
355 pub const SSL_OP_SINGLE_DH_USE
: c_ulong
= 0x00100000;
356 pub const SSL_OP_NO_SSLv2
: c_ulong
= 0x0;
358 pub const SSL_MAX_SSL_SESSION_ID_LENGTH
: c_int
= 32;
359 pub const SSL_MAX_SID_CTX_LENGTH
: c_int
= 32;
360 pub const SSL_MAX_MASTER_KEY_LENGTH
: c_int
= 48;
362 pub const SSLEAY_VERSION
: c_int
= 0;
363 pub const SSLEAY_CFLAGS
: c_int
= 2;
364 pub const SSLEAY_BUILT_ON
: c_int
= 3;
365 pub const SSLEAY_PLATFORM
: c_int
= 4;
366 pub const SSLEAY_DIR
: c_int
= 5;
368 pub const CRYPTO_LOCK_X509
: c_int
= 3;
369 pub const CRYPTO_LOCK_SSL_CTX
: c_int
= 12;
370 pub const CRYPTO_LOCK_SSL_SESSION
: c_int
= 14;
372 static mut MUTEXES
: *mut Vec
<Mutex
<()>> = 0 as *mut Vec
<Mutex
<()>>;
373 static mut GUARDS
: *mut Vec
<Option
<MutexGuard
<'
static, ()>>> = 0 as *mut Vec
<Option
<MutexGuard
<'
static, ()>>>;
375 unsafe extern fn locking_function(mode
: c_int
, n
: c_int
, _file
: *const c_char
,
377 let mutex
= &(*MUTEXES
)[n
as usize];
379 if mode
& ::CRYPTO_LOCK
!= 0 {
380 (*GUARDS
)[n
as usize] = Some(mutex
.lock().unwrap());
382 &(*GUARDS
)[n
as usize].take().expect("lock already unlocked");
387 static INIT
: Once
= ONCE_INIT
;
392 SSL_load_error_strings();
393 OPENSSL_add_all_algorithms_noconf();
395 let num_locks
= ::CRYPTO_num_locks();
396 let mut mutexes
= Box
::new(Vec
::new());
397 for _
in 0..num_locks
{
398 mutexes
.push(Mutex
::new(()));
400 MUTEXES
= mem
::transmute(mutexes
);
401 let guards
: Box
<Vec
<Option
<MutexGuard
<()>>>> =
402 Box
::new((0..num_locks
).map(|_
| None
).collect());
403 GUARDS
= mem
::transmute(guards
);
405 CRYPTO_set_locking_callback(locking_function
);
412 fn set_id_callback() {
413 unsafe extern fn thread_id() -> c_ulong
{
414 ::libc
::pthread_self() as c_ulong
418 CRYPTO_set_id_callback(thread_id
);
423 fn set_id_callback() {}
427 pub unsafe fn SSL_CTX_set_ecdh_auto(ctx
: *mut SSL_CTX
, onoff
: c_int
) -> c_int
{
428 ::SSL_CTX_ctrl(ctx
, SSL_CTRL_SET_ECDH_AUTO
, onoff
as c_long
, ptr
::null_mut()) as c_int
431 pub unsafe fn SSL_set_ecdh_auto(ssl
: *mut ::SSL
, onoff
: c_int
) -> c_int
{
432 ::SSL_ctrl(ssl
, SSL_CTRL_SET_ECDH_AUTO
, onoff
as c_long
, ptr
::null_mut()) as c_int
435 pub unsafe fn SSL_session_reused(ssl
: *mut ::SSL
) -> c_int
{
436 ::SSL_ctrl(ssl
, SSL_CTRL_GET_SESSION_REUSED
, 0, ptr
::null_mut()) as c_int
440 pub fn BIO_new(type_
: *mut BIO_METHOD
) -> *mut BIO
;
441 pub fn BIO_s_file() -> *mut BIO_METHOD
;
442 pub fn BIO_s_mem() -> *mut BIO_METHOD
;
444 pub fn get_rfc2409_prime_768(bn
: *mut BIGNUM
) -> *mut BIGNUM
;
445 pub fn get_rfc2409_prime_1024(bn
: *mut BIGNUM
) -> *mut BIGNUM
;
446 pub fn get_rfc3526_prime_1536(bn
: *mut BIGNUM
) -> *mut BIGNUM
;
447 pub fn get_rfc3526_prime_2048(bn
: *mut BIGNUM
) -> *mut BIGNUM
;
448 pub fn get_rfc3526_prime_3072(bn
: *mut BIGNUM
) -> *mut BIGNUM
;
449 pub fn get_rfc3526_prime_4096(bn
: *mut BIGNUM
) -> *mut BIGNUM
;
450 pub fn get_rfc3526_prime_6144(bn
: *mut BIGNUM
) -> *mut BIGNUM
;
451 pub fn get_rfc3526_prime_8192(bn
: *mut BIGNUM
) -> *mut BIGNUM
;
453 pub fn CRYPTO_malloc(num
: c_int
, file
: *const c_char
, line
: c_int
) -> *mut c_void
;
454 pub fn CRYPTO_free(buf
: *mut c_void
);
455 pub fn CRYPTO_num_locks() -> c_int
;
456 pub fn CRYPTO_set_locking_callback(func
: unsafe extern "C" fn(mode
: c_int
,
460 pub fn CRYPTO_set_id_callback(func
: unsafe extern "C" fn() -> c_ulong
);
462 pub fn ERR_load_crypto_strings();
464 pub fn RSA_generate_key(modsz
: c_int
,
466 cb
: Option
<extern fn(c_int
, c_int
, *mut c_void
)>,
467 cbarg
: *mut c_void
) -> *mut RSA
;
469 pub fn OCSP_cert_to_id(dgst
: *const ::EVP_MD
, subject
: *mut ::X509
, issuer
: *mut ::X509
) -> *mut ::OCSP_CERTID
;
471 pub fn PKCS12_create(pass
: *mut c_char
,
472 friendly_name
: *mut c_char
,
475 ca
: *mut stack_st_X509
,
480 keytype
: c_int
) -> *mut PKCS12
;
482 pub fn SSL_library_init() -> c_int
;
483 pub fn SSL_load_error_strings();
484 pub fn OPENSSL_add_all_algorithms_noconf();
485 pub fn HMAC_CTX_init(ctx
: *mut ::HMAC_CTX
);
486 pub fn HMAC_CTX_cleanup(ctx
: *mut ::HMAC_CTX
);
487 pub fn TLSv1_method() -> *const ::SSL_METHOD
;
488 pub fn SSLv23_method() -> *const ::SSL_METHOD
;
489 pub fn TLSv1_1_method() -> *const ::SSL_METHOD
;
490 pub fn TLSv1_2_method() -> *const ::SSL_METHOD
;
491 pub fn DTLSv1_method() -> *const ::SSL_METHOD
;
492 pub fn SSL_get_ex_new_index(argl
: c_long
, argp
: *mut c_void
,
493 new_func
: Option
<::CRYPTO_EX_new
>,
494 dup_func
: Option
<::CRYPTO_EX_dup
>,
495 free_func
: Option
<::CRYPTO_EX_free
>)
497 pub fn SSL_set_tmp_ecdh_callback(ssl
: *mut ::SSL
,
498 ecdh
: unsafe extern fn(ssl
: *mut ::SSL
,
502 pub fn SSL_CIPHER_get_version(cipher
: *const ::SSL_CIPHER
) -> *mut c_char
;
503 pub fn SSL_CTX_get_ex_new_index(argl
: c_long
, argp
: *mut c_void
,
504 new_func
: Option
<::CRYPTO_EX_new
>,
505 dup_func
: Option
<::CRYPTO_EX_dup
>,
506 free_func
: Option
<::CRYPTO_EX_free
>)
508 pub fn SSL_CTX_set_tmp_ecdh_callback(ctx
: *mut ::SSL_CTX
,
509 ecdh
: unsafe extern fn(ssl
: *mut ::SSL
,
513 pub fn X509_get_subject_name(x
: *mut ::X509
) -> *mut ::X509_NAME
;
514 pub fn X509_set_notAfter(x
: *mut ::X509
, tm
: *const ::ASN1_TIME
) -> c_int
;
515 pub fn X509_set_notBefore(x
: *mut ::X509
, tm
: *const ::ASN1_TIME
) -> c_int
;
516 pub fn X509_get_ext_d2i(x
: *mut ::X509
, nid
: c_int
, crit
: *mut c_int
, idx
: *mut c_int
) -> *mut c_void
;
517 pub fn X509_NAME_add_entry_by_NID(x
: *mut ::X509_NAME
, field
: c_int
, ty
: c_int
, bytes
: *mut c_uchar
, len
: c_int
, loc
: c_int
, set
: c_int
) -> c_int
;
518 pub fn X509_NAME_get_entry(n
: *mut ::X509_NAME
, loc
: c_int
) -> *mut ::X509_NAME_ENTRY
;
519 pub fn X509_NAME_ENTRY_get_data(ne
: *mut ::X509_NAME_ENTRY
) -> *mut ::ASN1_STRING
;
520 pub fn X509_STORE_CTX_get_chain(ctx
: *mut ::X509_STORE_CTX
) -> *mut stack_st_X509
;
521 pub fn X509V3_EXT_nconf_nid(conf
: *mut ::CONF
, ctx
: *mut ::X509V3_CTX
, ext_nid
: c_int
, value
: *mut c_char
) -> *mut ::X509_EXTENSION
;
522 pub fn X509V3_EXT_nconf(conf
: *mut ::CONF
, ctx
: *mut ::X509V3_CTX
, name
: *mut c_char
, value
: *mut c_char
) -> *mut ::X509_EXTENSION
;
523 pub fn ASN1_STRING_to_UTF8(out
: *mut *mut c_uchar
, s
: *mut ::ASN1_STRING
) -> c_int
;
524 pub fn ASN1_STRING_data(x
: *mut ::ASN1_STRING
) -> *mut c_uchar
;
525 pub fn CRYPTO_add_lock(pointer
: *mut c_int
,
529 line
: c_int
) -> c_int
;
530 pub fn EVP_MD_CTX_create() -> *mut EVP_MD_CTX
;
531 pub fn EVP_MD_CTX_destroy(ctx
: *mut EVP_MD_CTX
);
532 pub fn EVP_PKEY_bits(key
: *mut EVP_PKEY
) -> c_int
;
534 pub fn sk_new_null() -> *mut _STACK
;
535 pub fn sk_num(st
: *const _STACK
) -> c_int
;
536 pub fn sk_value(st
: *const _STACK
, n
: c_int
) -> *mut c_void
;
537 pub fn sk_free(st
: *mut _STACK
);
538 pub fn sk_push(st
: *mut _STACK
, data
: *mut c_void
) -> c_int
;
539 pub fn sk_pop_free(st
: *mut _STACK
, free
: Option
<unsafe extern "C" fn (*mut c_void
)>);
540 pub fn sk_pop(st
: *mut _STACK
) -> *mut c_void
;
542 pub fn SSLeay() -> c_ulong
;
543 pub fn SSLeay_version(key
: c_int
) -> *const c_char
;