---
title: 杂凑运算类
description: 本章节主要描述了杂凑运算类接口定义与规格限制。
url: "https://www.hikunpeng.com/document/detail/zh/kunpengcctrustzone/cca/devg/Kunpeng_ommercialcryptography_16_0030.html"
---

# 杂凑运算类

本章节主要描述了杂凑运算类接口定义与规格限制。

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

```
int SDF_HashInit(void *hSessionHandle, unsigned int uiAlgID, ECCrefPublicKey *pucPublicKey, unsigned char *pucID, unsigned int uiIDLength);
int SDF_HashUpdate(void *hSessionHandle, unsigned char *pucData, unsigned int uiDataLength);
int SDF_HashFinal(void *hSessionHandle, unsigned char *pucHash, unsigned int *puiHashLength);
```

外部杂凑运算类自定义接口如下：

```
int SDF_ExternalHashInit(void *hSessionHandle, unsigned int uiAlgID);
```


**表1 参数说明**

| 参数 | 描述 |
| --- | --- |
| hSessionHandle[in] | 会话句柄（内部使用hSessionHandle\->ctx 保存不透明 ctx）。 |
| uiAlgID[in] | 算法标识（应映射到具体哈希算法，目前只支持“SGD\_SM3”）。 |


**表2 返回值说明**

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


```
int SDF_ExternalHashUpdate(void *hSessionHandle, unsigned char *pucData, unsigned int uiDataLength);
```


**表3 参数说明**

| 参数 | 描述 |
| --- | --- |
| hSessionHandle[in] | 会话句柄。 |
| pucData[in] | 输入数据分片指针（当uiDataLength=0时不可为NULL）。 |
| uiDataLength[in] | 输入数据分片长度（字节）。 |


**表4 返回值说明**

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


```
int SDF_ExternalHashFinal(void *hSessionHandle, unsigned char *pucHash, unsigned int *puiHashLength);
```


**表5 参数说明**

| 参数 | 描述 |
| --- | --- |
| hSessionHandle[in] | 会话句柄。 |
| pucHash[out] | 哈希值输出缓冲区。 |
| puiHashLength[out] | 入参=输出缓冲区容量；出参=实际输出长度。 |


**表6 返回值说明**

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


#### 规格限制

- 杂凑运算类算法标识当前仅支持SGD_SM3。
- 签名ID长度不大于8KB。
- Hash结果缓冲区长度不小于32字节。
