KeyAgreementAlgorithm
internal enum KeyAgreementAlgorithm
The Key Agreement is a cryptographic method that allows users to compute shared secret key, after their public keys have been exchanged, allowing the use of a cryptographic algorithm.
-
Diffie-Hellman Key Agreement
Declaration
Swift
case DH -
Elliptic-Curve Diffie-Hellman Key Agreement
Declaration
Swift
case ECDH
-
Generate a new key pair for the specified
KeyAgreementAlgorithmandStandardizedDomainParameters.Important
The returned reference to the key pair has to be freed by the caller. The pointer will reference a
EVP_PKEYstructure (so useEVP_PKEY_freethen).Declaration
Swift
internal static func generateKeyPair(for algorithm: KeyAgreementAlgorithm, using params: StandardizedDomainParameters) throws -> OpaquePointerParameters
algorithmThe used
KeyAgreementAlgorithm(DH or ECDH).paramsThe used
StandardizedDomainParameters. It may be a standardized elliptic curve for ECDH or an algebric set for DH. Parameters includes the prime p, the generator g and the size of the prime-order subgroup generated by g.Return Value
A reference to the generated key pair.
-
Generate a new key pair using the specified
StandardizedDomainParameters.Important
The returned reference to the key pair has to be freed by the caller. The pointer will reference a
EVP_PKEYstructure (so useEVP_PKEY_freethen).Declaration
Swift
internal func generateKeyPair(params: StandardizedDomainParameters) throws -> OpaquePointerParameters
paramsThe used
StandardizedDomainParameters. It may be a standardized elliptic curve for ECDH or an algebric set for DH. Parameters includes the prime p, the generator g and the size of the prime-order subgroup generated by g.Return Value
A reference to the generated key pair.
-
Generate a key pair based on the parameters of an existing public key.
Throws
An error if key pair generation fails.
Important
The returned reference to the key pair has to be freed by the caller. The pointer will reference a
EVP_PKEYstructure (so useEVP_PKEY_freethen).Declaration
Swift
internal static func generateKeyPair(withParamsFrom publicKey: OpaquePointer) throws -> OpaquePointerParameters
publicKeyA reference to an existing public key.
Return Value
A reference to the generated key pair.
-
Compute the shared secret from the personal private key and the external public key using the specified
KeyAgreementAlgorithm.Tip: If you want to convert the returned reference to the shared secret into a byte representation as
[UInt8], you can useconvertToBytes(key:keyPair:for:)orconvertToBytes(key:keyPair:)functions.
Important
The returned reference to the shared secret has to be freed by the caller. If the used algorithm is DH, the pointer will reference a
BNstructure (so useBN_freethen), otherwise the pointer will reference aEC_POINTstucture (so useEC_POINT_freethen). If you don’t know the usedKeyAgreementAlgorithmor it is dynamic, you can also callfree(sharedSecret:)orfree(sharedSecret:for:)functions.Declaration
Swift
internal static func computeSharedSecret(personalKeyPair: OpaquePointer, externalPublicKey: [UInt8], using algorithm: KeyAgreementAlgorithm) throws -> OpaquePointerParameters
personalKeyPairThe personal key pair object containg personal public/private keys and used params.
externalPublicKeyThe bytes representing the external public key.
algorithmThe used
KeyAgreementAlgorithm(DH or ECDH)Return Value
A reference to the computed shared secret.
-
Compute the shared secret from the personal private key and the external public key.
Tip: If you want to convert the returned reference to the shared secret into a byte representation as
[UInt8], you can useconvertToBytes(key:keyPair:for:)orconvertToBytes(key:keyPair:)functions.
Important
The returned reference to the shared secret has to be freed by the caller. If the used algorithm is DH, the pointer will reference a
BNstructure (so useBN_freethen), otherwise the pointer will reference aEC_POINTstucture (so useEC_POINT_freethen). If you don’t know the usedKeyAgreementAlgorithmor it is dynamic, you can also callfree(sharedSecret:)orfree(sharedSecret:for:)functions.Declaration
Swift
internal func computeSharedSecret(personalKeyPair: OpaquePointer, externalPublicKey: [UInt8]) throws -> OpaquePointerParameters
personalKeyPairThe personal key pair object containg personal public/private keys and used params.
externalPublicKeyThe bytes representing the external public key.
Return Value
A reference to the computed shared secret.
-
Extract and return the public key from an
OpaquePointerkey pair.Throws
An error if the extraction process fails or if the key type is not supported.
Declaration
Swift
internal static func extractPublicKey(from keyPair: OpaquePointer) throws -> [UInt8]Parameters
keyPairAn
OpaquePointerrepresenting a key pair.Return Value
An array of bytes representing the extracted public key.
-
Extract and return the public key from an
OpaquePointerkey pair.Throws
An error if the extraction process fails.
Declaration
Swift
internal func extractPublicKey(from keyPair: OpaquePointer) throws -> [UInt8]Parameters
keyPairAn
OpaquePointerrepresenting a key pair.Return Value
An array of bytes representing the extracted public key.
-
Decode a public key from a byte array using the specified
OpaquePointerparameters.Throws
An error if the decoding process fails or if the key type is not supported.
Important
The returned reference to the public key has to be freed by the caller. The pointer will reference a
EVP_PKEYstructure (so useEVP_PKEY_freethen).Declaration
Swift
internal static func decodePublicKey(from bytes: [UInt8], withParams params: OpaquePointer) throws -> OpaquePointerParameters
bytesThe byte array representing the public key.
paramsOpaquePointerparameters for the decoding operation.Return Value
An
OpaquePointerrepresenting the decoded public key. -
Decode a public key from a byte array using the specified
OpaquePointerparameters.Throws
An error if the decoding process fails.
Important
The returned reference to the public key has to be freed by the caller. The pointer will reference a
EVP_PKEYstructure (so useEVP_PKEY_freethen).Declaration
Swift
internal func decodePublicKey(from bytes: [UInt8], withParams params: OpaquePointer) throws -> OpaquePointerParameters
bytesThe byte array representing the public key.
paramsOpaquePointerparameters for the decoding operation.Return Value
An
OpaquePointerrepresenting the decoded public key. -
Convert a key into an array of bytes using the specified
KeyAgreementAlgorithm.Throws
An error if the conversion fails.
Tip:
keyPairis required just using ECDH.
Declaration
Swift
internal static func convertToBytes(key: OpaquePointer, keyPair: OpaquePointer? = nil, for algorithm: KeyAgreementAlgorithm) throws -> [UInt8]Parameters
keyA key as an
OpaquePointer.keyPairA key pair as an
OpaquePointer?(defaultnil).algorithmThe
KeyAgreementAlgorithmused to perform the conversion.Return Value
An array of bytes representing the shared secret.
-
Convert a key into an array of bytes.
Throws
An error if the conversion fails.
Tip:
keyPairis required just using ECDH.
Declaration
Swift
internal func convertToBytes(key: OpaquePointer, keyPair: OpaquePointer? = nil) throws -> [UInt8]Parameters
sharedSecretA key as an
OpaquePointer.keyPairA key pair as an
OpaquePointer?(defaultnil).Return Value
An array of bytes representing the shared secret.
-
Free the shared secret reference computed with the given
KeyAgreementAlgorithm.Declaration
Swift
internal static func free(sharedSecret: OpaquePointer, for algorithm: KeyAgreementAlgorithm)Parameters
sharedSecretThe shared secret reference.
algorithmThe
KeyAgreementAlgorithmused to compute the secret. -
Free the shared secret reference.
Declaration
Swift
internal func free(sharedSecret: OpaquePointer)Parameters
sharedSecretThe shared secret reference.
View on GitHub
KeyAgreementAlgorithm Enumeration Reference