public final class ElGamalAESEngine extends Object
| Modifier and Type | Field and Description |
|---|---|
static int | MAX_TAGS_RECEIVEDenforced since release 0.6 |
| Constructor and Description |
|---|
ElGamalAESEngine(I2PAppContext ctx)Creates engine with given context and initializes crypto frequency stats. |
| Modifier and Type | Method and Description |
|---|---|
byte[] | decrypt(byte[] data,
PrivateKey targetPrivateKey,
SessionKeyManager keyManager)Decrypt the message using the given private key
and using tags from the specified key manager. |
(package private) byte[] | decryptAESBlock(byte[] encrypted,
int offset,
int encryptedLen,
SessionKey key,
byte[] iv,
byte[] sentTag,
Set<SessionTag> foundTags,
SessionKey foundKey)Decrypt the AES data with the session key and IV. |
byte[] | decryptFast(byte[] data,
PrivateKey targetPrivateKey,
SessionKeyManager keyManager)Tags only. |
byte[] | decryptSlow(byte[] data,
PrivateKey targetPrivateKey,
SessionKeyManager keyManager)Full ElG only. |
byte[] | encrypt(byte[] data,
PublicKey target,
SessionKey key,
Set<SessionTag> tagsForDelivery,
SessionTag currentTag,
long paddedSize)Encrypt the data to the target using the given key and deliver the specified tags
No new session key
This is the one called from GarlicMessageBuilder and is the primary entry point. |
byte[] | encrypt(byte[] data,
PublicKey target,
SessionKey key,
Set<SessionTag> tagsForDelivery,
SessionTag currentTag,
SessionKey newKey,
long paddedSize)Encrypt the unencrypted data to the target. |
(package private) byte[] | encryptAESBlock(byte[] data,
SessionKey key,
byte[] iv,
Set<SessionTag> tagsForDelivery,
SessionKey newKey,
long paddedSize)For both scenarios, this method encrypts the AES area using the given key, iv
and making sure the resulting data is at least as long as the paddedSize and
also mod 16 bytes. |
public static final int MAX_TAGS_RECEIVED
public ElGamalAESEngine(I2PAppContext ctx)
public byte[] decrypt(byte[] data,
PrivateKey targetPrivateKey,
SessionKeyManager keyManager)
throws DataFormatExceptionDataFormatExceptionbyte[] decryptAESBlock(byte[] encrypted,
int offset,
int encryptedLen,
SessionKey key,
byte[] iv,
byte[] sentTag,
Set<SessionTag> foundTags,
SessionKey foundKey)- 2 byte integer specifying the # of session tags - that many 32 byte session tags - 4 byte integer specifying data.length - SHA256 of data - 1 byte flag that, if == 1, is followed by a new SessionKey - data - random bytes, padding the total size to greater than paddedSize with a mod 16 = 0If anything doesn't match up in decryption, return null. Otherwise, return the decrypted data and update the session as necessary. If the sentTag is not null, consume it, but if it is null, record the keys, etc as part of a new session.
foundTags - set which is filled with any sessionTags found during decryptionfoundKey - out parameter. Data must be unset when called; may be filled with a new sessionKey found during decryptionpublic byte[] decryptFast(byte[] data,
PrivateKey targetPrivateKey,
SessionKeyManager keyManager)
throws DataFormatExceptionDataFormatExceptionpublic byte[] decryptSlow(byte[] data,
PrivateKey targetPrivateKey,
SessionKeyManager keyManager)
throws DataFormatExceptionDataFormatExceptionpublic byte[] encrypt(byte[] data,
PublicKey target,
SessionKey key,
Set<SessionTag> tagsForDelivery,
SessionTag currentTag,
long paddedSize)target - public key to which the data should be encrypted, must be ELGAMAL_2048.
May be null if key and currentTag are non-null.key - session key to use during encryptiontagsForDelivery - session tags to be associated with the key or null;
200 max enforced at receivercurrentTag - sessionTag to use, or null if it should use ElG (i.e. new session)paddedSize - minimum size in bytes of the body after padding it (if less than the
body's real size, no bytes are appended but the body is not truncated)IllegalArgumentException - on bad target EncTypepublic byte[] encrypt(byte[] data,
PublicKey target,
SessionKey key,
Set<SessionTag> tagsForDelivery,
SessionTag currentTag,
SessionKey newKey,
long paddedSize)target - public key to which the data should be encrypted, must be ELGAMAL_2048.
May be null if key and currentTag are non-null.key - session key to use during encryptiontagsForDelivery - session tags to be associated with the key (or newKey if specified), or null;
200 max enforced at receivercurrentTag - sessionTag to use, or null if it should use ElG (i.e. new session)newKey - key to be delivered to the target, with which the tagsForDelivery should be associated, or nullpaddedSize - minimum size in bytes of the body after padding it (if less than the
body's real size, no bytes are appended but the body is not truncated)IllegalArgumentException - on bad target EncType
Unused externally, only called by below (i.e. newKey is always null)final byte[] encryptAESBlock(byte[] data,
SessionKey key,
byte[] iv,
Set<SessionTag> tagsForDelivery,
SessionKey newKey,
long paddedSize)- 2 byte integer specifying the # of session tags - that many 32 byte session tags - 4 byte integer specifying data.length - SHA256 of data - 1 byte flag that, if == 1, is followed by a new SessionKey - data - random bytes, padding the total size to greater than paddedSize with a mod 16 = 0Note: package private for ElGamalTest.testAES()
tagsForDelivery - session tags to be associated with the key or null;
200 max enforced at receiver