• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * This file is part of the openHiTLS project.
3  *
4  * openHiTLS is licensed under the Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *
8  *     http://license.coscl.org.cn/MulanPSL2
9  *
10  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
11  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
12  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
13  * See the Mulan PSL v2 for more details.
14  */
15 
16 #include "hitls_build.h"
17 #if defined(HITLS_CRYPTO_EAL) && defined(HITLS_CRYPTO_PKEY)
18 
19 #include <securec.h>
20 #include "bsl_sal.h"
21 #include "crypt_errno.h"
22 #include "bsl_err_internal.h"
23 #include "eal_pkey_local.h"
24 #include "crypt_eal_pkey.h"
25 #include "eal_common.h"
26 
CRYPT_EAL_PkeyComputeShareKey(const CRYPT_EAL_PkeyCtx * pkey,const CRYPT_EAL_PkeyCtx * pubKey,uint8_t * share,uint32_t * shareLen)27 int32_t CRYPT_EAL_PkeyComputeShareKey(const CRYPT_EAL_PkeyCtx *pkey, const CRYPT_EAL_PkeyCtx *pubKey,
28     uint8_t *share, uint32_t *shareLen)
29 {
30     if (pkey == NULL || pubKey == NULL) {
31         EAL_ERR_REPORT(CRYPT_EVENT_ERR, CRYPT_ALGO_PKEY, CRYPT_PKEY_MAX, CRYPT_NULL_INPUT);
32         return CRYPT_NULL_INPUT;
33     }
34     if (pkey->id != pubKey->id) {
35         EAL_ERR_REPORT(CRYPT_EVENT_ERR, CRYPT_ALGO_PKEY, CRYPT_PKEY_MAX, CRYPT_EAL_ERR_ALGID);
36         return CRYPT_EAL_ERR_ALGID;
37     }
38     if (pkey->method == NULL || pkey->method->computeShareKey == NULL) {
39         EAL_ERR_REPORT(CRYPT_EVENT_ERR, CRYPT_ALGO_PKEY, CRYPT_PKEY_MAX, CRYPT_EAL_ALG_NOT_SUPPORT);
40         return CRYPT_EAL_ALG_NOT_SUPPORT;
41     }
42 
43     int32_t ret = pkey->method->computeShareKey(pkey->key, pubKey->key, share, shareLen);
44     if (ret != CRYPT_SUCCESS) {
45         EAL_ERR_REPORT(CRYPT_EVENT_ERR, CRYPT_ALGO_PKEY, CRYPT_PKEY_MAX, ret);
46     }
47     EAL_EventReport(CRYPT_EVENT_KEYAGGREMENT, CRYPT_ALGO_PKEY, pkey->id, CRYPT_SUCCESS);
48     return ret;
49 }
50 #endif
51