• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

zhaozg / lua-openssl / 14788361818

02 May 2025 03:43AM UTC coverage: 88.812% (-4.7%) from 93.466%
14788361818

push

travis-ci

zhaozg
ci: valgrind combine

8954 of 10082 relevant lines covered (88.81%)

1094.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.15
/src/compat.c
1
#include "openssl.h"
2
#include "private.h"
3

4
#include <lauxlib.h>
5
#include <lua.h>
6
#include <lualib.h>
7

8
#if OPENSSLV_LESS(0x10100000L)
9

10
int
11
BIO_up_ref(BIO *b)
23✔
12
{
13
  CRYPTO_add(&b->references, 1, CRYPTO_LOCK_BIO);
23✔
14
  return 1;
23✔
15
}
16
int
17
X509_up_ref(X509 *x)
7✔
18
{
19
  CRYPTO_add(&x->references, 1, CRYPTO_LOCK_X509);
7✔
20
  return 1;
7✔
21
}
22
int
23
X509_STORE_up_ref(X509_STORE *s)
40✔
24
{
25
  CRYPTO_add(&s->references, 1, CRYPTO_LOCK_X509_STORE);
40✔
26
  return 1;
40✔
27
}
28
int
29
EVP_PKEY_up_ref(EVP_PKEY *pkey)
2✔
30
{
31
  CRYPTO_add(&pkey->references, 1, CRYPTO_LOCK_EVP_PKEY);
2✔
32
  return 1;
2✔
33
}
34

35
int
36
SSL_up_ref(SSL *ssl)
9✔
37
{
38
  CRYPTO_add(&ssl->references, 1, CRYPTO_LOCK_SSL);
9✔
39
  return 1;
9✔
40
}
41

42
int
43
SSL_CTX_up_ref(SSL_CTX *ctx)
×
44
{
45
  CRYPTO_add(&ctx->references, 1, CRYPTO_LOCK_SSL_CTX);
×
46
  return 1;
×
47
}
48

49
int
50
SSL_SESSION_up_ref(SSL_SESSION *sess)
×
51
{
52
  CRYPTO_add(&sess->references, 1, CRYPTO_LOCK_SSL_SESSION);
×
53
  return 1;
×
54
}
55

56
void
57
ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps)
6✔
58
{
59
  *pr = sig->r;
6✔
60
  *ps = sig->s;
6✔
61
}
6✔
62
int
63
ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s)
6✔
64
{
65
  if (r == NULL || s == NULL) return 0;
6✔
66
  BN_free(sig->r);
6✔
67
  BN_free(sig->s);
6✔
68
  sig->r = r;
6✔
69
  sig->s = s;
6✔
70
  return 1;
6✔
71
}
72

73
#ifndef OPENSSL_NO_RSA
74
int
75
RSA_bits(const RSA *r)
4✔
76
{
77
  return (BN_num_bits(r->n));
4✔
78
}
79

80
void
81
RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
99✔
82
{
83
  if (n != NULL) *n = r->n;
99✔
84
  if (e != NULL) *e = r->e;
99✔
85
  if (d != NULL) *d = r->d;
99✔
86
}
99✔
87

88
void
89
RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
4✔
90
{
91
  if (p != NULL) *p = r->p;
4✔
92
  if (q != NULL) *q = r->q;
4✔
93
}
4✔
94

95
void
96
RSA_get0_crt_params(const RSA *r, const BIGNUM **dmp1, const BIGNUM **dmq1, const BIGNUM **iqmp)
4✔
97
{
98
  if (dmp1 != NULL) *dmp1 = r->dmp1;
4✔
99
  if (dmq1 != NULL) *dmq1 = r->dmq1;
4✔
100
  if (iqmp != NULL) *iqmp = r->iqmp;
4✔
101
}
4✔
102

103
RSA *
104
EVP_PKEY_get0_RSA(EVP_PKEY *pkey)
104✔
105
{
106
  if (pkey->type != EVP_PKEY_RSA) {
104✔
107
    return NULL;
×
108
  }
109
  return pkey->pkey.rsa;
104✔
110
}
111

