Class YYcrypto

java.lang.Object
  extended by YYcrypto

public final class YYcrypto
extends java.lang.Object


Field Summary
static java.math.BigInteger BIGG
           
static java.math.BigInteger BIGGPOW2ONEQUARTER
           
static java.math.BigInteger BIGGPOW2THREEQUARTERS
           
static java.math.BigInteger BIGGPOW2TWOQUARTERS
           
static java.math.BigInteger BIGGTOPOWEROF2
           
static java.math.BigInteger BIGP
           
static int ELGAMAL_EMBED_LEN
           
static int ELGAMAL_PTEXT_LEN
           
static int EMBED_TIMESTAMP_LEN
           
static int MIN_PASSWORD_LEN
           
static java.math.BigInteger POWEROF2
           
static java.math.BigInteger POWEROF2QUARTER
           
static int PRIVATE_KEY_LEN
           
static int PUBLIC_KEY_LEN
           
static int RERAND_CTEXT_LEN
           
 
Method Summary
static int computeJacobiSymbol(java.math.BigInteger a, java.math.BigInteger p)
           
static java.math.BigInteger elgamalEmbed(ByteArray inarr, YYrandom yyrandomobj)
          elgamalEmbed() is a probabilistic algorithm that encodes a plaintext and a fixed 4 byte identifier into an element of the prime order subgroup of Zp* having order q, the return value.
static java.math.BigInteger elgamalEncode(ByteArray inarr, YYrandom yyrandomobj)
          elgamalEncode() is a probabilistic algorithm that encodes a plaintext into an element of the prime order subgroup of Zp* having order q, the return value.
static ElGEmbedDecode elgamalUnembed(java.math.BigInteger h)
          If the expected embedded 4 byte identifier is not found then a proper plaintext is not returned.
static Elgamalkeypair generateElGamalKeyPair(boolean strongentropy, YYrandom yyrandomobj)
           
static java.math.BigInteger genRandomExponent(YYrandom yyrandomobj, boolean strongentropy)
           
static java.math.BigInteger getlowerhalf(java.math.BigInteger exp)
          This function supports ElGamal re-encryption in the yyrerandtrans instruction.
static java.math.BigInteger getlowermiddlequarter(java.math.BigInteger exp)
           
static java.math.BigInteger getlowerquarter(java.math.BigInteger exp)
           
static java.math.BigInteger getupperhalf(java.math.BigInteger exp)
          This function supports ElGamal re-encryption in the yyrerandtrans instruction.
static java.math.BigInteger getuppermiddlequarter(java.math.BigInteger exp)
           
static java.math.BigInteger getupperquarter(java.math.BigInteger exp)
           
static Hybridptext hybridDecrypt(ByteArray ciphertext, java.math.BigInteger invAtoX, YYrandom yyrandomobj)
           
static Hybridptext hybridDecrypt(ByteArray ciphertext, ByteArray privkey, YYrandom yyrandomobj, long millisec)
           
static Hybridctext hybridEncrypt(ByteArray plaintext, java.math.BigInteger parta, java.math.BigInteger partb, YYrandom yyrandomobj)
          Here (parta,partb) = (g^k,y^k) for random exponent k.
static Hybridctext hybridEncryptNoPrecomputation(ByteArray plaintext, ByteArray pubkey, YYrandom yyrandomobj)
           
static boolean isValidElGamalKeyPair(ByteArray pubkey, ByteArray privkey)
           
static boolean isValidPublicKey(ByteArray pubkey)
          Verifies that the public key pubkey is valid.
static void main(java.lang.String[] args)
           
static ByteArray md5(ByteArray input)
           
static java.math.BigInteger modexp(java.math.BigInteger base, java.math.BigInteger exp, java.math.BigInteger modulus)
           
static Pbdecres passwordBasedDecrypt(ByteArray ciphertext, java.lang.String password)
           
static ByteArray passwordBasedEncrypt(ByteArray plaintext, java.lang.String password, YYrandom yyrandomobj)
           
static boolean passwordIsValid(java.lang.String password)
           
static ByteArray passwordToBlowfishKey(java.lang.String password, ByteArray salt)
           
static Elgamalptext rerandDecrypt(ByteArray privkey, ByteArray ctext, YYrandom yyrandomobj, long millisec)
           
static Rerandelgamalctext rerandEncrypt(ByteArray pubkey, ByteArray ptext, YYrandom yyrandomobj)
           
static Rerandelgamalctext rerandrsaEncrypt(ByteArray pubkey, ByteArray ptext, YYrandom yyrandomobj)
           
static long timeelgamaldecryption(YYrandom yyrandomobj)
           
static ByteArray xteastreamdecipher(ByteArray ctext, ByteArray key)
           
static ByteArray xteastreamencipher(ByteArray ptext, ByteArray key, YYrandom yyrandomobj)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BIGP

public static final java.math.BigInteger BIGP

BIGG

public static final java.math.BigInteger BIGG

ELGAMAL_PTEXT_LEN

public static final int ELGAMAL_PTEXT_LEN
See Also:
Constant Field Values

PRIVATE_KEY_LEN

public static final int PRIVATE_KEY_LEN
See Also:
Constant Field Values

PUBLIC_KEY_LEN

public static final int PUBLIC_KEY_LEN
See Also:
Constant Field Values

RERAND_CTEXT_LEN

public static final int RERAND_CTEXT_LEN
See Also:
Constant Field Values

MIN_PASSWORD_LEN

public static final int MIN_PASSWORD_LEN
See Also:
Constant Field Values

EMBED_TIMESTAMP_LEN

public static final int EMBED_TIMESTAMP_LEN
See Also:
Constant Field Values

ELGAMAL_EMBED_LEN

public static final int ELGAMAL_EMBED_LEN
See Also:
Constant Field Values

POWEROF2

public static final java.math.BigInteger POWEROF2

POWEROF2QUARTER

public static final java.math.BigInteger POWEROF2QUARTER

BIGGPOW2ONEQUARTER

public static final java.math.BigInteger BIGGPOW2ONEQUARTER

BIGGPOW2TWOQUARTERS

public static final java.math.BigInteger BIGGPOW2TWOQUARTERS

BIGGPOW2THREEQUARTERS

public static final java.math.BigInteger BIGGPOW2THREEQUARTERS

BIGGTOPOWEROF2

public static final java.math.BigInteger BIGGTOPOWEROF2
Method Detail

modexp

public static java.math.BigInteger modexp(java.math.BigInteger base,
                                          java.math.BigInteger exp,
                                          java.math.BigInteger modulus)

getupperhalf

public static java.math.BigInteger getupperhalf(java.math.BigInteger exp)
                                         throws FeralcoreException
This function supports ElGamal re-encryption in the yyrerandtrans instruction. It is used to spread the computation of the modular exponentiation with the 4096-bit exponent out across multiple instruction execution cycles.

Throws:
FeralcoreException

getlowerhalf

public static java.math.BigInteger getlowerhalf(java.math.BigInteger exp)
                                         throws FeralcoreException
This function supports ElGamal re-encryption in the yyrerandtrans instruction. It is used to spread the computation of the modular exponentiation with the 4096-bit exponent out across multiple instruction execution cycles.

Throws:
FeralcoreException

getlowerquarter

public static java.math.BigInteger getlowerquarter(java.math.BigInteger exp)
                                            throws FeralcoreException
Throws:
FeralcoreException

getlowermiddlequarter

public static java.math.BigInteger getlowermiddlequarter(java.math.BigInteger exp)
                                                  throws FeralcoreException
Throws:
FeralcoreException

getuppermiddlequarter

public static java.math.BigInteger getuppermiddlequarter(java.math.BigInteger exp)
                                                  throws FeralcoreException
Throws:
FeralcoreException

getupperquarter

public static java.math.BigInteger getupperquarter(java.math.BigInteger exp)
                                            throws FeralcoreException
Throws:
FeralcoreException

isValidPublicKey

public static boolean isValidPublicKey(ByteArray pubkey)
                                throws FeralcoreException
Verifies that the public key pubkey is valid. It must have a specific length in bytes. It must be in the set of positive integers less than p and it must be in the prime order subgroup of Z_p^* of order q.

Throws:
FeralcoreException

hybridEncryptNoPrecomputation

public static Hybridctext hybridEncryptNoPrecomputation(ByteArray plaintext,
                                                        ByteArray pubkey,
                                                        YYrandom yyrandomobj)
                                                 throws FeralcoreException,
                                                        java.security.NoSuchAlgorithmException,
                                                        javax.crypto.NoSuchPaddingException,
                                                        java.security.InvalidKeyException,
                                                        javax.crypto.IllegalBlockSizeException,
                                                        javax.crypto.BadPaddingException,
                                                        java.io.FileNotFoundException,
                                                        java.io.IOException,
                                                        java.lang.InterruptedException,
                                                        java.lang.CloneNotSupportedException
Throws:
FeralcoreException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
java.io.FileNotFoundException
java.io.IOException
java.lang.InterruptedException
java.lang.CloneNotSupportedException

hybridEncrypt

public static Hybridctext hybridEncrypt(ByteArray plaintext,
                                        java.math.BigInteger parta,
                                        java.math.BigInteger partb,
                                        YYrandom yyrandomobj)
                                 throws FeralcoreException,
                                        java.security.NoSuchAlgorithmException,
                                        javax.crypto.NoSuchPaddingException,
                                        java.security.InvalidKeyException,
                                        javax.crypto.IllegalBlockSizeException,
                                        javax.crypto.BadPaddingException,
                                        java.io.FileNotFoundException,
                                        java.io.IOException,
                                        java.lang.InterruptedException,
                                        java.lang.CloneNotSupportedException
Here (parta,partb) = (g^k,y^k) for random exponent k. This is part of an ElGamal encryption operation.

Throws:
FeralcoreException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
java.io.FileNotFoundException
java.io.IOException
java.lang.InterruptedException
java.lang.CloneNotSupportedException

hybridDecrypt

public static Hybridptext hybridDecrypt(ByteArray ciphertext,
                                        java.math.BigInteger invAtoX,
                                        YYrandom yyrandomobj)
                                 throws FeralcoreException,
                                        java.security.NoSuchAlgorithmException,
                                        javax.crypto.NoSuchPaddingException,
                                        java.security.InvalidKeyException,
                                        java.io.FileNotFoundException,
                                        java.io.IOException,
                                        java.lang.InterruptedException,
                                        javax.crypto.IllegalBlockSizeException,
                                        javax.crypto.BadPaddingException
Throws:
FeralcoreException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
java.io.FileNotFoundException
java.io.IOException
java.lang.InterruptedException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException

hybridDecrypt

public static Hybridptext hybridDecrypt(ByteArray ciphertext,
                                        ByteArray privkey,
                                        YYrandom yyrandomobj,
                                        long millisec)
                                 throws FeralcoreException,
                                        java.security.NoSuchAlgorithmException,
                                        javax.crypto.NoSuchPaddingException,
                                        java.security.InvalidKeyException,
                                        java.io.FileNotFoundException,
                                        java.io.IOException,
                                        java.lang.InterruptedException,
                                        javax.crypto.IllegalBlockSizeException,
                                        javax.crypto.BadPaddingException
Throws:
FeralcoreException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
java.io.FileNotFoundException
java.io.IOException
java.lang.InterruptedException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException

passwordBasedEncrypt

public static ByteArray passwordBasedEncrypt(ByteArray plaintext,
                                             java.lang.String password,
                                             YYrandom yyrandomobj)
                                      throws FeralcoreException,
                                             java.security.NoSuchAlgorithmException,
                                             javax.crypto.NoSuchPaddingException,
                                             java.security.InvalidKeyException,
                                             javax.crypto.IllegalBlockSizeException,
                                             javax.crypto.BadPaddingException,
                                             java.io.FileNotFoundException,
                                             java.io.IOException,
                                             java.security.spec.InvalidKeySpecException,
                                             java.lang.CloneNotSupportedException
Throws:
FeralcoreException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
java.io.FileNotFoundException
java.io.IOException
java.security.spec.InvalidKeySpecException
java.lang.CloneNotSupportedException

passwordBasedDecrypt

