1 /*
2 * Copyright (C) 2023-2024 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/param_build.h>
18 #include "log.h"
19 #include "result.h"
20
21 ASN1_SEQUENCE(Sm2CipherText) = {
22 ASN1_SIMPLE(Sm2CipherText, c1X, BIGNUM),
23 ASN1_SIMPLE(Sm2CipherText, c1Y, BIGNUM),
24 ASN1_SIMPLE(Sm2CipherText, c3, ASN1_OCTET_STRING),
25 ASN1_SIMPLE(Sm2CipherText, c2, ASN1_OCTET_STRING),
26 } ASN1_SEQUENCE_END(Sm2CipherText)
27
28 IMPLEMENT_ASN1_FUNCTIONS(Sm2CipherText)
29
30 BIGNUM *OpensslBnDup(const BIGNUM *a)
31 {
32 return BN_dup(a);
33 }
34
OpensslBnClear(BIGNUM * a)35 void OpensslBnClear(BIGNUM *a)
36 {
37 BN_clear(a);
38 }
39
OpensslBnClearFree(BIGNUM * a)40 void OpensslBnClearFree(BIGNUM *a)
41 {
42 if (a != NULL) {
43 BN_clear_free(a);
44 }
45 }
46
OpensslBnNew(void)47 BIGNUM *OpensslBnNew(void)
48 {
49 return BN_new();
50 }
51
OpensslBnFree(BIGNUM * a)52 void OpensslBnFree(BIGNUM *a)
53 {
54 if (a != NULL) {
55 BN_free(a);
56 }
57 }
58
OpensslBin2Bn(const unsigned char * s,int len,BIGNUM * ret)59 BIGNUM *OpensslBin2Bn(const unsigned char *s, int len, BIGNUM *ret)
60 {
61 return BN_bin2bn(s, len, ret);
62 }
63
OpensslLeBin2Bn(const unsigned char * s,int len,BIGNUM * ret)64 BIGNUM *OpensslLeBin2Bn(const unsigned char *s, int len, BIGNUM *ret)
65 {
66 return BN_lebin2bn(s, len, ret);
67 }
68
OpensslBn2BinPad(const BIGNUM * a,unsigned char * to,int toLen)69 int OpensslBn2BinPad(const BIGNUM *a, unsigned char *to, int toLen)
70 {
71 return BN_bn2binpad(a, to, toLen);
72 }
73
OpensslBn2LeBinPad(const BIGNUM * a,unsigned char * to,int toLen)74 int OpensslBn2LeBinPad(const BIGNUM *a, unsigned char *to, int toLen)
75 {
76 return BN_bn2lebinpad(a, to, toLen);
77 }
78
OpensslBnCtxNew(void)79 BN_CTX *OpensslBnCtxNew(void)
80 {
81 return BN_CTX_new();
82 }
83
OpensslBnCtxFree(BN_CTX * ctx)84 void OpensslBnCtxFree(BN_CTX *ctx)
85 {
86 if (ctx != NULL) {
87 BN_CTX_free(ctx);
88 }
89 }
90
OpensslBnNumBytes(const BIGNUM * a)91 int OpensslBnNumBytes(const BIGNUM *a)
92 {
93 return BN_num_bytes(a);
94 }
95
OpensslBnSetWord(BIGNUM * a,unsigned int w)96 int OpensslBnSetWord(BIGNUM *a, unsigned int w)
97 {
98 return BN_set_word(a, w);
99 }
100
OpensslBnGetWord(const BIGNUM * a)101 unsigned int OpensslBnGetWord(const BIGNUM *a)
102 {
103 return BN_get_word(a);
104 }
105
OpensslBnNumBits(const BIGNUM * a)106 int OpensslBnNumBits(const BIGNUM *a)
107 {
108 return BN_num_bits(a);
109 }
110
OpensslHex2Bn(BIGNUM ** a,const char * str)111 int OpensslHex2Bn(BIGNUM **a, const char *str)
112 {
113 return BN_hex2bn(a, str);
114 }
115
OpensslBnCmp(const BIGNUM * a,const BIGNUM * b)116 int OpensslBnCmp(const BIGNUM *a, const BIGNUM *b)
117 {
118 return BN_cmp(a, b);
119 }
120
OpensslEcKeyNewByCurveName(int nid)121 EC_KEY *OpensslEcKeyNewByCurveName(int nid)
122 {
123 return EC_KEY_new_by_curve_name(nid);
124 }
125
OpensslEcPointDup(const EC_POINT * src,const EC_GROUP * group)126 EC_POINT *OpensslEcPointDup(const EC_POINT *src, const EC_GROUP *group)
127 {
128 return EC_POINT_dup(src, group);
129 }
130
OpensslEcKeyGenerateKey(EC_KEY * ecKey)131 int OpensslEcKeyGenerateKey(EC_KEY *ecKey)
132 {
133 return EC_KEY_generate_key(ecKey);
134 }
135
OpensslEcKeySetPublicKey(EC_KEY * key,const EC_POINT * pub)136 int OpensslEcKeySetPublicKey(EC_KEY *key, const EC_POINT *pub)
137 {
138 return EC_KEY_set_public_key(key, pub);
139 }
140
OpensslEcKeySetPrivateKey(EC_KEY * key,const BIGNUM * privKey)141 int OpensslEcKeySetPrivateKey(EC_KEY *key, const BIGNUM *privKey)
142 {
143 return EC_KEY_set_private_key(key, privKey);
144 }
145
OpensslEcKeyCheckKey(const EC_KEY * key)146 int OpensslEcKeyCheckKey(const EC_KEY *key)
147 {
148 return EC_KEY_check_key(key);
149 }
150
OpensslEcKeyGet0PublicKey(const EC_KEY * key)151 const EC_POINT *OpensslEcKeyGet0PublicKey(const EC_KEY *key)
152 {
153 return EC_KEY_get0_public_key(key);
154 }
155
OpensslEcKeyGet0PrivateKey(const EC_KEY * key)156 const BIGNUM *OpensslEcKeyGet0PrivateKey(const EC_KEY *key)
157 {
158 return EC_KEY_get0_private_key(key);
159 }
160
OpensslEcKeyGet0Group(const EC_KEY * key)161 const EC_GROUP *OpensslEcKeyGet0Group(const EC_KEY *key)
162 {
163 return EC_KEY_get0_group(key);
164 }
165
OpensslI2dEcPubKey(EC_KEY * a,unsigned char ** pp)166 int OpensslI2dEcPubKey(EC_KEY *a, unsigned char **pp)
167 {
168 return i2d_EC_PUBKEY(a, pp);
169 }
170
OpensslI2dEcPrivateKey(EC_KEY * key,unsigned char ** out)171 int OpensslI2dEcPrivateKey(EC_KEY *key, unsigned char **out)
172 {
173 return i2d_ECPrivateKey(key, out);
174 }
175
OpensslD2iEcPubKey(EC_KEY ** a,const unsigned char ** pp,long length)176 EC_KEY *OpensslD2iEcPubKey(EC_KEY **a, const unsigned char **pp, long length)
177 {
178 return d2i_EC_PUBKEY(a, pp, length);
179 }
180
OpensslD2iEcPrivateKey(EC_KEY ** key,const unsigned char ** in,long len)181 EC_KEY *OpensslD2iEcPrivateKey(EC_KEY **key, const unsigned char **in, long len)
182 {
183 return d2i_ECPrivateKey(key, in, len);
184 }
185
OpensslEcKeySetAsn1Flag(EC_KEY * key,int flag)186 void OpensslEcKeySetAsn1Flag(EC_KEY *key, int flag)
187 {
188 EC_KEY_set_asn1_flag(key, flag);
189 }
190
OpensslEcKeySetEncFlags(EC_KEY * ecKey,unsigned int flags)191 void OpensslEcKeySetEncFlags(EC_KEY *ecKey, unsigned int flags)
192 {
193 EC_KEY_set_enc_flags(ecKey, flags);
194 }
195
OpensslEcKeyFree(EC_KEY * key)196 void OpensslEcKeyFree(EC_KEY *key)
197 {
198 if (key != NULL) {
199 EC_KEY_free(key);
200 }
201 }
202
OpensslEcPointFree(EC_POINT * point)203 void OpensslEcPointFree(EC_POINT *point)
204 {
205 if (point != NULL) {
206 EC_POINT_free(point);
207 }
208 }
209
OpensslEcGroupNewCurveGfp(const BIGNUM * p,const BIGNUM * a,const BIGNUM * b,BN_CTX * ctx)210 EC_GROUP *OpensslEcGroupNewCurveGfp(const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
211 {
212 return EC_GROUP_new_curve_GFp(p, a, b, ctx);
213 }
214
OpensslEcGroupFree(EC_GROUP * group)215 void OpensslEcGroupFree(EC_GROUP *group)
216 {
217 if (group != NULL) {
218 EC_GROUP_free(group);
219 }
220 }
221
OpensslEcPointNew(const EC_GROUP * group)222 EC_POINT *OpensslEcPointNew(const EC_GROUP *group)
223 {
224 return EC_POINT_new(group);
225 }
226
OpensslEcPointCopy(EC_POINT * dst,const EC_POINT * src)227 int OpensslEcPointCopy(EC_POINT *dst, const EC_POINT *src)
228 {
229 return EC_POINT_copy(dst, src);
230 }
231
OpensslEcPointSetAffineCoordinatesGfp(const EC_GROUP * group,EC_POINT * point,const BIGNUM * x,const BIGNUM * y,BN_CTX * ctx)232 int OpensslEcPointSetAffineCoordinatesGfp(const EC_GROUP *group, EC_POINT *point, const BIGNUM *x,
233 const BIGNUM *y, BN_CTX *ctx)
234 {
235 return EC_POINT_set_affine_coordinates_GFp(group, point, x, y, ctx);
236 }
237
OpensslEcGroupSetGenerator(EC_GROUP * group,const EC_POINT * generator,const BIGNUM * order,const BIGNUM * cofactor)238 int OpensslEcGroupSetGenerator(EC_GROUP *group, const EC_POINT *generator, const BIGNUM *order,
239 const BIGNUM *cofactor)
240 {
241 return EC_GROUP_set_generator(group, generator, order, cofactor);
242 }
243
OpensslEcKeyNew(void)244 EC_KEY *OpensslEcKeyNew(void)
245 {
246 return EC_KEY_new();
247 }
248
OpensslEcKeyDup(const EC_KEY * ecKey)249 EC_KEY *OpensslEcKeyDup(const EC_KEY *ecKey)
250 {
251 return EC_KEY_dup(ecKey);
252 }
253
OpensslEcKeySetGroup(EC_KEY * key,const EC_GROUP * group)254 int OpensslEcKeySetGroup(EC_KEY *key, const EC_GROUP *group)
255 {
256 return EC_KEY_set_group(key, group);
257 }
258
OpensslEcGroupGetCurveGfp(const EC_GROUP * group,BIGNUM * p,BIGNUM * a,BIGNUM * b,BN_CTX * ctx)259 int OpensslEcGroupGetCurveGfp(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
260 {
261 return EC_GROUP_get_curve_GFp(group, p, a, b, ctx);
262 }
263
OpensslEcGroupGet0Generator(const EC_GROUP * group)264 const EC_POINT *OpensslEcGroupGet0Generator(const EC_GROUP *group)
265 {
266 return EC_GROUP_get0_generator(group);
267 }
268
OpensslEcPointGetAffineCoordinatesGfp(const EC_GROUP * group,const EC_POINT * point,BIGNUM * x,BIGNUM * y,BN_CTX * ctx)269 int OpensslEcPointGetAffineCoordinatesGfp(const EC_GROUP *group, const EC_POINT *point, BIGNUM *x,
270 BIGNUM *y, BN_CTX *ctx)
271 {
272 return EC_POINT_get_affine_coordinates_GFp(group, point, x, y, ctx);
273 }
274
OpensslEcGroupGetOrder(const EC_GROUP * group,BIGNUM * order,BN_CTX * ctx)275 int OpensslEcGroupGetOrder(const EC_GROUP *group, BIGNUM *order, BN_CTX *ctx)
276 {
277 return EC_GROUP_get_order(group, order, ctx);
278 }
279
OpensslEcGroupGetCofactor(const EC_GROUP * group,BIGNUM * cofactor,BN_CTX * ctx)280 int OpensslEcGroupGetCofactor(const EC_GROUP *group, BIGNUM *cofactor, BN_CTX *ctx)
281 {
282 return EC_GROUP_get_cofactor(group, cofactor, ctx);
283 }
284
OpensslEcGroupGetDegree(const EC_GROUP * group)285 int OpensslEcGroupGetDegree(const EC_GROUP *group)
286 {
287 return EC_GROUP_get_degree(group);
288 }
289
OpensslEcGroupDup(const EC_GROUP * a)290 EC_GROUP *OpensslEcGroupDup(const EC_GROUP *a)
291 {
292 return EC_GROUP_dup(a);
293 }
294
OpensslEcGroupSetCurveName(EC_GROUP * group,int nid)295 void OpensslEcGroupSetCurveName(EC_GROUP *group, int nid)
296 {
297 EC_GROUP_set_curve_name(group, nid);
298 }
299
OpensslEcGroupGetCurveName(const EC_GROUP * group)300 int OpensslEcGroupGetCurveName(const EC_GROUP *group)
301 {
302 return EC_GROUP_get_curve_name(group);
303 }
304
OpensslEcPointMul(const EC_GROUP * group,EC_POINT * r,const BIGNUM * gScalar,const EC_POINT * point,const BIGNUM * pScalar,BN_CTX * ctx)305 int OpensslEcPointMul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *gScalar, const EC_POINT *point,
306 const BIGNUM *pScalar, BN_CTX *ctx)
307 {
308 return EC_POINT_mul(group, r, gScalar, point, pScalar, ctx);
309 }
310
OpensslEvpMdCtxNew(void)311 EVP_MD_CTX *OpensslEvpMdCtxNew(void)
312 {
313 return EVP_MD_CTX_new();
314 }
315
OpensslEvpMdCtxFree(EVP_MD_CTX * ctx)316 void OpensslEvpMdCtxFree(EVP_MD_CTX *ctx)
317 {
318 if (ctx != NULL) {
319 EVP_MD_CTX_free(ctx);
320 }
321 }
322
OpensslEvpMdCtxSetPkeyCtx(EVP_MD_CTX * ctx,EVP_PKEY_CTX * pctx)323 void OpensslEvpMdCtxSetPkeyCtx(EVP_MD_CTX *ctx, EVP_PKEY_CTX *pctx)
324 {
325 EVP_MD_CTX_set_pkey_ctx(ctx, pctx);
326 }
327
OpensslEvpMdCtxGetPkeyCtx(EVP_MD_CTX * ctx)328 EVP_PKEY_CTX *OpensslEvpMdCtxGetPkeyCtx(EVP_MD_CTX *ctx)
329 {
330 return EVP_MD_CTX_get_pkey_ctx(ctx);
331 }
332
OpensslEvpDigestSignInit(EVP_MD_CTX * ctx,EVP_PKEY_CTX ** pctx,const EVP_MD * type,ENGINE * e,EVP_PKEY * pkey)333 int OpensslEvpDigestSignInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey)
334 {
335 return EVP_DigestSignInit(ctx, pctx, type, e, pkey);
336 }
337
OpensslEvpDigestSignUpdate(EVP_MD_CTX * ctx,const void * data,size_t count)338 int OpensslEvpDigestSignUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
339 {
340 return EVP_DigestSignUpdate(ctx, data, count);
341 }
342
OpensslEvpDigestSignFinal(EVP_MD_CTX * ctx,unsigned char * sigret,size_t * siglen)343 int OpensslEvpDigestSignFinal(EVP_MD_CTX *ctx, unsigned char *sigret, size_t *siglen)
344 {
345 return EVP_DigestSignFinal(ctx, sigret, siglen);
346 }
347
OpensslEvpDigestSign(EVP_MD_CTX * ctx,unsigned char * sig,size_t * siglen,const unsigned char * tbs,size_t tbslen)348 int OpensslEvpDigestSign(EVP_MD_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs, size_t tbslen)
349 {
350 return EVP_DigestSign(ctx, sig, siglen, tbs, tbslen);
351 }
352
OpensslEvpDigestVerifyInit(EVP_MD_CTX * ctx,EVP_PKEY_CTX ** pctx,const EVP_MD * type,ENGINE * e,EVP_PKEY * pkey)353 int OpensslEvpDigestVerifyInit(EVP_MD_CTX *ctx, EVP_PKEY_CTX **pctx, const EVP_MD *type, ENGINE *e, EVP_PKEY *pkey)
354 {
355 return EVP_DigestVerifyInit(ctx, pctx, type, e, pkey);
356 }
357
OpensslEvpDigestVerifyUpdate(EVP_MD_CTX * ctx,const void * data,size_t count)358 int OpensslEvpDigestVerifyUpdate(EVP_MD_CTX *ctx, const void *data, size_t count)
359 {
360 return EVP_DigestVerifyUpdate(ctx, data, count);
361 }
362
OpensslEvpDigestVerifyFinal(EVP_MD_CTX * ctx,const unsigned char * sig,size_t siglen)363 int OpensslEvpDigestVerifyFinal(EVP_MD_CTX *ctx, const unsigned char *sig, size_t siglen)
364 {
365 return EVP_DigestVerifyFinal(ctx, sig, siglen);
366 }
367
OpensslEvpDigestVerify(EVP_MD_CTX * ctx,unsigned char * sig,size_t siglen,const unsigned char * tbs,size_t tbslen)368 int OpensslEvpDigestVerify(EVP_MD_CTX *ctx, unsigned char *sig, size_t siglen,
369 const unsigned char *tbs, size_t tbslen)
370 {
371 return EVP_DigestVerify(ctx, sig, siglen, tbs, tbslen);
372 }
373
OpensslEvpPkeySignInit(EVP_PKEY_CTX * ctx)374 int OpensslEvpPkeySignInit(EVP_PKEY_CTX *ctx)
375 {
376 return EVP_PKEY_sign_init(ctx);
377 }
378
OpensslEvpPkeySign(EVP_PKEY_CTX * ctx,unsigned char * sig,size_t * siglen,const unsigned char * tbs,size_t tbslen)379 int OpensslEvpPkeySign(EVP_PKEY_CTX *ctx, unsigned char *sig, size_t *siglen, const unsigned char *tbs,
380 size_t tbslen)
381 {
382 return EVP_PKEY_sign(ctx, sig, siglen, tbs, tbslen);
383 }
384
OpensslEvpPkeyVerifyInit(EVP_PKEY_CTX * ctx)385 int OpensslEvpPkeyVerifyInit(EVP_PKEY_CTX *ctx)
386 {
387 return EVP_PKEY_verify_init(ctx);
388 }
389
OpensslEvpPkeyVerify(EVP_PKEY_CTX * ctx,const unsigned char * sig,size_t siglen,const unsigned char * tbs,size_t tbslen)390 int OpensslEvpPkeyVerify(EVP_PKEY_CTX *ctx, const unsigned char *sig, size_t siglen, const unsigned char *tbs,
391 size_t tbslen)
392 {
393 return EVP_PKEY_verify(ctx, sig, siglen, tbs, tbslen);
394 }
395
OpensslEvpPkeyCtxNewFromPkey(OSSL_LIB_CTX * libctx,EVP_PKEY * pkey,const char * propquery)396 EVP_PKEY_CTX *OpensslEvpPkeyCtxNewFromPkey(OSSL_LIB_CTX *libctx,
397 EVP_PKEY *pkey, const char *propquery)
398 {
399 return EVP_PKEY_CTX_new_from_pkey(libctx, pkey, propquery);
400 }
401
OpensslEvpPkeyNew(void)402 EVP_PKEY *OpensslEvpPkeyNew(void)
403 {
404 return EVP_PKEY_new();
405 }
406
OpensslEvpPkeyNewRawPublicKey(int type,ENGINE * e,const unsigned char * pub,size_t len)407 EVP_PKEY *OpensslEvpPkeyNewRawPublicKey(int type, ENGINE *e, const unsigned char *pub, size_t len)
408 {
409 return EVP_PKEY_new_raw_public_key(type, e, pub, len);
410 }
411
OpensslEvpPkeyNewRawPrivateKey(int type,ENGINE * e,const unsigned char * pub,size_t len)412 EVP_PKEY *OpensslEvpPkeyNewRawPrivateKey(int type, ENGINE *e, const unsigned char *pub, size_t len)
413 {
414 return EVP_PKEY_new_raw_private_key(type, e, pub, len);
415 }
416
OpensslEvpPkeyGetRawPublicKey(const EVP_PKEY * pkey,unsigned char * pub,size_t * len)417 int OpensslEvpPkeyGetRawPublicKey(const EVP_PKEY *pkey, unsigned char *pub, size_t *len)
418 {
419 return EVP_PKEY_get_raw_public_key(pkey, pub, len);
420 }
421
OpensslEvpPkeyGetRawPrivateKey(const EVP_PKEY * pkey,unsigned char * priv,size_t * len)422 int OpensslEvpPkeyGetRawPrivateKey(const EVP_PKEY *pkey, unsigned char *priv, size_t *len)
423 {
424 return EVP_PKEY_get_raw_private_key(pkey, priv, len);
425 }
426
OpensslEvpPkeyAssignEcKey(EVP_PKEY * pkey,EC_KEY * key)427 int OpensslEvpPkeyAssignEcKey(EVP_PKEY *pkey, EC_KEY *key)
428 {
429 return EVP_PKEY_assign_EC_KEY(pkey, key);
430 }
431
OpensslEvpPkeySet1EcKey(EVP_PKEY * pkey,EC_KEY * key)432 int OpensslEvpPkeySet1EcKey(EVP_PKEY *pkey, EC_KEY *key)
433 {
434 return EVP_PKEY_set1_EC_KEY(pkey, key);
435 }
436
OpensslEvpPkeyFree(EVP_PKEY * pkey)437 void OpensslEvpPkeyFree(EVP_PKEY *pkey)
438 {
439 if (pkey != NULL) {
440 EVP_PKEY_free(pkey);
441 }
442 }
443
OpensslEvpPkeyCtxNew(EVP_PKEY * pkey,ENGINE * e)444 EVP_PKEY_CTX *OpensslEvpPkeyCtxNew(EVP_PKEY *pkey, ENGINE *e)
445 {
446 return EVP_PKEY_CTX_new(pkey, e);
447 }
448
OpensslEvpPkeyDeriveInit(EVP_PKEY_CTX * ctx)449 int OpensslEvpPkeyDeriveInit(EVP_PKEY_CTX *ctx)
450 {
451 return EVP_PKEY_derive_init(ctx);
452 }
453
OpensslEvpPkeyDeriveSetPeer(EVP_PKEY_CTX * ctx,EVP_PKEY * peer)454 int OpensslEvpPkeyDeriveSetPeer(EVP_PKEY_CTX *ctx, EVP_PKEY *peer)
455 {
456 return EVP_PKEY_derive_set_peer(ctx, peer);
457 }
458
OpensslEvpPkeyDerive(EVP_PKEY_CTX * ctx,unsigned char * key,size_t * keylen)459 int OpensslEvpPkeyDerive(EVP_PKEY_CTX *ctx, unsigned char *key, size_t *keylen)
460 {
461 return EVP_PKEY_derive(ctx, key, keylen);
462 }
463
OpensslEvpPkeyCtxFree(EVP_PKEY_CTX * ctx)464 void OpensslEvpPkeyCtxFree(EVP_PKEY_CTX *ctx)
465 {
466 if (ctx != NULL) {
467 EVP_PKEY_CTX_free(ctx);
468 }
469 }
470
OpensslEvpPkeyEncrypt(EVP_PKEY_CTX * ctx,unsigned char * out,size_t * outlen,const unsigned char * in,size_t inlen)471 int OpensslEvpPkeyEncrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
472 const unsigned char *in, size_t inlen)
473 {
474 return EVP_PKEY_encrypt(ctx, out, outlen, in, inlen);
475 }
476
OpensslEvpPkeyDecrypt(EVP_PKEY_CTX * ctx,unsigned char * out,size_t * outlen,const unsigned char * in,size_t inlen)477 int OpensslEvpPkeyDecrypt(EVP_PKEY_CTX *ctx, unsigned char *out, size_t *outlen,
478 const unsigned char *in, size_t inlen)
479 {
480 return EVP_PKEY_decrypt(ctx, out, outlen, in, inlen);
481 }
482
OpensslEvpPkeyEncryptInit(EVP_PKEY_CTX * ctx)483 int OpensslEvpPkeyEncryptInit(EVP_PKEY_CTX *ctx)
484 {
485 return EVP_PKEY_encrypt_init(ctx);
486 }
487
OpensslEvpPkeyDecryptInit(EVP_PKEY_CTX * ctx)488 int OpensslEvpPkeyDecryptInit(EVP_PKEY_CTX *ctx)
489 {
490 return EVP_PKEY_decrypt_init(ctx);
491 }
492
OpensslEvpPkeyCtxNewId(int id,ENGINE * e)493 EVP_PKEY_CTX *OpensslEvpPkeyCtxNewId(int id, ENGINE *e)
494 {
495 return EVP_PKEY_CTX_new_id(id, e);
496 }
497
OpensslEvpPkeyBaseId(EVP_PKEY * pkey)498 int OpensslEvpPkeyBaseId(EVP_PKEY *pkey)
499 {
500 return EVP_PKEY_base_id(pkey);
501 }
502
OpensslEvpPkeyCtxNewFromName(OSSL_LIB_CTX * libctx,const char * name,const char * propquery)503 EVP_PKEY_CTX *OpensslEvpPkeyCtxNewFromName(OSSL_LIB_CTX *libctx, const char *name, const char *propquery)
504 {
505 return EVP_PKEY_CTX_new_from_name(libctx, name, propquery);
506 }
507
OpensslEvpPkeyVerifyRecoverInit(EVP_PKEY_CTX * ctx)508 int OpensslEvpPkeyVerifyRecoverInit(EVP_PKEY_CTX *ctx)
509 {
510 return EVP_PKEY_verify_recover_init(ctx);
511 }
512
OpensslEvpPkeyVerifyRecover(EVP_PKEY_CTX * ctx,unsigned char * rout,size_t * routlen,const unsigned char * sig,size_t siglen)513 int OpensslEvpPkeyVerifyRecover(EVP_PKEY_CTX *ctx, unsigned char *rout, size_t *routlen, const unsigned char *sig,
514 size_t siglen)
515 {
516 return EVP_PKEY_verify_recover(ctx, rout, routlen, sig, siglen);
517 }
518
OpensslOsslParamConstructUtf8String(const char * key,char * buf,size_t bsize)519 OSSL_PARAM OpensslOsslParamConstructUtf8String(const char *key, char *buf, size_t bsize)
520 {
521 return OSSL_PARAM_construct_utf8_string(key, buf, bsize);
522 }
523
OpensslOsslParamConstructOctetString(const char * key,void * buf,size_t bsize)524 OSSL_PARAM OpensslOsslParamConstructOctetString(const char *key, void *buf, size_t bsize)
525 {
526 return OSSL_PARAM_construct_octet_string(key, buf, bsize);
527 }
528
OpensslOsslParamConstructEnd(void)529 OSSL_PARAM OpensslOsslParamConstructEnd(void)
530 {
531 return OSSL_PARAM_construct_end();
532 }
533
OpensslEvpPkeyGenerate(EVP_PKEY_CTX * ctx,EVP_PKEY ** ppkey)534 int OpensslEvpPkeyGenerate(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
535 {
536 return EVP_PKEY_generate(ctx, ppkey);
537 }
538
OpensslOsslParamConstructUint(const char * key,unsigned int * buf)539 OSSL_PARAM OpensslOsslParamConstructUint(const char *key, unsigned int *buf)
540 {
541 return OSSL_PARAM_construct_uint(key, buf);
542 }
543
OpensslOsslParamConstructInt(const char * key,int * buf)544 OSSL_PARAM OpensslOsslParamConstructInt(const char *key, int *buf)
545 {
546 return OSSL_PARAM_construct_int(key, buf);
547 }
548
OpensslEvpPkeyCtxSet1Id(EVP_PKEY_CTX * ctx,const void * id,int idLen)549 int OpensslEvpPkeyCtxSet1Id(EVP_PKEY_CTX *ctx, const void *id, int idLen)
550 {
551 return EVP_PKEY_CTX_set1_id(ctx, id, idLen);
552 }
553
OpensslEvpPkeyParamGenInit(EVP_PKEY_CTX * ctx)554 int OpensslEvpPkeyParamGenInit(EVP_PKEY_CTX *ctx)
555 {
556 return EVP_PKEY_paramgen_init(ctx);
557 }
558
OpensslEvpPkeyCtxSetDsaParamgenBits(EVP_PKEY_CTX * ctx,int nbits)559 int OpensslEvpPkeyCtxSetDsaParamgenBits(EVP_PKEY_CTX *ctx, int nbits)
560 {
561 return EVP_PKEY_CTX_set_dsa_paramgen_bits(ctx, nbits);
562 }
563
OpensslEvpPkeyCtxSetParams(EVP_PKEY_CTX * ctx,const OSSL_PARAM * params)564 int OpensslEvpPkeyCtxSetParams(EVP_PKEY_CTX *ctx, const OSSL_PARAM *params)
565 {
566 return EVP_PKEY_CTX_set_params(ctx, params);
567 }
568
OpensslEvpPkeyParamGen(EVP_PKEY_CTX * ctx,EVP_PKEY ** ppkey)569 int OpensslEvpPkeyParamGen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
570 {
571 return EVP_PKEY_paramgen(ctx, ppkey);
572 }
573
OpensslEvpPkeyKeyGenInit(EVP_PKEY_CTX * ctx)574 int OpensslEvpPkeyKeyGenInit(EVP_PKEY_CTX *ctx)
575 {
576 return EVP_PKEY_keygen_init(ctx);
577 }
578
OpensslEvpPkeyKeyGen(EVP_PKEY_CTX * ctx,EVP_PKEY ** ppkey)579 int OpensslEvpPkeyKeyGen(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey)
580 {
581 return EVP_PKEY_keygen(ctx, ppkey);
582 }
583
OpensslEvpPkeySet1Dsa(EVP_PKEY * pkey,DSA * key)584 int OpensslEvpPkeySet1Dsa(EVP_PKEY *pkey, DSA *key)
585 {
586 return EVP_PKEY_set1_DSA(pkey, key);
587 }
588
OpensslEvpPkeyGet1Dsa(EVP_PKEY * pkey)589 DSA *OpensslEvpPkeyGet1Dsa(EVP_PKEY *pkey)
590 {
591 return EVP_PKEY_get1_DSA(pkey);
592 }
593
OpensslDsaNew(void)594 DSA *OpensslDsaNew(void)
595 {
596 return DSA_new();
597 }
598
OpensslDsaFree(DSA * dsa)599 void OpensslDsaFree(DSA *dsa)
600 {
601 if (dsa != NULL) {
602 DSA_free(dsa);
603 }
604 }
605
OpensslDsaUpRef(DSA * dsa)606 int OpensslDsaUpRef(DSA *dsa)
607 {
608 return DSA_up_ref(dsa);
609 }
610
OpensslDsaSet0Pqg(DSA * dsa,BIGNUM * p,BIGNUM * q,BIGNUM * g)611 int OpensslDsaSet0Pqg(DSA *dsa, BIGNUM *p, BIGNUM *q, BIGNUM *g)
612 {
613 return DSA_set0_pqg(dsa, p, q, g);
614 }
615
OpensslDsaSet0Key(DSA * dsa,BIGNUM * pubKey,BIGNUM * priKey)616 int OpensslDsaSet0Key(DSA *dsa, BIGNUM *pubKey, BIGNUM *priKey)
617 {
618 return DSA_set0_key(dsa, pubKey, priKey);
619 }
620
OpensslDsaGet0P(const DSA * dsa)621 const BIGNUM *OpensslDsaGet0P(const DSA *dsa)
622 {
623 return DSA_get0_p(dsa);
624 }
625
OpensslDsaGet0Q(const DSA * dsa)626 const BIGNUM *OpensslDsaGet0Q(const DSA *dsa)
627 {
628 return DSA_get0_q(dsa);
629 }
630
OpensslDsaGet0G(const DSA * dsa)631 const BIGNUM *OpensslDsaGet0G(const DSA *dsa)
632 {
633 return DSA_get0_g(dsa);
634 }
635
OpensslDsaGet0PubKey(const DSA * dsa)636 const BIGNUM *OpensslDsaGet0PubKey(const DSA *dsa)
637 {
638 return DSA_get0_pub_key(dsa);
639 }
640
OpensslDsaGet0PrivKey(const DSA * dsa)641 const BIGNUM *OpensslDsaGet0PrivKey(const DSA *dsa)
642 {
643 return DSA_get0_priv_key(dsa);
644 }
645
OpensslDsaGenerateKey(DSA * a)646 int OpensslDsaGenerateKey(DSA *a)
647 {
648 return DSA_generate_key(a);
649 }
650
OpensslD2iDsaPubKey(DSA ** dsa,const unsigned char ** ppin,long length)651 DSA *OpensslD2iDsaPubKey(DSA **dsa, const unsigned char **ppin, long length)
652 {
653 return d2i_DSA_PUBKEY(dsa, ppin, length);
654 }
655
OpensslD2iDsaPrivateKey(DSA ** dsa,const unsigned char ** ppin,long length)656 DSA *OpensslD2iDsaPrivateKey(DSA **dsa, const unsigned char **ppin, long length)
657 {
658 return d2i_DSAPrivateKey(dsa, ppin, length);
659 }
660
OpensslI2dDsaPubkey(DSA * dsa,unsigned char ** ppout)661 int OpensslI2dDsaPubkey(DSA *dsa, unsigned char **ppout)
662 {
663 return i2d_DSA_PUBKEY(dsa, ppout);
664 }
665
OpensslI2dDsaPrivateKey(DSA * dsa,unsigned char ** ppout)666 int OpensslI2dDsaPrivateKey(DSA *dsa, unsigned char **ppout)
667 {
668 return i2d_DSAPrivateKey(dsa, ppout);
669 }
670
OpensslEvpPkeyCheck(EVP_PKEY_CTX * ctx)671 int OpensslEvpPkeyCheck(EVP_PKEY_CTX *ctx)
672 {
673 return EVP_PKEY_check(ctx);
674 }
675
OpensslEvpPkeyDup(EVP_PKEY * a)676 EVP_PKEY *OpensslEvpPkeyDup(EVP_PKEY *a)
677 {
678 return EVP_PKEY_dup(a);
679 }
680
OpensslD2iPubKey(EVP_PKEY ** a,const unsigned char ** pp,long length)681 EVP_PKEY *OpensslD2iPubKey(EVP_PKEY **a, const unsigned char **pp, long length)
682 {
683 return d2i_PUBKEY(a, pp, length);
684 }
685
OpensslD2iPrivateKey(int type,EVP_PKEY ** a,const unsigned char ** pp,long length)686 EVP_PKEY *OpensslD2iPrivateKey(int type, EVP_PKEY **a, const unsigned char **pp, long length)
687 {
688 return d2i_PrivateKey(type, a, pp, length);
689 }
690
OpensslI2dPubKey(EVP_PKEY * pkey,unsigned char ** ppout)691 int OpensslI2dPubKey(EVP_PKEY *pkey, unsigned char **ppout)
692 {
693 return i2d_PUBKEY(pkey, ppout);
694 }
695
OpensslI2dPrivateKey(EVP_PKEY * pkey,unsigned char ** ppout)696 int OpensslI2dPrivateKey(EVP_PKEY *pkey, unsigned char **ppout)
697 {
698 return i2d_PrivateKey(pkey, ppout);
699 }
700
OpensslRsaNew(void)701 RSA *OpensslRsaNew(void)
702 {
703 return RSA_new();
704 }
705
OpensslRsaFree(RSA * rsa)706 void OpensslRsaFree(RSA *rsa)
707 {
708 if (rsa != NULL) {
709 RSA_free(rsa);
710 }
711 }
712
OpensslRsaGenerateMultiPrimeKey(RSA * rsa,int bits,int primes,BIGNUM * e,BN_GENCB * cb)713 int OpensslRsaGenerateMultiPrimeKey(RSA *rsa, int bits, int primes,
714 BIGNUM *e, BN_GENCB *cb)
715 {
716 return RSA_generate_multi_prime_key(rsa, bits, primes, e, cb);
717 }
718
OpensslRsaGenerateKeyEx(RSA * rsa,int bits,BIGNUM * e,BN_GENCB * cb)719 int OpensslRsaGenerateKeyEx(RSA *rsa, int bits, BIGNUM *e, BN_GENCB *cb)
720 {
721 return RSA_generate_key_ex(rsa, bits, e, cb);
722 }
723
OpensslRsaBits(const RSA * rsa)724 int OpensslRsaBits(const RSA *rsa)
725 {
726 return RSA_bits(rsa);
727 }
728
OpensslRsaSet0Key(RSA * r,BIGNUM * n,BIGNUM * e,BIGNUM * d)729 int OpensslRsaSet0Key(RSA *r, BIGNUM *n, BIGNUM *e, BIGNUM *d)
730 {
731 return RSA_set0_key(r, n, e, d);
732 }
733
OpensslRsaGet0Key(const RSA * r,const BIGNUM ** n,const BIGNUM ** e,const BIGNUM ** d)734 void OpensslRsaGet0Key(const RSA *r, const BIGNUM **n, const BIGNUM **e, const BIGNUM **d)
735 {
736 RSA_get0_key(r, n, e, d);
737 }
738
OpensslRsaGet0N(const RSA * d)739 const BIGNUM *OpensslRsaGet0N(const RSA *d)
740 {
741 return RSA_get0_n(d);
742 }
743
OpensslRsaGet0E(const RSA * d)744 const BIGNUM *OpensslRsaGet0E(const RSA *d)
745 {
746 return RSA_get0_e(d);
747 }
748
OpensslRsaGet0D(const RSA * d)749 const BIGNUM *OpensslRsaGet0D(const RSA *d)
750 {
751 return RSA_get0_d(d);
752 }
753
OpensslRsaGet0Factors(const RSA * r,const BIGNUM ** p,const BIGNUM ** q)754 void OpensslRsaGet0Factors(const RSA *r, const BIGNUM **p, const BIGNUM **q)
755 {
756 RSA_get0_factors(r, p, q);
757 }
758
OpensslRsaPublicKeyDup(RSA * rsa)759 RSA *OpensslRsaPublicKeyDup(RSA *rsa)
760 {
761 return RSAPublicKey_dup(rsa);
762 }
763
OpensslRsaPrivateKeyDup(RSA * rsa)764 RSA *OpensslRsaPrivateKeyDup(RSA *rsa)
765 {
766 return RSAPrivateKey_dup(rsa);
767 }
768
OpensslD2iRsaPubKey(RSA ** a,const unsigned char ** pp,long length)769 RSA *OpensslD2iRsaPubKey(RSA **a, const unsigned char **pp, long length)
770 {
771 return d2i_RSA_PUBKEY(a, pp, length);
772 }
773
OpensslI2dRsaPubKey(RSA * a,unsigned char ** pp)774 int OpensslI2dRsaPubKey(RSA *a, unsigned char **pp)
775 {
776 return i2d_RSA_PUBKEY(a, pp);
777 }
778
OpensslEvpPkeyCtxSetRsaPssSaltLen(EVP_PKEY_CTX * ctx,int saltlen)779 int OpensslEvpPkeyCtxSetRsaPssSaltLen(EVP_PKEY_CTX *ctx, int saltlen)
780 {
781 return EVP_PKEY_CTX_set_rsa_pss_saltlen(ctx, saltlen);
782 }
783
OpensslEvpPkeyCtxGetRsaPssSaltLen(EVP_PKEY_CTX * ctx,int * saltlen)784 int OpensslEvpPkeyCtxGetRsaPssSaltLen(EVP_PKEY_CTX *ctx, int *saltlen)
785 {
786 return EVP_PKEY_CTX_get_rsa_pss_saltlen(ctx, saltlen);
787 }
788
OpensslEvpPkeyCtxSetRsaPadding(EVP_PKEY_CTX * ctx,int pad)789 int OpensslEvpPkeyCtxSetRsaPadding(EVP_PKEY_CTX *ctx, int pad)
790 {
791 return EVP_PKEY_CTX_set_rsa_padding(ctx, pad);
792 }
793
OpensslEvpPkeyCtxSetRsaMgf1Md(EVP_PKEY_CTX * ctx,const EVP_MD * md)794 int OpensslEvpPkeyCtxSetRsaMgf1Md(EVP_PKEY_CTX *ctx, const EVP_MD *md)
795 {
796 return EVP_PKEY_CTX_set_rsa_mgf1_md(ctx, md);
797 }
798
OpensslEvpPkeyCtxSetRsaOaepMd(EVP_PKEY_CTX * ctx,const EVP_MD * md)799 int OpensslEvpPkeyCtxSetRsaOaepMd(EVP_PKEY_CTX *ctx, const EVP_MD *md)
800 {
801 return EVP_PKEY_CTX_set_rsa_oaep_md(ctx, md);
802 }
803
OpensslEvpPkeyCtxSet0RsaOaepLabel(EVP_PKEY_CTX * ctx,void * label,int len)804 int OpensslEvpPkeyCtxSet0RsaOaepLabel(EVP_PKEY_CTX *ctx, void *label, int len)
805 {
806 return EVP_PKEY_CTX_set0_rsa_oaep_label(ctx, label, len);
807 }
808
OpensslEvpPkeyCtxGet0RsaOaepLabel(EVP_PKEY_CTX * ctx,unsigned char ** label)809 int OpensslEvpPkeyCtxGet0RsaOaepLabel(EVP_PKEY_CTX *ctx, unsigned char **label)
810 {
811 return EVP_PKEY_CTX_get0_rsa_oaep_label(ctx, label);
812 }
813
OpensslD2iAutoPrivateKey(EVP_PKEY ** a,const unsigned char ** pp,long length)814 EVP_PKEY *OpensslD2iAutoPrivateKey(EVP_PKEY **a, const unsigned char **pp, long length)
815 {
816 return d2i_AutoPrivateKey(a, pp, length);
817 }
818
OpensslEvpPkeyGet1Rsa(EVP_PKEY * pkey)819 struct rsa_st *OpensslEvpPkeyGet1Rsa(EVP_PKEY *pkey)
820 {
821 return EVP_PKEY_get1_RSA(pkey);
822 }
823
OpensslEvpPkeySet1Rsa(EVP_PKEY * pkey,struct rsa_st * key)824 int OpensslEvpPkeySet1Rsa(EVP_PKEY *pkey, struct rsa_st *key)
825 {
826 return EVP_PKEY_set1_RSA(pkey, key);
827 }
828
OpensslEvpPkeyAssignRsa(EVP_PKEY * pkey,struct rsa_st * key)829 int OpensslEvpPkeyAssignRsa(EVP_PKEY *pkey, struct rsa_st *key)
830 {
831 return EVP_PKEY_assign_RSA(pkey, key);
832 }
833
OpensslI2dPkcs8PrivateKeyBio(BIO * bp,EVP_PKEY * x,const EVP_CIPHER * enc,char * kstr,int klen,pem_password_cb * cb,void * u)834 int OpensslI2dPkcs8PrivateKeyBio(BIO *bp, EVP_PKEY *x, const EVP_CIPHER *enc,
835 char *kstr, int klen, pem_password_cb *cb, void *u)
836 {
837 return i2d_PKCS8PrivateKey_bio(bp, x, enc, kstr, klen, cb, u);
838 }
839
OpensslPemWriteBioPkcs8PrivateKey(BIO * bp,const EVP_PKEY * x,const EVP_CIPHER * enc,const char * kstr,int klen,pem_password_cb * cb,void * u)840 int OpensslPemWriteBioPkcs8PrivateKey(BIO *bp, const EVP_PKEY *x, const EVP_CIPHER *enc,
841 const char *kstr, int klen, pem_password_cb *cb, void *u)
842 {
843 return PEM_write_bio_PKCS8PrivateKey(bp, x, enc, kstr, klen, cb, u);
844 }
845
OpensslPemWriteBioRsaPrivateKey(BIO * bp,RSA * x,const EVP_CIPHER * enc,unsigned char * kstr,int klen,pem_password_cb * cb,void * u)846 int OpensslPemWriteBioRsaPrivateKey(BIO *bp, RSA *x, const EVP_CIPHER *enc,
847 unsigned char *kstr, int klen, pem_password_cb *cb, void *u)
848 {
849 return PEM_write_bio_RSAPrivateKey(bp, x, enc, kstr, klen, cb, u);
850 }
851
OpensslPemWriteBioRsaPublicKey(BIO * bp,RSA * x)852 int OpensslPemWriteBioRsaPublicKey(BIO *bp, RSA *x)
853 {
854 return PEM_write_bio_RSAPublicKey(bp, x);
855 }
856
OpensslPemWriteBioRsaPubKey(BIO * bp,RSA * x)857 int OpensslPemWriteBioRsaPubKey(BIO *bp, RSA *x)
858 {
859 return PEM_write_bio_RSA_PUBKEY(bp, x);
860 }
861
OpensslBioNew(const BIO_METHOD * type)862 BIO *OpensslBioNew(const BIO_METHOD *type)
863 {
864 return BIO_new(type);
865 }
866
OpensslBioSMem(void)867 const BIO_METHOD *OpensslBioSMem(void)
868 {
869 return BIO_s_mem();
870 }
871
OpensslBioRead(BIO * b,void * data,int dlen)872 int OpensslBioRead(BIO *b, void *data, int dlen)
873 {
874 return BIO_read(b, data, dlen);
875 }
876
OpensslBioFreeAll(BIO * a)877 void OpensslBioFreeAll(BIO *a)
878 {
879 if (a != NULL) {
880 return BIO_free_all(a);
881 }
882 }
883
OpensslRandPrivBytes(unsigned char * buf,int num)884 int OpensslRandPrivBytes(unsigned char *buf, int num)
885 {
886 return RAND_priv_bytes(buf, num);
887 }
888
OpensslRandSeed(const void * buf,int num)889 void OpensslRandSeed(const void *buf, int num)
890 {
891 RAND_seed(buf, num);
892 }
893
OpensslEvpSha1(void)894 const EVP_MD *OpensslEvpSha1(void)
895 {
896 return EVP_sha1();
897 }
898
OpensslEvpSha224(void)899 const EVP_MD *OpensslEvpSha224(void)
900 {
901 return EVP_sha224();
902 }
903
OpensslEvpSha256(void)904 const EVP_MD *OpensslEvpSha256(void)
905 {
906 return EVP_sha256();
907 }
908
OpensslEvpSha384(void)909 const EVP_MD *OpensslEvpSha384(void)
910 {
911 return EVP_sha384();
912 }
913
OpensslEvpSha512(void)914 const EVP_MD *OpensslEvpSha512(void)
915 {
916 return EVP_sha512();
917 }
918
OpensslEvpMd5(void)919 const EVP_MD *OpensslEvpMd5(void)
920 {
921 return EVP_md5();
922 }
923
OpensslEvpSm3(void)924 const EVP_MD *OpensslEvpSm3(void)
925 {
926 return EVP_sm3();
927 }
928
OpensslEvpDigestFinalEx(EVP_MD_CTX * ctx,unsigned char * md,unsigned int * size)929 int OpensslEvpDigestFinalEx(EVP_MD_CTX *ctx, unsigned char *md, unsigned int *size)
930 {
931 return EVP_DigestFinal_ex(ctx, md, size);
932 }
933
OpensslEvpMdCtxSize(const EVP_MD_CTX * ctx)934 int OpensslEvpMdCtxSize(const EVP_MD_CTX *ctx)
935 {
936 return EVP_MD_CTX_size(ctx);
937 }
938
OpensslEvpDigestInitEx(EVP_MD_CTX * ctx,const EVP_MD * type,ENGINE * impl)939 int OpensslEvpDigestInitEx(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *impl)
940 {
941 return EVP_DigestInit_ex(ctx, type, impl);
942 }
943
OpensslHmacInitEx(HMAC_CTX * ctx,const void * key,int len,const EVP_MD * md,ENGINE * impl)944 int OpensslHmacInitEx(HMAC_CTX *ctx, const void *key, int len, const EVP_MD *md, ENGINE *impl)
945 {
946 return HMAC_Init_ex(ctx, key, len, md, impl);
947 }
948
OpensslHmacFinal(HMAC_CTX * ctx,unsigned char * md,unsigned int * len)949 int OpensslHmacFinal(HMAC_CTX *ctx, unsigned char *md, unsigned int *len)
950 {
951 return HMAC_Final(ctx, md, len);
952 }
953
OpensslHmacSize(const HMAC_CTX * ctx)954 size_t OpensslHmacSize(const HMAC_CTX *ctx)
955 {
956 return HMAC_size(ctx);
957 }
958
OpensslHmacCtxFree(HMAC_CTX * ctx)959 void OpensslHmacCtxFree(HMAC_CTX *ctx)
960 {
961 if (ctx != NULL) {
962 HMAC_CTX_free(ctx);
963 }
964 }
965
OpensslHmacCtxNew(void)966 HMAC_CTX *OpensslHmacCtxNew(void)
967 {
968 return HMAC_CTX_new();
969 }
970
OpensslEvpCipherCtxFree(EVP_CIPHER_CTX * ctx)971 void OpensslEvpCipherCtxFree(EVP_CIPHER_CTX *ctx)
972 {
973 if (ctx != NULL) {
974 EVP_CIPHER_CTX_free(ctx);
975 }
976 }
977
OpensslEvpAes128Ecb(void)978 const EVP_CIPHER *OpensslEvpAes128Ecb(void)
979 {
980 return EVP_aes_128_ecb();
981 }
982
OpensslEvpAes192Ecb(void)983 const EVP_CIPHER *OpensslEvpAes192Ecb(void)
984 {
985 return EVP_aes_192_ecb();
986 }
987
OpensslEvpAes256Ecb(void)988 const EVP_CIPHER *OpensslEvpAes256Ecb(void)
989 {
990 return EVP_aes_256_ecb();
991 }
992
OpensslEvpAes128Cbc(void)993 const EVP_CIPHER *OpensslEvpAes128Cbc(void)
994 {
995 return EVP_aes_128_cbc();
996 }
997
OpensslEvpAes192Cbc(void)998 const EVP_CIPHER *OpensslEvpAes192Cbc(void)
999 {
1000 return EVP_aes_192_cbc();
1001 }
1002
OpensslEvpAes256Cbc(void)1003 const EVP_CIPHER *OpensslEvpAes256Cbc(void)
1004 {
1005 return EVP_aes_256_cbc();
1006 }
1007
OpensslEvpAes128Ctr(void)1008 const EVP_CIPHER *OpensslEvpAes128Ctr(void)
1009 {
1010 return EVP_aes_128_ctr();
1011 }
1012
OpensslEvpAes192Ctr(void)1013 const EVP_CIPHER *OpensslEvpAes192Ctr(void)
1014 {
1015 return EVP_aes_192_ctr();
1016 }
1017
OpensslEvpAes256Ctr(void)1018 const EVP_CIPHER *OpensslEvpAes256Ctr(void)
1019 {
1020 return EVP_aes_256_ctr();
1021 }
1022
OpensslEvpAes128Ofb(void)1023 const EVP_CIPHER *OpensslEvpAes128Ofb(void)
1024 {
1025 return EVP_aes_128_ofb();
1026 }
1027
OpensslEvpAes192Ofb(void)1028 const EVP_CIPHER *OpensslEvpAes192Ofb(void)
1029 {
1030 return EVP_aes_192_ofb();
1031 }
1032
OpensslEvpAes256Ofb(void)1033 const EVP_CIPHER *OpensslEvpAes256Ofb(void)
1034 {
1035 return EVP_aes_256_ofb();
1036 }
1037
OpensslEvpAes128Cfb(void)1038 const EVP_CIPHER *OpensslEvpAes128Cfb(void)
1039 {
1040 return EVP_aes_128_cfb();
1041 }
1042
OpensslEvpAes192Cfb(void)1043 const EVP_CIPHER *OpensslEvpAes192Cfb(void)
1044 {
1045 return EVP_aes_192_cfb();
1046 }
1047
OpensslEvpAes256Cfb(void)1048 const EVP_CIPHER *OpensslEvpAes256Cfb(void)
1049 {
1050 return EVP_aes_256_cfb();
1051 }
1052
OpensslEvpAes128Cfb1(void)1053 const EVP_CIPHER *OpensslEvpAes128Cfb1(void)
1054 {
1055 return EVP_aes_128_cfb1();
1056 }
1057
OpensslEvpAes192Cfb1(void)1058 const EVP_CIPHER *OpensslEvpAes192Cfb1(void)
1059 {
1060 return EVP_aes_192_cfb1();
1061 }
1062
OpensslEvpAes256Cfb1(void)1063 const EVP_CIPHER *OpensslEvpAes256Cfb1(void)
1064 {
1065 return EVP_aes_256_cfb1();
1066 }
1067
OpensslEvpAes128Cfb128(void)1068 const EVP_CIPHER *OpensslEvpAes128Cfb128(void)
1069 {
1070 return EVP_aes_128_cfb128();
1071 }
1072
OpensslEvpAes192Cfb128(void)1073 const EVP_CIPHER *OpensslEvpAes192Cfb128(void)
1074 {
1075 return EVP_aes_192_cfb128();
1076 }
1077
OpensslEvpAes256Cfb128(void)1078 const EVP_CIPHER *OpensslEvpAes256Cfb128(void)
1079 {
1080 return EVP_aes_256_cfb128();
1081 }
1082
OpensslEvpAes128Cfb8(void)1083 const EVP_CIPHER *OpensslEvpAes128Cfb8(void)
1084 {
1085 return EVP_aes_128_cfb8();
1086 }
1087
OpensslEvpAes192Cfb8(void)1088 const EVP_CIPHER *OpensslEvpAes192Cfb8(void)
1089 {
1090 return EVP_aes_192_cfb8();
1091 }
1092
OpensslEvpAes256Cfb8(void)1093 const EVP_CIPHER *OpensslEvpAes256Cfb8(void)
1094 {
1095 return EVP_aes_256_cfb8();
1096 }
1097
OpensslEvpAes128Ccm(void)1098 const EVP_CIPHER *OpensslEvpAes128Ccm(void)
1099 {
1100 return EVP_aes_128_ccm();
1101 }
1102
OpensslEvpAes192Ccm(void)1103 const EVP_CIPHER *OpensslEvpAes192Ccm(void)
1104 {
1105 return EVP_aes_192_ccm();
1106 }
1107
OpensslEvpAes256Ccm(void)1108 const EVP_CIPHER *OpensslEvpAes256Ccm(void)
1109 {
1110 return EVP_aes_256_ccm();
1111 }
1112
OpensslEvpAes128Gcm(void)1113 const EVP_CIPHER *OpensslEvpAes128Gcm(void)
1114 {
1115 return EVP_aes_128_gcm();
1116 }
1117
OpensslEvpAes192Gcm(void)1118 const EVP_CIPHER *OpensslEvpAes192Gcm(void)
1119 {
1120 return EVP_aes_192_gcm();
1121 }
1122
OpensslEvpAes256Gcm(void)1123 const EVP_CIPHER *OpensslEvpAes256Gcm(void)
1124 {
1125 return EVP_aes_256_gcm();
1126 }
1127
OpensslEvpSm4Ecb(void)1128 const EVP_CIPHER *OpensslEvpSm4Ecb(void)
1129 {
1130 return EVP_sm4_ecb();
1131 }
1132
OpensslEvpSm4Cbc(void)1133 const EVP_CIPHER *OpensslEvpSm4Cbc(void)
1134 {
1135 return EVP_sm4_cbc();
1136 }
1137
OpensslEvpSm4Cfb(void)1138 const EVP_CIPHER *OpensslEvpSm4Cfb(void)
1139 {
1140 return EVP_sm4_cfb();
1141 }
1142
OpensslEvpSm4Cfb128(void)1143 const EVP_CIPHER *OpensslEvpSm4Cfb128(void)
1144 {
1145 return EVP_sm4_cfb128();
1146 }
1147
OpensslEvpSm4Ctr(void)1148 const EVP_CIPHER *OpensslEvpSm4Ctr(void)
1149 {
1150 return EVP_sm4_ctr();
1151 }
1152
OpensslEvpSm4Ofb(void)1153 const EVP_CIPHER *OpensslEvpSm4Ofb(void)
1154 {
1155 return EVP_sm4_ofb();
1156 }
1157
OpensslEvpCipherCtxNew(void)1158 EVP_CIPHER_CTX *OpensslEvpCipherCtxNew(void)
1159 {
1160 return EVP_CIPHER_CTX_new();
1161 }
1162
OpensslEvpCipherInit(EVP_CIPHER_CTX * ctx,const EVP_CIPHER * cipher,const unsigned char * key,const unsigned char * iv,int enc)1163 int OpensslEvpCipherInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
1164 const unsigned char *key, const unsigned char *iv, int enc)
1165 {
1166 return EVP_CipherInit(ctx, cipher, key, iv, enc);
1167 }
1168
OpensslEvpCipherCtxSetPadding(EVP_CIPHER_CTX * ctx,int pad)1169 int OpensslEvpCipherCtxSetPadding(EVP_CIPHER_CTX *ctx, int pad)
1170 {
1171 return EVP_CIPHER_CTX_set_padding(ctx, pad);
1172 }
1173
OpensslEvpCipherFinalEx(EVP_CIPHER_CTX * ctx,unsigned char * out,int * outl)1174 int OpensslEvpCipherFinalEx(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl)
1175 {
1176 return EVP_CipherFinal_ex(ctx, out, outl);
1177 }
1178
OpensslEvpCipherUpdate(EVP_CIPHER_CTX * ctx,unsigned char * out,int * outl,const unsigned char * in,int inl)1179 int OpensslEvpCipherUpdate(EVP_CIPHER_CTX *ctx, unsigned char *out, int *outl, const unsigned char *in, int inl)
1180 {
1181 return EVP_CipherUpdate(ctx, out, outl, in, inl);
1182 }
1183
OpensslEvpDesEde3Ecb(void)1184 const EVP_CIPHER *OpensslEvpDesEde3Ecb(void)
1185 {
1186 return EVP_des_ede3_ecb();
1187 }
1188
OpensslEvpDesEde3Cbc(void)1189 const EVP_CIPHER *OpensslEvpDesEde3Cbc(void)
1190 {
1191 return EVP_des_ede3_cbc();
1192 }
1193
OpensslEvpDesEde3Ofb(void)1194 const EVP_CIPHER *OpensslEvpDesEde3Ofb(void)
1195 {
1196 return EVP_des_ede3_ofb();
1197 }
1198
OpensslEvpDesEde3Cfb64(void)1199 const EVP_CIPHER *OpensslEvpDesEde3Cfb64(void)
1200 {
1201 return EVP_des_ede3_cfb64();
1202 }
1203
OpensslEvpDesEde3Cfb1(void)1204 const EVP_CIPHER *OpensslEvpDesEde3Cfb1(void)
1205 {
1206 return EVP_des_ede3_cfb1();
1207 }
1208
OpensslEvpDesEde3Cfb8(void)1209 const EVP_CIPHER *OpensslEvpDesEde3Cfb8(void)
1210 {
1211 return EVP_des_ede3_cfb8();
1212 }
1213
OpensslSm2CipherTextSize(const EC_KEY * key,const EVP_MD * digest,size_t msgLen,size_t * cipherTextSize)1214 int OpensslSm2CipherTextSize(const EC_KEY *key, const EVP_MD *digest, size_t msgLen, size_t *cipherTextSize)
1215 {
1216 return ossl_sm2_ciphertext_size(key, digest, msgLen, cipherTextSize);
1217 }
1218
OpensslSm2PlainTextSize(const unsigned char * cipherText,size_t cipherTextSize,size_t * plainTextSize)1219 int OpensslSm2PlainTextSize(const unsigned char *cipherText, size_t cipherTextSize, size_t *plainTextSize)
1220 {
1221 return ossl_sm2_plaintext_size(cipherText, cipherTextSize, plainTextSize);
1222 }
1223
OpensslOsslSm2Encrypt(const EC_KEY * key,const EVP_MD * digest,const uint8_t * msg,size_t msgLen,uint8_t * cipherTextBuf,size_t * cipherTextLen)1224 int OpensslOsslSm2Encrypt(const EC_KEY *key, const EVP_MD *digest, const uint8_t *msg,
1225 size_t msgLen, uint8_t *cipherTextBuf, size_t *cipherTextLen)
1226 {
1227 return ossl_sm2_encrypt(key, digest, msg, msgLen, cipherTextBuf, cipherTextLen);
1228 }
1229
OpensslOsslSm2Decrypt(const EC_KEY * key,const EVP_MD * digest,const uint8_t * cipherText,size_t cipherTextLen,uint8_t * plainTextBuf,size_t * plainTextLen)1230 int OpensslOsslSm2Decrypt(const EC_KEY *key, const EVP_MD *digest, const uint8_t *cipherText,
1231 size_t cipherTextLen, uint8_t *plainTextBuf, size_t *plainTextLen)
1232 {
1233 return ossl_sm2_decrypt(key, digest, cipherText, cipherTextLen, plainTextBuf, plainTextLen);
1234 }
1235
OpensslPkcs5Pbkdf2Hmac(const char * pass,int passlen,const unsigned char * salt,int saltlen,int iter,const EVP_MD * digest,int keylen,unsigned char * out)1236 int OpensslPkcs5Pbkdf2Hmac(const char *pass, int passlen, const unsigned char *salt,
1237 int saltlen, int iter, const EVP_MD *digest, int keylen, unsigned char *out)
1238 {
1239 return PKCS5_PBKDF2_HMAC(pass, passlen, salt, saltlen, iter, digest, keylen, out);
1240 }
1241
OpensslEcGroupNewByCurveName(int nid)1242 EC_GROUP *OpensslEcGroupNewByCurveName(int nid)
1243 {
1244 return EC_GROUP_new_by_curve_name(nid);
1245 }
1246
OpensslEvpCipherCtxCtrl(EVP_CIPHER_CTX * ctx,int type,int arg,void * ptr)1247 int OpensslEvpCipherCtxCtrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
1248 {
1249 return EVP_CIPHER_CTX_ctrl(ctx, type, arg, ptr);
1250 }
1251
OpensslDhNew(void)1252 DH *OpensslDhNew(void)
1253 {
1254 return DH_new();
1255 }
1256
OpensslDhComputeKeyPadded(unsigned char * key,const BIGNUM * pubKey,DH * dh)1257 int OpensslDhComputeKeyPadded(unsigned char *key, const BIGNUM *pubKey, DH *dh)
1258 {
1259 return DH_compute_key_padded(key, pubKey, dh);
1260 }
1261
OpensslDhFree(DH * dh)1262 void OpensslDhFree(DH *dh)
1263 {
1264 if (dh != NULL) {
1265 return DH_free(dh);
1266 }
1267 }
1268
OpensslDhGenerateKey(DH * dh)1269 int OpensslDhGenerateKey(DH *dh)
1270 {
1271 return DH_generate_key(dh);
1272 }
1273
OpensslDhGet0P(const DH * dh)1274 const BIGNUM *OpensslDhGet0P(const DH *dh)
1275 {
1276 return DH_get0_p(dh);
1277 }
1278
OpensslDhGet0Q(const DH * dh)1279 const BIGNUM *OpensslDhGet0Q(const DH *dh)
1280 {
1281 return DH_get0_q(dh);
1282 }
1283
OpensslDhGet0G(const DH * dh)1284 const BIGNUM *OpensslDhGet0G(const DH *dh)
1285 {
1286 return DH_get0_g(dh);
1287 }
1288
OpensslDhGetLength(const DH * dh)1289 long OpensslDhGetLength(const DH *dh)
1290 {
1291 return DH_get_length(dh);
1292 }
1293
OpensslDhSetLength(DH * dh,long length)1294 int OpensslDhSetLength(DH *dh, long length)
1295 {
1296 return DH_set_length(dh, length);
1297 }
1298
OpensslDhGet0PubKey(const DH * dh)1299 const BIGNUM *OpensslDhGet0PubKey(const DH *dh)
1300 {
1301 return DH_get0_pub_key(dh);
1302 }
1303
OpensslDhGet0PrivKey(const DH * dh)1304 const BIGNUM *OpensslDhGet0PrivKey(const DH *dh)
1305 {
1306 return DH_get0_priv_key(dh);
1307 }
1308
OpensslEvpPkeySet1Dh(EVP_PKEY * pkey,DH * key)1309 int OpensslEvpPkeySet1Dh(EVP_PKEY *pkey, DH *key)
1310 {
1311 return EVP_PKEY_set1_DH(pkey, key);
1312 }
1313
OpensslEvpPkeyGet1Dh(EVP_PKEY * pkey)1314 DH *OpensslEvpPkeyGet1Dh(EVP_PKEY *pkey)
1315 {
1316 return EVP_PKEY_get1_DH(pkey);
1317 }
1318
OpensslEvpPkeyAssignDh(EVP_PKEY * pkey,DH * key)1319 int OpensslEvpPkeyAssignDh(EVP_PKEY *pkey, DH *key)
1320 {
1321 return EVP_PKEY_assign_DH(pkey, key);
1322 }
1323
OpensslEvpPkeyCtxSetDhParamgenPrimeLen(EVP_PKEY_CTX * ctx,int pbits)1324 int OpensslEvpPkeyCtxSetDhParamgenPrimeLen(EVP_PKEY_CTX *ctx, int pbits)
1325 {
1326 return EVP_PKEY_CTX_set_dh_paramgen_prime_len(ctx, pbits);
1327 }
1328
OpensslEvpPkeyCtxSetSignatureMd(EVP_PKEY_CTX * ctx,const EVP_MD * md)1329 int OpensslEvpPkeyCtxSetSignatureMd(EVP_PKEY_CTX *ctx, const EVP_MD *md)
1330 {
1331 return EVP_PKEY_CTX_set_signature_md(ctx, md);
1332 }
1333
OpensslDhUpRef(DH * r)1334 int OpensslDhUpRef(DH *r)
1335 {
1336 return DH_up_ref(r);
1337 }
1338
OpensslDhSet0Pqg(DH * dh,BIGNUM * p,BIGNUM * q,BIGNUM * g)1339 int OpensslDhSet0Pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
1340 {
1341 return DH_set0_pqg(dh, p, q, g);
1342 }
1343
OpensslDhSet0Key(DH * dh,BIGNUM * pubKey,BIGNUM * privKey)1344 int OpensslDhSet0Key(DH *dh, BIGNUM *pubKey, BIGNUM *privKey)
1345 {
1346 return DH_set0_key(dh, pubKey, privKey);
1347 }
1348
OpensslD2iSm2CipherText(const uint8_t * ciphertext,size_t ciphertext_len)1349 struct Sm2CipherTextSt *OpensslD2iSm2CipherText(const uint8_t *ciphertext, size_t ciphertext_len)
1350 {
1351 return d2i_Sm2CipherText(NULL, &ciphertext, ciphertext_len);
1352 }
1353
OpensslSm2CipherTextFree(struct Sm2CipherTextSt * sm2Text)1354 void OpensslSm2CipherTextFree(struct Sm2CipherTextSt *sm2Text)
1355 {
1356 if (sm2Text != NULL) {
1357 Sm2CipherText_free(sm2Text);
1358 }
1359 }
1360
OpensslAsn1OctetStringFree(ASN1_OCTET_STRING * field)1361 void OpensslAsn1OctetStringFree(ASN1_OCTET_STRING *field)
1362 {
1363 if (field != NULL) {
1364 ASN1_OCTET_STRING_free(field);
1365 }
1366 }
1367
OpensslAsn1OctetStringNew(void)1368 ASN1_OCTET_STRING *OpensslAsn1OctetStringNew(void)
1369 {
1370 return ASN1_OCTET_STRING_new();
1371 }
1372
OpensslAsn1OctetStringSet(ASN1_OCTET_STRING * x,const unsigned char * d,int len)1373 int OpensslAsn1OctetStringSet(ASN1_OCTET_STRING *x, const unsigned char *d, int len)
1374 {
1375 return ASN1_STRING_set(x, d, len);
1376 }
1377
OpensslSm2CipherTextNew(void)1378 struct Sm2CipherTextSt *OpensslSm2CipherTextNew(void)
1379 {
1380 return Sm2CipherText_new();
1381 }
1382
OpensslI2dSm2CipherText(struct Sm2CipherTextSt * sm2Text,unsigned char ** returnData)1383 int OpensslI2dSm2CipherText(struct Sm2CipherTextSt *sm2Text, unsigned char **returnData)
1384 {
1385 return i2d_Sm2CipherText(sm2Text, returnData);
1386 }
1387
OpensslAsn1StringLength(ASN1_OCTET_STRING * p)1388 int OpensslAsn1StringLength(ASN1_OCTET_STRING *p)
1389 {
1390 return ASN1_STRING_length(p);
1391 }
1392
OpensslAsn1StringGet0Data(ASN1_OCTET_STRING * p)1393 const unsigned char *OpensslAsn1StringGet0Data(ASN1_OCTET_STRING *p)
1394 {
1395 return ASN1_STRING_get0_data(p);
1396 }
1397
OpensslEcPoint2Oct(const EC_GROUP * group,const EC_POINT * p,point_conversion_form_t form,unsigned char * buf,size_t len,BN_CTX * ctx)1398 size_t OpensslEcPoint2Oct(const EC_GROUP *group, const EC_POINT *p, point_conversion_form_t form,
1399 unsigned char *buf, size_t len, BN_CTX *ctx)
1400 {
1401 return EC_POINT_point2oct(group, p, form, buf, len, ctx);
1402 }
1403
OpensslOsslParamBldNew(void)1404 OSSL_PARAM_BLD *OpensslOsslParamBldNew(void)
1405 {
1406 return OSSL_PARAM_BLD_new();
1407 }
1408
OpensslOsslParamBldFree(OSSL_PARAM_BLD * bld)1409 void OpensslOsslParamBldFree(OSSL_PARAM_BLD *bld)
1410 {
1411 if (bld != NULL) {
1412 OSSL_PARAM_BLD_free(bld);
1413 }
1414 }
1415
OpensslOsslParamBldToParam(OSSL_PARAM_BLD * bld)1416 OSSL_PARAM *OpensslOsslParamBldToParam(OSSL_PARAM_BLD *bld)
1417 {
1418 return OSSL_PARAM_BLD_to_param(bld);
1419 }
1420
OpensslOsslParamBldPushUtf8String(OSSL_PARAM_BLD * bld,const char * key,const char * buf,size_t bsize)1421 int OpensslOsslParamBldPushUtf8String(OSSL_PARAM_BLD *bld, const char *key, const char *buf, size_t bsize)
1422 {
1423 return OSSL_PARAM_BLD_push_utf8_string(bld, key, buf, bsize);
1424 }
1425
OpensslOsslParamBldPushOctetString(OSSL_PARAM_BLD * bld,const char * key,const void * buf,size_t bsize)1426 int OpensslOsslParamBldPushOctetString(OSSL_PARAM_BLD *bld, const char *key, const void *buf, size_t bsize)
1427 {
1428 return OSSL_PARAM_BLD_push_octet_string(bld, key, buf, bsize);
1429 }
1430
OpensslEvpPkeyCtxSetEcParamgenCurveNid(EVP_PKEY_CTX * ctx,int nid)1431 int OpensslEvpPkeyCtxSetEcParamgenCurveNid(EVP_PKEY_CTX *ctx, int nid)
1432 {
1433 return EVP_PKEY_CTX_set_ec_paramgen_curve_nid(ctx, nid);
1434 }
1435
OpensslEvpPkeyFromDataInit(EVP_PKEY_CTX * ctx)1436 int OpensslEvpPkeyFromDataInit(EVP_PKEY_CTX *ctx)
1437 {
1438 return EVP_PKEY_fromdata_init(ctx);
1439 }
1440
OpensslEvpPkeyFromData(EVP_PKEY_CTX * ctx,EVP_PKEY ** ppkey,int selection,OSSL_PARAM params[])1441 int OpensslEvpPkeyFromData(EVP_PKEY_CTX *ctx, EVP_PKEY **ppkey, int selection, OSSL_PARAM params[])
1442 {
1443 return EVP_PKEY_fromdata(ctx, ppkey, selection, params);
1444 }
1445
OpensslEvpPkeyGet1EcKey(EVP_PKEY * pkey)1446 EC_KEY *OpensslEvpPkeyGet1EcKey(EVP_PKEY *pkey)
1447 {
1448 return EVP_PKEY_get1_EC_KEY(pkey);
1449 }
1450
OpensslOsslParamFree(OSSL_PARAM * params)1451 void OpensslOsslParamFree(OSSL_PARAM *params)
1452 {
1453 if (params != NULL) {
1454 OSSL_PARAM_free(params);
1455 }
1456 }
1457
OpensslEcOct2Point(const EC_GROUP * group,EC_POINT * p,const unsigned char * buf,size_t len,BN_CTX * ctx)1458 int OpensslEcOct2Point(const EC_GROUP *group, EC_POINT *p, const unsigned char *buf, size_t len, BN_CTX *ctx)
1459 {
1460 return EC_POINT_oct2point(group, p, buf, len, ctx);
1461 }
1462
OpensslEcPointSetAffineCoordinates(const EC_GROUP * group,EC_POINT * p,const BIGNUM * x,const BIGNUM * y,BN_CTX * ctx)1463 int OpensslEcPointSetAffineCoordinates(const EC_GROUP *group, EC_POINT *p,
1464 const BIGNUM *x, const BIGNUM *y, BN_CTX *ctx)
1465 {
1466 return EC_POINT_set_affine_coordinates(group, p, x, y, ctx);
1467 }
1468
OpensslEcPointGetAffineCoordinates(const EC_GROUP * group,const EC_POINT * p,BIGNUM * x,BIGNUM * y,BN_CTX * ctx)1469 int OpensslEcPointGetAffineCoordinates(const EC_GROUP *group, const EC_POINT *p,
1470 BIGNUM *x, BIGNUM *y, BN_CTX *ctx)
1471 {
1472 return EC_POINT_get_affine_coordinates(group, p, x, y, ctx);
1473 }
1474
OpensslEvpKdfFetch(OSSL_LIB_CTX * libctx,const char * algorithm,const char * properties)1475 EVP_KDF *OpensslEvpKdfFetch(OSSL_LIB_CTX *libctx, const char *algorithm,
1476 const char *properties)
1477 {
1478 return EVP_KDF_fetch(libctx, algorithm, properties);
1479 }
1480
OpensslEvpKdfCtxNew(EVP_KDF * kdf)1481 EVP_KDF_CTX *OpensslEvpKdfCtxNew(EVP_KDF *kdf)
1482 {
1483 return EVP_KDF_CTX_new(kdf);
1484 }
1485
OpensslEvpKdfFree(EVP_KDF * kdf)1486 void OpensslEvpKdfFree(EVP_KDF *kdf)
1487 {
1488 return EVP_KDF_free(kdf);
1489 }
1490
OpensslEvpKdfCtxFree(EVP_KDF_CTX * ctx)1491 void OpensslEvpKdfCtxFree(EVP_KDF_CTX *ctx)
1492 {
1493 return EVP_KDF_CTX_free(ctx);
1494 }
1495
OpensslEvpKdfDerive(EVP_KDF_CTX * ctx,unsigned char * key,size_t keylen,const OSSL_PARAM params[])1496 int OpensslEvpKdfDerive(EVP_KDF_CTX *ctx, unsigned char *key, size_t keylen,
1497 const OSSL_PARAM params[])
1498 {
1499 return EVP_KDF_derive(ctx, key, keylen, params);
1500 }
1501
OpensslOsslEncoderCtxNewForPkey(const EVP_PKEY * pkey,int selection,const char * outputType,const char * outputStruct,const char * propquery)1502 OSSL_ENCODER_CTX *OpensslOsslEncoderCtxNewForPkey(const EVP_PKEY *pkey,
1503 int selection,
1504 const char *outputType,
1505 const char *outputStruct,
1506 const char *propquery)
1507 {
1508 return OSSL_ENCODER_CTX_new_for_pkey(pkey, selection, outputType, outputStruct, propquery);
1509 }
1510
OpensslOsslEncoderToData(OSSL_ENCODER_CTX * ctx,unsigned char ** pdata,size_t * len)1511 int OpensslOsslEncoderToData(OSSL_ENCODER_CTX *ctx, unsigned char **pdata, size_t *len)
1512 {
1513 return OSSL_ENCODER_to_data(ctx, pdata, len);
1514 }
1515
OpensslOsslEncoderCtxFree(OSSL_ENCODER_CTX * ctx)1516 void OpensslOsslEncoderCtxFree(OSSL_ENCODER_CTX *ctx)
1517 {
1518 OSSL_ENCODER_CTX_free(ctx);
1519 }
1520
OpensslOsslDecoderCtxNewForPkey(EVP_PKEY ** pkey,const char * inputType,const char * inputStructure,const char * keytype,int selection,OSSL_LIB_CTX * libctx,const char * propquery)1521 OSSL_DECODER_CTX *OpensslOsslDecoderCtxNewForPkey(EVP_PKEY **pkey,
1522 const char *inputType,
1523 const char *inputStructure,
1524 const char *keytype, int selection,
1525 OSSL_LIB_CTX *libctx, const char *propquery)
1526 {
1527 return OSSL_DECODER_CTX_new_for_pkey(pkey, inputType, inputStructure, keytype, selection, libctx, propquery);
1528 }
1529
OpensslOsslDecoderFromData(OSSL_DECODER_CTX * ctx,const unsigned char ** pdata,size_t * len)1530 int OpensslOsslDecoderFromData(OSSL_DECODER_CTX *ctx, const unsigned char **pdata,
1531 size_t *len)
1532 {
1533 return OSSL_DECODER_from_data(ctx, pdata, len);
1534 }
1535
OpensslOsslDecoderCtxFree(OSSL_DECODER_CTX * ctx)1536 void OpensslOsslDecoderCtxFree(OSSL_DECODER_CTX *ctx)
1537 {
1538 OSSL_DECODER_CTX_free(ctx);
1539 }