From 978bc3541280344145908b64efb134551e074d37 Mon Sep 17 00:00:00 2001 From: xwb Date: Fri, 19 Jan 2024 09:16:44 +0000 Subject: [PATCH] add Signed-off-by: xwb --- .../crypto_operation/sm2_crypt_util.h | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 interfaces/innerkits/crypto_operation/sm2_crypt_util.h diff --git a/interfaces/innerkits/crypto_operation/sm2_crypt_util.h b/interfaces/innerkits/crypto_operation/sm2_crypt_util.h new file mode 100644 index 0000000..69ebe17 --- /dev/null +++ b/interfaces/innerkits/crypto_operation/sm2_crypt_util.h @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef HCF_SM2_CRYPT_UTIL_H +#define HCF_SM2_CRYPT_UTIL_H + +#include "blob.h" +#include "big_integer.h" + +typedef struct HcfSm2CipherTextSpec HcfSm2CipherTextSpec; +/** + * Provides the interface for specifying detailed data in the SM2 ciphertext in ASN.1 format. + */ +struct HcfSm2CipherTextSpec { + HcfBigInteger xCoordinate; // C1x, x coordinate of the public key + HcfBigInteger yCoordinate; // C1y, y coordinate of the public key + HcfBlob cipherTextData; // C2, cipher text data + HcfBlob hashData; // C3, hash data +}; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * Generate ASN.1 ciphertext in the given mode according to the SM2 detailed spec data. + */ +HcfResult HcfGenCipherTextBySpec(HcfSm2CipherTextSpec *spec, const char *mode, HcfBlob *output); + +/** + * Get the SM2 detailed spec data from the ASN.1 ciphertext with the given mode. + */ +HcfResult HcfGetCipherTextSpec(HcfBlob *cipherText, const char *mode, HcfSm2CipherTextSpec *outputSpec); + +#ifdef __cplusplus +} +#endif + +#endif -- Gitee