---
title: 非对称算法运算类
description: "本章节主要介绍了非对称算法类接口及其扩展接口的功能和相关规格限制。"
url: https://www.hikunpeng.com/document/detail/zh/kunpengcctrustzone/cca/devg/Kunpeng_ommercialcryptography_16_0028.html
sourcePath: /source/zh/kunpengcctrustzone/cca/devg/Kunpeng_ommercialcryptography_16_0028.html
indexId: 0a854473ad4575f73d6ed362fde36232c14a0cf1cd5c7c37d435673c8de3db3381
---
# 非对称算法运算类

本章节主要介绍了非对称算法类接口及其扩展接口的功能和相关规格限制。

非对称算法运算类接口支持如下，接口定义符合GM/T 0018-2023标准，接口参数与返回值可参考标准文档，算法标识描述可参考GM/T 0006-2023。

```
int SDF_ExternalVerify_ECC(void *hSessionHandle, unsigned int uiAlgID, ECCrefPublicKey *pucPublicKey, unsigned char *pucDataInput, unsigned int uiInputLength, ECCSignature *pucSignature);
int SDF_InternalSign_ECC(void *hSessionHandle, unsigned int uiISKIndex, unsigned char *pucData, unsigned int uiDataLength, ECCSignature *pucSignature);
int SDF_InternalVerify_ECC(void *hSessionHandle, unsigned int uiISKIndex, unsigned char *pucData, unsigned int uiDataLength, ECCSignature *pucSignature);
int SDF_ExternalEncrypt_ECC(void *hSessionHandle, unsigned int uiAlgID, ECCrefPublicKey *pucPublicKey, unsigned char *pucData, unsigned int uiDataLength, ECCCipher *pucEncature);
```

#### 自定义接口

- 使用外部ECC公钥对ECC签名值进行验证运算。

```
int SDF_ExternalSign_ECC(void *hSessionHandle, unsigned int uiAlgID, ECCrefPrivateKey *pucPrivateKey, unsigned char *pucData, unsigned int uiDataLength, ECCSignature *pucSignature);
```


**表1 参数说明**

| 参数 | 描述 |
| --- | --- |
| hSessionHandle[in] | 与设备建立的会话句柄 |
| uiAlgID[in] | 算法标识，指定使用的ECC算法，暂无限制 |
| pucPrivateKey[in] | 外部ECC私钥结构，密钥长度不超过256bit |
| pucData[in] | 缓冲区指针，用于存放外部输入的数据 |
| uiDataLength[in] | 输入的数据长度，固定32字节 |
| pucSignature[out] | 缓冲区指针，用于存放输出的签名值（加密结果buffer长度大于等于输入的数据明文长度） |


**表2 返回值说明**

| 返回值 | 说明 |
| --- | --- |
| 0 | 成功 |
| 非0 | 失败，返回错误码 |


- 使用外部ECC私钥对数据进行解密运算。

```
int SDF_ExternalDecrypt_ECC(void *hSessionHandle, unsigned int uiAlgID, ECCrefPrivateKey *pucPrivateKey, ECCCipher *pucEncData, unsigned char *pucData, unsigned int *puiDataLength);
```


**表3 参数说明**

| 参数 | 描述 |
| --- | --- |
| hSessionHandle[in] | 与设备建立的会话句柄 |
| uiAlgID[in] | 算法标识，指定使用的ECC算法，暂无限制 |
| pucPrivateKey[in] | 外部ECC私钥结构，密钥长度不超过256bit |
| pucEncData[in] | 缓冲区指针，用于存放外部输入的数据密文，数据长度不大于20K |
| pucData[out] | 缓冲区指针，用于存放解密结果 |
| puiDataLength[out] | 输出的解密结果长度，输入值小于等于500K，大于等于输入的数据密文长度 |


**表4 返回值说明**

| 返回值 | 说明 |
| --- | --- |
| 0 | 成功 |
| 非0 | 失败，返回错误码 |


- 使用内部ECC公钥对数据进行加密运算。

```
int SDF_InternalEncrypt_ECC(void *hSessionHandle, unsigned int uiISKIndex, unsigned char *pucData, unsigned int uiDataLength, ECCCipher *pucEncData);
```


**表5 参数说明**

| 参数 | 描述 |
| --- | --- |
| hSessionHandle[in] | 与设备建立的会话句柄 |
| uiISKIndex[in] | 内部密钥索引值，范围0~2048 |
| pucData[in] | 缓冲区指针，用于存放输入数据 |
| uiDataLength[in] | 输入数据长度，不大于20K |
| pucEncData[out] | 缓冲区指针，用于存放输出的数据密文（加密结果buffer长度大于等于输入的数据明文长度） |


**表6 返回值说明**

| 返回值 | 说明 |
| --- | --- |
| 0 | 成功 |
| 非0 | 失败，返回错误码 |


- 使用内部ECC私钥对数据进行解密运算。

```
int SDF_InternalDecrypt_ECC(void *hSessionHandle, unsigned int uiISKIndex, unsigned int ECCKeyType, ECCCipher *pucEncData, unsigned char *pucData, unsigned int *puiDataLength);
```


**表7 参数说明**

| 参数 | 描述 |
| --- | --- |
| hSessionHandle[in] | 与设备建立的会话句柄 |
| uiISKIndex[in] | 内部密钥索引值，范围0~2048 |
| ECCKeyType[in] | 内部密钥类型，SGD\_SM2\_3指定加密私钥，SGD\_SM2\_1指定签名私钥 |
| pucEncData[in] | 缓冲区指针，用于存放外部输入的数据密文，数据长度不大于20K |
| pucData[out] | 缓冲区指针，用于存放解密结果 |
| puiDataLength[out] | 输出的解密结果长度，输出值不大于500K，大于等于输入的数据密文长度 |


**表8 返回值说明**

| 返回值 | 说明 |
| --- | --- |
| 0 | 成功 |
| 非0 | 失败，返回错误码 |


#### 规格限制

- 外部输入的ECC公钥长度当前仅支持256bit。
- 签名验签输入数据为待签数据的杂凑值，长度限制为32字节。
- 加解密数据长度不大于20K，解密结果长度不大于500K。
- 加密密钥使用说明和密钥密码强度相关内容请参见  加密密钥使用说明
和  密钥密码强度
。
