1# crypto_key_agreement.h 2 3<!--Kit: Crypto Architecture Kit--> 4<!--Subsystem: Security--> 5<!--Owner: @zxz--3--> 6<!--Designer: @lanming--> 7<!--Tester: @PAFT--> 8<!--Adviser: @zengyawen--> 9 10## Overview 11 12Defines key agreement APIs. 13 14**Header file**: <CryptoArchitectureKit/crypto_key_agreement.h> 15 16**Library**: libohcrypto.so 17 18**System capability**: SystemCapability.Security.CryptoFramework 19 20**Since**: 20 21 22**Related Module**: [CryptoKeyAgreementApi](capi-cryptokeyagreementapi.md) 23 24## Summary 25 26### Structs 27 28| Name| typedef Keyword| Description| 29| -- | -- | -- | 30| [OH_CryptoKeyAgreement](capi-cryptokeyagreementapi-oh-cryptokeyagreement.md) | OH_CryptoKeyAgreement | Defines a struct for key agreement.| 31 32### Functions 33 34| Name| Description| 35| -- | -- | 36| [OH_Crypto_ErrCode OH_CryptoKeyAgreement_Create(const char *algoName, OH_CryptoKeyAgreement **ctx)](#oh_cryptokeyagreement_create) | Creates a key agreement instance based on the given algorithm name.| 37| [OH_Crypto_ErrCode OH_CryptoKeyAgreement_GenerateSecret(OH_CryptoKeyAgreement *ctx, OH_CryptoPrivKey *privkey,OH_CryptoPubKey *pubkey, Crypto_DataBlob *secret)](#oh_cryptokeyagreement_generatesecret) | Generates the secret value of key agreement.| 38| [void OH_CryptoKeyAgreement_Destroy(OH_CryptoKeyAgreement *ctx)](#oh_cryptokeyagreement_destroy) | Destroys a key agreement instance.| 39 40## Function Description 41 42### OH_CryptoKeyAgreement_Create() 43 44``` 45OH_Crypto_ErrCode OH_CryptoKeyAgreement_Create(const char *algoName, OH_CryptoKeyAgreement **ctx) 46``` 47 48**Description** 49 50Creates a key agreement instance based on the given algorithm name. 51 52**Since**: 20 53 54 55**Parameters** 56 57| Name| Description| 58| -- | -- | 59| const char *algoName | Algorithm name of the key agreement instance to be created.<br> For example, **ECC** or **X25519**.| 60| [OH_CryptoKeyAgreement](capi-cryptokeyagreementapi-oh-cryptokeyagreement.md) **ctx | Key agreement instance.| 61 62**Returns** 63 64| Type| Description| 65| -- | -- | 66| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br> **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br> **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br> **CRYPTO_PARAMETER_CHECK_FAILED**: The parameter check failed.<br> **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.| 67 68### OH_CryptoKeyAgreement_GenerateSecret() 69 70``` 71OH_Crypto_ErrCode OH_CryptoKeyAgreement_GenerateSecret(OH_CryptoKeyAgreement *ctx, OH_CryptoPrivKey *privkey,OH_CryptoPubKey *pubkey, Crypto_DataBlob *secret) 72``` 73 74**Description** 75 76Generates the secret value of key agreement. 77 78**Since**: 20 79 80 81**Parameters** 82 83| Name| Description| 84| -- | -- | 85| [OH_CryptoKeyAgreement](capi-cryptokeyagreementapi-oh-cryptokeyagreement.md) *ctx | Key agreement instance.| 86| [OH_CryptoPrivKey](capi-cryptoasymkeyapi-oh-cryptoprivkey.md) *privkey | Private key.| 87| [OH_CryptoPubKey](capi-cryptoasymkeyapi-oh-cryptopubkey.md) *pubkey | Public key.| 88| [Crypto_DataBlob](capi-cryptocommonapi-crypto-datablob.md) *secret | Secret value.| 89 90**Returns** 91 92| Type| Description| 93| -- | -- | 94| [OH_Crypto_ErrCode](capi-crypto-common-h.md#oh_crypto_errcode) | **CRYPTO_SUCCESS**: The operation is successful.<br> **CRYPTO_NOT_SUPPORTED**: The operation is not supported.<br> **CRYPTO_MEMORY_ERROR**: A memory error occurs.<br> **CRYPTO_PARAMETER_CHECK_FAILED**: The parameter check failed.<br> **CRYPTO_OPERTION_ERROR**: Failed to call an API of a third-party algorithm library.| 95 96### OH_CryptoKeyAgreement_Destroy() 97 98``` 99void OH_CryptoKeyAgreement_Destroy(OH_CryptoKeyAgreement *ctx) 100``` 101 102**Description** 103 104Destroys a key agreement instance. 105 106**Since**: 20 107 108 109**Parameters** 110 111| Name| Description| 112| -- | -- | 113| [OH_CryptoKeyAgreement](capi-cryptokeyagreementapi-oh-cryptokeyagreement.md) *ctx | Key agreement instance.| 114