112
int
113
RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
1✔
114
{
115
  /* If the fields n and e in r are NULL, the corresponding input
116
   * parameters MUST be non-NULL for n and e.  d may be
117
   * left NULL (in case only the public key is used).
118
   */
119
  if ((r->n == NULL && n == NULL) || (r->e == NULL && e == NULL)) return 0;
1✔
120

121
  if (n != NULL) {
1✔
122
    BN_free(r->n);
1✔
123
    r->n = n;
1✔
124
  }
125
  if (e != NULL) {
1✔
126
    BN_free(r->e);
1✔
127
    r->e = e;
1✔
128
  }
129
  if (d != NULL) {
1✔
130
    BN_free(r->d);
1✔
131
    r->d = d;
1✔
132
  }
133

134
  return 1;
1✔
135
}
136

137
int
138
RSA_set0_factors(RSA *r, BIGNUM *p, BIGNUM *q)
1✔
139
{
140
  /* If the fields p and q in r are NULL, the corresponding input
141
   * parameters MUST be non-NULL.
142
   */
143
  if ((r->p == NULL && p == NULL) || (r->q == NULL && q == NULL)) return 0;
1✔
144

145
  if (p != NULL) {
1✔
146
    BN_free(r->p);
1✔
147
    r->p = p;
1✔
148
  }
149
  if (q != NULL) {
1✔
150
    BN_free(r->q);
1✔
151
    r->q = q;
1✔
152
  }
153

154
  return 1;
1✔
155
}
156

157
int
158
RSA_set0_crt_params(RSA *r, BIGNUM *dmp1, BIGNUM *dmq1, BIGNUM *iqmp)
1✔
159
{
160
  /* If the fields dmp1, dmq1 and iqmp in r are NULL, the corresponding input
161
   * parameters MUST be non-NULL.
162
   */
163
  if ((r->dmp1 == NULL && dmp1 == NULL) || (r->dmq1 == NULL && dmq1 == NULL)
1✔
164
      || (r->iqmp == NULL && iqmp == NULL))
1✔
165
    return 0;
×
166

167
  if (dmp1 != NULL) {
1✔
168
    BN_free(r->dmp1);
1✔
169
    r->dmp1 = dmp1;
1✔
170
  }
171
  if (dmq1 != NULL) {
1✔
172
    BN_free(r->dmq1);
1✔
173
    r->dmq1 = dmq1;
1✔
174
  }
175
  if (iqmp != NULL) {
1✔
176
    BN_free(r->iqmp);
1✔
177
    r->iqmp = iqmp;
1✔
178
  }
179

180
  return 1;
1✔
181
}
182
#endif
183

184
#ifndef OPENSSL_NO_HMAC
185
HMAC_CTX *
186
HMAC_CTX_new(void)
2✔
187
{
188
  HMAC_CTX *ctx = OPENSSL_malloc(sizeof(HMAC_CTX));
2✔
189

190
  if (ctx != NULL) {
2✔
191
    HMAC_CTX_init(ctx);
2✔
192
  }
193
  return ctx;
2✔
194
}
195

196
void
197
HMAC_CTX_free(HMAC_CTX *ctx)
2✔
198
{
199
  if (ctx != NULL) {
2✔
200
    HMAC_CTX_cleanup(ctx);
2✔
201
    OPENSSL_free(ctx);
2✔
202
  }
203
}
2✔
204
#endif
205

206
#ifndef OPENSSL_NO_DSA
207
int
208
DSA_bits(const DSA *dsa)
2✔
209
{
210
  return BN_num_bits(dsa->p);
2✔
211
}
212

213
DSA *
214
EVP_PKEY_get0_DSA(EVP_PKEY *pkey)
80✔
215
{
216
  if (pkey->type != EVP_PKEY_DSA) {
80✔
217
    return NULL;
×
218
  }
219
  return pkey->pkey.dsa;
80✔
220
}
221

