Dh Delphi DLL Reference Documentation

Dh

Current Version: 11.5.0

Chilkat.Dh

Perform Diffie-Hellman shared-secret key exchange.

Chilkat.Dh provides the core operations needed for Diffie-Hellman shared-secret exchange. It allows two parties to agree on a shared secret over an insecure channel by using common Diffie-Hellman parameters, generating public exchange values, and computing the same shared secret from the other party's public value.

Choose known parameters

Use UseKnownPrime when the application wants to use a predefined Diffie-Hellman prime group.

Generate parameters

Use GenPG to generate Diffie-Hellman parameters when custom prime and generator values are required.

Set custom P and G

Use SetPG when the prime and generator are already known or have been received from another party or protocol.

Create the exchange value

Use CreateE to create the public Diffie-Hellman value that is sent to the other party.

Compute the shared secret

Use FindK with the other party's public exchange value to compute the shared secret.

Use the result carefully

The shared secret is typically used as input to a key derivation step before being used for encryption or authentication.

Common pattern: Select or generate the Diffie-Hellman parameters, create your public exchange value with CreateE, exchange public values with the other party, then call FindK to compute the shared secret. The primary methods are UseKnownPrime, GenPG, SetPG, CreateE, and FindK.

Create/Dispose

var
myObject: HCkDh;

begin
myObject := CkDh_Create();

// ...

CkDh_Dispose(myObject);
end;
function CkDh_Create: HCkDh; stdcall;

Creates an instance of the HCkDh object and returns a handle (i.e. a Pointer). The handle is passed in the 1st argument for the functions listed on this page.

procedure CkDh_Dispose(handle: HCkDh); stdcall;

Objects created by calling CkDh_Create must be freed by calling this method. A memory leak occurs if a handle is not disposed by calling this function.

Properties

DebugLogFilePath
procedure CkDh_getDebugLogFilePath(objHandle: HCkDh; outPropVal: HCkString); stdcall;
procedure CkDh_putDebugLogFilePath(objHandle: HCkDh; newPropVal: PWideChar); stdcall;
function CkDh__debugLogFilePath(objHandle: HCkDh): PWideChar; stdcall;

If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.

Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.

Possible causes of hangs include:

  • A timeout property set to 0, indicating an infinite timeout.
  • A hang occurring within an event callback in the application code.
  • An internal bug in the Chilkat code causing the hang.

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top
G
function CkDh_getG(objHandle: HCkDh): Integer; stdcall;

The generator. The value of G should be either 2 or 5.

top
LastErrorHtml
procedure CkDh_getLastErrorHtml(objHandle: HCkDh; outPropVal: HCkString); stdcall;
function CkDh__lastErrorHtml(objHandle: HCkDh): PWideChar; stdcall;

Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

See the notes about PWideChar memory ownership and validity.

top
LastErrorText
procedure CkDh_getLastErrorText(objHandle: HCkDh; outPropVal: HCkString); stdcall;
function CkDh__lastErrorText(objHandle: HCkDh): PWideChar; stdcall;

Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

See the notes about PWideChar memory ownership and validity.

top
LastErrorXml
procedure CkDh_getLastErrorXml(objHandle: HCkDh; outPropVal: HCkString); stdcall;
function CkDh__lastErrorXml(objHandle: HCkDh): PWideChar; stdcall;

Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.

See the notes about PWideChar memory ownership and validity.

top
LastMethodSuccess
function CkDh_getLastMethodSuccess(objHandle: HCkDh): wordbool; stdcall;
procedure CkDh_putLastMethodSuccess(objHandle: HCkDh; newPropVal: wordbool); stdcall;

Indicates the success or failure of the most recent method call: True means success, False means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.

top
P
procedure CkDh_getP(objHandle: HCkDh; outPropVal: HCkString); stdcall;
function CkDh__p(objHandle: HCkDh): PWideChar; stdcall;

A safe large prime returned as a hex string. The hex string represent a bignum in SSH1 format.

See the notes about PWideChar memory ownership and validity.

