已开启
[docs] 修复 aclnnCrypto 文档原型名与示例 IV 缓冲区越界读取 #131
NUAA_wqy创建于 15 天前
[docs] 修复 aclnnCrypto 文档原型名与示例 IV 缓冲区越界读取 #131
已开启
共 1 个文件变更+8-3
| @@ -34,7 +34,7 @@ | |||
| 34 | 34 | ||
| 35 | 每个算子分为两段式接口,必须先调用“aclnnCryptoGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnCrypto”接口执行计算。 | 35 | 每个算子分为两段式接口,必须先调用“aclnnCryptoGetWorkspaceSize”接口获取计算所需workspace大小以及包含了算子计算流程的执行器,再调用“aclnnCrypto”接口执行计算。 |
| 36 | ```c++ | 36 | ```c++ |
| 37 | -aclnnStatus aclnnCryptoAicpuGetWorkspaceSize( | 37 | +aclnnStatus aclnnCryptoGetWorkspaceSize( |
| 38 | const aclTensor *key, | 38 | const aclTensor *key, |
| 39 | const aclTensor *inputText, | 39 | const aclTensor *inputText, |
| 40 | aclTensor *outputText, | 40 | aclTensor *outputText, |
| @@ -48,7 +48,7 @@ aclnnStatus aclnnCryptoAicpuGetWorkspaceSize( | |||
| 48 | ``` | 48 | ``` |
| 49 | 49 | ||
| 50 | ```c++ | 50 | ```c++ |
| 51 | -aclnnStatus aclnnCryptoAicpu( | 51 | +aclnnStatus aclnnCrypto( |
| 52 | void *workspace, | 52 | void *workspace, |
| 53 | uint64_t workspaceSize, | 53 | uint64_t workspaceSize, |
| 54 | aclOpExecutor *executor, | 54 | aclOpExecutor *executor, |
| @@ -486,6 +486,11 @@ template <typename T> | |||
| 486 | int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, | 486 | int CreateAclTensor(const std::vector<T>& hostData, const std::vector<int64_t>& shape, void** deviceAddr, |
| 487 | aclDataType dataType, aclTensor** tensor) { | 487 | aclDataType dataType, aclTensor** tensor) { |
| 488 | auto size = GetShapeSize(shape) * sizeof(T); | 488 | auto size = GetShapeSize(shape) * sizeof(T); |
| 489 | + if (static_cast<size_t>(size) > hostData.size() * sizeof(T)) { | ||
| 490 | + LOG_PRINT("CreateAclTensor failed: hostData %zu bytes < shape %zu bytes\n", | ||
| 491 | + hostData.size() * sizeof(T), static_cast<size_t>(size)); | ||
| 492 | + return -1; | ||
| 493 | + } | ||
| 489 | auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); | 494 | auto ret = aclrtMalloc(deviceAddr, size, ACL_MEM_MALLOC_HUGE_FIRST); |
| 490 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); | 495 | CHECK_RET(ret == ACL_SUCCESS, LOG_PRINT("aclrtMalloc failed. ERROR: %d\n", ret); return ret); |
| 491 | 496 | ||
| @@ -612,7 +617,7 @@ int main(int argc, char *argv[]) { | |||
| 612 | std::vector<uint8_t> keyHostData(16, 0x11); // key数据 | 617 | std::vector<uint8_t> keyHostData(16, 0x11); // key数据 |
| 613 | std::vector<uint8_t> inputHostData(msg_len, 0x00); // 输入数据 | 618 | std::vector<uint8_t> inputHostData(msg_len, 0x00); // 输入数据 |
| 614 | 619 | ||
| 615 | - std::vector<uint8_t> ivHostData(16, 0x1f); // iv | 620 | + std::vector<uint8_t> ivHostData(32, 0x1f); // iv, must match iv_shape_data={32} |
| 616 | std::vector<uint32_t> opConfigHostData = {1, static_cast<uint32_t>(mode), static_cast<uint32_t>(alg_type), 1, 34, 0}; // 配置version, mode, alg_type, key_type, keyId, device_id | 621 | std::vector<uint32_t> opConfigHostData = {1, static_cast<uint32_t>(mode), static_cast<uint32_t>(alg_type), 1, 34, 0}; // 配置version, mode, alg_type, key_type, keyId, device_id |
| 617 | std::vector<uint8_t> outputHostData(msg_len, 0); // 输出 | 622 | std::vector<uint8_t> outputHostData(msg_len, 0); // 输出 |
| 618 | std::vector<uint32_t> yHostData = {0}; // 输出 | 623 | std::vector<uint32_t> yHostData = {0}; // 输出 |