222
void
223
DSA_get0_pqg(const DSA *d, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
2✔
224
{
225
  if (p != NULL) *p = d->p;
2✔
226
  if (q != NULL) *q = d->q;
2✔
227
  if (g != NULL) *g = d->g;
2✔
228
}
2✔
229

230
int
231
DSA_set0_pqg(DSA *d, BIGNUM *p, BIGNUM *q, BIGNUM *g)
1✔
232
{
233
  /* If the fields p, q and g in d are NULL, the corresponding input
234
   * parameters MUST be non-NULL.
235
   */
236
  if ((d->p == NULL && p == NULL) || (d->q == NULL && q == NULL) || (d->g == NULL && g == NULL))
1✔
237
    return 0;
×
238

239
  if (p != NULL) {
1✔
240
    BN_free(d->p);
1✔
241
    d->p = p;
1✔
242
  }
243
  if (q != NULL) {
1✔
244
    BN_free(d->q);
1✔
245
    d->q = q;
1✔
246
  }
247
  if (g != NULL) {
1✔
248
    BN_free(d->g);
1✔
249
    d->g = g;
1✔
250
  }
251

252
  return 1;
1✔
253
}
254

255
void
256
DSA_get0_key(const DSA *d, const BIGNUM **pub_key, const BIGNUM **priv_key)
73✔
257
{
258
  if (pub_key != NULL) *pub_key = d->pub_key;
73✔
259
  if (priv_key != NULL) *priv_key = d->priv_key;
73✔
260
}
73✔
261

262
int
263
DSA_set0_key(DSA *d, BIGNUM *pub_key, BIGNUM *priv_key)
1✔
264
{
265
  /* If the field pub_key in d is NULL, the corresponding input
266
   * parameters MUST be non-NULL.  The priv_key field may
267
   * be left NULL.
268
   */
269
  if (d->pub_key == NULL && pub_key == NULL) return 0;
1✔
270

271
  if (pub_key != NULL) {
1✔
272
    BN_free(d->pub_key);
1✔
273
    d->pub_key = pub_key;
1✔
274
  }
275
  if (priv_key != NULL) {
1✔
276
    BN_free(d->priv_key);
1✔
277
    d->priv_key = priv_key;
1✔
278
  }
279

280
  return 1;
1✔
281
}
282
#endif
283

284
#ifndef OPENSSL_NO_EC
285
EC_KEY *
286
EVP_PKEY_get0_EC_KEY(EVP_PKEY *pkey)
88✔
287
{
288
  if (pkey->type != EVP_PKEY_EC) {
88✔
289
    return NULL;
×
290
  }
291
  return pkey->pkey.ec;
88✔
292
}
293
#endif
294

295
#ifndef OPENSSL_NO_DH
296
DH *
297
EVP_PKEY_get0_DH(EVP_PKEY *pkey)
60✔
298
{
299
  if (pkey->type != EVP_PKEY_DH) {
60✔
300
    return NULL;
×
301
  }
302
  return pkey->pkey.dh;
60✔
303
}
304

305
int
306
DH_bits(const DH *dh)
2✔
307
{
308
  return BN_num_bits(dh->p);
2✔
309
}
310

311
void
312
DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
62✔
313
{
314
  if (pub_key != NULL) *pub_key = dh->pub_key;
62✔
315
  if (priv_key != NULL) *priv_key = dh->priv_key;
62✔
316
}
62✔
317

318
int
319
DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key)
1✔
320
{
321
  /* If the field pub_key in dh is NULL, the corresponding input
322
   * parameters MUST be non-NULL.  The priv_key field may
323
   * be left NULL.
324
   */
325
  if (dh->pub_key == NULL && pub_key == NULL) return 0;
1✔
326

327
  if (pub_key != NULL) {
1✔
328
    BN_free(dh->pub_key);
1✔
329
    dh->pub_key = pub_key;
1✔
330
  }
331
  if (priv_key != NULL) {
1✔
332
    BN_free(dh->priv_key);
1✔
333
    dh->priv_key = priv_key;
1✔
334
  }
335

336
  return 1;
1✔
337
}
338
void
339
DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
2✔
340
{
341
  if (p != NULL) *p = dh->p;
2✔
342
  if (q != NULL) *q = dh->q;
2✔
343
  if (g != NULL) *g = dh->g;
2✔
344
}
2✔
345