top
VerboseLogging
function CkDh_getVerboseLogging(objHandle: HCkDh): wordbool; stdcall;
procedure CkDh_putVerboseLogging(objHandle: HCkDh; newPropVal: wordbool); stdcall;

If set to True, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is False. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.

top
Version
procedure CkDh_getVersion(objHandle: HCkDh; outPropVal: HCkString); stdcall;
function CkDh__version(objHandle: HCkDh): PWideChar; stdcall;

Version of the component/library, such as "10.1.0"

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top

Methods

CreateE
function CkDh_CreateE(objHandle: HCkDh;
    numBits: Integer;
    outStr: HCkString): wordbool; stdcall;
function CkDh__createE(objHandle: HCkDh;
    numBits: Integer): PWideChar; stdcall;

The 1st step in Diffie-Hellman key exchange (to generate a shared-secret). The numBits should be twice the size (in bits) of the shared secret to be generated. For example, if you are using DH to create a 128-bit AES session key, then numBits should be set to 256. Returns E as a bignum in SSH-format as a hex string.

Returns True for success, False for failure.

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top
FindK
function CkDh_FindK(objHandle: HCkDh;
    E: PWideChar;
    outStr: HCkString): wordbool; stdcall;
function CkDh__findK(objHandle: HCkDh;
    E: PWideChar): PWideChar; stdcall;

The 2nd and final step in Diffie-Hellman (DH) key exchange. E is the E created by the other party. Returns the shared secret (K) as an SSH1-format bignum encoded as a hex string.

Returns True for success, False for failure.

See the notes about PWideChar memory ownership and validity.

More Information and Examples
top
GenPG
function CkDh_GenPG(objHandle: HCkDh;
    numBits: Integer;
    G: Integer): wordbool; stdcall;

Generates a large safe prime that is numBits bits in size using the generator G. Generating a new (random) P is expensive in both time and CPU cycles. A prime should be 1024 or more bits in length.

Returns True for success, False for failure.

top
SetPG
function CkDh_SetPG(objHandle: HCkDh;
    p: PWideChar;
    g: Integer): wordbool; stdcall;

Sets explicit values for P and G. Returns True if P and G conform to the requirements for Diffie-Hellman. P is an SSH1-format bignum passed as a hexidecimalized string.

Returns True for success, False for failure.

More Information and Examples
top
UseKnownPrime
procedure CkDh_UseKnownPrime(objHandle: HCkDh;
    index: Integer) stdcall;

Sets P and G to a known safe prime. The index may have the following values:

1: First Oakley Default Group from RFC2409, section 6.1. Generator is 2. The prime is: 2^768 - 2 ^704 - 1 + 2^64 * { [2^638 pi] + 149686 }

2: Prime for 2nd Oakley Group (RFC 2409) -- 1024-bit MODP Group. Generator is 2. The prime is: 2^1024 - 2^960 - 1 + 2^64 * { [2^894 pi] + 129093 }.

3: 1536-bit MODP Group from RFC3526, Section 2. Generator is 2. The prime is: 2^1536 - 2^1472 - 1 + 2^64 * { [2^1406 pi] + 741804 }

4: Prime for 14th Oakley Group (RFC 3526) -- 2048-bit MODP Group. Generator is 2. The prime is: 2^2048 - 2^1984 - 1 + 2^64 * { [2^1918 pi] + 124476 }

5: 3072-bit MODP Group from RFC3526, Section 4. Generator is 2. The prime is: 2^3072 - 2^3008 - 1 + 2^64 * { [2^2942 pi] + 1690314 }

6: 4096-bit MODP Group from RFC3526, Section 5. Generator is 2. The prime is: 2^4096 - 2^4032 - 1 + 2^64 * { [2^3966 pi] + 240904 }

7: 6144-bit MODP Group from RFC3526, Section 6. Generator is 2. The prime is: 2^6144 - 2^6080 - 1 + 2^64 * { [2^6014 pi] + 929484 }

8: 8192-bit MODP Group from RFC3526, Section 7. Generator is 2. The prime is: 2^8192 - 2^8128 - 1 + 2^64 * { [2^8062 pi] + 4743158 }

More Information and Examples
top