class ref name: crypto
category-group: security
layer: 2

synopsis.
"crypto_o" is the base class for a set of encryptors. It forms the base of all ciphers implemented in the Z Directory. The API provides a consistent interface, allowing you to use all ciphers, both symmetric algorithms (eg Nile-crypt, AES, DES) and asymmetic (pair_crypt) in a similar manner.

member functions (primary)

crypto_o()
SIGNATURE: crypto_o ()
SYNOPSIS:
creates a a new crypto_o object. the object's internal variable that identifies the type of cipher the object is, 'my_ID', is set to zcrypno_UNDEFINED.
 

crypto_o(crypto_o)
SIGNATURE: crypto_o (const crypto_o &that)
SYNOPSIS:
creates a a new crypt object. Although this is a copy constructor, this c-tor is a no-op. It is exactly the same as the default constructor.
 

operator = (crypto_o)
SIGNATURE: const crypt &operator = (const crypto_o &rhs)
SYNOPSIS:
This assignment operator is a no-op. It does absolutely nothing. To do a real copy, the object must be a sub-class of crypto_o.
PARAMETERS

  • rhs: [input] the object intended to be copied
  •  

    {dtor}()
    SIGNATURE: ~crypto_o ()
    SYNOPSIS: this does nothing and is a c++ placeholder.
    TRAITS: this function is inline virtual
     

    input_chunksize()
    SIGNATURE: size_t input_chunksize (int *pi = NULL) const
    SYNOPSIS:
    defines the number of bytes that the size of the input string [to be encoded] must be a multiple of. This function is pure virtual, and must be defined in a subclass.
    PARAMETERS

  • pi: [output] error indicator variable
  • RETURNS: [See corresponding API in a sub-class]
    TRAITS: this function is a pure virtual function; hence, the object cannot be instantiated.
     

    output_chunksize()
    SIGNATURE: size_t output_chunksize (int *pi = NULL) const
    SYNOPSIS: the size of the output string will be a multiple of this value.
    PARAMETERS

  • pi: [output] error indicator variable
  • RETURNS: [See corresponding API in a sub-class]
    TRAITS: this function is a pure virtual function; hence, the object cannot be instantiated.
     

    class_ID()
    SIGNATURE: int class_ID () const
    SYNOPSIS:
    returns the Z Directory ID code of the type of cipher class the object is. For the current class (crypto_o), this is zcrypno_UNDEFINED. This is actually set to a real cipher's ID by the constructors of sub-classes:

    • zcrypno_CLEAR - "encrypt" from clear text to clear text. This is basically a no-op non-encryptor. It can be used for testing or learning purposes.
    • zcrypno_ROT13 - implements ROT-13 "encryption", a very elementary encryption algorithm that maps a value to another value. This should *not* be used for any serious encryption needs.
    • zcrypno_COOLHASH
    • zcrypno_NILE - implements "Nile encryption". Little is known about this symmtric cipher.
    • zcrypno_VETTRA - Vettrasoft-proprietary encryption algorithm. [Currently] this is a weak encryptor due to its short password size.
    • zcrypno_DES - implements the basic, standard, plain-vanilla DES (Data Encryption Standard) encryption algorithm. DES is old ('70s) and is considered not secure nowadays.
    • zcrypno_CHAMBERS
    • zcrypno_BLOWFISH - implements Blowfish encryption
    • zcrypno_RSA - implements RSA. This is the only asymmetric cipher [currently] provided.
    • zcrypno_RIJNDAEL - implements Rijndael encryption (AES).

    TRAITS: this function is inline.
     

    set_key()
    SIGNATURE: int set_key (const string_o &s, int *pi = NULL)
    SYNOPSIS: sets the object's key.
    PARAMETERS

    • s: the password to assign to the object
    • pi: [output] error indicator variable. Values:
      0: success
      zcrypERR_BADKEY: the input string format does not conform to the correct syntax
    DESCRIPTION:
    for assymetric ciphers (or any algorithm requiring more than a single password) it is possible to provide multiple keys by using a custom format for input parameter 's'. This depends on the sub-class.
    TRAITS: this function is pure virtual
     

    clone()
    SIGNATURE: crypto_o *clone () const
    SYNOPSIS:
    copies the current object [via new], and provides a pointer to the newly-allocated object. It is the client application's responsibility to delete this object.
    TRAITS: this function is pure virtual
     

    encrypt()
    SIGNATURE: int encrypt (const string_o &sin, string_o &sot, size_t *nb)
    SYNOPSIS:
    this function does the actual encryption. the object must be initialized with a password prior to calling this. the input and output strings should be set to binary mode and the output string should have a pre-allocated buffer set to the appropriate size, big enough to recieve the output (see string_o's functions setmode_binary() and force_size()). The signiture of this API function is set in the base class and is common to all Z Directory encryptors.
     

    decrypt()
    SIGNATURE: int decrypt (const string_o &sin, string_o &sot, size_t *nb)
    SYNOPSIS:
    does the actual decryption. this function is the converse of encrypt(). the object must be initialized with the key (password.