346
int
347
DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
1✔
348
{
349
  /* If the fields p and g in d are NULL, the corresponding input
350
   * parameters MUST be non-NULL.  q may remain NULL.
351
   */
352
  if ((dh->p == NULL && p == NULL) || (dh->g == NULL && g == NULL)) return 0;
1✔
353

354
  if (p != NULL) {
1✔
355
    BN_free(dh->p);
1✔
356
    dh->p = p;
1✔
357
  }
358
  if (q != NULL) {
1✔
359
    BN_free(dh->q);
×
360
    dh->q = q;
×
361
  }
362
  if (g != NULL) {
1✔
363
    BN_free(dh->g);
1✔
364
    dh->g = g;
1✔
365
  }
366

367
  if (q != NULL) {
1✔
368
    dh->length = BN_num_bits(q);
×
369
  }
370

371
  return 1;
1✔
372
}
373
#endif
374

375
int
376
EVP_CIPHER_CTX_reset(EVP_CIPHER_CTX *ctx)
8✔
377
{
378
  int ret;
379

380
  ret = EVP_CIPHER_CTX_cleanup(ctx);
8✔
381
  if (!ret) EVP_CIPHER_CTX_init(ctx);
8✔
382
  return ret;
8✔
383
}
384

385
EVP_MD_CTX *
386
EVP_MD_CTX_new(void)
×
387
{
388
  EVP_MD_CTX *ctx = OPENSSL_malloc(sizeof(EVP_MD_CTX));
×
389
  if (ctx) memset(ctx, 0, sizeof(*ctx));
×
390
  return ctx;
×
391
}
392

393
int
394
EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
12✔
395
{
396
  return EVP_MD_CTX_cleanup(ctx);
12✔
397
}
398

399
void
400
EVP_MD_CTX_free(EVP_MD_CTX *ctx)
14✔
401
{
402
  EVP_MD_CTX_cleanup(ctx);
14✔
403
  OPENSSL_free(ctx);
14✔
404
}
14✔
405

406
void
407
X509_REQ_get0_signature(const X509_REQ *req, const ASN1_BIT_STRING **psig, const X509_ALGOR **palg)
31✔
408
{
409
  if (psig != NULL) *psig = req->signature;
31✔
410
  if (palg != NULL) *palg = req->sig_alg;
31✔
411
}
31✔
412

413
void
414
X509_CRL_get0_signature(const X509_CRL *crl, const ASN1_BIT_STRING **psig, const X509_ALGOR **palg)
2✔
415
{
416
  if (psig != NULL) *psig = crl->signature;
2✔
417
  if (palg != NULL) *palg = crl->sig_alg;
2✔
418
}
2✔
419

420
const ASN1_TIME *
421
X509_CRL_get0_lastUpdate(const X509_CRL *crl)
5✔
422
{
423
  return crl->crl->lastUpdate;
5✔
424
}
425

426
const ASN1_TIME *
427
X509_CRL_get0_nextUpdate(const X509_CRL *crl)
5✔
428
{
429
  return crl->crl->nextUpdate;
5✔
430
}
431

432
#endif /* OPENSSL_VERSION_NUMBER < 0x10100000L &&                                                  \
433
          !defined(LIBRESSL_VERSION_NUMBER) */
434

435
#if OPENSSLV_LESS(0x10100000L) || IS_LIBRESSL()
436

437
X509_PUBKEY *
438
X509_REQ_get_X509_PUBKEY(X509_REQ *req)
29✔
439
{
440
#if OPENSSLV_LESS(0x10100000L) || LIBRESSLV_LESS(0x3050000fL)
441
  return req->req_info->pubkey;
29✔
442
#else
443
  return NULL;
444
#endif
445
}
446

