Changeset d6e3501
- Timestamp:
- Nov 23, 2018 2:22:08 PM (2 years ago)
- Branches:
- master
- Children:
- 43e0d4f9, d4caafb5
- Parents:
- 535f2da
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
core/java/test/junit/net/i2p/crypto/CryptoTestSuite.java
r535f2da rd6e3501 25 25 suite.addTestSuite(CryptixRijndael_AlgorithmTest.class); 26 26 suite.addTestSuite(DSATest.class); 27 suite.addTestSuite(ElGamalTest.class);28 27 suite.addTestSuite(HMACSHA256Test.class); 29 28 suite.addTestSuite(KeyGeneratorTest.class); -
router/java/test/junit/net/i2p/router/crypto/ElGamalTest.java
r535f2da rd6e3501 1 package net.i2p. crypto;1 package net.i2p.router.crypto; 2 2 /* 3 3 * free (adj.): unencumbered; not under the control of others … … 17 17 import junit.framework.TestCase; 18 18 import net.i2p.I2PAppContext; 19 import net.i2p.crypto.KeyGenerator; 20 import net.i2p.crypto.SHA256Generator; 19 21 import net.i2p.data.Base64; 20 22 import net.i2p.data.DataFormatException; … … 25 27 import net.i2p.data.SessionKey; 26 28 import net.i2p.data.SessionTag; 29 import net.i2p.router.crypto.ElGamalAESEngine; 27 30 import net.i2p.util.RandomSource; 28 31 … … 127 130 protected void setUp() { 128 131 _context = I2PAppContext.getGlobalContext(); 129 Object o = YKGenerator.class;132 //Object o = YKGenerator.class; 130 133 } 131 134 … … 156 159 String msg = "Hello world"; 157 160 158 byte encrypted[] = _context.elGamalAESEngine().encryptAESBlock(DataHelper.getASCII(msg), sessionKey, iv, null, null, 64); 161 ElGamalAESEngine e = new ElGamalAESEngine(_context); 162 byte encrypted[] = e.encryptAESBlock(DataHelper.getASCII(msg), sessionKey, iv, null, null, 64); 159 163 Set<SessionTag> foundTags = new HashSet<SessionTag>(); 160 164 SessionKey foundKey = new SessionKey(); 161 165 byte decrypted[] = null; 162 166 try{ 163 decrypted = _context.elGamalAESEngine().decryptAESBlock(encrypted, 0, encrypted.length, sessionKey, iv, null, foundTags, foundKey);167 decrypted = e.decryptAESBlock(encrypted, 0, encrypted.length, sessionKey, iv, null, foundTags, foundKey); 164 168 }catch(DataFormatException dfe){ 165 169 dfe.printStackTrace(); … … 181 185 if (key == null) 182 186 key = _context.sessionKeyManager().createSession(pubKey); 183 byte[] encrypted = _context.elGamalAESEngine().encrypt(DataHelper.getASCII(msg), pubKey, key, null, null, 64); 187 ElGamalAESEngine e = new ElGamalAESEngine(_context); 188 byte[] encrypted = e.encrypt(DataHelper.getASCII(msg), pubKey, key, null, null, 64); 184 189 byte[] decrypted = null; 185 190 try{ 186 decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey, _context.sessionKeyManager());191 decrypted = e.decrypt(encrypted, privKey, _context.sessionKeyManager()); 187 192 }catch(DataFormatException dfe){ 188 193 dfe.printStackTrace(); … … 257 262 258 263 public void testLoop(){ 264 ElGamalAESEngine e = new ElGamalAESEngine(_context); 259 265 for(int i = 0; i < 5; i++){ 260 266 Object keys[] = KeyGenerator.getInstance().generatePKIKeypair(); … … 268 274 key = _context.sessionKeyManager().createSession(pubKey); 269 275 270 byte[] encrypted = _context.elGamalAESEngine().encrypt(msg, pubKey, key, null, null, 1024);276 byte[] encrypted = e.encrypt(msg, pubKey, key, null, null, 1024); 271 277 byte[] decrypted = null; 272 278 try{ 273 decrypted = _context.elGamalAESEngine().decrypt(encrypted, privKey, _context.sessionKeyManager());279 decrypted = e.decrypt(encrypted, privKey, _context.sessionKeyManager()); 274 280 }catch(DataFormatException dfe){ 275 281 dfe.printStackTrace(); … … 371 377 } 372 378 379 /**** 380 Package private, move back to net.i2p.crypto if we want to test it 373 381 public void testYKGen(){ 374 382 RandomSource.getInstance().nextBoolean(); … … 379 387 } 380 388 } 389 ****/ 381 390 } -
router/java/test/junit/net/i2p/router/crypto/SessionEncryptionTest.java
r535f2da rd6e3501 22 22 import net.i2p.data.SessionKey; 23 23 import net.i2p.data.SessionTag; 24 import net.i2p.router.crypto.ElGamalAESEngine; 24 25 25 26 /** … … 49 50 byte[] msg = DataHelper.getASCII("msg 1"); 50 51 51 byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, null, null, 64); 52 byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm); 52 ElGamalAESEngine e = new ElGamalAESEngine(_context); 53 byte emsg[] = e.encrypt(msg, pubKey, curKey, null, null, 64); 54 byte dmsg[] = e.decrypt(emsg, privKey, skm); 53 55 assertTrue(DataHelper.eq(dmsg, msg)); 54 56 } … … 63 65 byte[] msg = DataHelper.getASCII("msg 2"); 64 66 65 byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, null, null, 64); 66 byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm); 67 ElGamalAESEngine e = new ElGamalAESEngine(_context); 68 byte emsg[] = e.encrypt(msg, pubKey, curKey, null, null, 64); 69 byte dmsg[] = e.decrypt(emsg, privKey, skm); 67 70 assertTrue(DataHelper.eq(dmsg, msg)); 68 71 } … … 102 105 byte[] msg5 = DataHelper.getASCII("msg 5"); 103 106 104 byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, null, 64); 105 106 byte dmsg1[] = _context.elGamalAESEngine().decrypt(emsg1, privKey, skm); 107 ElGamalAESEngine e = new ElGamalAESEngine(_context); 108 byte emsg1[] = e.encrypt(msg1, pubKey, curKey, firstTags, null, 64); 109 110 byte dmsg1[] = e.decrypt(emsg1, privKey, skm); 107 111 assertTrue(DataHelper.eq(dmsg1, msg1)); 108 112 … … 117 121 assertNotNull(curTag); 118 122 119 byte emsg2[] = _context.elGamalAESEngine().encrypt(msg2, pubKey, curKey, null, curTag, 64);120 121 byte dmsg2[] = _context.elGamalAESEngine().decrypt(emsg2, privKey, skm);123 byte emsg2[] = e.encrypt(msg2, pubKey, curKey, null, curTag, 64); 124 125 byte dmsg2[] = e.decrypt(emsg2, privKey, skm); 122 126 assertTrue(DataHelper.eq(dmsg2, msg2)); 123 127 … … 131 135 assertNotNull(curKey); 132 136 133 byte emsg3[] = _context.elGamalAESEngine().encrypt(msg3, pubKey, curKey, secondTags, curTag, 64);134 135 byte dmsg3[] = _context.elGamalAESEngine().decrypt(emsg3, privKey, skm);137 byte emsg3[] = e.encrypt(msg3, pubKey, curKey, secondTags, curTag, 64); 138 139 byte dmsg3[] = e.decrypt(emsg3, privKey, skm); 136 140 assertTrue(DataHelper.eq(dmsg3, msg3)); 137 141 … … 147 151 assertNotNull(curKey); 148 152 149 byte emsg4[] = _context.elGamalAESEngine().encrypt(msg4, pubKey, curKey, null, curTag, 64);150 151 byte dmsg4[] = _context.elGamalAESEngine().decrypt(emsg4, privKey, skm);153 byte emsg4[] = e.encrypt(msg4, pubKey, curKey, null, curTag, 64); 154 155 byte dmsg4[] = e.decrypt(emsg4, privKey, skm); 152 156 assertTrue(DataHelper.eq(dmsg4, msg4)); 153 157 … … 159 163 assertNotNull(curKey); 160 164 161 byte emsg5[] = _context.elGamalAESEngine().encrypt(msg5, pubKey, curKey, null, curTag, 64);162 163 byte dmsg5[] = _context.elGamalAESEngine().decrypt(emsg5, privKey, skm);165 byte emsg5[] = e.encrypt(msg5, pubKey, curKey, null, curTag, 64); 166 167 byte dmsg5[] = e.decrypt(emsg5, privKey, skm); 164 168 assertTrue(DataHelper.eq(dmsg5, msg5)); 165 169 … … 202 206 byte[] msg5 = DataHelper.getASCII("msg 5"); 203 207 204 byte emsg1[] = _context.elGamalAESEngine().encrypt(msg1, pubKey, curKey, firstTags, null, 64); 205 206 byte dmsg1[] = _context.elGamalAESEngine().decrypt(emsg1, privKey, skm); 208 ElGamalAESEngine e = new ElGamalAESEngine(_context); 209 byte emsg1[] = e.encrypt(msg1, pubKey, curKey, firstTags, null, 64); 210 211 byte dmsg1[] = e.decrypt(emsg1, privKey, skm); 207 212 assertTrue(DataHelper.eq(dmsg1, msg1)); 208 213 … … 217 222 assertNotNull(curTag); 218 223 219 byte emsg2[] = _context.elGamalAESEngine().encrypt(msg2, pubKey, curKey, null, curTag, 64);220 221 byte dmsg2[] = _context.elGamalAESEngine().decrypt(emsg2, privKey, skm);224 byte emsg2[] = e.encrypt(msg2, pubKey, curKey, null, curTag, 64); 225 226 byte dmsg2[] = e.decrypt(emsg2, privKey, skm); 222 227 assertTrue(DataHelper.eq(dmsg2, msg2)); 223 228 … … 230 235 assertNotNull(curKey); 231 236 232 byte emsg3[] = _context.elGamalAESEngine().encrypt(msg3, pubKey, curKey, secondTags, curTag, nextKey, 64);233 234 byte dmsg3[] = _context.elGamalAESEngine().decrypt(emsg3, privKey, skm);237 byte emsg3[] = e.encrypt(msg3, pubKey, curKey, secondTags, curTag, nextKey, 64); 238 239 byte dmsg3[] = e.decrypt(emsg3, privKey, skm); 235 240 assertTrue(DataHelper.eq(dmsg3, msg3)); 236 241 … … 246 251 assertNotNull(curKey); 247 252 248 byte emsg4[] = _context.elGamalAESEngine().encrypt(msg4, pubKey, curKey, null, curTag, 64);249 250 byte dmsg4[] = _context.elGamalAESEngine().decrypt(emsg4, privKey, skm);253 byte emsg4[] = e.encrypt(msg4, pubKey, curKey, null, curTag, 64); 254 255 byte dmsg4[] = e.decrypt(emsg4, privKey, skm); 251 256 assertTrue(DataHelper.eq(dmsg4, msg4)); 252 257 … … 259 264 assertNotNull(curKey); 260 265 261 byte emsg5[] = _context.elGamalAESEngine().encrypt(msg5, pubKey, curKey, null, curTag, 64);262 263 byte dmsg5[] = _context.elGamalAESEngine().decrypt(emsg5, privKey, skm);266 byte emsg5[] = e.encrypt(msg5, pubKey, curKey, null, curTag, 64); 267 268 byte dmsg5[] = e.decrypt(emsg5, privKey, skm); 264 269 assertTrue(DataHelper.eq(dmsg5, msg5)); 265 270 … … 279 284 SessionKey curKey = skm.createSession(pubKey); 280 285 286 ElGamalAESEngine e = new ElGamalAESEngine(_context); 281 287 for (int i = 0; i < 1000; i++) { 282 288 Set<SessionTag> tags = null; … … 294 300 byte[] msg = DataHelper.getASCII("msg " + i); 295 301 296 byte emsg[] = _context.elGamalAESEngine().encrypt(msg, pubKey, curKey, tags, curTag, nextKey, 64);297 298 byte dmsg[] = _context.elGamalAESEngine().decrypt(emsg, privKey, skm);302 byte emsg[] = e.encrypt(msg, pubKey, curKey, tags, curTag, nextKey, 64); 303 304 byte dmsg[] = e.decrypt(emsg, privKey, skm); 299 305 assertTrue(DataHelper.eq(dmsg, msg)); 300 306
Note: See TracChangeset
for help on using the changeset viewer.