public static Pbdecres passwordBasedDecrypt(ByteArray ciphertext,
                                            java.lang.String password)
                                     throws FeralcoreException,
                                            java.security.NoSuchAlgorithmException,
                                            javax.crypto.NoSuchPaddingException,
                                            java.security.InvalidKeyException,
                                            java.security.spec.InvalidKeySpecException,
                                            javax.crypto.IllegalBlockSizeException,
                                            javax.crypto.BadPaddingException
Throws:
FeralcoreException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
java.security.spec.InvalidKeySpecException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException

passwordIsValid

public static boolean passwordIsValid(java.lang.String password)

passwordToBlowfishKey

public static ByteArray passwordToBlowfishKey(java.lang.String password,
                                              ByteArray salt)
                                       throws FeralcoreException,
                                              java.security.NoSuchAlgorithmException,
                                              java.security.spec.InvalidKeySpecException
Throws:
FeralcoreException
java.security.NoSuchAlgorithmException
java.security.spec.InvalidKeySpecException

elgamalEmbed

public static java.math.BigInteger elgamalEmbed(ByteArray inarr,
                                                YYrandom yyrandomobj)
                                         throws FeralcoreException,
                                                java.io.FileNotFoundException,
                                                java.io.IOException,
                                                java.security.NoSuchAlgorithmException
elgamalEmbed() is a probabilistic algorithm that encodes a plaintext and a fixed 4 byte identifier into an element of the prime order subgroup of Zp* having order q, the return value. This encoder is needed since not all (4096/8)-byte arrays are elements of this subgroup (when viewed as unsigned integers in binary). A timestamp is used instead of a nonce since it serves the same purpose: allowing a proper ElGamal plaintext in the prime order subgroup to be found and it also does two things: (1) mitigates replay attacks since freshness is checked, and (2) is nice and small, maximizing the bit length of the RSA public key.

Throws:
FeralcoreException
java.io.FileNotFoundException
java.io.IOException
java.security.NoSuchAlgorithmException

elgamalUnembed

public static ElGEmbedDecode elgamalUnembed(java.math.BigInteger h)
                                     throws java.security.NoSuchAlgorithmException,
                                            FeralcoreException
If the expected embedded 4 byte identifier is not found then a proper plaintext is not returned.

Throws:
java.security.NoSuchAlgorithmException
FeralcoreException

elgamalEncode

public static java.math.BigInteger elgamalEncode(ByteArray inarr,
                                                 YYrandom yyrandomobj)
                                          throws FeralcoreException,
                                                 java.io.FileNotFoundException,
                                                 java.io.IOException,
                                                 java.security.NoSuchAlgorithmException
elgamalEncode() is a probabilistic algorithm that encodes a plaintext into an element of the prime order subgroup of Zp* having order q, the return value. This encoder is needed since not all (4096/8)-byte arrays are elements of this subgroup (when viewed as unsigned integers in binary).

Throws:
FeralcoreException
java.io.FileNotFoundException
java.io.IOException
java.security.NoSuchAlgorithmException

md5

public static ByteArray md5(ByteArray input)
                     throws java.security.NoSuchAlgorithmException
Throws:
java.security.NoSuchAlgorithmException

isValidElGamalKeyPair

public static boolean isValidElGamalKeyPair(ByteArray pubkey,
                                            ByteArray privkey)

genRandomExponent

public static java.math.BigInteger genRandomExponent(YYrandom yyrandomobj,
                                                     boolean strongentropy)
                                              throws FeralcoreException,
                                                     java.io.FileNotFoundException,
                                                     java.io.IOException,
                                                     java.io.FileNotFoundException,
                                                     java.io.IOException,
                                                     java.lang.InterruptedException,
                                                     java.lang.CloneNotSupportedException
Throws:
FeralcoreException
java.io.FileNotFoundException
java.io.IOException
java.lang.InterruptedException
java.lang.CloneNotSupportedException

rerandDecrypt

public static Elgamalptext rerandDecrypt(ByteArray privkey,
                                         ByteArray ctext,
                                         YYrandom yyrandomobj,
                                         long millisec)
                                  throws FeralcoreException,
                                         java.io.FileNotFoundException,
                                         java.io.IOException,
                                         java.security.NoSuchAlgorithmException,
                                         java.lang.InterruptedException
