Dh Delphi DLL Reference Documentation

Dh

Current Version: 9.5.0.73

Diffie-Hellman key-exchange component.

Diffie-Hellman (D-H) key exchange is a cryptographic protocol that allows two parties that have no prior knowledge of each other to jointly establish a shared secret key over an insecure communications channel. This key can then be used to encrypt subsequent communications using a symmetric key cipher.

Synonyms of Diffie-Hellman key exchange include:

  • Diffie-Hellman key agreement
  • Diffie-Hellman key establishment
  • Diffie-Hellman key negotiation
  • exponential key exchange

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, causes each Chilkat method or property call to automatically append it's LastErrorText to the specified log file. The information is appended such that if a hang or crash occurs, it is possible to see the context in which the problem occurred, as well as a history of all Chilkat calls up to the point of the problem. The VerboseLogging property can be set to provide more detailed information.

This property is typically used for debugging the rare cases where a Chilkat method call hangs or generates an exception that halts program execution (i.e. crashes). A hang or crash should generally never happen. The typical causes of a hang are:

  1. a timeout related property was set to 0 to explicitly indicate that an infinite timeout is desired,
  2. the hang is actually a hang within an event callback (i.e. it is a hang within the application code), or
  3. there is an internal problem (bug) in the Chilkat code that causes the hang.

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 information in HTML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

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

Provides information in plain-text format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

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

Provides information in XML format about the last method/property called. If a method call returns a value indicating failure, or behaves unexpectedly, examine this property to get more information.

top
LastMethodSuccess
function CkDh_getLastMethodSuccess(objHandle: HCkDh): wordbool; stdcall;
procedure CkDh_putLastMethodSuccess(objHandle: HCkDh; newPropVal: wordbool); stdcall;
Introduced in version 9.5.0.52

Indicate whether the last method call succeeded or failed. A value of True indicates success, a value of False indicates failure. This property is automatically set for method calls. It is not modified by property accesses. The property is automatically set to indicate success for the following types of method calls:

  • Any method that returns a string.
  • Any method returning a Chilkat object, binary bytes, or a date/time.
  • Any method returning a standard boolean status value where success = True and failure = False.
  • Any method returning an integer where failure is defined by a return value less than zero.

Note: Methods that do not fit the above requirements will always set this property equal to True. For example, a method that returns no value (such as a "void" in C++) will technically always succeed.

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.

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 "9.5.0.63"

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.

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.

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
SaveLastError
function CkDh_SaveLastError(objHandle: HCkDh;
    path: PWideChar): wordbool; stdcall;

Saves the last-error information (the contents of LastErrorXml) to an XML formatted file.

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
UnlockComponent
function CkDh_UnlockComponent(objHandle: HCkDh;
    unlockCode: PWideChar): wordbool; stdcall;

Unlocks the component. This must be called once prior to calling any other method. A fully-functional 30-day trial is automatically started when an arbitrary string is passed to this method. For example, passing "Hello", or "abc123" will unlock the component for the 1st thirty days after the initial install.

Returns True for success, False for failure.

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