447
#if !IS_LIBRESSL() || LIBRESSLV_LESS(0x3050000fL)
448

449
int
450
i2d_re_X509_REQ_tbs(X509_REQ *req, unsigned char **pp)
2✔
451
{
452
  req->req_info->enc.modified = 1;
2✔
453
  return i2d_X509_REQ_INFO(req->req_info, pp);
2✔
454
}
455

456
#if !IS_LIBRESSL() || LIBRESSLV_LESS(0x3040100fL)
457
int
458
BN_bn2binpad(const BIGNUM *a, unsigned char *to, int tolen)
7✔
459
{
460
  int ret;
461
  int sz = BN_num_bytes(a);
7✔
462
  if (sz > tolen) return -1;
7✔
463

464
  memset(to, 0, tolen);
7✔
465
  ret = BN_bn2bin(a, to + tolen - sz);
7✔
466
  if (ret >= 0) return ret + (tolen - sz);
7✔
467
  return ret;
×
468
}
469
#endif
470

471
#if !IS_LIBRESSL() || LIBRESSLV_LESS(0x3030000fL)
472
const unsigned char *
473
ASN1_STRING_get0_data(const ASN1_STRING *x)
45✔
474
{
475
  return x->data;
45✔
476
}
477

478
const ASN1_INTEGER *
479
X509_get0_serialNumber(const X509 *a)
14✔
480
{
481
  return a->cert_info->serialNumber;
14✔
482
}
483

484
const STACK_OF(X509_EXTENSION) * X509_get0_extensions(const X509 *x)
16✔
485
{
486
  return x->cert_info->extensions;
16✔
487
}
488

489
const ASN1_TIME *
490
X509_REVOKED_get0_revocationDate(const X509_REVOKED *x)
10✔
491
{
492
  return x->revocationDate;
10✔
493
}
494

495
const ASN1_INTEGER *
496
X509_REVOKED_get0_serialNumber(const X509_REVOKED *x)
10✔
497
{
498
  return x->serialNumber;
10✔
499
}
500

501
const STACK_OF(X509_EXTENSION) * X509_REVOKED_get0_extensions(const X509_REVOKED *r)
10✔
502
{
503
  return r->extensions;
10✔
504
}
505

506
const STACK_OF(X509_EXTENSION) * X509_CRL_get0_extensions(const X509_CRL *crl)
4✔
507
{
508
  return crl->crl->extensions;
4✔
509
}
510
#endif /* !IS_LIBRESSL() || LIBRESSLV_LESS(0x3030000fL) */
511

512
#ifndef OPENSSL_NO_OCSP
513

514
#if !IS_LIBRESSL() || LIBRESSLV_LESS(0x3030000fL)
515
const OCSP_CERTID *
516
OCSP_SINGLERESP_get0_id(const OCSP_SINGLERESP *single)
1✔
517
{
518
  return single->certId;
1✔
519
}
520
#endif /* !IS_LIBRESSL() || LIBRESSLV_LESS(0x3030000fL) */
521

522
const ASN1_GENERALIZEDTIME *
523
OCSP_resp_get0_produced_at(const OCSP_BASICRESP *bs)
1✔
524
{
525
  return bs->tbsResponseData->producedAt;
1✔
526
}
527

528
const STACK_OF(X509) * OCSP_resp_get0_certs(const OCSP_BASICRESP *bs)
1✔
529
{
530
  return bs->certs;
1✔
531
}
532

533
int
534
OCSP_resp_get0_id(const OCSP_BASICRESP *bs, const ASN1_OCTET_STRING **pid, const X509_NAME **pname)
1✔
535
{
536
  const OCSP_RESPID *rid = bs->tbsResponseData->responderId;
1✔
537

538
  if (rid->type == V_OCSP_RESPID_NAME) {
1✔
539
    *pname = rid->value.byName;
1✔
540
    *pid = NULL;
1✔
541
  } else if (rid->type == V_OCSP_RESPID_KEY) {
×
542
    *pid = rid->value.byKey;
×
543
    *pname = NULL;
×
544
  } else {
545
    return 0;
×
546
  }
547
  return 1;
1✔
548
}
549