Throws:
FeralcoreException
java.io.FileNotFoundException
java.io.IOException
java.security.NoSuchAlgorithmException
java.lang.InterruptedException

rerandrsaEncrypt

public static Rerandelgamalctext rerandrsaEncrypt(ByteArray pubkey,
                                                  ByteArray ptext,
                                                  YYrandom yyrandomobj)
                                           throws FeralcoreException,
                                                  java.io.FileNotFoundException,
                                                  java.io.IOException,
                                                  java.security.NoSuchAlgorithmException,
                                                  java.lang.InterruptedException,
                                                  java.lang.CloneNotSupportedException
Throws:
FeralcoreException
java.io.FileNotFoundException
java.io.IOException
java.security.NoSuchAlgorithmException
java.lang.InterruptedException
java.lang.CloneNotSupportedException

rerandEncrypt

public static Rerandelgamalctext rerandEncrypt(ByteArray pubkey,
                                               ByteArray ptext,
                                               YYrandom yyrandomobj)
                                        throws FeralcoreException,
                                               java.io.FileNotFoundException,
                                               java.io.IOException,
                                               java.security.NoSuchAlgorithmException,
                                               java.lang.InterruptedException,
                                               java.lang.CloneNotSupportedException
Throws:
FeralcoreException
java.io.FileNotFoundException
java.io.IOException
java.security.NoSuchAlgorithmException
java.lang.InterruptedException
java.lang.CloneNotSupportedException

generateElGamalKeyPair

public static Elgamalkeypair generateElGamalKeyPair(boolean strongentropy,
                                                    YYrandom yyrandomobj)
                                             throws FeralcoreException,
                                                    java.io.FileNotFoundException,
                                                    java.io.IOException,
                                                    java.lang.InterruptedException,
                                                    java.lang.CloneNotSupportedException
Throws:
FeralcoreException
java.io.FileNotFoundException
java.io.IOException
java.lang.InterruptedException
java.lang.CloneNotSupportedException

timeelgamaldecryption

public static long timeelgamaldecryption(YYrandom yyrandomobj)
                                  throws FeralcoreException,
                                         java.io.FileNotFoundException,
                                         java.io.IOException,
                                         java.lang.InterruptedException,
                                         java.lang.CloneNotSupportedException
Throws:
FeralcoreException
java.io.FileNotFoundException
java.io.IOException
java.lang.InterruptedException
java.lang.CloneNotSupportedException

computeJacobiSymbol

public static int computeJacobiSymbol(java.math.BigInteger a,
                                      java.math.BigInteger p)
                               throws FeralcoreException
Throws:
FeralcoreException

xteastreamencipher

public static ByteArray xteastreamencipher(ByteArray ptext,
                                           ByteArray key,
                                           YYrandom yyrandomobj)
                                    throws FeralcoreException,
                                           java.io.FileNotFoundException,
                                           java.io.IOException
Throws:
FeralcoreException
java.io.FileNotFoundException
java.io.IOException

xteastreamdecipher

public static ByteArray xteastreamdecipher(ByteArray ctext,
                                           ByteArray key)
                                    throws FeralcoreException
Throws:
FeralcoreException

main

public static void main(java.lang.String[] args)
                 throws FeralcoreException,
                        java.security.NoSuchAlgorithmException,
                        javax.crypto.NoSuchPaddingException,
                        java.security.InvalidKeyException,
                        javax.crypto.IllegalBlockSizeException,
                        javax.crypto.BadPaddingException,
                        java.io.FileNotFoundException,
                        java.io.IOException,
                        java.security.spec.InvalidKeySpecException,
                        java.lang.InterruptedException,
                        java.lang.CloneNotSupportedException
Throws:
FeralcoreException
java.security.NoSuchAlgorithmException
javax.crypto.NoSuchPaddingException
java.security.InvalidKeyException
javax.crypto.IllegalBlockSizeException
javax.crypto.BadPaddingException
java.io.FileNotFoundException
java.io.IOException
java.security.spec.InvalidKeySpecException
java.lang.InterruptedException
java.lang.CloneNotSupportedException