1 /*
2 * Copyright (C) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "openssl_adapter.h"
17 #include "openssl_adapter_mock.h"
18
19 #include "log.h"
20 #include "result.h"
21
22 static uint32_t g_mockIndex = __INT32_MAX__;
23 static uint32_t g_callNum = 0;
24 static bool g_isRecordCallNum = false;
25 static bool g_isNeedSpecialMock = false;
26
Is_Need_Mock(void)27 static bool Is_Need_Mock(void)
28 {
29 if (!g_isRecordCallNum) {
30 return false;
31 }
32 g_callNum++;
33 if (g_callNum == g_mockIndex) {
34 LOGI("mock malloc return NULL.");
35 return true;
36 }
37 return false;
38 }
39
StartRecordOpensslCallNum(void)40 void StartRecordOpensslCallNum(void)
41 {
42 ResetOpensslCallNum();
43 g_isRecordCallNum = true;
44 }
45
EndRecordOpensslCallNum(void)46 void EndRecordOpensslCallNum(void)
47 {
48 ResetOpensslCallNum();
49 g_isRecordCallNum = false;
50 }
51
GetOpensslCallNum(void)52 uint32_t GetOpensslCallNum(void)
53 {
54 return g_callNum;
55 }
56
ResetOpensslCallNum(void)57 void ResetOpensslCallNum(void)
58 {
59 g_callNum = 0;
60 g_mockIndex = __INT32_MAX__;
61 }
62
SetOpensslCallMockIndex(uint32_t index)63 void SetOpensslCallMockIndex(uint32_t index)
64 {
65 g_mockIndex = index;
66 }
67
Openssl_BN_dup(const BIGNUM * a)68 BIGNUM *Openssl_BN_dup(const BIGNUM *a)
69 {
70 if (Is_Need_Mock()) {
71 return NULL;
72 }
73 return BN_dup(a);
74 }
75
Openssl_BN_clear(BIGNUM * a)76 void Openssl_BN_clear(BIGNUM *a)
77 {
78 BN_clear(a);
79 }
80
Openssl_BN_clear_free(BIGNUM * a)81 void Openssl_BN_clear_free(BIGNUM *a)
82 {
83 BN_clear_free(a);
84 }
85
Openssl_BN_free(BIGNUM * a)86 void Openssl_BN_free(BIGNUM *a)
87 {
88 BN_free(a);
89 }
90
Openssl_BN_new(void)91 BIGNUM *Openssl_BN_new(void)
92 {
93 if (Is_Need_Mock()) {
94 return NULL;
95 }
96 return BN_new();
97 }
98
Openssl_BN_bin2bn(const unsigned char * s,int len,BIGNUM * ret)99 BIGNUM *Openssl_BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
100 {
101 if (Is_Need_Mock()) {
102 return NULL;
103 }
104 return BN_bin2bn(s, len, ret);
105 }
106
Openssl_BN_lebin2bn(const unsigned char * s,int len,BIGNUM * ret)107 BIGNUM *Openssl_BN_lebin2bn(const unsigned char *s, int len, BIGNUM *ret)
108 {
109 if (Is_Need_Mock()) {
110 return NULL;
111 }
112 return BN_lebin2bn(s, len, ret);
113 }
114
Openssl_BN_bn2binpad(const BIGNUM * a,unsigned char * to,int toLen)115 int Openssl_BN_bn2binpad(const BIGNUM *a, unsigned char *to, int toLen)
116 {
117 if (Is_Need_Mock()) {
118 return -1;
119 }
120 return BN_bn2binpad(a, to, toLen);
121 }
122
Openssl_BN_bn2lebinpad(const BIGNUM * a,unsigned char * to,int tolen)123 int Openssl_BN_bn2lebinpad(const BIGNUM *a, unsigned char *to, int tolen)
124 {
125 if (Is_Need_Mock()) {
126 return -1;
127 }
128 return BN_bn2lebinpad(a, to, tolen);
129 }
130
Openssl_BN_CTX_new(void)131 BN_CTX *Openssl_BN_CTX_new(void)
132 {
133 if (Is_Need_Mock()) {
134 return NULL;
135 }
136 return BN_CTX_new();
137 }
138
Openssl_BN_CTX_free(BN_CTX * ctx)139 void Openssl_BN_CTX_free(BN_CTX *ctx)
140 {
141 BN_CTX_free(ctx);
142 }
143
Openssl_BN_num_bytes(const BIGNUM * a)144 int Openssl_BN_num_bytes(const BIGNUM *a)
145 {
146 if (Is_Need_Mock()) {
147 return -1;
148 }
149 return BN_num_bytes(a);
150 }
151
Openssl_BN_set_word(BIGNUM * a,unsigned int w)152 int Openssl_BN_set_word(BIGNUM *a, unsigned int w)
153 {
154 if (Is_Need_Mock()) {
155 return -1;
156 }
157 return BN_set_word(a, w);
158 }
159
Openssl_BN_get_word(const BIGNUM * a)160 unsigned int Openssl_BN_get_word(const BIGNUM *a)
161 {
162 if (Is_Need_Mock()) {
163 return 0;
164 }
165 return BN_get_word(a);
166 }
167
Openssl_BN_num_bits(const BIGNUM * a)168 int Openssl_BN_num_bits(const BIGNUM *a)
169 {
170 if (Is_Need_Mock()) {
171 return -1;
172 }
173 return BN_num_bits(a);
174 }
175
Openssl_BN_hex2bn(BIGNUM ** a,const char * str)176 int Openssl_BN_hex2bn(BIGNUM **a, const char *str)
177 {
178 if (Is_Need_Mock()) {
179 return -1;
180 }
181 return BN_hex2bn(a, str);
182 }
183
Openssl_BN_cmp(const BIGNUM * a,const BIGNUM * b)184 int Openssl_BN_cmp(const BIGNUM *a, const BIGNUM *b)
185 {
186 if (Is_Need_Mock()) {
187 return -1;
188 }
189 return BN_cmp(a, b);
190 }
191
Openssl_EC_KEY_new_by_curve_name(int nid)192 EC_KEY *Openssl_EC_KEY_new_by_curve_name(int nid)
193 {
194 if (Is_Need_Mock()) {
195 return NULL;
196 }
197 return EC_KEY_new_by_curve_name(nid);
198 }
199
Openssl_EC_POINT_dup(const EC_POINT * src,const EC_GROUP * group)200 EC_POINT *Openssl_EC_POINT_dup(const EC_POINT *src, const EC_GROUP *group)
201 {
202 if (Is_Need_Mock()) {
203 return NULL;
204 }
205 return EC_POINT_dup(src, group);
206 }
207
Openssl_EC_KEY_generate_key(EC_KEY * eckey)208 int Openssl_EC_KEY_generate_key(EC_KEY *eckey)
209 {
210 if (Is_Need_Mock()) {
211 return -1;
212 }
213 return EC_KEY_generate_key(eckey);
214 }
215
Openssl_EC_KEY_set_public_key(EC_KEY * key,const EC_POINT * pub)216 int Openssl_EC_KEY_set_public_key(EC_KEY *key, const EC_POINT *pub)
217 {
218 if (Is_Need_Mock()) {
219 return -1;
220 }
221 return EC_KEY_set_public_key(key, pub);
222 }
223
Openssl_EC_KEY_set_private_key(EC_KEY * key,const BIGNUM * priv_key)224 int Openssl_EC_KEY_set_private_key(EC_KEY *key, const BIGNUM *priv_key)
225 {
226 if (Is_Need_Mock()) {
227 return -1;
228 }
229 return EC_KEY_set_private_key(key, priv_key);
230 }
231
Openssl_EC_KEY_check_key(const EC_KEY * key)232 int Openssl_EC_KEY_check_key(const EC_KEY *key)
233 {
234 if (Is_Need_Mock()) {
235 return -1;
236 }
237 return EC_KEY_check_key(key);
238 }
239
Openssl_EC_KEY_get0_public_key(const EC_KEY * key)240 const EC_POINT *Openssl_EC_KEY_get0_public_key(const EC_KEY *key)
241 {
242 if (Is_Need_Mock()) {
243 return NULL;
244 }
245 return EC_KEY_get0_public_key(key);
246 }
247
Openssl_EC_KEY_get0_private_key(const EC_KEY * key)248 const BIGNUM *Openssl_EC_KEY_get0_private_key(const EC_KEY *key)
249 {
250 if (Is_Need_Mock()) {
251 return NULL;
252 }
253 return EC_KEY_get0_private_key(key);
254 }
255
Openssl_EC_KEY_get0_group(const EC_KEY * key)256 const EC_GROUP *Openssl_EC_KEY_get0_group(const EC_KEY *key)
257 {
258 if (Is_Need_Mock()) {
259 return NULL;
260 }
261 return EC_KEY_get0_group(key);
262 }
263
Openssl_EC_GROUP_dup(const EC_GROUP * a)264 EC_GROUP *Openssl_EC_GROUP_dup(const EC_GROUP *a)
265 {
266 if (Is_Need_Mock()) {
267 return NULL;
268 }
269 return EC_GROUP_dup(a);
270 }
271
Openssl_EC_GROUP_free(EC_GROUP * group)272 void Openssl_EC_GROUP_free(EC_GROUP *group)
273 {
274 EC_GROUP_free(group);
275 }
276
Openssl_EC_KEY_new(void)277 EC_KEY *Openssl_EC_KEY_new(void)
278 {
279 if (Is_Need_Mock()) {
280 return NULL;
281 }
282 return EC_KEY_new();
283 }
284
Openssl_EC_KEY_dup(const EC_KEY * ecKey)285 EC_KEY *Openssl_EC_KEY_dup(const EC_KEY *ecKey)
286 {
287 if (Is_Need_Mock()) {
288 return NULL;
289 }
290 return EC_KEY_dup(ecKey);
291 }
292
Openssl_EC_KEY_set_group(EC_KEY * key,const EC_GROUP * group)293 int Openssl_EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)
294 {
295 if (Is_Need_Mock()) {
296 return -1;
297 }
298 return EC_KEY_set_group(key, group);
299 }
300
Openssl_EC_POINT_get_affine_coordinates_GFp(const EC_GROUP * group,const EC_POINT * point,BIGNUM * x,BIGNUM * y,BN_CTX * ctx)301 int Openssl_EC_POINT_get_affine_coordinates_GFp(const EC_GROUP *group, const EC_POINT *point, BIGNUM *x,
302 BIGNUM *y, BN_CTX *ctx)
303 {
304 if (Is_Need_Mock()) {
305 return -1;
306 }
307 return EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx);
308 }
309
Openssl_EC_GROUP_get_degree(const EC_GROUP * group)310 int Openssl_EC_GROUP_get_degree(const EC_GROUP *group)
311 {
312 if (Is_Need_Mock()) {
313 return -1;
314 }
315 return EC_GROUP_get_degree(group);
316 }
317
Openssl_EC_GROUP_get_curve_GFp(const EC_GROUP * group,BIGNUM * p,BIGNUM * a,BIGNUM * b,BN_CTX * ctx)318 int Openssl_EC_GROUP_get_curve_GFp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
319 {
320 if (Is_Need_Mock()) {
321 return -1;
322 }
323 return EC_GROUP_get_curve_GFp(group, p, a, b, ctx);
324 }
325
Openssl_EC_GROUP_get0_generator(const EC_GROUP * group)326 const EC_POINT *Openssl_EC_GROUP_get0_generator(const EC_GROUP *group)
327 {
328 if (Is_Need_Mock()) {
329 return NULL;
330 }
331 return EC_GROUP_get0_generator(group);
332 }
333
Openssl_EC_GROUP_get_order(const EC_GROUP * group,BIGNUM * order,BN_CTX * ctx)334 int Openssl_EC_GROUP_get_order(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
335 {
336 if (Is_Need_Mock()) {
337 return -1;
338 }
339 return EC_GROUP_get_order(group, order, ctx);
340 }
341
Openssl_EC_GROUP_get_cofactor(const EC_GROUP * group,BIGNUM * cofactor,BN_CTX * ctx)342 int Openssl_EC_GROUP_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
343 {
344 if (Is_Need_Mock()) {
345 return -1;
346 }
347 return EC_GROUP_get_cofactor(group, cofactor, ctx);
348 }
349
Openssl_EC_GROUP_new_curve_GFp(const BIGNUM * p,const BIGNUM * a,const BIGNUM * b,BN_CTX * ctx)350 EC_GROUP *Openssl_EC_GROUP_new_curve_GFp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
351 {
352 if (Is_Need_Mock()) {
353 return NULL;
354 }
355 return EC_GROUP_new_curve_GFp(p, a, b, ctx);
356 }
357
Openssl_EC_POINT_new(const EC_GROUP * group)358 EC_POINT *Openssl_EC_POINT_new(const EC_GROUP *group)
359 {
360 if (Is_Need_Mock()) {
361 return NULL;
362 }
363 return EC_POINT_new(group);
364 }
365
Openssl_EC_POINT_set_affine_coordinates_GFp(const EC_GROUP * group,EC_POINT * point,const BIGNUM * x,const BIGNUM * y,BN_CTX * ctx)366 int Openssl_EC_POINT_set_affine_coordinates_GFp(const EC_GROUP *group, EC_POINT *point, const BIGNUM *x,
367 const BIGNUM *y, BN_CTX *ctx)
368 {
369 if (Is_Need_Mock()) {
370 return -1;
371 }
372 return EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx);
373 }
374
Openssl_EC_GROUP_set_generator(EC_GROUP * group,const EC_POINT * generator,const BIGNUM * order,const BIGNUM * cofactor)375 int Openssl_EC_GROUP_set_generator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order,
376 const BIGNUM *cofactor)
377 {
378 if (Is_Need_Mock()) {
379 return -1;
380 }
381 return EC_GROUP_set_generator(group, generator, order, cofactor);
382 }
383
Openssl_EC_GROUP_set_curve_name(EC_GROUP * group,int nid)384 void Openssl_EC_GROUP_set_curve_name(EC_GROUP *group, int nid)
385 {
386 if (Is_Need_Mock()) {
387 return;
388 }
389 EC_GROUP_set_curve_name(group, nid);
390 }
391
Openssl_EC_GROUP_get_curve_name(const EC_GROUP * group)392 int Openssl_EC_GROUP_get_curve_name(const EC_GROUP *group)
393 {
394 if (Is_Need_Mock()) {
395 return 0;
396 }
397 return EC_GROUP_get_curve_name(group);
398 }
399
Openssl_EC_POINT_mul(const EC_GROUP * group,EC_POINT * r,const BIGNUM * g_scalar,const EC_POINT * point,const BIGNUM * p_scalar,BN_CTX * ctx)400 int Openssl_EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar, const EC_POINT *point,
401 const BIGNUM *p_scalar, BN_CTX *ctx)
402 {
403 if (Is_Need_Mock()) {
404 return -1;
405 }
406 return EC_POINT_mul(group, r, g_scalar, point, p_scalar, ctx);
407 }
408
Openssl_i2d_EC_PUBKEY(EC_KEY * a,unsigned char ** pp)409 int Openssl_i2d_EC_PUBKEY(EC_KEY *a, unsigned char **pp)
410 {
411 if (Is_Need_Mock()) {
412 return -1;
413 }
414 return i2d_EC_PUBKEY(a, pp);
415 }
416
Openssl_i2d_ECPrivateKey(EC_KEY * key,unsigned char ** out)417 int Openssl_i2d_ECPrivateKey(EC_KEY *key, unsigned char **out)
418 {
419 if (Is_Need_Mock()) {
420 return -1;
421 }
422 return i2d_ECPrivateKey(key, out);
423 }
424
Openssl_d2i_EC_PUBKEY(EC_KEY ** a,const unsigned char ** pp,long length)425 EC_KEY *Openssl_d2i_EC_PUBKEY(EC_KEY **a, const unsigned char **pp, long length)
426 {
427 if (Is_Need_Mock()) {
428 return NULL;
429 }
430 return d2i_EC_PUBKEY(a, pp, length);
431 }
432
Openssl_d2i_ECPrivateKey(EC_KEY ** key,const unsigned char ** in,long len)433 EC_KEY *Openssl_d2i_ECPrivateKey(EC_KEY **key, const unsigned char **in, long len)
434 {
435 if (Is_Need_Mock()) {
436 return NULL;
437 }
438 return d2i_ECPrivateKey(key, in, len);
439 }
440
Openssl_EC_KEY_set_asn1_flag(EC_KEY * key,int flag)441 void Openssl_EC_KEY_set_asn1_flag(EC_KEY *key, int flag)
442 {
443 EC_KEY_set_asn1_flag(key, flag);
444 }
445
Openssl_EC_KEY_set_enc_flags(EC_KEY * eckey,unsigned int flags)446 void Openssl_EC_KEY_set_enc_flags(EC_KEY *eckey, unsigned int flags)
447 {
448 EC_KEY_set_enc_flags(eckey, flags);
449 }
450
Openssl_EC_KEY_free(EC_KEY * key)451 void Openssl_EC_KEY_free(EC_KEY *key)
452 {
453 EC_KEY_free(key);
454 }
455
Openssl_EC_POINT_free(EC_POINT * point)456 void Openssl_EC_POINT_free(EC_POINT *point)
457 {
458 EC_POINT_free(point);
459 }
460
Openssl_EVP_MD_CTX_new(void)461 EVP_MD_CTX *Openssl_EVP_MD_CTX_new(void)
462 {
463 if (Is_Need_Mock()) {
464 return NULL;
465 }
466 return EVP_MD_CTX_new();
467 }
468
Openssl_EVP_MD_CTX_free(EVP_MD_CTX * ctx)469 void Openssl_EVP_MD_CTX_free(EVP_MD_CTX *ctx)
470 {
471 EVP_MD_CTX_free(ctx);
472 }
473
Openssl_EVP_DigestSignInit(EVP_MD_CTX * ctx,EVP_PKEY_CTX ** pctx,const EVP_MD * type,ENGINE * e,EVP_PKEY * pkey)474 int Openssl_EVP_DigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey)
475 {
476 if (Is_Need_Mock()) {
477 return -1;
478 }
479 return EVP_DigestSignInit(ctx, pctx, type, e, pkey);
480 }
481
Openssl_EVP_DigestSignUpdate(EVP_MD_CTX * ctx,const void * data,size_t count)482 int Openssl_EVP_DigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
483 {
484 if (Is_Need_Mock()) {
485 return -1;
486 }
487 return EVP_DigestSignUpdate(ctx, data, count);
488 }
489
Openssl_EVP_DigestSignFinal(EVP_MD_CTX * ctx,unsigned char * sigret,size_t * siglen)490 int Openssl_EVP_DigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen)
491 {
492 if (sigret != NULL && g_isNeedSpecialMock) {
493 g_callNum++;
494 }
495 if (Is_Need_Mock()) {
496 if (sigret == NULL) {
497 return -1;
498 }
499 if (g_isNeedSpecialMock) {
500 int res = EVP_DigestSignFinal(ctx, sigret, siglen);
501 *siglen = *siglen * 2;
502 g_isNeedSpecialMock = false;
503 return res;
504 }
505 g_isNeedSpecialMock = true;
506 return -1;
507 }
508 if (sigret != NULL) {
509 g_callNum++;
510 }
511 return EVP_DigestSignFinal(ctx, sigret, siglen);
512 }
513
Openssl_EVP_DigestVerifyInit(EVP_MD_CTX * ctx,EVP_PKEY_CTX ** pctx,const EVP_MD * type,ENGINE * e,EVP_PKEY * pkey)514 int Openssl_EVP_DigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey)
515 {
516 if (Is_Need_Mock()) {
517 return -1;
518 }
519 return EVP_DigestVerifyInit(ctx, pctx, type, e, pkey);
520 }
521
Openssl_EVP_DigestVerifyUpdate(EVP_MD_CTX * ctx,const void * data,size_t count)522 int Openssl_EVP_DigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
523 {
524 if (Is_Need_Mock()) {
525 return -1;
526 }
527 return EVP_DigestVerifyUpdate(ctx, data, count);
528 }
529
Openssl_EVP_DigestVerifyFinal(EVP_MD_CTX * ctx,const unsigned char * sig,size_t siglen)530 int Openssl_EVP_DigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen)
531 {
532 if (Is_Need_Mock()) {
533 return -1;
534 }
535 return EVP_DigestVerifyFinal(ctx, sig, siglen);
536 }
537
Openssl_EVP_PKEY_sign_init(EVP_PKEY_CTX * ctx)538 int Openssl_EVP_PKEY_sign_init(EVP_PKEY_CTX *ctx)
539 {
540 if (Is_Need_Mock()) {
541 return -1;
542 }
543 return EVP_PKEY_sign_init(ctx);
544 }
545
Openssl_EVP_PKEY_sign(EVP_PKEY_CTX * ctx,unsigned char * sig,size_t * siglen,const unsigned char * tbs,size_t tbslen)546 int Openssl_EVP_PKEY_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs,
547 size_t tbslen)
548 {
549 if (Is_Need_Mock()) {
550 return -1;
551 }
552 return EVP_PKEY_sign(ctx, sig, siglen, tbs, tbslen);
553 }
554
Openssl_EVP_PKEY_verify_init(EVP_PKEY_CTX * ctx)555 int Openssl_EVP_PKEY_verify_init(EVP_PKEY_CTX *ctx)
556 {
557 if (Is_Need_Mock()) {
558 return -1;
559 }
560 return EVP_PKEY_verify_init(ctx);
561 }
562
Openssl_EVP_PKEY_verify(EVP_PKEY_CTX * ctx,const unsigned char * sig,size_t siglen,const unsigned char * tbs,size_t tbslen)563 int Openssl_EVP_PKEY_verify(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs,
564 size_t tbslen)
565 {
566 if (Is_Need_Mock()) {
567 return -1;
568 }
569 return EVP_PKEY_verify(ctx, sig, siglen, tbs, tbslen);
570 }
571
Openssl_EVP_PKEY_new(void)572 EVP_PKEY *Openssl_EVP_PKEY_new(void)
573 {
574 if (Is_Need_Mock()) {
575 return NULL;
576 }
577 return EVP_PKEY_new();
578 }
579
Openssl_EVP_PKEY_assign_EC_KEY(EVP_PKEY * pkey,EC_KEY * key)580 int Openssl_EVP_PKEY_assign_EC_KEY(EVP_PKEY *pkey, EC_KEY *key)
581 {
582 if (Is_Need_Mock()) {
583 return -1;
584 }
585 return EVP_PKEY_assign_EC_KEY(pkey, key);
586 }
587
Openssl_EVP_PKEY_free(EVP_PKEY * pkey)588 void Openssl_EVP_PKEY_free(EVP_PKEY *pkey)
589 {
590 EVP_PKEY_free(pkey);
591 }
592
Openssl_EVP_PKEY_CTX_new(EVP_PKEY * pkey,ENGINE * e)593 EVP_PKEY_CTX *Openssl_EVP_PKEY_CTX_new(EVP_PKEY *pkey, ENGINE *e)
594 {
595 if (Is_Need_Mock()) {
596 return NULL;
597 }
598 return EVP_PKEY_CTX_new(pkey, e);
599 }
600
Openssl_EVP_PKEY_derive_init(EVP_PKEY_CTX * ctx)601 int Openssl_EVP_PKEY_derive_init(EVP_PKEY_CTX *ctx)
602 {
603 if (Is_Need_Mock()) {
604 return -1;
605 }
606 return EVP_PKEY_derive_init(ctx);
607 }
608
Openssl_EVP_PKEY_derive_set_peer(EVP_PKEY_CTX * ctx,EVP_PKEY * peer)609 int Openssl_EVP_PKEY_derive_set_peer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer)
610 {
611 if (Is_Need_Mock()) {
612 return -1;
613 }
614 return EVP_PKEY_derive_set_peer(ctx, peer);
615 }
616
Openssl_EVP_PKEY_derive(EVP_PKEY_CTX * ctx,unsigned char * key,size_t * keylen)617 int Openssl_EVP_PKEY_derive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
618 {
619 if (key != NULL && g_isNeedSpecialMock) {
620 g_callNum++;
621 }
622 if (Is_Need_Mock()) {
623 if (key == NULL) {
624 return -1;
625 }
626 if (g_isNeedSpecialMock) {
627 int res = EVP_PKEY_derive(ctx, key, keylen);
628 *keylen = *keylen * 2;
629 g_isNeedSpecialMock = false;
630 return res;
631 }
632 g_isNeedSpecialMock = true;
633 return -1;
634 }
635 if (key != NULL) {
636 g_callNum++;
637 }
638 return EVP_PKEY_derive(ctx, key, keylen);
639 }
640
Openssl_EVP_PKEY_encrypt(EVP_PKEY_CTX * ctx,unsigned char * out,size_t * outlen,const unsigned char * in,size_t inlen)641 int Openssl_EVP_PKEY_encrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
642 const unsigned char *in, size_t inlen)
643 {
644 return EVP_PKEY_encrypt(ctx, out, outlen, in, inlen);
645 }
646
Openssl_EVP_PKEY_decrypt(EVP_PKEY_CTX * ctx,unsigned char * out,size_t * outlen,const unsigned char * in,size_t inlen)647 int Openssl_EVP_PKEY_decrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
648 const unsigned char *in, size_t inlen)
649 {
650 return EVP_PKEY_decrypt(ctx, out, outlen, in, inlen);
651 }
652
Openssl_EVP_PKEY_encrypt_init(EVP_PKEY_CTX * ctx)653 int Openssl_EVP_PKEY_encrypt_init(EVP_PKEY_CTX *ctx)
654 {
655 return EVP_PKEY_encrypt_init(ctx);
656 }
657
Openssl_EVP_PKEY_decrypt_init(EVP_PKEY_CTX * ctx)658 int Openssl_EVP_PKEY_decrypt_init(EVP_PKEY_CTX *ctx)
659 {
660 return EVP_PKEY_decrypt_init(ctx);
661 }
662
Openssl_EVP_PKEY_CTX_free(EVP_PKEY_CTX * ctx)663 void Openssl_EVP_PKEY_CTX_free(EVP_PKEY_CTX *ctx)
664 {
665 EVP_PKEY_CTX_free(ctx);
666 }
667
Openssl_EVP_PKEY_CTX_new_id(int id,ENGINE * e)668 EVP_PKEY_CTX *Openssl_EVP_PKEY_CTX_new_id(int id, ENGINE *e)
669 {
670 if (Is_Need_Mock()) {
671 return NULL;
672 }
673 return EVP_PKEY_CTX_new_id(id, e);
674 }
675
Openssl_EVP_PKEY_paramgen_init(EVP_PKEY_CTX * ctx)676 int Openssl_EVP_PKEY_paramgen_init(EVP_PKEY_CTX *ctx)
677 {
678 if (Is_Need_Mock()) {
679 return -1;
680 }
681 return EVP_PKEY_paramgen_init(ctx);
682 }
683
Openssl_EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX * ctx,int nbits)684 int Openssl_EVP_PKEY_CTX_set_dsa_paramgen_bits(EVP_PKEY_CTX *ctx, int nbits)
685 {
686 if (Is_Need_Mock()) {
687 return -1;
688 }
689 return EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits);
690 }
691
Openssl_EVP_PKEY_paramgen(EVP_PKEY_CTX * ctx,EVP_PKEY ** ppkey)692 int Openssl_EVP_PKEY_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
693 {
694 if (Is_Need_Mock()) {
695 return -1;
696 }
697 return EVP_PKEY_paramgen(ctx, ppkey);
698 }
699
Openssl_EVP_PKEY_keygen_init(EVP_PKEY_CTX * ctx)700 int Openssl_EVP_PKEY_keygen_init(EVP_PKEY_CTX *ctx)
701 {
702 if (Is_Need_Mock()) {
703 return -1;
704 }
705 return EVP_PKEY_keygen_init(ctx);
706 }
707
Openssl_EVP_PKEY_keygen(EVP_PKEY_CTX * ctx,EVP_PKEY ** ppkey)708 int Openssl_EVP_PKEY_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
709 {
710 if (Is_Need_Mock()) {
711 return -1;
712 }
713 return EVP_PKEY_keygen(ctx, ppkey);
714 }
715
Openssl_EVP_PKEY_set1_DSA(EVP_PKEY * pkey,DSA * key)716 int Openssl_EVP_PKEY_set1_DSA(EVP_PKEY *pkey, DSA *key)
717 {
718 if (Is_Need_Mock()) {
719 return -1;
720 }
721 return EVP_PKEY_set1_DSA(pkey, key);
722 }
723
Openssl_EVP_PKEY_get1_DSA(EVP_PKEY * pkey)724 DSA *Openssl_EVP_PKEY_get1_DSA(EVP_PKEY *pkey)
725 {
726 if (Is_Need_Mock()) {
727 return NULL;
728 }
729 return EVP_PKEY_get1_DSA(pkey);
730 }
731
Openssl_DSA_new(void)732 DSA *Openssl_DSA_new(void)
733 {
734 if (Is_Need_Mock()) {
735 return NULL;
736 }
737 return DSA_new();
738 }
739
Openssl_DSA_free(DSA * dsa)740 void Openssl_DSA_free(DSA *dsa)
741 {
742 DSA_free(dsa);
743 }
744
Openssl_DSA_up_ref(DSA * dsa)745 int Openssl_DSA_up_ref(DSA *dsa)
746 {
747 if (Is_Need_Mock()) {
748 return -1;
749 }
750 return DSA_up_ref(dsa);
751 }
752
Openssl_DSA_set0_pqg(DSA * dsa,BIGNUM * p,BIGNUM * q,BIGNUM * g)753 int Openssl_DSA_set0_pqg(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g)
754 {
755 if (Is_Need_Mock()) {
756 return -1;
757 }
758 return DSA_set0_pqg(dsa, p, q, g);
759 }
760
Openssl_DSA_set0_key(DSA * dsa,BIGNUM * pub_key,BIGNUM * pri_key)761 int Openssl_DSA_set0_key(DSA *dsa, BIGNUM *pub_key, BIGNUM *pri_key)
762 {
763 if (Is_Need_Mock()) {
764 return -1;
765 }
766 return DSA_set0_key(dsa, pub_key, pri_key);
767 }
768
Openssl_DSA_get0_p(const DSA * dsa)769 const BIGNUM *Openssl_DSA_get0_p(const DSA *dsa)
770 {
771 if (Is_Need_Mock()) {
772 return NULL;
773 }
774 return DSA_get0_p(dsa);
775 }
776
Openssl_DSA_get0_q(const DSA * dsa)777 const BIGNUM *Openssl_DSA_get0_q(const DSA *dsa)
778 {
779 if (Is_Need_Mock()) {
780 return NULL;
781 }
782 return DSA_get0_q(dsa);
783 }
784
Openssl_DSA_get0_g(const DSA * dsa)785 const BIGNUM *Openssl_DSA_get0_g(const DSA *dsa)
786 {
787 if (Is_Need_Mock()) {
788 return NULL;
789 }
790 return DSA_get0_g(dsa);
791 }
792
Openssl_DSA_get0_pub_key(const DSA * dsa)793 const BIGNUM *Openssl_DSA_get0_pub_key(const DSA *dsa)
794 {
795 if (Is_Need_Mock()) {
796 return NULL;
797 }
798 return DSA_get0_pub_key(dsa);
799 }
800
Openssl_DSA_get0_priv_key(const DSA * dsa)801 const BIGNUM *Openssl_DSA_get0_priv_key(const DSA *dsa)
802 {
803 if (Is_Need_Mock()) {
804 return NULL;
805 }
806 return DSA_get0_priv_key(dsa);
807 }
808
Openssl_DSA_generate_key(DSA * a)809 int Openssl_DSA_generate_key(DSA *a)
810 {
811 if (Is_Need_Mock()) {
812 return -1;
813 }
814 return DSA_generate_key(a);
815 }
816
Openssl_d2i_DSA_PUBKEY(DSA ** dsa,const unsigned char ** ppin,long length)817 DSA *Openssl_d2i_DSA_PUBKEY(DSA **dsa, const unsigned char **ppin, long length)
818 {
819 if (Is_Need_Mock()) {
820 return NULL;
821 }
822 return d2i_DSA_PUBKEY(dsa, ppin, length);
823 }
824
Openssl_d2i_DSAPrivateKey(DSA ** dsa,const unsigned char ** ppin,long length)825 DSA *Openssl_d2i_DSAPrivateKey(DSA **dsa, const unsigned char **ppin, long length)
826 {
827 if (Is_Need_Mock()) {
828 return NULL;
829 }
830 return d2i_DSAPrivateKey(dsa, ppin, length);
831 }
832
Openssl_i2d_DSA_PUBKEY(DSA * dsa,unsigned char ** ppout)833 int Openssl_i2d_DSA_PUBKEY(DSA *dsa, unsigned char **ppout)
834 {
835 if (Is_Need_Mock()) {
836 return -1;
837 }
838 return i2d_DSA_PUBKEY(dsa, ppout);
839 }
840
Openssl_i2d_DSAPrivateKey(DSA * dsa,unsigned char ** ppout)841 int Openssl_i2d_DSAPrivateKey(DSA *dsa, unsigned char **ppout)
842 {
843 if (Is_Need_Mock()) {
844 return -1;
845 }
846 return i2d_DSAPrivateKey(dsa, ppout);
847 }
848
Openssl_RSA_new(void)849 RSA *Openssl_RSA_new(void)
850 {
851 return RSA_new();
852 }
853
Openssl_RSA_free(RSA * rsa)854 void Openssl_RSA_free(RSA *rsa)
855 {
856 RSA_free(rsa);
857 }
858
Openssl_RSA_generate_multi_prime_key(RSA * rsa,int bits,int primes,BIGNUM * e,BN_GENCB * cb)859 int Openssl_RSA_generate_multi_prime_key(RSA *rsa, int bits, int primes,
860 BIGNUM *e, BN_GENCB *cb)
861 {
862 return RSA_generate_multi_prime_key(rsa, bits, primes, e, cb);
863 }
864
Openssl_RSA_generate_key_ex(RSA * rsa,int bits,BIGNUM * e,BN_GENCB * cb)865 int Openssl_RSA_generate_key_ex(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb)
866 {
867 return RSA_generate_key_ex(rsa, bits, e, cb);
868 }
869
Openssl_RSA_bits(const RSA * rsa)870 int Openssl_RSA_bits(const RSA *rsa)
871 {
872 return RSA_bits(rsa);
873 }
874
Openssl_RSA_set0_key(RSA * r,BIGNUM * n,BIGNUM * e,BIGNUM * d)875 int Openssl_RSA_set0_key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
876 {
877 return RSA_set0_key(r, n, e, d);
878 }
879
Openssl_RSA_get0_key(const RSA * r,const BIGNUM ** n,const BIGNUM ** e,const BIGNUM ** d)880 void Openssl_RSA_get0_key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
881 {
882 RSA_get0_key(r, n, e, d);
883 }
884
Openssl_RSA_get0_n(const RSA * d)885 const BIGNUM *Openssl_RSA_get0_n(const RSA *d)
886 {
887 return RSA_get0_n(d);
888 }
889
Openssl_RSA_get0_e(const RSA * d)890 const BIGNUM *Openssl_RSA_get0_e(const RSA *d)
891 {
892 return RSA_get0_e(d);
893 }
894
Openssl_RSA_get0_d(const RSA * d)895 const BIGNUM *Openssl_RSA_get0_d(const RSA *d)
896 {
897 return RSA_get0_d(d);
898 }
899
Openssl_RSA_get0_factors(const RSA * r,const BIGNUM ** p,const BIGNUM ** q)900 void Openssl_RSA_get0_factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
901 {
902 RSA_get0_factors(r, p, q);
903 }
904
Openssl_RSAPublicKey_dup(RSA * rsa)905 RSA *Openssl_RSAPublicKey_dup(RSA *rsa)
906 {
907 return RSAPublicKey_dup(rsa);
908 }
909
Openssl_RSAPrivateKey_dup(RSA * rsa)910 RSA *Openssl_RSAPrivateKey_dup(RSA *rsa)
911 {
912 return RSAPrivateKey_dup(rsa);
913 }
914
Openssl_d2i_RSA_PUBKEY(RSA ** a,const unsigned char ** pp,long length)915 RSA *Openssl_d2i_RSA_PUBKEY(RSA **a, const unsigned char **pp, long length)
916 {
917 return d2i_RSA_PUBKEY(a, pp, length);
918 }
919
Openssl_i2d_RSA_PUBKEY(RSA * a,unsigned char ** pp)920 int Openssl_i2d_RSA_PUBKEY(RSA *a, unsigned char **pp)
921 {
922 return i2d_RSA_PUBKEY(a, pp);
923 }
924
Openssl_EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX * ctx,int saltlen)925 int Openssl_EVP_PKEY_CTX_set_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int saltlen)
926 {
927 return EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, saltlen);
928 }
929
Openssl_EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX * ctx,int * saltlen)930 int Openssl_EVP_PKEY_CTX_get_rsa_pss_saltlen(EVP_PKEY_CTX *ctx, int *saltlen)
931 {
932 return EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, saltlen);
933 }
934
Openssl_EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX * ctx,int pad)935 int Openssl_EVP_PKEY_CTX_set_rsa_padding(EVP_PKEY_CTX *ctx, int pad)
936 {
937 return EVP_PKEY_CTX_set_rsa_padding(ctx, pad);
938 }
939
Openssl_EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX * ctx,const EVP_MD * md)940 int Openssl_EVP_PKEY_CTX_set_rsa_mgf1_md(EVP_PKEY_CTX *ctx, const EVP_MD *md)
941 {
942 return EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md);
943 }
944
Openssl_EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX * ctx,const EVP_MD * md)945 int Openssl_EVP_PKEY_CTX_set_rsa_oaep_md(EVP_PKEY_CTX *ctx, const EVP_MD *md)
946 {
947 return EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md);
948 }
949
Openssl_EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX * ctx,void * label,int len)950 int Openssl_EVP_PKEY_CTX_set0_rsa_oaep_label(EVP_PKEY_CTX *ctx, void *label, int len)
951 {
952 return EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, label, len);
953 }
954
Openssl_EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX * ctx,unsigned char ** label)955 int Openssl_EVP_PKEY_CTX_get0_rsa_oaep_label(EVP_PKEY_CTX *ctx, unsigned char **label)
956 {
957 return EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, label);
958 }
959
Openssl_d2i_AutoPrivateKey(EVP_PKEY ** a,const unsigned char ** pp,long length)960 EVP_PKEY *Openssl_d2i_AutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, long length)
961 {
962 return d2i_AutoPrivateKey(a, pp, length);
963 }
964
Openssl_EVP_PKEY_get1_RSA(EVP_PKEY * pkey)965 struct rsa_st *Openssl_EVP_PKEY_get1_RSA(EVP_PKEY *pkey)
966 {
967 return EVP_PKEY_get1_RSA(pkey);
968 }
969
Openssl_EVP_PKEY_set1_RSA(EVP_PKEY * pkey,struct rsa_st * key)970 int Openssl_EVP_PKEY_set1_RSA(EVP_PKEY *pkey, struct rsa_st *key)
971 {
972 return EVP_PKEY_set1_RSA(pkey, key);
973 }
974
Openssl_EVP_PKEY_assign_RSA(EVP_PKEY * pkey,struct rsa_st * key)975 int Openssl_EVP_PKEY_assign_RSA(EVP_PKEY *pkey, struct rsa_st *key)
976 {
977 return EVP_PKEY_assign_RSA(pkey, key);
978 }
979
Openssl_i2d_PKCS8PrivateKey_bio(BIO * bp,EVP_PKEY * x,const EVP_CIPHER * enc,char * kstr,int klen,pem_password_cb * cb,void * u)980 int Openssl_i2d_PKCS8PrivateKey_bio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
981 char *kstr, int klen, pem_password_cb *cb, void *u)
982 {
983 return i2d_PKCS8PrivateKey_bio(bp, x, enc, kstr, klen, cb, u);
984 }
985
Openssl_BIO_new(const BIO_METHOD * type)986 BIO *Openssl_BIO_new(const BIO_METHOD *type)
987 {
988 return BIO_new(type);
989 }
990
Openssl_BIO_s_mem(void)991 const BIO_METHOD *Openssl_BIO_s_mem(void)
992 {
993 return BIO_s_mem();
994 }
995
Openssl_BIO_read(BIO * b,void * data,int dlen)996 int Openssl_BIO_read(BIO *b, void *data, int dlen)
997 {
998 return BIO_read(b, data, dlen);
999 }
1000
Openssl_BIO_free_all(BIO * a)1001 void Openssl_BIO_free_all(BIO *a)
1002 {
1003 return BIO_free_all(a);
1004 }
1005
Openssl_RAND_priv_bytes(unsigned char * buf,int num)1006 int Openssl_RAND_priv_bytes(unsigned char *buf, int num)
1007 {
1008 if (Is_Need_Mock()) {
1009 return -1;
1010 }
1011 return RAND_priv_bytes(buf, num);
1012 }
1013
Openssl_RAND_seed(const void * buf,int num)1014 void Openssl_RAND_seed(const void *buf, int num)
1015 {
1016 RAND_seed(buf, num);
1017 }
1018
Openssl_EVP_sha1(void)1019 const EVP_MD *Openssl_EVP_sha1(void)
1020 {
1021 if (Is_Need_Mock()) {
1022 return NULL;
1023 }
1024 return EVP_sha1();
1025 }
1026
Openssl_EVP_sha224(void)1027 const EVP_MD *Openssl_EVP_sha224(void)
1028 {
1029 if (Is_Need_Mock()) {
1030 return NULL;
1031 }
1032 return EVP_sha224();
1033 }
1034
Openssl_EVP_sha256(void)1035 const EVP_MD *Openssl_EVP_sha256(void)
1036 {
1037 if (Is_Need_Mock()) {
1038 return NULL;
1039 }
1040 return EVP_sha256();
1041 }
1042
Openssl_EVP_sha384(void)1043 const EVP_MD *Openssl_EVP_sha384(void)
1044 {
1045 if (Is_Need_Mock()) {
1046 return NULL;
1047 }
1048 return EVP_sha384();
1049 }
1050
Openssl_EVP_sha512(void)1051 const EVP_MD *Openssl_EVP_sha512(void)
1052 {
1053 if (Is_Need_Mock()) {
1054 return NULL;
1055 }
1056 return EVP_sha512();
1057 }
1058
Openssl_EVP_md5(void)1059 const EVP_MD *Openssl_EVP_md5(void)
1060 {
1061 if (Is_Need_Mock()) {
1062 return NULL;
1063 }
1064 return EVP_md5();
1065 }
1066
Openssl_EVP_DigestFinal_ex(EVP_MD_CTX * ctx,unsigned char * md,unsigned int * size)1067 int Openssl_EVP_DigestFinal_ex(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
1068 {
1069 if (Is_Need_Mock()) {
1070 return -1;
1071 }
1072 return EVP_DigestFinal_ex(ctx, md, size);
1073 }
1074
Openssl_EVP_MD_CTX_size(const EVP_MD_CTX * ctx)1075 int Openssl_EVP_MD_CTX_size(const EVP_MD_CTX *ctx)
1076 {
1077 if (Is_Need_Mock()) {
1078 return -1;
1079 }
1080 return EVP_MD_CTX_size(ctx);
1081 }
1082
Openssl_EVP_DigestInit_ex(EVP_MD_CTX * ctx,const EVP_MD * type,ENGINE * impl)1083 int Openssl_EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
1084 {
1085 if (Is_Need_Mock()) {
1086 return -1;
1087 }
1088 return EVP_DigestInit_ex(ctx, type, impl);
1089 }
1090
Openssl_HMAC_Init_ex(HMAC_CTX * ctx,const void * key,int len,const EVP_MD * md,ENGINE * impl)1091 int Openssl_HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md, ENGINE *impl)
1092 {
1093 if (Is_Need_Mock()) {
1094 return -1;
1095 }
1096 return HMAC_Init_ex(ctx, key, len, md, impl);
1097 }
1098
Openssl_HMAC_Final(HMAC_CTX * ctx,unsigned char * md,unsigned int * len)1099 int Openssl_HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
1100 {
1101 if (Is_Need_Mock()) {
1102 return -1;
1103 }
1104 return HMAC_Final(ctx, md, len);
1105 }
1106
Openssl_HMAC_size(const HMAC_CTX * ctx)1107 size_t Openssl_HMAC_size(const HMAC_CTX *ctx)
1108 {
1109 if (Is_Need_Mock()) {
1110 return -1;
1111 }
1112 return HMAC_size(ctx);
1113 }
1114
Openssl_HMAC_CTX_free(HMAC_CTX * ctx)1115 void Openssl_HMAC_CTX_free(HMAC_CTX *ctx)
1116 {
1117 HMAC_CTX_free(ctx);
1118 }
1119
Openssl_HMAC_CTX_new(void)1120 HMAC_CTX *Openssl_HMAC_CTX_new(void)
1121 {
1122 if (Is_Need_Mock()) {
1123 return NULL;
1124 }
1125 return HMAC_CTX_new();
1126 }
1127
Openssl_EVP_CIPHER_CTX_free(EVP_CIPHER_CTX * ctx)1128 void Openssl_EVP_CIPHER_CTX_free(EVP_CIPHER_CTX *ctx)
1129 {
1130 EVP_CIPHER_CTX_free(ctx);
1131 }
1132
Openssl_EVP_aes_128_ecb(void)1133 const EVP_CIPHER *Openssl_EVP_aes_128_ecb(void)
1134 {
1135 if (Is_Need_Mock()) {
1136 return NULL;
1137 }
1138 return EVP_aes_128_ecb();
1139 }
1140
Openssl_EVP_aes_192_ecb(void)1141 const EVP_CIPHER *Openssl_EVP_aes_192_ecb(void)
1142 {
1143 if (Is_Need_Mock()) {
1144 return NULL;
1145 }
1146 return EVP_aes_192_ecb();
1147 }
1148
Openssl_EVP_aes_256_ecb(void)1149 const EVP_CIPHER *Openssl_EVP_aes_256_ecb(void)
1150 {
1151 if (Is_Need_Mock()) {
1152 return NULL;
1153 }
1154 return EVP_aes_256_ecb();
1155 }
1156
Openssl_EVP_aes_128_cbc(void)1157 const EVP_CIPHER *Openssl_EVP_aes_128_cbc(void)
1158 {
1159 if (Is_Need_Mock()) {
1160 return NULL;
1161 }
1162 return EVP_aes_128_cbc();
1163 }
1164
Openssl_EVP_aes_192_cbc(void)1165 const EVP_CIPHER *Openssl_EVP_aes_192_cbc(void)
1166 {
1167 if (Is_Need_Mock()) {
1168 return NULL;
1169 }
1170 return EVP_aes_192_cbc();
1171 }
1172
Openssl_EVP_aes_256_cbc(void)1173 const EVP_CIPHER *Openssl_EVP_aes_256_cbc(void)
1174 {
1175 if (Is_Need_Mock()) {
1176 return NULL;
1177 }
1178 return EVP_aes_256_cbc();
1179 }
1180
Openssl_EVP_aes_128_ctr(void)1181 const EVP_CIPHER *Openssl_EVP_aes_128_ctr(void)
1182 {
1183 if (Is_Need_Mock()) {
1184 return NULL;
1185 }
1186 return EVP_aes_128_ctr();
1187 }
1188
Openssl_EVP_aes_192_ctr(void)1189 const EVP_CIPHER *Openssl_EVP_aes_192_ctr(void)
1190 {
1191 if (Is_Need_Mock()) {
1192 return NULL;
1193 }
1194 return EVP_aes_192_ctr();
1195 }
1196
Openssl_EVP_aes_256_ctr(void)1197 const EVP_CIPHER *Openssl_EVP_aes_256_ctr(void)
1198 {
1199 if (Is_Need_Mock()) {
1200 return NULL;
1201 }
1202 return EVP_aes_256_ctr();
1203 }
1204
Openssl_EVP_aes_128_ofb(void)1205 const EVP_CIPHER *Openssl_EVP_aes_128_ofb(void)
1206 {
1207 if (Is_Need_Mock()) {
1208 return NULL;
1209 }
1210 return EVP_aes_128_ofb();
1211 }
1212
Openssl_EVP_aes_192_ofb(void)1213 const EVP_CIPHER *Openssl_EVP_aes_192_ofb(void)
1214 {
1215 if (Is_Need_Mock()) {
1216 return NULL;
1217 }
1218 return EVP_aes_192_ofb();
1219 }
1220
Openssl_EVP_aes_256_ofb(void)1221 const EVP_CIPHER *Openssl_EVP_aes_256_ofb(void)
1222 {
1223 if (Is_Need_Mock()) {
1224 return NULL;
1225 }
1226 return EVP_aes_256_ofb();
1227 }
1228
Openssl_EVP_aes_128_cfb(void)1229 const EVP_CIPHER *Openssl_EVP_aes_128_cfb(void)
1230 {
1231 if (Is_Need_Mock()) {
1232 return NULL;
1233 }
1234 return EVP_aes_128_cfb();
1235 }
1236
Openssl_EVP_aes_192_cfb(void)1237 const EVP_CIPHER *Openssl_EVP_aes_192_cfb(void)
1238 {
1239 if (Is_Need_Mock()) {
1240 return NULL;
1241 }
1242 return EVP_aes_192_cfb();
1243 }
1244
Openssl_EVP_aes_256_cfb(void)1245 const EVP_CIPHER *Openssl_EVP_aes_256_cfb(void)
1246 {
1247 if (Is_Need_Mock()) {
1248 return NULL;
1249 }
1250 return EVP_aes_256_cfb();
1251 }
1252
Openssl_EVP_aes_128_cfb1(void)1253 const EVP_CIPHER *Openssl_EVP_aes_128_cfb1(void)
1254 {
1255 if (Is_Need_Mock()) {
1256 return NULL;
1257 }
1258 return EVP_aes_128_cfb1();
1259 }
1260
Openssl_EVP_aes_192_cfb1(void)1261 const EVP_CIPHER *Openssl_EVP_aes_192_cfb1(void)
1262 {
1263 if (Is_Need_Mock()) {
1264 return NULL;
1265 }
1266 return EVP_aes_192_cfb1();
1267 }
1268
Openssl_EVP_aes_256_cfb1(void)1269 const EVP_CIPHER *Openssl_EVP_aes_256_cfb1(void)
1270 {
1271 if (Is_Need_Mock()) {
1272 return NULL;
1273 }
1274 return EVP_aes_256_cfb1();
1275 }
1276
Openssl_EVP_aes_128_cfb128(void)1277 const EVP_CIPHER *Openssl_EVP_aes_128_cfb128(void)
1278 {
1279 if (Is_Need_Mock()) {
1280 return NULL;
1281 }
1282 return EVP_aes_128_cfb128();
1283 }
1284
Openssl_EVP_aes_192_cfb128(void)1285 const EVP_CIPHER *Openssl_EVP_aes_192_cfb128(void)
1286 {
1287 if (Is_Need_Mock()) {
1288 return NULL;
1289 }
1290 return EVP_aes_192_cfb128();
1291 }
1292
Openssl_EVP_aes_256_cfb128(void)1293 const EVP_CIPHER *Openssl_EVP_aes_256_cfb128(void)
1294 {
1295 if (Is_Need_Mock()) {
1296 return NULL;
1297 }
1298 return EVP_aes_256_cfb128();
1299 }
1300
Openssl_EVP_aes_128_cfb8(void)1301 const EVP_CIPHER *Openssl_EVP_aes_128_cfb8(void)
1302 {
1303 if (Is_Need_Mock()) {
1304 return NULL;
1305 }
1306 return EVP_aes_128_cfb8();
1307 }
1308
Openssl_EVP_aes_192_cfb8(void)1309 const EVP_CIPHER *Openssl_EVP_aes_192_cfb8(void)
1310 {
1311 if (Is_Need_Mock()) {
1312 return NULL;
1313 }
1314 return EVP_aes_192_cfb8();
1315 }
1316
Openssl_EVP_aes_256_cfb8(void)1317 const EVP_CIPHER *Openssl_EVP_aes_256_cfb8(void)
1318 {
1319 if (Is_Need_Mock()) {
1320 return NULL;
1321 }
1322 return EVP_aes_256_cfb8();
1323 }
1324
Openssl_EVP_aes_128_ccm(void)1325 const EVP_CIPHER *Openssl_EVP_aes_128_ccm(void)
1326 {
1327 if (Is_Need_Mock()) {
1328 return NULL;
1329 }
1330 return EVP_aes_128_ccm();
1331 }
1332
Openssl_EVP_aes_192_ccm(void)1333 const EVP_CIPHER *Openssl_EVP_aes_192_ccm(void)
1334 {
1335 if (Is_Need_Mock()) {
1336 return NULL;
1337 }
1338 return EVP_aes_192_ccm();
1339 }
1340
Openssl_EVP_aes_256_ccm(void)1341 const EVP_CIPHER *Openssl_EVP_aes_256_ccm(void)
1342 {
1343 if (Is_Need_Mock()) {
1344 return NULL;
1345 }
1346 return EVP_aes_256_ccm();
1347 }
1348
Openssl_EVP_aes_128_gcm(void)1349 const EVP_CIPHER *Openssl_EVP_aes_128_gcm(void)
1350 {
1351 if (Is_Need_Mock()) {
1352 return NULL;
1353 }
1354 return EVP_aes_128_gcm();
1355 }
1356
Openssl_EVP_aes_192_gcm(void)1357 const EVP_CIPHER *Openssl_EVP_aes_192_gcm(void)
1358 {
1359 if (Is_Need_Mock()) {
1360 return NULL;
1361 }
1362 return EVP_aes_192_gcm();
1363 }
1364
Openssl_EVP_aes_256_gcm(void)1365 const EVP_CIPHER *Openssl_EVP_aes_256_gcm(void)
1366 {
1367 if (Is_Need_Mock()) {
1368 return NULL;
1369 }
1370 return EVP_aes_256_gcm();
1371 }
1372
Openssl_EVP_CIPHER_CTX_new(void)1373 EVP_CIPHER_CTX *Openssl_EVP_CIPHER_CTX_new(void)
1374 {
1375 if (Is_Need_Mock()) {
1376 return NULL;
1377 }
1378 return EVP_CIPHER_CTX_new();
1379 }
1380
Openssl_EVP_CipherInit(EVP_CIPHER_CTX * ctx,const EVP_CIPHER * cipher,const unsigned char * key,const unsigned char * iv,int enc)1381 int Openssl_EVP_CipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
1382 const unsigned char *key, const unsigned char *iv, int enc)
1383 {
1384 if (Is_Need_Mock()) {
1385 return -1;
1386 }
1387 return EVP_CipherInit(ctx, cipher, key, iv, enc);
1388 }
1389
Openssl_EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX * ctx,int pad)1390 int Openssl_EVP_CIPHER_CTX_set_padding(EVP_CIPHER_CTX *ctx, int pad)
1391 {
1392 if (Is_Need_Mock()) {
1393 return -1;
1394 }
1395 return EVP_CIPHER_CTX_set_padding(ctx, pad);
1396 }
1397
Openssl_EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX * ctx,int type,int arg,void * ptr)1398 int Openssl_EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
1399 {
1400 if (Is_Need_Mock()) {
1401 return -1;
1402 }
1403 return EVP_CIPHER_CTX_ctrl(ctx, type, arg, ptr);
1404 }
1405
Openssl_EVP_CipherFinal_ex(EVP_CIPHER_CTX * ctx,unsigned char * out,int * outl)1406 int Openssl_EVP_CipherFinal_ex(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
1407 {
1408 if (Is_Need_Mock()) {
1409 return -1;
1410 }
1411 return EVP_CipherFinal_ex(ctx, out, outl);
1412 }
1413
Openssl_EVP_CipherUpdate(EVP_CIPHER_CTX * ctx,unsigned char * out,int * outl,const unsigned char * in,int inl)1414 int Openssl_EVP_CipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl)
1415 {
1416 if (Is_Need_Mock()) {
1417 return -1;
1418 }
1419 return EVP_CipherUpdate(ctx, out, outl, in, inl);
1420 }
1421
Openssl_EVP_des_ede3_ecb(void)1422 const EVP_CIPHER *Openssl_EVP_des_ede3_ecb(void)
1423 {
1424 if (Is_Need_Mock()) {
1425 return NULL;
1426 }
1427 return EVP_des_ede3_ecb();
1428 }
1429
Openssl_EVP_des_ede3_cbc(void)1430 const EVP_CIPHER *Openssl_EVP_des_ede3_cbc(void)
1431 {
1432 if (Is_Need_Mock()) {
1433 return NULL;
1434 }
1435 return EVP_des_ede3_cbc();
1436 }
1437
Openssl_EVP_des_ede3_ofb(void)1438 const EVP_CIPHER *Openssl_EVP_des_ede3_ofb(void)
1439 {
1440 if (Is_Need_Mock()) {
1441 return NULL;
1442 }
1443 return EVP_des_ede3_ofb();
1444 }
1445
Openssl_EVP_des_ede3_cfb64(void)1446 const EVP_CIPHER *Openssl_EVP_des_ede3_cfb64(void)
1447 {
1448 if (Is_Need_Mock()) {
1449 return NULL;
1450 }
1451 return EVP_des_ede3_cfb64();
1452 }
1453
Openssl_EVP_des_ede3_cfb1(void)1454 const EVP_CIPHER *Openssl_EVP_des_ede3_cfb1(void)
1455 {
1456 if (Is_Need_Mock()) {
1457 return NULL;
1458 }
1459 return EVP_des_ede3_cfb1();
1460 }
1461
Openssl_EVP_des_ede3_cfb8(void)1462 const EVP_CIPHER *Openssl_EVP_des_ede3_cfb8(void)
1463 {
1464 if (Is_Need_Mock()) {
1465 return NULL;
1466 }
1467 return EVP_des_ede3_cfb8();
1468 }