550
const ASN1_OCTET_STRING *
551
OCSP_resp_get0_signature(const OCSP_BASICRESP *bs)
1✔
552
{
553
  return bs->signature;
1✔
554
}
555

556
const X509_ALGOR *
557
OCSP_resp_get0_tbs_sigalg(const OCSP_BASICRESP *bs)
1✔
558
{
559
  return bs->signatureAlgorithm;
1✔
560
}
561
#endif /* OPENSSL_NO_OCSP */
562

563
#endif /* !IS_LIBRESSL() || LIBRESSLV_LESS(0x3030000fL) */
564

565
#ifndef OPENSSL_NO_TS
566

567
#if !IS_LIBRESSL() || LIBRESSLV_LESS(0x3060000fL)
568

569
const ASN1_INTEGER *
570
TS_STATUS_INFO_get0_status(const TS_STATUS_INFO *a)
8✔
571
{
572
  return a->status;
8✔
573
}
574
const STACK_OF(ASN1_UTF8STRING) * TS_STATUS_INFO_get0_text(const TS_STATUS_INFO *a)
8✔
575
{
576
  return a->text;
8✔
577
}
578

579
const ASN1_BIT_STRING *
580
TS_STATUS_INFO_get0_failure_info(const TS_STATUS_INFO *a)
8✔
581
{
582
  return a->failure_info;
8✔
583
}
584

585
int
586
TS_VERIFY_CTX_add_flags(TS_VERIFY_CTX *ctx, int f)
12✔
587
{
588
  ctx->flags |= f;
12✔
589
  return ctx->flags;
12✔
590
}
591

592
int
593
TS_VERIFY_CTX_set_flags(TS_VERIFY_CTX *ctx, int f)
12✔
594
{
595
  ctx->flags = f;
12✔
596
  return ctx->flags;
12✔
597
}
598

599
BIO *
600
TS_VERIFY_CTX_set_data(TS_VERIFY_CTX *ctx, BIO *b)
24✔
601
{
602
  ctx->data = b;
24✔
603
  return ctx->data;
24✔
604
}
605

606
X509_STORE *
607
TS_VERIFY_CTX_set_store(TS_VERIFY_CTX *ctx, X509_STORE *s)
36✔
608
{
609
  ctx->store = s;
36✔
610
  return ctx->store;
36✔
611
}
612

613
STACK_OF(X509) * TS_VERIFY_CTS_set_certs(TS_VERIFY_CTX *ctx, STACK_OF(X509) * certs)
×
614
{
615
  ctx->certs = certs;
×
616
  return ctx->certs;
×
617
}
618

619
unsigned char *
620
TS_VERIFY_CTX_set_imprint(TS_VERIFY_CTX *ctx, unsigned char *hexstr, long len)
24✔
621
{
622
  OPENSSL_free(ctx->imprint);
24✔
623
  ctx->imprint = hexstr;
24✔
624
  ctx->imprint_len = len;
24✔
625
  return ctx->imprint;
24✔
626
}
627
#endif /* !IS_LIBRESSL() || LIBRESSLV_LESS(0x3060000fL) */
628
#endif /* OPENSSL_NO_TS */
629

630
#endif /* OPENSSLV_LESS(0x10100000L) || IS_LIBRESSL() */
631

632
#if IS_LIBRESSL() && LIBRESSLV_LESS(0x3050000fL)
633
#ifndef OPENSSL_NO_DSA
634
int
635
DSA_bits(const DSA *dsa)
636
{
637
  return BN_num_bits(dsa->p);
638
}
639
#endif
640

641
int
642
i2d_re_X509_tbs(X509 *x, unsigned char **pp)
643
{
644
  x->cert_info->enc.modified = 1;
645
  return i2d_X509_CINF(x->cert_info, pp);
646
}
647
#endif /* IS_LIBRESSL() && LIBRESSLV_LESS(0x3050000fL)*/
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc