Unit rtcCrypt

Description
Uses
Classes, Interfaces, Objects and Records
Functions and Procedures
Types
Constants
Variables

Description

Encryption Unit - Copyright 2004-2018 (c) Teppi Technology (https://rtc.teppi.net)

This unit provides simple-to-use classes for Random Number Generation, Encryption, Decryption, Asymmetric RSA Key Generation, (De-)Serialization, Digest Hashing, Signing and Verification using EMSA-PKCS#1-v1.5 encoding.

Random Number Generator and RSA Encryption are based on multi-precision integer arithmetic and RSA routines written by W.Ehrhardt, available online at http://www.wolfgang-ehrhardt.de/mp_intro.html

Overview

Classes, Interfaces, Objects and Records

Name Description
Class TRtcCryptObject RTC "Crypt" Object
Class TRtcCrypt  
Class ERtcRSA  
Class TRtcISAAC ISAAC Random Numbers Generator
Class TRtcRSA Asymmetric "RSA" Encryption/Decryption
Class TRtcISAACrypt RTC Encryption with ISAAC random numbers

Functions and Procedures

function SHA1_Digest(const M: RtcByteArray):RtcByteArray; overload;
function SHA1_Digest(const M: RtcString):RtcString; overload;
function MD5Code4Bit(const M: RtcString):RtcString;
function MD5Code5bit(const M: RtcString):RtcString;
function MD5Code6bit(const M: RtcString):RtcString;
function MD5Code8bit(const M: RtcString):RtcString;
function rtcGenerateKey(const Prefix:RtcString; RndLen:integer; Big:boolean):RtcString;
function rtcCalculateLock(const Key: RtcString): RtcString;
function rtcMakePublicKey(const Prefix:RtcString):RtcString;
function rtcKeyPublic(const Key: RtcString):boolean;
function rtcKeyValid(const Key: RtcString):boolean;
function rtcLockValid(const Lock: RtcString):boolean;
function rtcKeyLockMatch(const Key,Lock:RtcString):boolean;
function rtcKeyMD5Code8BitLockMatch(const Key,MD5Code8BitLock:RtcString):boolean;
procedure Crypt(var s:RtcString; const key:RtcString);
procedure DeCrypt(var s:RtcString; const key:RtcString);
procedure CryptEx(var s:RtcByteArray; const key:RtcByteArray);
procedure DeCryptEx(var s:RtcByteArray; const key:RtcByteArray);

Types

RtcHashType = (...);

Constants

MAX_RTCKEYLOCK_LENGTH = 26*3+1;
LengthOfMD5Code4Bit = 32;
LengthOfMD5Code5Bit = 26;
LengthOfMD5Code6Bit = 22;
LengthOfMD5Code8Bit = 16;
LengthOfSHA1Digest = 20;

Description

Functions and Procedures

function SHA1_Digest(const M: RtcByteArray):RtcByteArray; overload;

Create a SHA-1 hash digest (length=20) from "M"

function SHA1_Digest(const M: RtcString):RtcString; overload;

Create a SHA-1 hash digest (length=20) from "M"

function MD5Code4Bit(const M: RtcString):RtcString;

Create a standard MD5 hash digest (length=32) from "M", encoded using 4 bits per character ('0'-'9' and 'a'-'f')

function MD5Code5bit(const M: RtcString):RtcString;

Create a 5bit-coded MD5 hash digest (length=26) from "M", safe for use in HTML and URLs (only contains alpha-numerics), encoded using 5 bits per character ('0'-'9' and 'a'-'z')

function MD5Code6bit(const M: RtcString):RtcString;

Create a 6bit-coded MD5 hash digest (length=22) from "M", safe for use in HTML and URLs (does not contain reserved HTML characters) but NOT safe for use in File names (case sensitive), encoded using 6 bits per character ('0'-'9', 'a'-'z', 'A'-'Z', '@' and '$')

function MD5Code8bit(const M: RtcString):RtcString;

Create a Binary-coded MD5 hash digest (length=16) from "M", encoded using 8 bits per character (#0 - #255)

function rtcGenerateKey(const Prefix:RtcString; RndLen:integer; Big:boolean):RtcString;

Generate a New, Unique Key. RndLen = number of random characters to generate for "salt"; if 0, "salt" will NOT be used and the Key will be smaller. Prefix = prefix to use as part of the main key and "salt". Big = if TRUE, returns a bigger Key using 2 GUIDs (79 or 53 characters); if FALSE, returns a smaller Key using 1 GUID (53 or 27 chars). Result = Key starting with "K" and containing the Key code (0..9, A..Z).

NOTE: Except for the starting "K" character in the Key and "L" character in the "Lock" code, the Key and Lock codes do NOT contain any other instances of "K" or "L" characters. This makes it possible to concatenate multiple Keys and Locks into a single string ready for transfer and storage, without using additional "envelopes" or formats.

function rtcCalculateLock(const Key: RtcString): RtcString;

Calculate Lock from Key. Key = Key containing the code generated using "rtcGenerateKey". Result = Lock starting with "L" and containing the Lock code (0..9, A..Z)

function rtcMakePublicKey(const Prefix:RtcString):RtcString;

Calculate a Public Key from a Prefix (free text), which can be used by all Clients as a Public Channel (for example: "Lobby"). Public Keys do NOT have a "Lock", they are exactly 26 characters long and do NOT contain any instances of "K" or "L" characters. Public Keys do NOT contain random charactes, but are calculated to always generate the exact same "Key" from the same "Prefix".

function rtcKeyPublic(const Key: RtcString):boolean;

Is this a PUBLIC Key (not used with a Lock) ?

function rtcKeyValid(const Key: RtcString):boolean;

Is "Key" valid (could have been generated by rtcGenerateKey or rtcMakePublicKey)?

function rtcLockValid(const Lock: RtcString):boolean;

Is "Lock" valid (could have been generated by rtcCalculateLock)?

function rtcKeyLockMatch(const Key,Lock:RtcString):boolean;

Does the "Key" match the "Lock"?

function rtcKeyMD5Code8BitLockMatch(const Key,MD5Code8BitLock:RtcString):boolean;

Does the "Key" match a MD5Code8Bit encoded "Lock"?

procedure Crypt(var s:RtcString; const key:RtcString);
 
procedure DeCrypt(var s:RtcString; const key:RtcString);
 
procedure CryptEx(var s:RtcByteArray; const key:RtcByteArray);
 
procedure DeCryptEx(var s:RtcByteArray; const key:RtcByteArray);
 

Types

RtcHashType = (...);

Valid hash algorithms for RSA signature schemes. Only the hash digests and algorithm identifiers are used, not the actual hash functions, i.e. the digests have to be calculated externally.

Values
  • rtch_MD2: 16-byte MD2 Hash
  • rtch_MD5: 16-byte MD5 Hash
  • rtch_RMD160: 20-byte RMD160 Hash
  • rtch_SHA1: 20-byte SHA1 Hash
  • rtch_SHA224: 28-byte SHA224 Hash
  • rtch_SHA256: 32-byte SHA256 Hash
  • rtch_SHA384: 48-Byte SHA384 Hash
  • rtch_SHA512: 64-Byte SHA512 Hash
  • rtch_Custom: Custom Hash (NO Hash Type Header injected)

Constants

MAX_RTCKEYLOCK_LENGTH = 26*3+1;

{$IFNDEF RTC_NORSA}

LengthOfMD5Code4Bit = 32;
 
LengthOfMD5Code5Bit = 26;
 
LengthOfMD5Code6Bit = 22;
 
LengthOfMD5Code8Bit = 16;
 
LengthOfSHA1Digest = 20;
 

Generated by PasDoc 0.14.0.