All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class is.hi.logir.cryptonite.Cryptonite

java.lang.Object
   |
   +----is.hi.logir.cryptonite.Cryptonite

public abstract class Cryptonite
extends Object
This class contains numerous static and final utility functions along with global variables for the Cryptonite package.

Author:
Logi Ragnarsson (logir@hi.is)

Variable Index

 o BIT
The binary digits "0" and "1".
 o keySource
The object used to store and retrieve keys.
 o NIBBLE
The hexadecimal digits "0" through "f".
 o primeCertainty
We allow a chance of 0.5**primeCertainty chance that the primes we generate are in fact composite numbers.
 o random
random is used by descendants of this class to generate random numbers.

Constructor Index

 o Cryptonite()

Method Index

 o binString(int)
Return the content of a as a string of binary digits.
 o binString(long)
Return the content of a as a string of binary digits.
 o equal(byte[], byte[])
Return true iff the two array contain the same bytes.
 o equalRelaxed(byte[], byte[])
Return true iff the two arrays contain the same data, except possibly any number of zeroes from the front.
 o fromHexNibble(char)
Return te number choresponding to the four-bix hexadecimal nibble in n.
 o fromHexString(String)
Return the array of bytes describet by the hexadecimal string hex.
 o fromString(Reader)
Parse the given Cipher Description String (CDS).
 o fromString(String)
Parse the given Cipher Description String (CDS).
 o hexString(byte)
Return the content of a as a string of hexadecimal digits.
 o hexString(byte[])
Return the content of buf as a string of hexadecimal digits.
 o hexString(int)
Return the content of a as a string of hexadecimal digits.
 o hexString(long)
Return the content of a as a string of hexadecimal digits.
 o makeLong(byte[], int, int)
Collect the bits from buf[i..i+length-1] into a long.
 o makeSessionKey(String, byte[])
 o pastSpace(Reader)
Read characters from t until a non-space character is reached and return that character.
 o pickBits(int, byte[])
Construct an int by picking bits from a.
 o pickBits(long, byte[])
Construct an long by picking bits from a.
 o prettyCDS(String)
Returns a nicely formated version of the CDS.
 o readInt(InputStream)
Read an integer from in in bigendian order.
 o writeBytes(long, byte[], int, int)
Write the bytes from a into dest[i..i+length-1].
 o writeInt(OutputStream, int)
Write x to out in bigendian order.

Variables

 o random
 public static Random random
random is used by descendants of this class to generate random numbers. It should be a cryptographically secure random number generator, preferably without any period, which rules out all generators based on iterated functions, such as java.util.Random.

If the file /dev/random exists, random is initialized set an instance of the RandomFromReader class which read that file. Otherwise it is initialized to an instance of the RandomSpinner class.

See Also:
RandomSpinner, RandomFromReader
 o primeCertainty
 public static int primeCertainty
We allow a chance of 0.5**primeCertainty chance that the primes we generate are in fact composite numbers.

The default value of 32 will give a false prime less than once in every 4,000,000,000 tries.

 o keySource
 public static KeySource keySource
The object used to store and retrieve keys. It is used by the lookup(fingerprint) CDS.

 o NIBBLE
 public static char NIBBLE[]
The hexadecimal digits "0" through "f".

 o BIT
 public static char BIT[]
The binary digits "0" and "1".

Constructors

 o Cryptonite
 public Cryptonite()

Methods

 o makeLong
 public static final long makeLong(byte buf[],
                                   int i,
                                   int length)
Collect the bits from buf[i..i+length-1] into a long.

 o writeBytes
 public static final void writeBytes(long a,
                                     byte dest[],
                                     int i,
                                     int length)
Write the bytes from a into dest[i..i+length-1].

 o pickBits
 public static final int pickBits(int a,
                                  byte bits[])
Construct an int by picking bits from a. The number in bits[i] is the index of the bit within a that should be put at index i in the result.

The most-significant bit is number 0.

 o pickBits
 public static final long pickBits(long a,
                                   byte bits[])
Construct an long by picking bits from a. The number in bits[i] is the index of the bit within a that should be put at index i in the result.

The most-significant bit is number 0.

 o hexString
 public static final String hexString(byte buf[])
Return the content of buf as a string of hexadecimal digits.

 o hexString
 public static final String hexString(long a)
Return the content of a as a string of hexadecimal digits.

 o hexString
 public static final String hexString(int a)
Return the content of a as a string of hexadecimal digits.

 o hexString
 public static final String hexString(byte a)
Return the content of a as a string of hexadecimal digits.

 o fromHexNibble
 public static byte fromHexNibble(char n)
Return te number choresponding to the four-bix hexadecimal nibble in n.

 o fromHexString
 public static byte[] fromHexString(String hex)
Return the array of bytes describet by the hexadecimal string hex.

 o binString
 public static final String binString(long a)
Return the content of a as a string of binary digits.

 o binString
 public static final String binString(int a)
Return the content of a as a string of binary digits.

 o equal
 public static boolean equal(byte a[],
                             byte b[])
Return true iff the two array contain the same bytes.

 o equalRelaxed
 public static boolean equalRelaxed(byte a[],
                                    byte b[])
Return true iff the two arrays contain the same data, except possibly any number of zeroes from the front.

 o writeInt
 public static final void writeInt(OutputStream out,
                                   int x) throws IOException
Write x to out in bigendian order.

 o readInt
 public static final int readInt(InputStream in) throws IOException
Read an integer from in in bigendian order.

 o makeSessionKey
 public static CipherKey makeSessionKey(String keyType,
                                        byte bits[]) throws InvalidCDSException
 o pastSpace
 public static int pastSpace(Reader r) throws IOException
Read characters from t until a non-space character is reached and return that character.

 o fromString
 public static Object fromString(Reader cds) throws InvalidCDSException, IOException
Parse the given Cipher Description String (CDS). This method can be used to parse a CDS such as that returned by the Cryptonitie toString() methods and return the described object.

The CDS syntax is one of:

ClassName is the name of a class to generate. By default the string "is.hi.logir.cryptonite." is prepended to the class name and an instance created with the ClassName(String) constructor. See the documentation for various classes for details.

The lookup(fingerprint) CDS assumes fingerprint to be a CDS for a Fingerprint object. It then looks up the key with the specified fingerprint in the keySource.

This method may throw exceptions with very long, nested explanations if an exception occurs in a sub-CDS.

Throws: IOException
if an error occured reading characers from in
Throws: InvalidCDSException
if the CDS is in some way malformed.
See Also:
keySource
 o fromString
 public static Object fromString(String cds) throws InvalidCDSException
Parse the given Cipher Description String (CDS).

Throws: InvalidCDSException
if the CDS is in some way malformed.
 o prettyCDS
 public static String prettyCDS(String cds)
Returns a nicely formated version of the CDS. (not yet implemented)


All Packages  Class Hierarchy  This Package  Previous  Next  Index