|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.logi.crypto.Crypto
org.logi.crypto.keys.K
org.logi.crypto.keys.DHKey
This object holds one Diffie-Hellman key. They can be used for Diffie-Hellman key-exchange with the DHKeyExNoninter and related classes or directly for encryption and signatures, in which case it uses the ElGamal algorithm.
The modulus and generator for the group from which the key is chosen are fixed for a given key-size. They are pre-calculated for a few bit-sizes, but take long to claculate for others.
The CDS for a Diffie-Hellman key is DHKey(x,g,m,pub)
for a public key or DHKey(x,g,m,pri)
for a private
key. In both cases x
,g
and m
are
hexadecimal numbers.
DHKeyExNoninter
Field Summary |
Fields inherited from class org.logi.crypto.keys.K |
fingerprint, otherFingerprint |
Fields inherited from class org.logi.crypto.Crypto |
BIT, cdsPath, EMPTY_ARRAY, FOUR, keySource, NIBBLE, ONE, primeCertainty, random, TWO, ZERO |
Constructor Summary | |
DHKey(java.math.BigInteger x,
java.math.BigInteger g,
java.math.BigInteger m,
boolean pri)
Create a new Diffie-Hellman key object. |
|
DHKey(int n)
Create a random private DHKey with an n
bit modulus. |
Method Summary | |
protected Fingerprint |
calcFingerprint(boolean other,
java.lang.String algorithm)
Calculate the fingerprint for this key or the other in the pair. |
int |
cipherBlockSize()
Returns the size of the blocks that can be decrypted in one call to decrypt(). |
static KeyPair |
createKeys(int n)
Create a pair of public/private keys in a group with an n bit modulo. |
void |
decrypt(byte[] source,
int i,
byte[] dest,
int j)
Decrypt one block of data. |
void |
encrypt(byte[] source,
int i,
byte[] dest,
int j)
Encrypt one block of data. |
boolean |
equals(java.lang.Object o)
Return true iff the two keys are equivalent. |
java.lang.String |
getAlgorithm()
The name of the algorithm is "Diffie-Hellman". |
java.math.BigInteger |
getG()
Return the generator for this key. |
static java.math.BigInteger |
getGenerator(java.math.BigInteger m)
Return a Generator for a modulus group. |
java.math.BigInteger |
getKey()
Return the BigInteger representing this key. |
java.math.BigInteger |
getM()
Return the modulus for this key. |
static java.math.BigInteger |
getModulus(int n)
Return a Diffie-Hellman modulus. |
DHKey |
getPublic()
Return the public key from the pair. |
int |
getSize()
Return the "size" of the key. |
boolean |
isPrivate()
Returns true iff this is a private key. |
boolean |
matches(Key key)
Check if a key mathces this. |
static DHKey |
parseCDS(java.lang.String key)
If "DHKey( key )" is a valid CDS for a DHKey, then DHKey.parseCDS(key) will return the described DHKey object. |
int |
plainBlockSize()
Returns the size of the blocks that can be encrypted in one call to encrypt(). |
Signature |
sign(Fingerprint fp)
Create a signature for a Fingerprint fith a private key. |
int |
signatureSize()
Returns the length of a signature in bytes. |
int |
signBlockSize()
Returns the maximum size in bytes of the fingerprints that can be signed. |
java.lang.String |
toString()
Return a CDS for this key. |
boolean |
verify(Signature s,
Fingerprint fp)
Verify a Signature on a Fingerprint with a public key. |
Methods inherited from class org.logi.crypto.keys.K |
getFingerprint, getFingerprint, hashCode, matchFingerprint, matchFingerprint |
Methods inherited from class org.logi.crypto.Crypto |
binString, binString, equal, equalRelaxed, equalSub, fromHexNibble, fromHexString, fromString, fromString, hexString, hexString, hexString, hexString, hexString, initRandom, initRandom, makeClass, makeInt, makeLong, makeSessionKey, pastSpace, pickBits, pickBits, readBlock, readInt, writeBytes, writeBytes, writeInt |
Methods inherited from class java.lang.Object |
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Methods inherited from interface org.logi.crypto.keys.Key |
getFingerprint, getFingerprint, hashCode, matchFingerprint, matchFingerprint |
Constructor Detail |
public DHKey(java.math.BigInteger x, java.math.BigInteger g, java.math.BigInteger m, boolean pri)
x
in the group modulo m
with generator
g
. It is a private key iff pri is
true
.
public DHKey(int n)
n
bit modulus.
Pre-calcualted modula exist for bit lengths 256, 512, 1024 and 2048. Using these values saves a lot of time and does not weaken the keys.
Method Detail |
public static DHKey parseCDS(java.lang.String key) throws InvalidCDSException
A valid CDS can be created by calling the DHKey.toString() method.
InvalidCDSException
- if the CDS is malformed.Crypto.fromString(String)
public static java.math.BigInteger getModulus(int n)
Return the largest prime p
< 2^n
such
that (p
-1)/2 is prime. This takes a long time unless
n
is one of 256, 512, 1024 or 2048.
The reason for the second constraint on p
is to make
the Discrete-Logarithm problem harder in the group Z_p. In
particular it thwarts the Pholig-Hellman algorithm.
public static java.math.BigInteger getGenerator(java.math.BigInteger m)
Returns the smallest number g
> 1 with
gcd(g
,m-1
)=1.
public static KeyPair createKeys(int n)
n
bit modulo.
Pre-calcualted modula exist for bit lengths 256, 512, 1024 and 2048. Using these values saves a lot of time and does not weaken the keys.
public int getSize()
getSize
in interface Key
public java.lang.String getAlgorithm()
getAlgorithm
in interface Key
public boolean isPrivate()
isPrivate
in interface Key
public DHKey getPublic()
public java.math.BigInteger getKey()
public java.math.BigInteger getM()
public java.math.BigInteger getG()
protected Fingerprint calcFingerprint(boolean other, java.lang.String algorithm) throws InvalidCDSException
calcFingerprint
in class K
InvalidCDSException
public final boolean equals(java.lang.Object o)
public boolean matches(Key key)
matches
in interface Key
public java.lang.String toString()
public int plainBlockSize()
plainBlockSize
in interface CipherKey
public int cipherBlockSize()
cipherBlockSize
in interface CipherKey
public void encrypt(byte[] source, int i, byte[] dest, int j)
source
starting at offset i
and
ciphertext is written to dest
, starting at
offset j
.
The amount of data read and written will match the values returned
by plainBlockSize()
and cipherBlockSize()
.
encrypt
in interface CipherKey
public void decrypt(byte[] source, int i, byte[] dest, int j)
source
starting at offset i
and
plaintext is written to dest
, starting at
offset j
.
The amount of data read and written will match the values returned
by cipherBlockSize()
and plainBlockSize()
.
decrypt
in interface CipherKey
public int signBlockSize()
signBlockSize
in interface SignatureKey
public int signatureSize()
signatureSize
in interface SignatureKey
public Signature sign(Fingerprint fp) throws KeyException
sign
in interface SignatureKey
KeyException
- if the key modulus is shorter than the signature.
KeyException
- if this is not a private keypublic boolean verify(Signature s, Fingerprint fp) throws KeyException
The method returns true iff s
is a signature for
fp
created with the mathcin private key.
verify
in interface SignatureKey
KeyException
- if this is not a public key
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |