View | Details | Return to bug 26067 | Differences between
and this patch

Collapse All | Expand All

(-)DiffieHellmanImpl.java (-3 / +2 lines)
Lines 99-106 Link Here
99
99
100
    result = pub.getY().modPow(key.getX(), s1.getP());
100
    result = pub.getY().modPow(key.getX(), s1.getP());
101
    if (! lastPhase)
101
    if (! lastPhase)
102
      throw new IllegalArgumentException("This key-agreement MUST be concluded in one step only");
102
      throw new IllegalArgumentException(
103
103
          "This key-agreement MUST be concluded in one step only");
104
    last_phase_done = true;
104
    last_phase_done = true;
105
    return null;
105
    return null;
106
  }
106
  }
Lines 117-123 Link Here
117
        System.arraycopy(buf, 1, buf2, 0, buf2.length);
117
        System.arraycopy(buf, 1, buf2, 0, buf2.length);
118
        buf = buf2;
118
        buf = buf2;
119
      }
119
      }
120
121
    return buf;
120
    return buf;
122
  }
121
  }
123
122
(-)GnuCrypto.java (-102 / +57 lines)
Lines 49-72 Link Here
49
import java.util.Set;
49
import java.util.Set;
50
50
51
/**
51
/**
52
 * <p>The GNU Crypto implementation of the Java Cryptographic Extension (JCE)
52
 * The additional GNU algorithm implementation as a Java Cryptographic Extension
53
 * Provider.</p>
53
 * (JCE) Provider.
54
 *
54
 * 
55
 * @see java.security.Provider
55
 * @see java.security.Provider
56
 */
56
 */
57
public final class GnuCrypto extends Provider
57
public final class GnuCrypto
58
    extends Provider
58
{
59
{
59
60
  // Constants and variables
61
  // -------------------------------------------------------------------------
62
63
  // Constructor(s)
64
  // -------------------------------------------------------------------------
65
66
  /**
67
   * <p>The <a href="http://www.gnu.org/software/gnu-crypto/">GNU Crypto</a>
68
   * Provider.</p>
69
   */
70
  public GnuCrypto()
60
  public GnuCrypto()
71
  {
61
  {
72
    super(Registry.GNU_CRYPTO, 2.1, "GNU Crypto JCE Provider");
62
    super(Registry.GNU_CRYPTO, 2.1, "GNU Crypto JCE Provider");
Lines 120-127 Link Here
120
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.AES.class.getName());
110
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.AES.class.getName());
121
        put("Cipher.PBEWithHMacHavalAndAnubis",
111
        put("Cipher.PBEWithHMacHavalAndAnubis",
122
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Anubis.class.getName());
112
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Anubis.class.getName());
123
        put(
113
        put("Cipher.PBEWithHMacHavalAndBlowfish",
124
            "Cipher.PBEWithHMacHavalAndBlowfish",
125
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Blowfish.class.getName());
114
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Blowfish.class.getName());
126
        put("Cipher.PBEWithHMacHavalAndCast5",
115
        put("Cipher.PBEWithHMacHavalAndCast5",
127
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Cast5.class.getName());
116
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Cast5.class.getName());
Lines 133-140 Link Here
133
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Serpent.class.getName());
122
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Serpent.class.getName());
134
        put("Cipher.PBEWithHMacHavalAndSquare",
123
        put("Cipher.PBEWithHMacHavalAndSquare",
135
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Square.class.getName());
124
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Square.class.getName());
136
        put(
125
        put("Cipher.PBEWithHMacHavalAndTripleDES",
137
            "Cipher.PBEWithHMacHavalAndTripleDES",
138
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.TripleDES.class.getName());
126
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.TripleDES.class.getName());
139
        put("Cipher.PBEWithHMacHavalAndTwofish",
127
        put("Cipher.PBEWithHMacHavalAndTwofish",
140
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Twofish.class.getName());
128
            gnu.javax.crypto.jce.cipher.PBES2.HMacHaval.Twofish.class.getName());
Lines 228-235 Link Here
228
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.AES.class.getName());
216
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.AES.class.getName());
229
        put("Cipher.PBEWithHMacSHA256AndAnubis",
217
        put("Cipher.PBEWithHMacSHA256AndAnubis",
230
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Anubis.class.getName());
218
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Anubis.class.getName());
231
        put(
219
        put("Cipher.PBEWithHMacSHA256AndBlowfish",
232
            "Cipher.PBEWithHMacSHA256AndBlowfish",
233
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Blowfish.class.getName());
220
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Blowfish.class.getName());
234
        put("Cipher.PBEWithHMacSHA256AndCast5",
221
        put("Cipher.PBEWithHMacSHA256AndCast5",
235
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Cast5.class.getName());
222
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Cast5.class.getName());
Lines 237-260 Link Here
237
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.DES.class.getName());
224
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.DES.class.getName());
238
        put("Cipher.PBEWithHMacSHA256AndKhazad",
225
        put("Cipher.PBEWithHMacSHA256AndKhazad",
239
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Khazad.class.getName());
226
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Khazad.class.getName());
240
        put(
227
        put("Cipher.PBEWithHMacSHA256AndSerpent",
241
            "Cipher.PBEWithHMacSHA256AndSerpent",
242
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Serpent.class.getName());
228
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Serpent.class.getName());
243
        put("Cipher.PBEWithHMacSHA256AndSquare",
229
        put("Cipher.PBEWithHMacSHA256AndSquare",
244
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Square.class.getName());
230
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Square.class.getName());
245
        put(
231
        put("Cipher.PBEWithHMacSHA256AndTripleDES",
246
            "Cipher.PBEWithHMacSHA256AndTripleDES",
247
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.TripleDES.class.getName());
232
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.TripleDES.class.getName());
248
        put(
233
        put("Cipher.PBEWithHMacSHA256AndTwofish",
249
            "Cipher.PBEWithHMacSHA256AndTwofish",
250
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Twofish.class.getName());
234
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA256.Twofish.class.getName());
251
235
252
        put("Cipher.PBEWithHMacSHA384AndAES",
236
        put("Cipher.PBEWithHMacSHA384AndAES",
253
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.AES.class.getName());
237
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.AES.class.getName());
254
        put("Cipher.PBEWithHMacSHA384AndAnubis",
238
        put("Cipher.PBEWithHMacSHA384AndAnubis",
255
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Anubis.class.getName());
239
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Anubis.class.getName());
256
        put(
240
        put("Cipher.PBEWithHMacSHA384AndBlowfish",
257
            "Cipher.PBEWithHMacSHA384AndBlowfish",
258
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Blowfish.class.getName());
241
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Blowfish.class.getName());
259
        put("Cipher.PBEWithHMacSHA384AndCast5",
242
        put("Cipher.PBEWithHMacSHA384AndCast5",
260
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Cast5.class.getName());
243
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Cast5.class.getName());
Lines 262-285 Link Here
262
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.DES.class.getName());
245
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.DES.class.getName());
263
        put("Cipher.PBEWithHMacSHA384AndKhazad",
246
        put("Cipher.PBEWithHMacSHA384AndKhazad",
264
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Khazad.class.getName());
247
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Khazad.class.getName());
265
        put(
248
        put("Cipher.PBEWithHMacSHA384AndSerpent",
266
            "Cipher.PBEWithHMacSHA384AndSerpent",
267
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Serpent.class.getName());
249
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Serpent.class.getName());
268
        put("Cipher.PBEWithHMacSHA384AndSquare",
250
        put("Cipher.PBEWithHMacSHA384AndSquare",
269
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Square.class.getName());
251
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Square.class.getName());
270
        put(
252
        put("Cipher.PBEWithHMacSHA384AndTripleDES",
271
            "Cipher.PBEWithHMacSHA384AndTripleDES",
272
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.TripleDES.class.getName());
253
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.TripleDES.class.getName());
273
        put(
254
        put("Cipher.PBEWithHMacSHA384AndTwofish",
274
            "Cipher.PBEWithHMacSHA384AndTwofish",
275
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Twofish.class.getName());
255
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA384.Twofish.class.getName());
276
256
277
        put("Cipher.PBEWithHMacSHA512AndAES",
257
        put("Cipher.PBEWithHMacSHA512AndAES",
278
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.AES.class.getName());
258
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.AES.class.getName());
279
        put("Cipher.PBEWithHMacSHA512AndAnubis",
259
        put("Cipher.PBEWithHMacSHA512AndAnubis",
280
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Anubis.class.getName());
260
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Anubis.class.getName());
281
        put(
261
        put("Cipher.PBEWithHMacSHA512AndBlowfish",
282
            "Cipher.PBEWithHMacSHA512AndBlowfish",
283
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Blowfish.class.getName());
262
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Blowfish.class.getName());
284
        put("Cipher.PBEWithHMacSHA512AndCast5",
263
        put("Cipher.PBEWithHMacSHA512AndCast5",
285
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Cast5.class.getName());
264
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Cast5.class.getName());
Lines 287-310 Link Here
287
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.DES.class.getName());
266
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.DES.class.getName());
288
        put("Cipher.PBEWithHMacSHA512AndKhazad",
267
        put("Cipher.PBEWithHMacSHA512AndKhazad",
289
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Khazad.class.getName());
268
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Khazad.class.getName());
290
        put(
269
        put("Cipher.PBEWithHMacSHA512AndSerpent",
291
            "Cipher.PBEWithHMacSHA512AndSerpent",
292
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Serpent.class.getName());
270
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Serpent.class.getName());
293
        put("Cipher.PBEWithHMacSHA512AndSquare",
271
        put("Cipher.PBEWithHMacSHA512AndSquare",
294
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Square.class.getName());
272
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Square.class.getName());
295
        put(
273
        put("Cipher.PBEWithHMacSHA512AndTripleDES",
296
            "Cipher.PBEWithHMacSHA512AndTripleDES",
297
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.TripleDES.class.getName());
274
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.TripleDES.class.getName());
298
        put(
275
        put("Cipher.PBEWithHMacSHA512AndTwofish",
299
            "Cipher.PBEWithHMacSHA512AndTwofish",
300
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Twofish.class.getName());
276
            gnu.javax.crypto.jce.cipher.PBES2.HMacSHA512.Twofish.class.getName());
301
277
302
        put("Cipher.PBEWithHMacTigerAndAES",
278
        put("Cipher.PBEWithHMacTigerAndAES",
303
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.AES.class.getName());
279
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.AES.class.getName());
304
        put("Cipher.PBEWithHMacTigerAndAnubis",
280
        put("Cipher.PBEWithHMacTigerAndAnubis",
305
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Anubis.class.getName());
281
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Anubis.class.getName());
306
        put(
282
        put("Cipher.PBEWithHMacTigerAndBlowfish",
307
            "Cipher.PBEWithHMacTigerAndBlowfish",
308
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Blowfish.class.getName());
283
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Blowfish.class.getName());
309
        put("Cipher.PBEWithHMacTigerAndCast5",
284
        put("Cipher.PBEWithHMacTigerAndCast5",
310
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Cast5.class.getName());
285
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Cast5.class.getName());
Lines 316-359 Link Here
316
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Serpent.class.getName());
291
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Serpent.class.getName());
317
        put("Cipher.PBEWithHMacTigerAndSquare",
292
        put("Cipher.PBEWithHMacTigerAndSquare",
318
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Square.class.getName());
293
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Square.class.getName());
319
        put(
294
        put("Cipher.PBEWithHMacTigerAndTripleDES",
320
            "Cipher.PBEWithHMacTigerAndTripleDES",
321
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.TripleDES.class.getName());
295
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.TripleDES.class.getName());
322
        put("Cipher.PBEWithHMacTigerAndTwofish",
296
        put("Cipher.PBEWithHMacTigerAndTwofish",
323
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Twofish.class.getName());
297
            gnu.javax.crypto.jce.cipher.PBES2.HMacTiger.Twofish.class.getName());
324
298
325
        put("Cipher.PBEWithHMacWhirlpoolAndAES",
299
        put("Cipher.PBEWithHMacWhirlpoolAndAES",
326
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.AES.class.getName());
300
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.AES.class.getName());
327
        put(
301
        put("Cipher.PBEWithHMacWhirlpoolAndAnubis",
328
            "Cipher.PBEWithHMacWhirlpoolAndAnubis",
329
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Anubis.class.getName());
302
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Anubis.class.getName());
330
        put(
303
        put("Cipher.PBEWithHMacWhirlpoolAndBlowfish",
331
            "Cipher.PBEWithHMacWhirlpoolAndBlowfish",
332
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Blowfish.class.getName());
304
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Blowfish.class.getName());
333
        put(
305
        put("Cipher.PBEWithHMacWhirlpoolAndCast5",
334
            "Cipher.PBEWithHMacWhirlpoolAndCast5",
335
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Cast5.class.getName());
306
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Cast5.class.getName());
336
        put("Cipher.PBEWithHMacWhirlpoolAndDES",
307
        put("Cipher.PBEWithHMacWhirlpoolAndDES",
337
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.DES.class.getName());
308
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.DES.class.getName());
338
        put(
309
        put("Cipher.PBEWithHMacWhirlpoolAndKhazad",
339
            "Cipher.PBEWithHMacWhirlpoolAndKhazad",
340
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Khazad.class.getName());
310
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Khazad.class.getName());
341
        put(
311
        put("Cipher.PBEWithHMacWhirlpoolAndSerpent",
342
            "Cipher.PBEWithHMacWhirlpoolAndSerpent",
343
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Serpent.class.getName());
312
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Serpent.class.getName());
344
        put(
313
        put("Cipher.PBEWithHMacWhirlpoolAndSquare",
345
            "Cipher.PBEWithHMacWhirlpoolAndSquare",
346
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Square.class.getName());
314
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Square.class.getName());
347
        put(
315
        put("Cipher.PBEWithHMacWhirlpoolAndTripleDES",
348
            "Cipher.PBEWithHMacWhirlpoolAndTripleDES",
349
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.TripleDES.class.getName());
316
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.TripleDES.class.getName());
350
        put(
317
        put("Cipher.PBEWithHMacWhirlpoolAndTwofish",
351
            "Cipher.PBEWithHMacWhirlpoolAndTwofish",
352
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Twofish.class.getName());
318
            gnu.javax.crypto.jce.cipher.PBES2.HMacWhirlpool.Twofish.class.getName());
353
319
354
        // SecretKeyFactory interface to PBKDF2.
320
        // SecretKeyFactory interface to PBKDF2.
355
        put(
321
        put("SecretKeyFactory.PBKDF2WithHMacHaval",
356
            "SecretKeyFactory.PBKDF2WithHMacHaval",
357
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacHaval.class.getName());
322
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacHaval.class.getName());
358
        put("SecretKeyFactory.PBKDF2WithHMacMD2",
323
        put("SecretKeyFactory.PBKDF2WithHMacMD2",
359
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacMD2.class.getName());
324
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacMD2.class.getName());
Lines 361-390 Link Here
361
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacMD4.class.getName());
326
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacMD4.class.getName());
362
        put("SecretKeyFactory.PBKDF2WithHMacMD5",
327
        put("SecretKeyFactory.PBKDF2WithHMacMD5",
363
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacMD5.class.getName());
328
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacMD5.class.getName());
364
        put(
329
        put("SecretKeyFactory.PBKDF2WithHMacSHA1",
365
            "SecretKeyFactory.PBKDF2WithHMacSHA1",
366
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA1.class.getName());
330
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA1.class.getName());
367
        put(
331
        put("SecretKeyFactory.PBKDF2WithHMacSHA256",
368
            "SecretKeyFactory.PBKDF2WithHMacSHA256",
369
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA256.class.getName());
332
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA256.class.getName());
370
        put(
333
        put("SecretKeyFactory.PBKDF2WithHMacSHA384",
371
            "SecretKeyFactory.PBKDF2WithHMacSHA384",
372
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA384.class.getName());
334
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA384.class.getName());
373
        put(
335
        put("SecretKeyFactory.PBKDF2WithHMacSHA512",
374
            "SecretKeyFactory.PBKDF2WithHMacSHA512",
375
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA512.class.getName());
336
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacSHA512.class.getName());
376
        put(
337
        put("SecretKeyFactory.PBKDF2WithHMacTiger",
377
            "SecretKeyFactory.PBKDF2WithHMacTiger",
378
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacTiger.class.getName());
338
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacTiger.class.getName());
379
        put(
339
        put("SecretKeyFactory.PBKDF2WithHMacWhirlpool",
380
            "SecretKeyFactory.PBKDF2WithHMacWhirlpool",
381
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacWhirlpool.class.getName());
340
            gnu.javax.crypto.jce.PBKDF2SecretKeyFactory.HMacWhirlpool.class.getName());
382
341
383
        // Simple SecretKeyFactory implementations.
342
        // Simple SecretKeyFactory implementations.
384
        put("SecretKeyFactory.Anubis",
343
        put("SecretKeyFactory.Anubis",
385
            gnu.javax.crypto.jce.key.AnubisSecretKeyFactoryImpl.class.getName());
344
            gnu.javax.crypto.jce.key.AnubisSecretKeyFactoryImpl.class.getName());
386
        put(
345
        put("SecretKeyFactory.Blowfish",
387
            "SecretKeyFactory.Blowfish",
388
            gnu.javax.crypto.jce.key.BlowfishSecretKeyFactoryImpl.class.getName());
346
            gnu.javax.crypto.jce.key.BlowfishSecretKeyFactoryImpl.class.getName());
389
        put("SecretKeyFactory.Cast5",
347
        put("SecretKeyFactory.Cast5",
390
            gnu.javax.crypto.jce.key.Cast5SecretKeyFactoryImpl.class.getName());
348
            gnu.javax.crypto.jce.key.Cast5SecretKeyFactoryImpl.class.getName());
Lines 392-402 Link Here
392
            gnu.javax.crypto.jce.key.DESSecretKeyFactoryImpl.class.getName());
350
            gnu.javax.crypto.jce.key.DESSecretKeyFactoryImpl.class.getName());
393
        put("SecretKeyFactory.Khazad",
351
        put("SecretKeyFactory.Khazad",
394
            gnu.javax.crypto.jce.key.KhazadSecretKeyFactoryImpl.class.getName());
352
            gnu.javax.crypto.jce.key.KhazadSecretKeyFactoryImpl.class.getName());
395
        put(
353
        put("SecretKeyFactory.Rijndael",
396
            "SecretKeyFactory.Rijndael",
397
            gnu.javax.crypto.jce.key.RijndaelSecretKeyFactoryImpl.class.getName());
354
            gnu.javax.crypto.jce.key.RijndaelSecretKeyFactoryImpl.class.getName());
398
        put(
355
        put("SecretKeyFactory.Serpent",
399
            "SecretKeyFactory.Serpent",
400
            gnu.javax.crypto.jce.key.SerpentSecretKeyFactoryImpl.class.getName());
356
            gnu.javax.crypto.jce.key.SerpentSecretKeyFactoryImpl.class.getName());
401
        put("SecretKeyFactory.Square",
357
        put("SecretKeyFactory.Square",
402
            gnu.javax.crypto.jce.key.SquareSecretKeyFactoryImpl.class.getName());
358
            gnu.javax.crypto.jce.key.SquareSecretKeyFactoryImpl.class.getName());
Lines 410-416 Link Here
410
        put("AlgorithmParameters.BlockCipherParameters",
366
        put("AlgorithmParameters.BlockCipherParameters",
411
            gnu.javax.crypto.jce.params.BlockCipherParameters.class.getName());
367
            gnu.javax.crypto.jce.params.BlockCipherParameters.class.getName());
412
368
413
414
        // KeyGenerator Adapter implementations
369
        // KeyGenerator Adapter implementations
415
        put("KeyGenerator.Anubis",
370
        put("KeyGenerator.Anubis",
416
            gnu.javax.crypto.jce.key.AnubisKeyGeneratorImpl.class.getName());
371
            gnu.javax.crypto.jce.key.AnubisKeyGeneratorImpl.class.getName());
Lines 541-559 Link Here
541
        put("Alg.Alias.Cipher.RSA", "RSAES-PKCS1-v1_5");
496
        put("Alg.Alias.Cipher.RSA", "RSAES-PKCS1-v1_5");
542
497
543
        // SecureRandom
498
        // SecureRandom
544
        put("SecureRandom.ARCFOUR", gnu.javax.crypto.jce.prng.ARCFourRandomSpi.class.getName());
499
        put("SecureRandom.ARCFOUR",
500
            gnu.javax.crypto.jce.prng.ARCFourRandomSpi.class.getName());
545
        put("SecureRandom.ARCFOUR ImplementedIn", "Software");
501
        put("SecureRandom.ARCFOUR ImplementedIn", "Software");
546
        put("SecureRandom.CSPRNG", gnu.javax.crypto.jce.prng.CSPRNGSpi.class.getName());
502
        put("SecureRandom.CSPRNG",
503
            gnu.javax.crypto.jce.prng.CSPRNGSpi.class.getName());
547
        put("SecureRandom.CSPRNG ImplementedIn", "Software");
504
        put("SecureRandom.CSPRNG ImplementedIn", "Software");
548
        put("SecureRandom.ICM", gnu.javax.crypto.jce.prng.ICMRandomSpi.class.getName());
505
        put("SecureRandom.ICM",
506
            gnu.javax.crypto.jce.prng.ICMRandomSpi.class.getName());
549
        put("SecureRandom.ICM ImplementedIn", "Software");
507
        put("SecureRandom.ICM ImplementedIn", "Software");
550
        put("SecureRandom.UMAC-KDF", gnu.javax.crypto.jce.prng.UMacRandomSpi.class.getName());
508
        put("SecureRandom.UMAC-KDF",
509
            gnu.javax.crypto.jce.prng.UMacRandomSpi.class.getName());
551
        put("SecureRandom.UMAC-KDF ImplementedIn", "Software");
510
        put("SecureRandom.UMAC-KDF ImplementedIn", "Software");
552
        put("SecureRandom.Fortuna", gnu.javax.crypto.jce.prng.FortunaImpl.class.getName ());
511
        put("SecureRandom.Fortuna",
512
            gnu.javax.crypto.jce.prng.FortunaImpl.class.getName());
553
        put("SecureRandom.Fortuna ImplementedIn", "Software");
513
        put("SecureRandom.Fortuna ImplementedIn", "Software");
554
514
555
        // KeyStore
515
        // KeyStore
556
        put("KeyStore.GKR", gnu.javax.crypto.jce.keyring.GnuKeyring.class.getName());
516
        put("KeyStore.GKR",
517
            gnu.javax.crypto.jce.keyring.GnuKeyring.class.getName());
557
        put("Alg.Alias.KeyStore.GnuKeyring", "GKR");
518
        put("Alg.Alias.KeyStore.GnuKeyring", "GKR");
558
519
559
        // KeyPairGenerator ---------------------------------------------------
520
        // KeyPairGenerator ---------------------------------------------------
Lines 587-599 Link Here
587
    });
548
    });
588
  }
549
  }
589
550
590
  // Class methods
591
  // -------------------------------------------------------------------------
592
593
  /**
551
  /**
594
   * <p>Returns a {@link Set} of names of symmetric key block cipher algorithms
552
   * Returns a {@link Set} of names of symmetric key block cipher algorithms
595
   * available from this {@link Provider}.</p>
553
   * available from this {@link Provider}.
596
   *
554
   * 
597
   * @return a {@link Set} of cipher names (Strings).
555
   * @return a {@link Set} of cipher names (Strings).
598
   */
556
   */
599
  public static final Set getCipherNames()
557
  public static final Set getCipherNames()
Lines 605-620 Link Here
605
  }
563
  }
606
564
607
  /**
565
  /**
608
   * <p>Returns a {@link Set} of names of MAC algorithms available from
566
   * Returns a {@link Set} of names of MAC algorithms available from this
609
   * this {@link Provider}.</p>
567
   * {@link Provider}.
610
   *
568
   * 
611
   * @return a {@link Set} of MAC names (Strings).
569
   * @return a {@link Set} of MAC names (Strings).
612
   */
570
   */
613
  public static final Set getMacNames()
571
  public static final Set getMacNames()
614
  {
572
  {
615
    return MacFactory.getNames();
573
    return MacFactory.getNames();
616
  }
574
  }
617
618
  // Instance methods
619
  // -------------------------------------------------------------------------
620
}
575
}
(-)GnuSasl.java (-42 / +52 lines)
Lines 47-99 Link Here
47
import java.security.Provider;
47
import java.security.Provider;
48
import java.util.Set;
48
import java.util.Set;
49
49
50
public final class GnuSasl extends Provider
50
public final class GnuSasl
51
    extends Provider
51
{
52
{
52
53
  // Constructor.
54
  // -------------------------------------------------------------------------
55
56
  public GnuSasl()
53
  public GnuSasl()
57
  {
54
  {
58
    super (Registry.GNU_SASL, 2.1, "GNU Crypto SASL Provider");
55
    super(Registry.GNU_SASL, 2.1, "GNU SASL Provider");
59
56
60
    AccessController.doPrivileged (new PrivilegedAction()
57
    AccessController.doPrivileged(new PrivilegedAction()
58
    {
59
      public Object run()
61
      {
60
      {
62
        public Object run()
61
        // SASL Client and Server mechanisms
63
        {
62
        put("SaslClientFactory.ANONYMOUS",
64
          // SASL Client and Server mechanisms
63
            gnu.javax.crypto.sasl.ClientFactory.class.getName());
65
          put("SaslClientFactory.ANONYMOUS", gnu.javax.crypto.sasl.ClientFactory.class.getName());
64
        put("SaslClientFactory.PLAIN",
66
          put("SaslClientFactory.PLAIN", gnu.javax.crypto.sasl.ClientFactory.class.getName());
65
            gnu.javax.crypto.sasl.ClientFactory.class.getName());
67
          put("SaslClientFactory.CRAM-MD5", gnu.javax.crypto.sasl.ClientFactory.class.getName());
66
        put("SaslClientFactory.CRAM-MD5",
68
          put("SaslClientFactory.SRP", gnu.javax.crypto.sasl.ClientFactory.class.getName());
67
            gnu.javax.crypto.sasl.ClientFactory.class.getName());
69
68
        put("SaslClientFactory.SRP",
70
          put("SaslServerFactory.ANONYMOUS", gnu.javax.crypto.sasl.ServerFactory.class.getName());
69
            gnu.javax.crypto.sasl.ClientFactory.class.getName());
71
          put("SaslServerFactory.PLAIN", gnu.javax.crypto.sasl.ServerFactory.class.getName());
70
72
          put("SaslServerFactory.CRAM-MD5", gnu.javax.crypto.sasl.ServerFactory.class.getName());
71
        put("SaslServerFactory.ANONYMOUS",
73
          put("SaslServerFactory.SRP-MD5", gnu.javax.crypto.sasl.ServerFactory.class.getName());
72
            gnu.javax.crypto.sasl.ServerFactory.class.getName());
74
          put("SaslServerFactory.SRP-SHA-160", gnu.javax.crypto.sasl.ServerFactory.class.getName());
73
        put("SaslServerFactory.PLAIN",
75
          put("SaslServerFactory.SRP-RIPEMD128", gnu.javax.crypto.sasl.ServerFactory.class.getName());
74
            gnu.javax.crypto.sasl.ServerFactory.class.getName());
76
          put("SaslServerFactory.SRP-RIPEMD160", gnu.javax.crypto.sasl.ServerFactory.class.getName());
75
        put("SaslServerFactory.CRAM-MD5",
77
          put("SaslServerFactory.SRP-TIGER", gnu.javax.crypto.sasl.ServerFactory.class.getName());
76
            gnu.javax.crypto.sasl.ServerFactory.class.getName());
78
          put("SaslServerFactory.SRP-WHIRLPOOL", gnu.javax.crypto.sasl.ServerFactory.class.getName());
77
        put("SaslServerFactory.SRP-MD5",
79
78
            gnu.javax.crypto.sasl.ServerFactory.class.getName());
80
          put("Alg.Alias.SaslServerFactory.SRP-SHS", "SRP-SHA-160");
79
        put("SaslServerFactory.SRP-SHA-160",
81
          put("Alg.Alias.SaslServerFactory.SRP-SHA", "SRP-SHA-160");
80
            gnu.javax.crypto.sasl.ServerFactory.class.getName());
82
          put("Alg.Alias.SaslServerFactory.SRP-SHA1", "SRP-SHA-160");
81
        put("SaslServerFactory.SRP-RIPEMD128",
83
          put("Alg.Alias.SaslServerFactory.SRP-SHA-1", "SRP-SHA-160");
82
            gnu.javax.crypto.sasl.ServerFactory.class.getName());
84
          put("Alg.Alias.SaslServerFactory.SRP-SHA160", "SRP-SHA-160");
83
        put("SaslServerFactory.SRP-RIPEMD160",
85
          put("Alg.Alias.SaslServerFactory.SRP-RIPEMD-128", "SRP-RIPEMD128");
84
            gnu.javax.crypto.sasl.ServerFactory.class.getName());
86
          put("Alg.Alias.SaslServerFactory.SRP-RIPEMD-160", "SRP-RIPEMD160");
85
        put("SaslServerFactory.SRP-TIGER",
87
86
            gnu.javax.crypto.sasl.ServerFactory.class.getName());
88
          return null;
87
        put("SaslServerFactory.SRP-WHIRLPOOL",
89
        }
88
            gnu.javax.crypto.sasl.ServerFactory.class.getName());
90
      });
89
90
        put("Alg.Alias.SaslServerFactory.SRP-SHS", "SRP-SHA-160");
91
        put("Alg.Alias.SaslServerFactory.SRP-SHA", "SRP-SHA-160");
92
        put("Alg.Alias.SaslServerFactory.SRP-SHA1", "SRP-SHA-160");
93
        put("Alg.Alias.SaslServerFactory.SRP-SHA-1", "SRP-SHA-160");
94
        put("Alg.Alias.SaslServerFactory.SRP-SHA160", "SRP-SHA-160");
95
        put("Alg.Alias.SaslServerFactory.SRP-RIPEMD-128", "SRP-RIPEMD128");
96
        put("Alg.Alias.SaslServerFactory.SRP-RIPEMD-160", "SRP-RIPEMD160");
97
98
        return null;
99
      }
100
    });
91
  }
101
  }
92
102
93
  /**
103
  /**
94
   * <p>Returns a {@link Set} of names of SASL Client mechanisms available from
104
   * Returns a {@link Set} of names of SASL Client mechanisms available from
95
   * this {@link Provider}.</p>
105
   * this {@link Provider}.
96
   *
106
   * 
97
   * @return a {@link Set} of SASL Client mechanisms (Strings).
107
   * @return a {@link Set} of SASL Client mechanisms (Strings).
98
   */
108
   */
99
  public static final Set getSaslClientMechanismNames()
109
  public static final Set getSaslClientMechanismNames()
Lines 102-110 Link Here
102
  }
112
  }
103
113
104
  /**
114
  /**
105
   * <p>Returns a {@link Set} of names of SASL Server mechanisms available from
115
   * Returns a {@link Set} of names of SASL Server mechanisms available from
106
   * this {@link Provider}.</p>
116
   * this {@link Provider}.
107
   *
117
   * 
108
   * @return a {@link Set} of SASL Server mechanisms (Strings).
118
   * @return a {@link Set} of SASL Server mechanisms (Strings).
109
   */
119
   */
110
  public static final Set getSaslServerMechanismNames()
120
  public static final Set getSaslServerMechanismNames()
(-)PBKDF2SecretKeyFactory.java (-43 / +32 lines)
Lines 53-109 Link Here
53
import gnu.java.security.prng.LimitReachedException;
53
import gnu.java.security.prng.LimitReachedException;
54
import gnu.javax.crypto.prng.PRNGFactory;
54
import gnu.javax.crypto.prng.PRNGFactory;
55
55
56
public abstract class PBKDF2SecretKeyFactory extends SecretKeyFactorySpi
56
public abstract class PBKDF2SecretKeyFactory
57
    extends SecretKeyFactorySpi
57
{
58
{
58
59
  // Constants and fields.
60
  // ------------------------------------------------------------------------
61
62
  protected String macName;
59
  protected String macName;
63
64
  private static final int DEFAULT_ITERATION_COUNT = 1000;
60
  private static final int DEFAULT_ITERATION_COUNT = 1000;
65
66
  private static final int DEFAULT_KEY_LEN = 32;
61
  private static final int DEFAULT_KEY_LEN = 32;
67
62
68
  // Constructor.
69
  // ------------------------------------------------------------------------
70
71
  protected PBKDF2SecretKeyFactory(String macName)
63
  protected PBKDF2SecretKeyFactory(String macName)
72
  {
64
  {
73
    this.macName = macName;
65
    this.macName = macName;
74
  }
66
  }
75
67
76
  // Instance methods.
77
  // ------------------------------------------------------------------------
78
79
  protected SecretKey engineGenerateSecret(KeySpec spec)
68
  protected SecretKey engineGenerateSecret(KeySpec spec)
80
      throws InvalidKeySpecException
69
      throws InvalidKeySpecException
81
  {
70
  {
82
    if (!(spec instanceof PBEKeySpec))
71
    if (! (spec instanceof PBEKeySpec))
83
      {
72
      throw new InvalidKeySpecException("not a PBEKeySpec");
84
        throw new InvalidKeySpecException("not a PBEKeySpec");
85
      }
86
    IRandom kdf = PRNGFactory.getInstance("PBKDF2-" + macName);
73
    IRandom kdf = PRNGFactory.getInstance("PBKDF2-" + macName);
87
    HashMap attr = new HashMap();
74
    HashMap attr = new HashMap();
88
    attr.put(IPBE.PASSWORD, ((PBEKeySpec) spec).getPassword());
75
    attr.put(IPBE.PASSWORD, ((PBEKeySpec) spec).getPassword());
89
    byte[] salt = ((PBEKeySpec) spec).getSalt();
76
    byte[] salt = ((PBEKeySpec) spec).getSalt();
90
    if (salt == null)
77
    if (salt == null)
91
      {
78
      salt = new byte[0];
92
        salt = new byte[0];
93
      }
94
    attr.put(IPBE.SALT, salt);
79
    attr.put(IPBE.SALT, salt);
95
    int ic = ((PBEKeySpec) spec).getIterationCount();
80
    int ic = ((PBEKeySpec) spec).getIterationCount();
96
    if (ic <= 0)
81
    if (ic <= 0)
97
      {
82
      ic = DEFAULT_ITERATION_COUNT;
98
        ic = DEFAULT_ITERATION_COUNT;
99
      }
100
    attr.put(IPBE.ITERATION_COUNT, Integer.valueOf(ic));
83
    attr.put(IPBE.ITERATION_COUNT, Integer.valueOf(ic));
101
    kdf.init(attr);
84
    kdf.init(attr);
102
    int len = ((PBEKeySpec) spec).getKeyLength();
85
    int len = ((PBEKeySpec) spec).getKeyLength();
103
    if (len <= 0)
86
    if (len <= 0)
104
      {
87
      len = DEFAULT_KEY_LEN;
105
        len = DEFAULT_KEY_LEN;
106
      }
107
    byte[] dk = new byte[len];
88
    byte[] dk = new byte[len];
108
    try
89
    try
109
      {
90
      {
Lines 113-119 Link Here
113
      {
94
      {
114
        throw new IllegalArgumentException(lre.toString());
95
        throw new IllegalArgumentException(lre.toString());
115
      }
96
      }
116
117
    return new SecretKeySpec(dk, "PBKDF2");
97
    return new SecretKeySpec(dk, "PBKDF2");
118
  }
98
  }
119
99
Lines 128-137 Link Here
128
    return new SecretKeySpec(key.getEncoded(), key.getAlgorithm());
108
    return new SecretKeySpec(key.getEncoded(), key.getAlgorithm());
129
  }
109
  }
130
110
131
  // Inner classes.
111
  public static class HMacHaval
132
  // ------------------------------------------------------------------------
112
      extends PBKDF2SecretKeyFactory
133
134
  public static class HMacHaval extends PBKDF2SecretKeyFactory
135
  {
113
  {
136
    public HMacHaval()
114
    public HMacHaval()
137
    {
115
    {
Lines 139-145 Link Here
139
    }
117
    }
140
  }
118
  }
141
119
142
  public static class HMacMD2 extends PBKDF2SecretKeyFactory
120
  public static class HMacMD2
121
      extends PBKDF2SecretKeyFactory
143
  {
122
  {
144
    public HMacMD2()
123
    public HMacMD2()
145
    {
124
    {
Lines 147-153 Link Here
147
    }
126
    }
148
  }
127
  }
149
128
150
  public static class HMacMD4 extends PBKDF2SecretKeyFactory
129
  public static class HMacMD4
130
      extends PBKDF2SecretKeyFactory
151
  {
131
  {
152
    public HMacMD4()
132
    public HMacMD4()
153
    {
133
    {
Lines 155-161 Link Here
155
    }
135
    }
156
  }
136
  }
157
137
158
  public static class HMacMD5 extends PBKDF2SecretKeyFactory
138
  public static class HMacMD5
139
      extends PBKDF2SecretKeyFactory
159
  {
140
  {
160
    public HMacMD5()
141
    public HMacMD5()
161
    {
142
    {
Lines 163-169 Link Here
163
    }
144
    }
164
  }
145
  }
165
146
166
  public static class HMacRipeMD128 extends PBKDF2SecretKeyFactory
147
  public static class HMacRipeMD128
148
      extends PBKDF2SecretKeyFactory
167
  {
149
  {
168
    public HMacRipeMD128()
150
    public HMacRipeMD128()
169
    {
151
    {
Lines 171-177 Link Here
171
    }
153
    }
172
  }
154
  }
173
155
174
  public static class HMacRipeMD160 extends PBKDF2SecretKeyFactory
156
  public static class HMacRipeMD160
157
      extends PBKDF2SecretKeyFactory
175
  {
158
  {
176
    public HMacRipeMD160()
159
    public HMacRipeMD160()
177
    {
160
    {
Lines 179-185 Link Here
179
    }
162
    }
180
  }
163
  }
181
164
182
  public static class HMacSHA1 extends PBKDF2SecretKeyFactory
165
  public static class HMacSHA1
166
      extends PBKDF2SecretKeyFactory
183
  {
167
  {
184
    public HMacSHA1()
168
    public HMacSHA1()
185
    {
169
    {
Lines 187-193 Link Here
187
    }
171
    }
188
  }
172
  }
189
173
190
  public static class HMacSHA256 extends PBKDF2SecretKeyFactory
174
  public static class HMacSHA256
175
      extends PBKDF2SecretKeyFactory
191
  {
176
  {
192
    public HMacSHA256()
177
    public HMacSHA256()
193
    {
178
    {
Lines 195-201 Link Here
195
    }
180
    }
196
  }
181
  }
197
182
198
  public static class HMacSHA384 extends PBKDF2SecretKeyFactory
183
  public static class HMacSHA384
184
      extends PBKDF2SecretKeyFactory
199
  {
185
  {
200
    public HMacSHA384()
186
    public HMacSHA384()
201
    {
187
    {
Lines 203-209 Link Here
203
    }
189
    }
204
  }
190
  }
205
191
206
  public static class HMacSHA512 extends PBKDF2SecretKeyFactory
192
  public static class HMacSHA512
193
      extends PBKDF2SecretKeyFactory
207
  {
194
  {
208
    public HMacSHA512()
195
    public HMacSHA512()
209
    {
196
    {
Lines 211-217 Link Here
211
    }
198
    }
212
  }
199
  }
213
200
214
  public static class HMacTiger extends PBKDF2SecretKeyFactory
201
  public static class HMacTiger
202
      extends PBKDF2SecretKeyFactory
215
  {
203
  {
216
    public HMacTiger()
204
    public HMacTiger()
217
    {
205
    {
Lines 219-229 Link Here
219
    }
207
    }
220
  }
208
  }
221
209
222
  public static class HMacWhirlpool extends PBKDF2SecretKeyFactory
210
  public static class HMacWhirlpool
211
      extends PBKDF2SecretKeyFactory
223
  {
212
  {
224
    public HMacWhirlpool()
213
    public HMacWhirlpool()
225
    {
214
    {
226
      super("HMAC-WHIRLPOOL");
215
      super("HMAC-WHIRLPOOL");
227
    }
216
    }
228
  }
217
  }
229
}
218
}
(-)cipher/AESSpi.java (-17 / +7 lines)
Lines 50-72 Link Here
50
import java.security.spec.InvalidParameterSpecException;
50
import java.security.spec.InvalidParameterSpecException;
51
51
52
/**
52
/**
53
 * The implementation of the AES <i>Service Provider Interface</i>
53
 * The implementation of the AES <i>Service Provider Interface</i> (<b>SPI</b>)
54
 * (<b>SPI</b>) adapter.
54
 * adapter.
55
 */
55
 */
56
public final class AESSpi extends CipherAdapter
56
public final class AESSpi
57
    extends CipherAdapter
57
{
58
{
58
59
  // Constructors.
60
  // -----------------------------------------------------------------------
61
62
  public AESSpi()
59
  public AESSpi()
63
  {
60
  {
64
    super(Registry.AES_CIPHER, 16);
61
    super(Registry.AES_CIPHER, 16);
65
  }
62
  }
66
63
67
  // Methods from CipherAdapter
68
  // -----------------------------------------------------------------------
69
70
  protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params,
64
  protected void engineInit(int opmode, Key key, AlgorithmParameterSpec params,
71
                            SecureRandom random) throws InvalidKeyException,
65
                            SecureRandom random) throws InvalidKeyException,
72
      InvalidAlgorithmParameterException
66
      InvalidAlgorithmParameterException
Lines 74-83 Link Here
74
    if (params instanceof BlockCipherParameterSpec)
68
    if (params instanceof BlockCipherParameterSpec)
75
      {
69
      {
76
        if (((BlockCipherParameterSpec) params).getBlockSize() != 16)
70
        if (((BlockCipherParameterSpec) params).getBlockSize() != 16)
77
          {
71
          throw new InvalidAlgorithmParameterException(
78
            throw new InvalidAlgorithmParameterException(
72
              "AES block size must be 16 bytes");
79
                                                         "AES block size must be 16 bytes");
80
          }
81
      }
73
      }
82
    super.engineInit(opmode, key, params, random);
74
    super.engineInit(opmode, key, params, random);
83
  }
75
  }
Lines 90-98 Link Here
90
    try
82
    try
91
      {
83
      {
92
        if (params != null)
84
        if (params != null)
93
          {
85
          spec = params.getParameterSpec(BlockCipherParameterSpec.class);
94
            spec = params.getParameterSpec(BlockCipherParameterSpec.class);
95
          }
96
      }
86
      }
97
    catch (InvalidParameterSpecException ipse)
87
    catch (InvalidParameterSpecException ipse)
98
      {
88
      {
(-)cipher/ARCFourSpi.java (-36 / +13 lines)
Lines 62-90 Link Here
62
import javax.crypto.ShortBufferException;
62
import javax.crypto.ShortBufferException;
63
63
64
/**
64
/**
65
 * The <i>Service Provider Interface</i> (<b>SPI</b>) for the ARCFOUR
65
 * The <i>Service Provider Interface</i> (<b>SPI</b>) for the ARCFOUR stream
66
 * stream cipher.
66
 * cipher.
67
 */
67
 */
68
public class ARCFourSpi extends CipherSpi
68
public class ARCFourSpi
69
    extends CipherSpi
69
{
70
{
70
71
  // Constants and variables.
72
  // -----------------------------------------------------------------------
73
74
  private IRandom keystream;
71
  private IRandom keystream;
75
72
76
  // Constructors.
77
  // -----------------------------------------------------------------------
78
79
  public ARCFourSpi()
73
  public ARCFourSpi()
80
  {
74
  {
81
    super();
75
    super();
82
    keystream = PRNGFactory.getInstance(Registry.ARCFOUR_PRNG);
76
    keystream = PRNGFactory.getInstance(Registry.ARCFOUR_PRNG);
83
  }
77
  }
84
78
85
  // Methods implementing CipherSpi.
86
  // -----------------------------------------------------------------------
87
88
  protected int engineGetBlockSize()
79
  protected int engineGetBlockSize()
89
  {
80
  {
90
    return 0; // stream cipher.
81
    return 0; // stream cipher.
Lines 119-132 Link Here
119
      throws InvalidKeyException
110
      throws InvalidKeyException
120
  {
111
  {
121
    if (mode != Cipher.ENCRYPT_MODE && mode != Cipher.DECRYPT_MODE)
112
    if (mode != Cipher.ENCRYPT_MODE && mode != Cipher.DECRYPT_MODE)
122
      {
113
      throw new IllegalArgumentException(
123
        throw new IllegalArgumentException(
114
          "arcfour is for encryption or decryption only");
124
                                           "arcfour is for encryption or decryption only");
115
    if (key == null || ! key.getFormat().equalsIgnoreCase("RAW"))
125
      }
116
      throw new InvalidKeyException("key must be non-null raw bytes");
126
    if (key == null || !key.getFormat().equalsIgnoreCase("RAW"))
127
      {
128
        throw new InvalidKeyException("key must be non-null raw bytes");
129
      }
130
    HashMap attrib = new HashMap();
117
    HashMap attrib = new HashMap();
131
    attrib.put(ARCFour.ARCFOUR_KEY_MATERIAL, key.getEncoded());
118
    attrib.put(ARCFour.ARCFOUR_KEY_MATERIAL, key.getEncoded());
132
    keystream.init(attrib);
119
    keystream.init(attrib);
Lines 149-164 Link Here
149
  protected byte[] engineUpdate(byte[] in, int offset, int length)
136
  protected byte[] engineUpdate(byte[] in, int offset, int length)
150
  {
137
  {
151
    if (length < 0 || offset < 0 || length + offset > in.length)
138
    if (length < 0 || offset < 0 || length + offset > in.length)
152
      {
139
      throw new ArrayIndexOutOfBoundsException();
153
        throw new ArrayIndexOutOfBoundsException();
154
      }
155
    byte[] result = new byte[length];
140
    byte[] result = new byte[length];
156
    try
141
    try
157
      {
142
      {
158
        for (int i = 0; i < length; i++)
143
        for (int i = 0; i < length; i++)
159
          {
144
          result[i] = (byte)(in[i + offset] ^ keystream.nextByte());
160
            result[i] = (byte) (in[i + offset] ^ keystream.nextByte());
161
          }
162
      }
145
      }
163
    catch (LimitReachedException wontHappen)
146
    catch (LimitReachedException wontHappen)
164
      {
147
      {
Lines 171-189 Link Here
171
  {
154
  {
172
    if (length < 0 || inOffset < 0 || length + inOffset > in.length
155
    if (length < 0 || inOffset < 0 || length + inOffset > in.length
173
        || outOffset < 0)
156
        || outOffset < 0)
174
      {
157
      throw new ArrayIndexOutOfBoundsException();
175
        throw new ArrayIndexOutOfBoundsException();
176
      }
177
    if (outOffset + length > out.length)
158
    if (outOffset + length > out.length)
178
      {
159
      throw new ShortBufferException();
179
        throw new ShortBufferException();
180
      }
181
    try
160
    try
182
      {
161
      {
183
        for (int i = 0; i < length; i++)
162
        for (int i = 0; i < length; i++)
184
          {
163
          out[i + outOffset] = (byte)(in[i + inOffset] ^ keystream.nextByte());
185
            out[i + outOffset] = (byte) (in[i + inOffset] ^ keystream.nextByte());
186
          }
187
      }
164
      }
188
    catch (LimitReachedException wontHappen)
165
    catch (LimitReachedException wontHappen)
189
      {
166
      {
(-)cipher/AnubisSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the Anubis <i>Service Provider Interface</i>
44
 * The implementation of the Anubis <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class AnubisSpi extends CipherAdapter
47
public final class AnubisSpi
48
    extends CipherAdapter
48
{
49
{
49
50
  // Constructors.
51
  // --------------------------------------------------------------------
52
53
  public AnubisSpi()
50
  public AnubisSpi()
54
  {
51
  {
55
    super(Registry.ANUBIS_CIPHER);
52
    super(Registry.ANUBIS_CIPHER);
(-)cipher/BlowfishSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the Blowfish <i>Service Provider Interface</i>
44
 * The implementation of the Blowfish <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class BlowfishSpi extends CipherAdapter
47
public final class BlowfishSpi
48
    extends CipherAdapter
48
{
49
{
49
50
  // Constructors.
51
  // --------------------------------------------------------------------
52
53
  public BlowfishSpi()
50
  public BlowfishSpi()
54
  {
51
  {
55
    super(Registry.BLOWFISH_CIPHER);
52
    super(Registry.BLOWFISH_CIPHER);
(-)cipher/Cast5Spi.java (-17 / +3 lines)
Lines 43-68 Link Here
43
/**
43
/**
44
 * The implementation of the <code>CAST5</code> (a.k.a. CAST-128) <i>Service
44
 * The implementation of the <code>CAST5</code> (a.k.a. CAST-128) <i>Service
45
 * Provider Interface</i> (<b>SPI</b>) Adapter.
45
 * Provider Interface</i> (<b>SPI</b>) Adapter.
46
 *
47
 * @version Revision: $
48
 */
46
 */
49
public class Cast5Spi extends CipherAdapter
47
public class Cast5Spi
48
    extends CipherAdapter
50
{
49
{
51
52
  // Constants and variables
53
  // -------------------------------------------------------------------------
54
55
  // Constructor(s)
56
  // -------------------------------------------------------------------------
57
58
  public Cast5Spi()
50
  public Cast5Spi()
59
  {
51
  {
60
    super(Registry.CAST5_CIPHER);
52
    super(Registry.CAST5_CIPHER);
61
  }
53
  }
62
54
}
63
  // Class methods
64
  // -------------------------------------------------------------------------
65
66
  // Instance methods
67
  // -------------------------------------------------------------------------
68
}
(-)cipher/CipherAdapter.java (-133 / +58 lines)
Lines 39-46 Link Here
39
package gnu.javax.crypto.jce.cipher;
39
package gnu.javax.crypto.jce.cipher;
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
import gnu.javax.crypto.cipher.IBlockCipher;
43
import gnu.javax.crypto.cipher.CipherFactory;
42
import gnu.javax.crypto.cipher.CipherFactory;
43
import gnu.javax.crypto.cipher.IBlockCipher;
44
import gnu.javax.crypto.jce.spec.BlockCipherParameterSpec;
44
import gnu.javax.crypto.jce.spec.BlockCipherParameterSpec;
45
import gnu.javax.crypto.mode.IMode;
45
import gnu.javax.crypto.mode.IMode;
46
import gnu.javax.crypto.mode.ModeFactory;
46
import gnu.javax.crypto.mode.ModeFactory;
Lines 68-128 Link Here
68
import javax.crypto.spec.IvParameterSpec;
68
import javax.crypto.spec.IvParameterSpec;
69
69
70
/**
70
/**
71
 * <p>The implementation of a generic {@link Cipher} <i>Adapter</i> class to
71
 * The implementation of a generic {@link Cipher} <i>Adapter</i> class to wrap
72
 * wrap GNU Crypto cipher instances.</p>
72
 * GNU cipher instances.
73
 *
73
 * <p>
74
 * <p>This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
74
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
75
 * the {@link Cipher} class, which provides the functionality of symmetric-key
75
 * the {@link Cipher} class, which provides the functionality of symmetric-key
76
 * block ciphers, such as the AES.<p>
76
 * block ciphers, such as the AES.
77
 *
77
 * <p>
78
 * <p>This base class defines all of the abstract methods in {@link CipherSpi},
78
 * This base class defines all of the abstract methods in {@link CipherSpi},
79
 * but does not define the (non-abstract) key wrapping functions that extended
79
 * but does not define the (non-abstract) key wrapping functions that extended
80
 * the base cipher SPI, and these methods thus immediately throw an
80
 * the base cipher SPI, and these methods thus immediately throw an
81
 * {@link UnsupportedOperationException}. If a cipher implementation provides
81
 * {@link UnsupportedOperationException}. If a cipher implementation provides
82
 * this functionality, or if it in fact accepts parameters other than the key
82
 * this functionality, or if it in fact accepts parameters other than the key
83
 * and the initialization vector, the subclass should override those methods.
83
 * and the initialization vector, the subclass should override those methods.
84
 * Otherwise a subclass need only call the {@link #CipherAdapter(String)}
84
 * Otherwise a subclass need only call the {@link #CipherAdapter(String)}
85
 * constructor with the name of the cipher.</p>
85
 * constructor with the name of the cipher.
86
 */
86
 */
87
class CipherAdapter extends CipherSpi
87
class CipherAdapter
88
    extends CipherSpi
88
{
89
{
89
90
  // Constants and variables.
91
  // -------------------------------------------------------------------------
92
93
  /** Our cipher instance. */
90
  /** Our cipher instance. */
94
  protected IBlockCipher cipher;
91
  protected IBlockCipher cipher;
95
96
  /** Our mode instance. */
92
  /** Our mode instance. */
97
  protected IMode mode;
93
  protected IMode mode;
98
99
  /** Our padding instance. */
94
  /** Our padding instance. */
100
  protected IPad pad;
95
  protected IPad pad;
101
102
  /** The current key size. */
96
  /** The current key size. */
103
  protected int keyLen;
97
  protected int keyLen;
104
105
  /** Our attributes map. */
98
  /** Our attributes map. */
106
  protected Map attributes;
99
  protected Map attributes;
107
108
  /** An incomplete block. */
100
  /** An incomplete block. */
109
  protected byte[] partBlock;
101
  protected byte[] partBlock;
110
111
  /** The number of bytes in {@link #partBlock}. */
102
  /** The number of bytes in {@link #partBlock}. */
112
  protected int partLen;
103
  protected int partLen;
113
114
  /** The length of blocks we are processing. */
104
  /** The length of blocks we are processing. */
115
  protected int blockLen;
105
  protected int blockLen;
116
106
117
  // Constructor(s)
118
  // -------------------------------------------------------------------------
119
120
  /**
107
  /**
121
   * <p>Protected constructor to be called by subclasses. The cipher name
108
   * Protected constructor to be called by subclasses. The cipher name argument
122
   * argument should be the appropriate one listed in {@link gnu.java.security.Registry}.
109
   * should be the appropriate one listed in {@link Registry}. The basic cipher
123
   * The basic cipher instance is created, along with an instance of the
110
   * instance is created, along with an instance of the
124
   * {@link gnu.javax.crypto.mode.ECB} mode and no padding.</p>
111
   * {@link gnu.javax.crypto.mode.ECB} mode and no padding.
125
   *
112
   * 
126
   * @param cipherName The cipher to instantiate.
113
   * @param cipherName The cipher to instantiate.
127
   * @param blockLen The block length to use.
114
   * @param blockLen The block length to use.
128
   */
115
   */
Lines 136-143 Link Here
136
  }
123
  }
137
124
138
  /**
125
  /**
139
   * <p>Creates a new cipher adapter with the default block size.</p>
126
   * Creates a new cipher adapter with the default block size.
140
   *
127
   * 
141
   * @param cipherName The cipher to instantiate.
128
   * @param cipherName The cipher to instantiate.
142
   */
129
   */
143
  protected CipherAdapter(String cipherName)
130
  protected CipherAdapter(String cipherName)
Lines 149-157 Link Here
149
    attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(blockLen));
136
    attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(blockLen));
150
  }
137
  }
151
138
152
  // Instance methods implementing javax.crypto.CipherSpi.
153
  // -------------------------------------------------------------------------
154
155
  protected void engineSetMode(String modeName) throws NoSuchAlgorithmException
139
  protected void engineSetMode(String modeName) throws NoSuchAlgorithmException
156
  {
140
  {
157
    if (modeName.length() >= 3
141
    if (modeName.length() >= 3
Lines 172-185 Link Here
172
          }
156
          }
173
      }
157
      }
174
    else
158
    else
175
      {
159
      attributes.remove(IMode.MODE_BLOCK_SIZE);
176
        attributes.remove(IMode.MODE_BLOCK_SIZE);
177
      }
178
    mode = ModeFactory.getInstance(modeName, cipher, blockLen);
160
    mode = ModeFactory.getInstance(modeName, cipher, blockLen);
179
    if (mode == null)
161
    if (mode == null)
180
      {
162
      throw new NoSuchAlgorithmException(modeName);
181
        throw new NoSuchAlgorithmException(modeName);
182
      }
183
  }
163
  }
184
164
185
  protected void engineSetPadding(String padName) throws NoSuchPaddingException
165
  protected void engineSetPadding(String padName) throws NoSuchPaddingException
Lines 191-207 Link Here
191
      }
171
      }
192
    pad = PadFactory.getInstance(padName);
172
    pad = PadFactory.getInstance(padName);
193
    if (pad == null)
173
    if (pad == null)
194
      {
174
      throw new NoSuchPaddingException(padName);
195
        throw new NoSuchPaddingException(padName);
196
      }
197
  }
175
  }
198
176
199
  protected int engineGetBlockSize()
177
  protected int engineGetBlockSize()
200
  {
178
  {
201
    if (cipher != null)
179
    if (cipher != null)
202
      {
180
      return blockLen;
203
        return blockLen;
204
      }
205
    return 0;
181
    return 0;
206
  }
182
  }
207
183
Lines 215-231 Link Here
215
  {
191
  {
216
    byte[] iv = (byte[]) attributes.get(IMode.IV);
192
    byte[] iv = (byte[]) attributes.get(IMode.IV);
217
    if (iv == null)
193
    if (iv == null)
218
      {
194
      return null;
219
        return null;
220
      }
221
    return (byte[]) iv.clone();
195
    return (byte[]) iv.clone();
222
  }
196
  }
223
197
224
  protected AlgorithmParameters engineGetParameters()
198
  protected AlgorithmParameters engineGetParameters()
225
  {
199
  {
226
    BlockCipherParameterSpec spec = new BlockCipherParameterSpec(
200
    byte[] iv = (byte[]) attributes.get(IMode.IV);
227
                                                                 (byte[]) attributes.get(IMode.IV),
201
    int cipherBlockSize = cipher.currentBlockSize();
228
                                                                 cipher.currentBlockSize(),
202
    BlockCipherParameterSpec spec = new BlockCipherParameterSpec(iv,
203
                                                                 cipherBlockSize,
229
                                                                 keyLen);
204
                                                                 keyLen);
230
    AlgorithmParameters params;
205
    AlgorithmParameters params;
231
    try
206
    try
Lines 280-294 Link Here
280
        attributes.put(IMode.STATE, Integer.valueOf(IMode.DECRYPTION));
255
        attributes.put(IMode.STATE, Integer.valueOf(IMode.DECRYPTION));
281
        break;
256
        break;
282
      }
257
      }
283
    if (!key.getFormat().equalsIgnoreCase("RAW"))
258
    if (! key.getFormat().equalsIgnoreCase("RAW"))
284
      {
259
      throw new InvalidKeyException("bad key format " + key.getFormat());
285
        throw new InvalidKeyException("bad key format " + key.getFormat());
286
      }
287
    byte[] kb = key.getEncoded();
260
    byte[] kb = key.getEncoded();
288
    if (keyLen == 0)
261
    if (keyLen == 0)
289
      {
262
      keyLen = kb.length;
290
        keyLen = kb.length;
291
      }
292
    else if (keyLen < kb.length)
263
    else if (keyLen < kb.length)
293
      {
264
      {
294
        byte[] kbb = kb;
265
        byte[] kbb = kb;
Lines 304-315 Link Here
304
      InvalidAlgorithmParameterException
275
      InvalidAlgorithmParameterException
305
  {
276
  {
306
    if (params == null)
277
    if (params == null)
307
      {  
278
      {
308
        // All cipher modes require parameters (like an IV) except ECB. When
279
        // All cipher modes require parameters (like an IV) except ECB. When
309
        // these cant be derived from the given key then it must be generated
280
        // these cant be derived from the given key then it must be generated
310
        // randomly if in ENCRYPT or WRAP mode. Parameters that have defaults
281
        // randomly if in ENCRYPT or WRAP mode. Parameters that have defaults
311
        // for our cipher must be set to these defaults.
282
        // for our cipher must be set to these defaults.
312
        if(! mode.name().toLowerCase().startsWith(Registry.ECB_MODE + "("))
283
        if (! mode.name().toLowerCase().startsWith(Registry.ECB_MODE + "("))
313
          {
284
          {
314
            switch (opmode)
285
            switch (opmode)
315
              {
286
              {
Lines 323-342 Link Here
323
                throw new InvalidAlgorithmParameterException(
294
                throw new InvalidAlgorithmParameterException(
324
                    "Required algorithm parameters are missing for mode: "
295
                    "Required algorithm parameters are missing for mode: "
325
                    + mode.name());
296
                    + mode.name());
326
              } 
297
              }
327
          }
298
          }
328
        // Add default for block length etc.
299
        // Add default for block length etc.
329
        blockLen = cipher.defaultBlockSize();
300
        blockLen = cipher.defaultBlockSize();
330
        attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(blockLen));
301
        attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE,
302
                       Integer.valueOf(blockLen));
331
        keyLen = 0;
303
        keyLen = 0;
332
      }
304
      }
333
    else if (params instanceof BlockCipherParameterSpec)
305
    else if (params instanceof BlockCipherParameterSpec)
334
      {
306
      {
335
        attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE,
307
        BlockCipherParameterSpec bcps = (BlockCipherParameterSpec) params;
336
                       Integer.valueOf(((BlockCipherParameterSpec) params).getBlockSize()));
308
        blockLen = bcps.getBlockSize();
337
        attributes.put(IMode.IV, ((BlockCipherParameterSpec) params).getIV());
309
        attributes.put(IBlockCipher.CIPHER_BLOCK_SIZE, Integer.valueOf(blockLen));
338
        keyLen = ((BlockCipherParameterSpec) params).getKeySize();
310
        attributes.put(IMode.IV, bcps.getIV());
339
        blockLen = ((BlockCipherParameterSpec) params).getBlockSize();
311
        keyLen = bcps.getKeySize();
340
      }
312
      }
341
    else if (params instanceof IvParameterSpec)
313
    else if (params instanceof IvParameterSpec)
342
      {
314
      {
Lines 356-364 Link Here
356
    try
328
    try
357
      {
329
      {
358
        if (params != null)
330
        if (params != null)
359
          {
331
          spec = params.getParameterSpec(BlockCipherParameterSpec.class);
360
            spec = params.getParameterSpec(BlockCipherParameterSpec.class);
361
          }
362
      }
332
      }
363
    catch (InvalidParameterSpecException ignored)
333
    catch (InvalidParameterSpecException ignored)
364
      {
334
      {
Lines 375-465 Link Here
375
      {
345
      {
376
        engineUpdate(input, off, len, out, 0);
346
        engineUpdate(input, off, len, out, 0);
377
      }
347
      }
378
    catch (ShortBufferException x)
348
    catch (ShortBufferException x) // should not happen
379
      { // should not happen
349
      {
380
        x.printStackTrace(System.err);
350
        x.printStackTrace(System.err);
381
      }
351
      }
382
    return out;
352
    return out;
383
  }
353
  }
384
354
385
  //   protected int
386
  //   engineUpdate(byte[] in, int inOff, int inLen, byte[] out, int outOff)
387
  //   throws ShortBufferException
388
  //   {
389
  //      int blockSize = mode.currentBlockSize();
390
  //      int count = (partLen + inLen) / blockSize;
391
  //      if (count * blockSize > out.length - outOff) {
392
  //         throw new ShortBufferException();
393
  //      }
394
  //      byte[] buf;
395
  //      if (partLen > 0 && count > 0) {
396
  //         buf = new byte[partLen + inLen];
397
  //         System.arraycopy(partBlock, 0, buf, 0, partLen);
398
  //         if (in != null && inLen > 0) {
399
  //            System.arraycopy(in, inOff, buf, partLen, inLen);
400
  //         }
401
  //         partLen = 0;
402
  //         inOff = 0;
403
  //      } else {
404
  //         buf = in;
405
  //      }
406
  //      for (int i = 0; i < count; i++) {
407
  //         mode.update(buf, i * blockSize + inOff, out, i * blockSize + outOff);
408
  //      }
409
  //      if (inOff + inLen > count * blockSize) {
410
  //         partLen = (inOff + inLen) - (count * blockSize);
411
  //         System.arraycopy(in, count * blockSize, partBlock, 0, partLen);
412
  //      }
413
  //      return count * blockSize;
414
  //   }
415
416
  protected int engineUpdate(byte[] in, int inOff, int inLen, byte[] out,
355
  protected int engineUpdate(byte[] in, int inOff, int inLen, byte[] out,
417
                             int outOff) throws ShortBufferException
356
                             int outOff) throws ShortBufferException
418
  {
357
  {
419
    if (inLen == 0)
358
    if (inLen == 0) // nothing to process
420
      { // nothing to process
359
      return 0;
421
        return 0;
422
      }
423
    final int blockSize = mode.currentBlockSize();
360
    final int blockSize = mode.currentBlockSize();
424
    final int blockCount = (partLen + inLen) / blockSize;
361
    final int blockCount = (partLen + inLen) / blockSize;
425
    final int result = blockCount * blockSize;
362
    final int result = blockCount * blockSize;
426
    if (result > out.length - outOff)
363
    if (result > out.length - outOff)
364
      throw new ShortBufferException();
365
    if (blockCount == 0) // not enough bytes for even 1 block
427
      {
366
      {
428
        throw new ShortBufferException();
429
      }
430
    if (blockCount == 0)
431
      { // not enough bytes for even 1 block
432
        System.arraycopy(in, inOff, partBlock, partLen, inLen);
367
        System.arraycopy(in, inOff, partBlock, partLen, inLen);
433
        partLen += inLen;
368
        partLen += inLen;
434
        return 0;
369
        return 0;
435
      }
370
      }
436
    final byte[] buf;
371
    final byte[] buf;
437
    // we have enough bytes for at least 1 block
372
    // we have enough bytes for at least 1 block
438
    if (partLen == 0)
373
    if (partLen == 0) // if no cached bytes use input
439
      { // if no cached bytes use input
374
      buf = in;
440
        buf = in;
375
    else // prefix input with cached bytes
441
      }
376
      {
442
    else
443
      { // prefix input with cached bytes
444
        buf = new byte[partLen + inLen];
377
        buf = new byte[partLen + inLen];
445
        System.arraycopy(partBlock, 0, buf, 0, partLen);
378
        System.arraycopy(partBlock, 0, buf, 0, partLen);
446
        if (in != null && inLen > 0)
379
        if (in != null && inLen > 0)
447
          {
380
          System.arraycopy(in, inOff, buf, partLen, inLen);
448
            System.arraycopy(in, inOff, buf, partLen, inLen);
449
          }
450
        inOff = 0;
381
        inOff = 0;
451
      }
382
      }
452
    for (int i = 0; i < blockCount; i++)
383
    for (int i = 0; i < blockCount; i++) // update blockCount * blockSize
453
      { // update blockCount * blockSize
384
      {
454
        mode.update(buf, inOff, out, outOff);
385
        mode.update(buf, inOff, out, outOff);
455
        inOff += blockSize;
386
        inOff += blockSize;
456
        outOff += blockSize;
387
        outOff += blockSize;
457
      }
388
      }
458
    partLen += inLen - result;
389
    partLen += inLen - result;
459
    if (partLen > 0)
390
    if (partLen > 0) // cache remaining bytes from buf
460
      { // cache remaining bytes from buf
391
      System.arraycopy(buf, inOff, partBlock, 0, partLen);
461
        System.arraycopy(buf, inOff, partBlock, 0, partLen);
462
      }
463
    return result;
392
    return result;
464
  }
393
  }
465
394
Lines 499-507 Link Here
499
    else
428
    else
500
      {
429
      {
501
        if (partLen > 0)
430
        if (partLen > 0)
502
          {
431
          throw new IllegalBlockSizeException(partLen + " trailing bytes");
503
            throw new IllegalBlockSizeException(partLen + " trailing bytes");
504
          }
505
        result = buf;
432
        result = buf;
506
      }
433
      }
507
434
Lines 524-532 Link Here
524
  {
451
  {
525
    byte[] buf = engineDoFinal(in, inOff, inLen);
452
    byte[] buf = engineDoFinal(in, inOff, inLen);
526
    if (out.length + outOff < buf.length)
453
    if (out.length + outOff < buf.length)
527
      {
454
      throw new ShortBufferException();
528
        throw new ShortBufferException();
529
      }
530
    System.arraycopy(buf, 0, out, outOff, buf.length);
455
    System.arraycopy(buf, 0, out, outOff, buf.length);
531
    return buf.length;
456
    return buf.length;
532
  }
457
  }
(-)cipher/DESSpi.java (-7 / +4 lines)
Lines 41-55 Link Here
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
/**
43
/**
44
 * The implementation of the DES <i>Service Provider Interface</i>
44
 * The implementation of the DES <i>Service Provider Interface</i> (<b>SPI</b>)
45
 * (<b>SPI</b>) adapter.
45
 * adapter.
46
 */
46
 */
47
public final class DESSpi extends CipherAdapter
47
public final class DESSpi
48
    extends CipherAdapter
48
{
49
{
49
50
  // Constructors.
51
  // --------------------------------------------------------------------
52
53
  public DESSpi()
50
  public DESSpi()
54
  {
51
  {
55
    super(Registry.DES_CIPHER);
52
    super(Registry.DES_CIPHER);
(-)cipher/KhazadSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the Khazad <i>Service Provider Interface</i>
44
 * The implementation of the Khazad <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class KhazadSpi extends CipherAdapter
47
public final class KhazadSpi
48
    extends CipherAdapter
48
{
49
{
49
50
  // Constructors.
51
  // --------------------------------------------------------------------
52
53
  public KhazadSpi()
50
  public KhazadSpi()
54
  {
51
  {
55
    super(Registry.KHAZAD_CIPHER);
52
    super(Registry.KHAZAD_CIPHER);
(-)cipher/NullCipherSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the Null cipher <i>Service Provider Interface</i>
44
 * The implementation of the Null cipher <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class NullCipherSpi extends CipherAdapter
47
public final class NullCipherSpi
48
    extends CipherAdapter
48
{
49
{
49
50
  // Constructors.
51
  // -----------------------------------------------------------------------
52
53
  public NullCipherSpi()
50
  public NullCipherSpi()
54
  {
51
  {
55
    super(Registry.NULL_CIPHER);
52
    super(Registry.NULL_CIPHER);
(-)cipher/PBES2.java (-241 / +270 lines)
Lines 55-74 Link Here
55
import javax.crypto.spec.SecretKeySpec;
55
import javax.crypto.spec.SecretKeySpec;
56
56
57
/**
57
/**
58
 * <p>.</p>
59
 */
58
 */
60
public abstract class PBES2 extends CipherAdapter
59
public abstract class PBES2
60
    extends CipherAdapter
61
{
61
{
62
63
  // Constants and variables
64
  // -------------------------------------------------------------------------
65
66
  /** The HMac (PRF) algorithm name. */
62
  /** The HMac (PRF) algorithm name. */
67
  protected String macName;
63
  protected String macName;
68
64
69
  // Constructor(s)
70
  // -------------------------------------------------------------------------
71
72
  protected PBES2(String cipherName, int blockLen, String macName)
65
  protected PBES2(String cipherName, int blockLen, String macName)
73
  {
66
  {
74
    super(cipherName, blockLen);
67
    super(cipherName, blockLen);
Lines 81-95 Link Here
81
    this.macName = macName;
74
    this.macName = macName;
82
  }
75
  }
83
76
84
  // Instance methods
85
  // -------------------------------------------------------------------------
86
87
  protected void engineInit(int opmode, Key key, SecureRandom random)
77
  protected void engineInit(int opmode, Key key, SecureRandom random)
88
      throws InvalidKeyException
78
      throws InvalidKeyException
89
  {
79
  {
90
    if (!(key instanceof PBEKey))
80
    if (! (key instanceof PBEKey))
91
      throw new InvalidKeyException("not a PBE key");
81
      throw new InvalidKeyException("not a PBE key");
92
93
    super.engineInit(opmode, genkey((PBEKey) key), random);
82
    super.engineInit(opmode, genkey((PBEKey) key), random);
94
  }
83
  }
95
84
Lines 97-105 Link Here
97
                            SecureRandom random) throws InvalidKeyException,
86
                            SecureRandom random) throws InvalidKeyException,
98
      InvalidAlgorithmParameterException
87
      InvalidAlgorithmParameterException
99
  {
88
  {
100
    if (!(key instanceof PBEKey))
89
    if (! (key instanceof PBEKey))
101
      throw new InvalidKeyException("not a PBE key");
90
      throw new InvalidKeyException("not a PBE key");
102
103
    super.engineInit(opmode, genkey((PBEKey) key), params, random);
91
    super.engineInit(opmode, genkey((PBEKey) key), params, random);
104
  }
92
  }
105
93
Lines 107-115 Link Here
107
                            SecureRandom random) throws InvalidKeyException,
95
                            SecureRandom random) throws InvalidKeyException,
108
      InvalidAlgorithmParameterException
96
      InvalidAlgorithmParameterException
109
  {
97
  {
110
    if (!(key instanceof PBEKey))
98
    if (! (key instanceof PBEKey))
111
      throw new InvalidKeyException("not a PBE key");
99
      throw new InvalidKeyException("not a PBE key");
112
113
    super.engineInit(opmode, genkey((PBEKey) key), params, random);
100
    super.engineInit(opmode, genkey((PBEKey) key), params, random);
114
  }
101
  }
115
102
Lines 117-125 Link Here
117
  {
104
  {
118
    IRandom kdf = PRNGFactory.getInstance("PBKDF2-" + macName);
105
    IRandom kdf = PRNGFactory.getInstance("PBKDF2-" + macName);
119
    if (kdf == null)
106
    if (kdf == null)
120
      {
107
      throw new IllegalArgumentException("no such KDF: PBKDF2-" + macName);
121
        throw new IllegalArgumentException("no such KDF: PBKDF2-" + macName);
122
      }
123
    HashMap attrib = new HashMap();
108
    HashMap attrib = new HashMap();
124
    attrib.put(IPBE.ITERATION_COUNT, Integer.valueOf(key.getIterationCount()));
109
    attrib.put(IPBE.ITERATION_COUNT, Integer.valueOf(key.getIterationCount()));
125
    attrib.put(IPBE.PASSWORD, key.getPassword());
110
    attrib.put(IPBE.PASSWORD, key.getPassword());
Lines 139-159 Link Here
139
      }
124
      }
140
    catch (LimitReachedException shouldNotHappen)
125
    catch (LimitReachedException shouldNotHappen)
141
      {
126
      {
142
        //         throw new Error(shouldNotHappen);
143
        throw new Error(String.valueOf(shouldNotHappen));
127
        throw new Error(String.valueOf(shouldNotHappen));
144
      }
128
      }
145
    return new SecretKeySpec(dk, cipher.name());
129
    return new SecretKeySpec(dk, cipher.name());
146
  }
130
  }
147
131
148
  // Inner classe(s)
132
  public static class HMacSHA1
149
  // =========================================================================
133
      extends PBES2
150
151
  public static class HMacSHA1 extends PBES2
152
  {
134
  {
153
154
    // Constructor(s)
155
    // ---------------------------------------------------------------------
156
157
    public HMacSHA1(String cipher, int blockLen)
135
    public HMacSHA1(String cipher, int blockLen)
158
    {
136
    {
159
      super(cipher, blockLen, "HMAC-SHA1");
137
      super(cipher, blockLen, "HMAC-SHA1");
Lines 164-173 Link Here
164
      super(cipher, "HMAC-SHA1");
142
      super(cipher, "HMAC-SHA1");
165
    }
143
    }
166
144
167
    // Inner classe(s)
145
    public static class AES
168
    // ======================================================================
146
        extends HMacSHA1
169
170
    public static class AES extends HMacSHA1
171
    {
147
    {
172
      public AES()
148
      public AES()
173
      {
149
      {
Lines 175-181 Link Here
175
      }
151
      }
176
    }
152
    }
177
153
178
    public static class Anubis extends HMacSHA1
154
    public static class Anubis
155
        extends HMacSHA1
179
    {
156
    {
180
      public Anubis()
157
      public Anubis()
181
      {
158
      {
Lines 183-189 Link Here
183
      }
160
      }
184
    }
161
    }
185
162
186
    public static class Blowfish extends HMacSHA1
163
    public static class Blowfish
164
        extends HMacSHA1
187
    {
165
    {
188
      public Blowfish()
166
      public Blowfish()
189
      {
167
      {
Lines 191-197 Link Here
191
      }
169
      }
192
    }
170
    }
193
171
194
    public static class Cast5 extends HMacSHA1
172
    public static class Cast5
173
        extends HMacSHA1
195
    {
174
    {
196
      public Cast5()
175
      public Cast5()
197
      {
176
      {
Lines 199-205 Link Here
199
      }
178
      }
200
    }
179
    }
201
180
202
    public static class DES extends HMacSHA1
181
    public static class DES
182
        extends HMacSHA1
203
    {
183
    {
204
      public DES()
184
      public DES()
205
      {
185
      {
Lines 207-213 Link Here
207
      }
187
      }
208
    }
188
    }
209
189
210
    public static class Khazad extends HMacSHA1
190
    public static class Khazad
191
        extends HMacSHA1
211
    {
192
    {
212
      public Khazad()
193
      public Khazad()
213
      {
194
      {
Lines 215-221 Link Here
215
      }
196
      }
216
    }
197
    }
217
198
218
    public static class Serpent extends HMacSHA1
199
    public static class Serpent
200
        extends HMacSHA1
219
    {
201
    {
220
      public Serpent()
202
      public Serpent()
221
      {
203
      {
Lines 223-229 Link Here
223
      }
205
      }
224
    }
206
    }
225
207
226
    public static class Square extends HMacSHA1
208
    public static class Square
209
        extends HMacSHA1
227
    {
210
    {
228
      public Square()
211
      public Square()
229
      {
212
      {
Lines 231-237 Link Here
231
      }
214
      }
232
    }
215
    }
233
216
234
    public static class TripleDES extends HMacSHA1
217
    public static class TripleDES
218
        extends HMacSHA1
235
    {
219
    {
236
      public TripleDES()
220
      public TripleDES()
237
      {
221
      {
Lines 239-245 Link Here
239
      }
223
      }
240
    }
224
    }
241
225
242
    public static class Twofish extends HMacSHA1
226
    public static class Twofish
227
        extends HMacSHA1
243
    {
228
    {
244
      public Twofish()
229
      public Twofish()
245
      {
230
      {
Lines 248-259 Link Here
248
    }
233
    }
249
  }
234
  }
250
235
251
  public static class HMacMD5 extends PBES2
236
  public static class HMacMD5
237
      extends PBES2
252
  {
238
  {
253
254
    // Constructor(s)
255
    // ----------------------------------------------------------------------
256
257
    public HMacMD5(String cipher, int blockLen)
239
    public HMacMD5(String cipher, int blockLen)
258
    {
240
    {
259
      super(cipher, blockLen, "HMAC-MD5");
241
      super(cipher, blockLen, "HMAC-MD5");
Lines 264-273 Link Here
264
      super(cipher, "HMAC-MD5");
246
      super(cipher, "HMAC-MD5");
265
    }
247
    }
266
248
267
    // Inner classe(s)
249
    public static class AES
268
    // ======================================================================
250
        extends HMacMD5
269
270
    public static class AES extends HMacMD5
271
    {
251
    {
272
      public AES()
252
      public AES()
273
      {
253
      {
Lines 275-281 Link Here
275
      }
255
      }
276
    }
256
    }
277
257
278
    public static class Anubis extends HMacMD5
258
    public static class Anubis
259
        extends HMacMD5
279
    {
260
    {
280
      public Anubis()
261
      public Anubis()
281
      {
262
      {
Lines 283-289 Link Here
283
      }
264
      }
284
    }
265
    }
285
266
286
    public static class Blowfish extends HMacMD5
267
    public static class Blowfish
268
        extends HMacMD5
287
    {
269
    {
288
      public Blowfish()
270
      public Blowfish()
289
      {
271
      {
Lines 291-297 Link Here
291
      }
273
      }
292
    }
274
    }
293
275
294
    public static class Cast5 extends HMacMD5
276
    public static class Cast5
277
        extends HMacMD5
295
    {
278
    {
296
      public Cast5()
279
      public Cast5()
297
      {
280
      {
Lines 299-305 Link Here
299
      }
282
      }
300
    }
283
    }
301
284
302
    public static class DES extends HMacMD5
285
    public static class DES
286
        extends HMacMD5
303
    {
287
    {
304
      public DES()
288
      public DES()
305
      {
289
      {
Lines 307-313 Link Here
307
      }
291
      }
308
    }
292
    }
309
293
310
    public static class Khazad extends HMacMD5
294
    public static class Khazad
295
        extends HMacMD5
311
    {
296
    {
312
      public Khazad()
297
      public Khazad()
313
      {
298
      {
Lines 315-321 Link Here
315
      }
300
      }
316
    }
301
    }
317
302
318
    public static class Serpent extends HMacMD5
303
    public static class Serpent
304
        extends HMacMD5
319
    {
305
    {
320
      public Serpent()
306
      public Serpent()
321
      {
307
      {
Lines 323-329 Link Here
323
      }
309
      }
324
    }
310
    }
325
311
326
    public static class Square extends HMacMD5
312
    public static class Square
313
        extends HMacMD5
327
    {
314
    {
328
      public Square()
315
      public Square()
329
      {
316
      {
Lines 331-337 Link Here
331
      }
318
      }
332
    }
319
    }
333
320
334
    public static class TripleDES extends HMacMD5
321
    public static class TripleDES
322
        extends HMacMD5
335
    {
323
    {
336
      public TripleDES()
324
      public TripleDES()
337
      {
325
      {
Lines 339-345 Link Here
339
      }
327
      }
340
    }
328
    }
341
329
342
    public static class Twofish extends HMacMD5
330
    public static class Twofish
331
        extends HMacMD5
343
    {
332
    {
344
      public Twofish()
333
      public Twofish()
345
      {
334
      {
Lines 348-359 Link Here
348
    }
337
    }
349
  }
338
  }
350
339
351
  public static class HMacMD2 extends PBES2
340
  public static class HMacMD2
341
      extends PBES2
352
  {
342
  {
353
354
    // Constructor(s)
355
    // ----------------------------------------------------------------------
356
357
    public HMacMD2(String cipher, int blockLen)
343
    public HMacMD2(String cipher, int blockLen)
358
    {
344
    {
359
      super(cipher, blockLen, "HMAC-MD2");
345
      super(cipher, blockLen, "HMAC-MD2");
Lines 364-373 Link Here
364
      super(cipher, "HMAC-MD2");
350
      super(cipher, "HMAC-MD2");
365
    }
351
    }
366
352
367
    // Inner classe(s)
353
    public static class AES
368
    // ======================================================================
354
        extends HMacMD2
369
370
    public static class AES extends HMacMD2
371
    {
355
    {
372
      public AES()
356
      public AES()
373
      {
357
      {
Lines 375-381 Link Here
375
      }
359
      }
376
    }
360
    }
377
361
378
    public static class Anubis extends HMacMD2
362
    public static class Anubis
363
        extends HMacMD2
379
    {
364
    {
380
      public Anubis()
365
      public Anubis()
381
      {
366
      {
Lines 383-389 Link Here
383
      }
368
      }
384
    }
369
    }
385
370
386
    public static class Blowfish extends HMacMD2
371
    public static class Blowfish
372
        extends HMacMD2
387
    {
373
    {
388
      public Blowfish()
374
      public Blowfish()
389
      {
375
      {
Lines 391-397 Link Here
391
      }
377
      }
392
    }
378
    }
393
379
394
    public static class Cast5 extends HMacMD2
380
    public static class Cast5
381
        extends HMacMD2
395
    {
382
    {
396
      public Cast5()
383
      public Cast5()
397
      {
384
      {
Lines 399-405 Link Here
399
      }
386
      }
400
    }
387
    }
401
388
402
    public static class DES extends HMacMD2
389
    public static class DES
390
        extends HMacMD2
403
    {
391
    {
404
      public DES()
392
      public DES()
405
      {
393
      {
Lines 407-413 Link Here
407
      }
395
      }
408
    }
396
    }
409
397
410
    public static class Khazad extends HMacMD2
398
    public static class Khazad
399
        extends HMacMD2
411
    {
400
    {
412
      public Khazad()
401
      public Khazad()
413
      {
402
      {
Lines 415-421 Link Here
415
      }
404
      }
416
    }
405
    }
417
406
418
    public static class Serpent extends HMacMD2
407
    public static class Serpent
408
        extends HMacMD2
419
    {
409
    {
420
      public Serpent()
410
      public Serpent()
421
      {
411
      {
Lines 423-429 Link Here
423
      }
413
      }
424
    }
414
    }
425
415
426
    public static class Square extends HMacMD2
416
    public static class Square
417
        extends HMacMD2
427
    {
418
    {
428
      public Square()
419
      public Square()
429
      {
420
      {
Lines 431-437 Link Here
431
      }
422
      }
432
    }
423
    }
433
424
434
    public static class TripleDES extends HMacMD2
425
    public static class TripleDES
426
        extends HMacMD2
435
    {
427
    {
436
      public TripleDES()
428
      public TripleDES()
437
      {
429
      {
Lines 439-445 Link Here
439
      }
431
      }
440
    }
432
    }
441
433
442
    public static class Twofish extends HMacMD2
434
    public static class Twofish
435
        extends HMacMD2
443
    {
436
    {
444
      public Twofish()
437
      public Twofish()
445
      {
438
      {
Lines 448-459 Link Here
448
    }
441
    }
449
  }
442
  }
450
443
451
  public static class HMacMD4 extends PBES2
444
  public static class HMacMD4
445
      extends PBES2
452
  {
446
  {
453
454
    // Constructor(s)
455
    // ----------------------------------------------------------------------
456
457
    public HMacMD4(String cipher, int blockLen)
447
    public HMacMD4(String cipher, int blockLen)
458
    {
448
    {
459
      super(cipher, blockLen, "HMAC-MD4");
449
      super(cipher, blockLen, "HMAC-MD4");
Lines 464-473 Link Here
464
      super(cipher, "HMAC-MD4");
454
      super(cipher, "HMAC-MD4");
465
    }
455
    }
466
456
467
    // Inner classe(s)
457
    public static class AES
468
    // ======================================================================
458
        extends HMacMD4
469
470
    public static class AES extends HMacMD4
471
    {
459
    {
472
      public AES()
460
      public AES()
473
      {
461
      {
Lines 475-481 Link Here
475
      }
463
      }
476
    }
464
    }
477
465
478
    public static class Anubis extends HMacMD4
466
    public static class Anubis
467
        extends HMacMD4
479
    {
468
    {
480
      public Anubis()
469
      public Anubis()
481
      {
470
      {
Lines 483-489 Link Here
483
      }
472
      }
484
    }
473
    }
485
474
486
    public static class Blowfish extends HMacMD4
475
    public static class Blowfish
476
        extends HMacMD4
487
    {
477
    {
488
      public Blowfish()
478
      public Blowfish()
489
      {
479
      {
Lines 491-497 Link Here
491
      }
481
      }
492
    }
482
    }
493
483
494
    public static class Cast5 extends HMacMD4
484
    public static class Cast5
485
        extends HMacMD4
495
    {
486
    {
496
      public Cast5()
487
      public Cast5()
497
      {
488
      {
Lines 499-505 Link Here
499
      }
490
      }
500
    }
491
    }
501
492
502
    public static class DES extends HMacMD4
493
    public static class DES
494
        extends HMacMD4
503
    {
495
    {
504
      public DES()
496
      public DES()
505
      {
497
      {
Lines 507-513 Link Here
507
      }
499
      }
508
    }
500
    }
509
501
510
    public static class Khazad extends HMacMD4
502
    public static class Khazad
503
        extends HMacMD4
511
    {
504
    {
512
      public Khazad()
505
      public Khazad()
513
      {
506
      {
Lines 515-521 Link Here
515
      }
508
      }
516
    }
509
    }
517
510
518
    public static class Serpent extends HMacMD4
511
    public static class Serpent
512
        extends HMacMD4
519
    {
513
    {
520
      public Serpent()
514
      public Serpent()
521
      {
515
      {
Lines 523-529 Link Here
523
      }
517
      }
524
    }
518
    }
525
519
526
    public static class Square extends HMacMD4
520
    public static class Square
521
        extends HMacMD4
527
    {
522
    {
528
      public Square()
523
      public Square()
529
      {
524
      {
Lines 531-537 Link Here
531
      }
526
      }
532
    }
527
    }
533
528
534
    public static class TripleDES extends HMacMD4
529
    public static class TripleDES
530
        extends HMacMD4
535
    {
531
    {
536
      public TripleDES()
532
      public TripleDES()
537
      {
533
      {
Lines 539-545 Link Here
539
      }
535
      }
540
    }
536
    }
541
537
542
    public static class Twofish extends HMacMD4
538
    public static class Twofish
539
        extends HMacMD4
543
    {
540
    {
544
      public Twofish()
541
      public Twofish()
545
      {
542
      {
Lines 548-559 Link Here
548
    }
545
    }
549
  }
546
  }
550
547
551
  public static class HMacHaval extends PBES2
548
  public static class HMacHaval
549
      extends PBES2
552
  {
550
  {
553
554
    // Constructor(s)
555
    // ---------------------------------------------------------------------
556
557
    public HMacHaval(String cipher, int blockLen)
551
    public HMacHaval(String cipher, int blockLen)
558
    {
552
    {
559
      super(cipher, blockLen, "HMAC-HAVAL");
553
      super(cipher, blockLen, "HMAC-HAVAL");
Lines 564-573 Link Here
564
      super(cipher, "HMAC-HAVAL");
558
      super(cipher, "HMAC-HAVAL");
565
    }
559
    }
566
560
567
    // Inner classe(s)
561
    public static class AES
568
    // ======================================================================
562
        extends HMacHaval
569
570
    public static class AES extends HMacHaval
571
    {
563
    {
572
      public AES()
564
      public AES()
573
      {
565
      {
Lines 575-581 Link Here
575
      }
567
      }
576
    }
568
    }
577
569
578
    public static class Anubis extends HMacHaval
570
    public static class Anubis
571
        extends HMacHaval
579
    {
572
    {
580
      public Anubis()
573
      public Anubis()
581
      {
574
      {
Lines 583-589 Link Here
583
      }
576
      }
584
    }
577
    }
585
578
586
    public static class Blowfish extends HMacHaval
579
    public static class Blowfish
580
        extends HMacHaval
587
    {
581
    {
588
      public Blowfish()
582
      public Blowfish()
589
      {
583
      {
Lines 591-597 Link Here
591
      }
585
      }
592
    }
586
    }
593
587
594
    public static class Cast5 extends HMacHaval
588
    public static class Cast5
589
        extends HMacHaval
595
    {
590
    {
596
      public Cast5()
591
      public Cast5()
597
      {
592
      {
Lines 599-605 Link Here
599
      }
594
      }
600
    }
595
    }
601
596
602
    public static class DES extends HMacHaval
597
    public static class DES
598
        extends HMacHaval
603
    {
599
    {
604
      public DES()
600
      public DES()
605
      {
601
      {
Lines 607-613 Link Here
607
      }
603
      }
608
    }
604
    }
609
605
610
    public static class Khazad extends HMacHaval
606
    public static class Khazad
607
        extends HMacHaval
611
    {
608
    {
612
      public Khazad()
609
      public Khazad()
613
      {
610
      {
Lines 615-621 Link Here
615
      }
612
      }
616
    }
613
    }
617
614
618
    public static class Serpent extends HMacHaval
615
    public static class Serpent
616
        extends HMacHaval
619
    {
617
    {
620
      public Serpent()
618
      public Serpent()
621
      {
619
      {
Lines 623-629 Link Here
623
      }
621
      }
624
    }
622
    }
625
623
626
    public static class Square extends HMacHaval
624
    public static class Square
625
        extends HMacHaval
627
    {
626
    {
628
      public Square()
627
      public Square()
629
      {
628
      {
Lines 631-637 Link Here
631
      }
630
      }
632
    }
631
    }
633
632
634
    public static class TripleDES extends HMacHaval
633
    public static class TripleDES
634
        extends HMacHaval
635
    {
635
    {
636
      public TripleDES()
636
      public TripleDES()
637
      {
637
      {
Lines 639-645 Link Here
639
      }
639
      }
640
    }
640
    }
641
641
642
    public static class Twofish extends HMacHaval
642
    public static class Twofish
643
        extends HMacHaval
643
    {
644
    {
644
      public Twofish()
645
      public Twofish()
645
      {
646
      {
Lines 648-659 Link Here
648
    }
649
    }
649
  }
650
  }
650
651
651
  public static class HMacRipeMD128 extends PBES2
652
  public static class HMacRipeMD128
653
      extends PBES2
652
  {
654
  {
653
654
    // Constructor(s)
655
    // ----------------------------------------------------------------------
656
657
    public HMacRipeMD128(String cipher, int blockLen)
655
    public HMacRipeMD128(String cipher, int blockLen)
658
    {
656
    {
659
      super(cipher, blockLen, "HMAC-RIPEMD128");
657
      super(cipher, blockLen, "HMAC-RIPEMD128");
Lines 664-673 Link Here
664
      super(cipher, "HMAC-RIPEMD128");
662
      super(cipher, "HMAC-RIPEMD128");
665
    }
663
    }
666
664
667
    // Inner classe(s)
665
    public static class AES
668
    // ======================================================================
666
        extends HMacRipeMD128
669
670
    public static class AES extends HMacRipeMD128
671
    {
667
    {
672
      public AES()
668
      public AES()
673
      {
669
      {
Lines 675-681 Link Here
675
      }
671
      }
676
    }
672
    }
677
673
678
    public static class Anubis extends HMacRipeMD128
674
    public static class Anubis
675
        extends HMacRipeMD128
679
    {
676
    {
680
      public Anubis()
677
      public Anubis()
681
      {
678
      {
Lines 683-689 Link Here
683
      }
680
      }
684
    }
681
    }
685
682
686
    public static class Blowfish extends HMacRipeMD128
683
    public static class Blowfish
684
        extends HMacRipeMD128
687
    {
685
    {
688
      public Blowfish()
686
      public Blowfish()
689
      {
687
      {
Lines 691-697 Link Here
691
      }
689
      }
692
    }
690
    }
693
691
694
    public static class Cast5 extends HMacRipeMD128
692
    public static class Cast5
693
        extends HMacRipeMD128
695
    {
694
    {
696
      public Cast5()
695
      public Cast5()
697
      {
696
      {
Lines 699-705 Link Here
699
      }
698
      }
700
    }
699
    }
701
700
702
    public static class DES extends HMacRipeMD128
701
    public static class DES
702
        extends HMacRipeMD128
703
    {
703
    {
704
      public DES()
704
      public DES()
705
      {
705
      {
Lines 707-713 Link Here
707
      }
707
      }
708
    }
708
    }
709
709
710
    public static class Khazad extends HMacRipeMD128
710
    public static class Khazad
711
        extends HMacRipeMD128
711
    {
712
    {
712
      public Khazad()
713
      public Khazad()
713
      {
714
      {
Lines 715-721 Link Here
715
      }
716
      }
716
    }
717
    }
717
718
718
    public static class Serpent extends HMacRipeMD128
719
    public static class Serpent
720
        extends HMacRipeMD128
719
    {
721
    {
720
      public Serpent()
722
      public Serpent()
721
      {
723
      {
Lines 723-729 Link Here
723
      }
725
      }
724
    }
726
    }
725
727
726
    public static class Square extends HMacRipeMD128
728
    public static class Square
729
        extends HMacRipeMD128
727
    {
730
    {
728
      public Square()
731
      public Square()
729
      {
732
      {
Lines 731-737 Link Here
731
      }
734
      }
732
    }
735
    }
733
736
734
    public static class TripleDES extends HMacRipeMD128
737
    public static class TripleDES
738
        extends HMacRipeMD128
735
    {
739
    {
736
      public TripleDES()
740
      public TripleDES()
737
      {
741
      {
Lines 739-745 Link Here
739
      }
743
      }
740
    }
744
    }
741
745
742
    public static class Twofish extends HMacRipeMD128
746
    public static class Twofish
747
        extends HMacRipeMD128
743
    {
748
    {
744
      public Twofish()
749
      public Twofish()
745
      {
750
      {
Lines 748-759 Link Here
748
    }
753
    }
749
  }
754
  }
750
755
751
  public static class HMacRipeMD160 extends PBES2
756
  public static class HMacRipeMD160
757
      extends PBES2
752
  {
758
  {
753
754
    // Constructor(s)
755
    // ----------------------------------------------------------------------
756
757
    public HMacRipeMD160(String cipher, int blockLen)
759
    public HMacRipeMD160(String cipher, int blockLen)
758
    {
760
    {
759
      super(cipher, blockLen, "HMAC-RIPEMD160");
761
      super(cipher, blockLen, "HMAC-RIPEMD160");
Lines 764-773 Link Here
764
      super(cipher, "HMAC-RIPEMD160");
766
      super(cipher, "HMAC-RIPEMD160");
765
    }
767
    }
766
768
767
    // Inner classe(s)
769
    public static class AES
768
    // ======================================================================
770
        extends HMacRipeMD160
769
770
    public static class AES extends HMacRipeMD160
771
    {
771
    {
772
      public AES()
772
      public AES()
773
      {
773
      {
Lines 775-781 Link Here
775
      }
775
      }
776
    }
776
    }
777
777
778
    public static class Anubis extends HMacRipeMD160
778
    public static class Anubis
779
        extends HMacRipeMD160
779
    {
780
    {
780
      public Anubis()
781
      public Anubis()
781
      {
782
      {
Lines 783-789 Link Here
783
      }
784
      }
784
    }
785
    }
785
786
786
    public static class Blowfish extends HMacRipeMD160
787
    public static class Blowfish
788
        extends HMacRipeMD160
787
    {
789
    {
788
      public Blowfish()
790
      public Blowfish()
789
      {
791
      {
Lines 791-797 Link Here
791
      }
793
      }
792
    }
794
    }
793
795
794
    public static class Cast5 extends HMacRipeMD160
796
    public static class Cast5
797
        extends HMacRipeMD160
795
    {
798
    {
796
      public Cast5()
799
      public Cast5()
797
      {
800
      {
Lines 799-805 Link Here
799
      }
802
      }
800
    }
803
    }
801
804
802
    public static class DES extends HMacRipeMD160
805
    public static class DES
806
        extends HMacRipeMD160
803
    {
807
    {
804
      public DES()
808
      public DES()
805
      {
809
      {
Lines 807-813 Link Here
807
      }
811
      }
808
    }
812
    }
809
813
810
    public static class Khazad extends HMacRipeMD160
814
    public static class Khazad
815
        extends HMacRipeMD160
811
    {
816
    {
812
      public Khazad()
817
      public Khazad()
813
      {
818
      {
Lines 815-821 Link Here
815
      }
820
      }
816
    }
821
    }
817
822
818
    public static class Serpent extends HMacRipeMD160
823
    public static class Serpent
824
        extends HMacRipeMD160
819
    {
825
    {
820
      public Serpent()
826
      public Serpent()
821
      {
827
      {
Lines 823-829 Link Here
823
      }
829
      }
824
    }
830
    }
825
831
826
    public static class Square extends HMacRipeMD160
832
    public static class Square
833
        extends HMacRipeMD160
827
    {
834
    {
828
      public Square()
835
      public Square()
829
      {
836
      {
Lines 831-837 Link Here
831
      }
838
      }
832
    }
839
    }
833
840
834
    public static class TripleDES extends HMacRipeMD160
841
    public static class TripleDES
842
        extends HMacRipeMD160
835
    {
843
    {
836
      public TripleDES()
844
      public TripleDES()
837
      {
845
      {
Lines 839-845 Link Here
839
      }
847
      }
840
    }
848
    }
841
849
842
    public static class Twofish extends HMacRipeMD160
850
    public static class Twofish
851
        extends HMacRipeMD160
843
    {
852
    {
844
      public Twofish()
853
      public Twofish()
845
      {
854
      {
Lines 848-859 Link Here
848
    }
857
    }
849
  }
858
  }
850
859
851
  public static class HMacSHA256 extends PBES2
860
  public static class HMacSHA256
861
      extends PBES2
852
  {
862
  {
853
854
    // Constructor(s)
855
    // ---------------------------------------------------------------------
856
857
    public HMacSHA256(String cipher, int blockLen)
863
    public HMacSHA256(String cipher, int blockLen)
858
    {
864
    {
859
      super(cipher, blockLen, "HMAC-SHA-256");
865
      super(cipher, blockLen, "HMAC-SHA-256");
Lines 864-873 Link Here
864
      super(cipher, "HMAC-SHA-256");
870
      super(cipher, "HMAC-SHA-256");
865
    }
871
    }
866
872
867
    // Inner classe(s)
873
    public static class AES
868
    // ======================================================================
874
        extends HMacSHA256
869
870
    public static class AES extends HMacSHA256
871
    {
875
    {
872
      public AES()
876
      public AES()
873
      {
877
      {
Lines 875-881 Link Here
875
      }
879
      }
876
    }
880
    }
877
881
878
    public static class Anubis extends HMacSHA256
882
    public static class Anubis
883
        extends HMacSHA256
879
    {
884
    {
880
      public Anubis()
885
      public Anubis()
881
      {
886
      {
Lines 883-889 Link Here
883
      }
888
      }
884
    }
889
    }
885
890
886
    public static class Blowfish extends HMacSHA256
891
    public static class Blowfish
892
        extends HMacSHA256
887
    {
893
    {
888
      public Blowfish()
894
      public Blowfish()
889
      {
895
      {
Lines 891-897 Link Here
891
      }
897
      }
892
    }
898
    }
893
899
894
    public static class Cast5 extends HMacSHA256
900
    public static class Cast5
901
        extends HMacSHA256
895
    {
902
    {
896
      public Cast5()
903
      public Cast5()
897
      {
904
      {
Lines 899-905 Link Here
899
      }
906
      }
900
    }
907
    }
901
908
902
    public static class DES extends HMacSHA256
909
    public static class DES
910
        extends HMacSHA256
903
    {
911
    {
904
      public DES()
912
      public DES()
905
      {
913
      {
Lines 907-913 Link Here
907
      }
915
      }
908
    }
916
    }
909
917
910
    public static class Khazad extends HMacSHA256
918
    public static class Khazad
919
        extends HMacSHA256
911
    {
920
    {
912
      public Khazad()
921
      public Khazad()
913
      {
922
      {
Lines 915-921 Link Here
915
      }
924
      }
916
    }
925
    }
917
926
918
    public static class Serpent extends HMacSHA256
927
    public static class Serpent
928
        extends HMacSHA256
919
    {
929
    {
920
      public Serpent()
930
      public Serpent()
921
      {
931
      {
Lines 923-929 Link Here
923
      }
933
      }
924
    }
934
    }
925
935
926
    public static class Square extends HMacSHA256
936
    public static class Square
937
        extends HMacSHA256
927
    {
938
    {
928
      public Square()
939
      public Square()
929
      {
940
      {
Lines 931-937 Link Here
931
      }
942
      }
932
    }
943
    }
933
944
934
    public static class TripleDES extends HMacSHA256
945
    public static class TripleDES
946
        extends HMacSHA256
935
    {
947
    {
936
      public TripleDES()
948
      public TripleDES()
937
      {
949
      {
Lines 939-945 Link Here
939
      }
951
      }
940
    }
952
    }
941
953
942
    public static class Twofish extends HMacSHA256
954
    public static class Twofish
955
        extends HMacSHA256
943
    {
956
    {
944
      public Twofish()
957
      public Twofish()
945
      {
958
      {
Lines 948-959 Link Here
948
    }
961
    }
949
  }
962
  }
950
963
951
  public static class HMacSHA384 extends PBES2
964
  public static class HMacSHA384
965
      extends PBES2
952
  {
966
  {
953
954
    // Constructor(s)
955
    // ---------------------------------------------------------------------
956
957
    public HMacSHA384(String cipher, int blockLen)
967
    public HMacSHA384(String cipher, int blockLen)
958
    {
968
    {
959
      super(cipher, blockLen, "HMAC-SHA-384");
969
      super(cipher, blockLen, "HMAC-SHA-384");
Lines 964-973 Link Here
964
      super(cipher, "HMAC-SHA-384");
974
      super(cipher, "HMAC-SHA-384");
965
    }
975
    }
966
976
967
    // Inner classe(s)
977
    public static class AES
968
    // ======================================================================
978
        extends HMacSHA384
969
970
    public static class AES extends HMacSHA384
971
    {
979
    {
972
      public AES()
980
      public AES()
973
      {
981
      {
Lines 975-981 Link Here
975
      }
983
      }
976
    }
984
    }
977
985
978
    public static class Anubis extends HMacSHA384
986
    public static class Anubis
987
        extends HMacSHA384
979
    {
988
    {
980
      public Anubis()
989
      public Anubis()
981
      {
990
      {
Lines 983-989 Link Here
983
      }
992
      }
984
    }
993
    }
985
994
986
    public static class Blowfish extends HMacSHA384
995
    public static class Blowfish
996
        extends HMacSHA384
987
    {
997
    {
988
      public Blowfish()
998
      public Blowfish()
989
      {
999
      {
Lines 991-997 Link Here
991
      }
1001
      }
992
    }
1002
    }
993
1003
994
    public static class Cast5 extends HMacSHA384
1004
    public static class Cast5
1005
        extends HMacSHA384
995
    {
1006
    {
996
      public Cast5()
1007
      public Cast5()
997
      {
1008
      {
Lines 999-1005 Link Here
999
      }
1010
      }
1000
    }
1011
    }
1001
1012
1002
    public static class DES extends HMacSHA384
1013
    public static class DES
1014
        extends HMacSHA384
1003
    {
1015
    {
1004
      public DES()
1016
      public DES()
1005
      {
1017
      {
Lines 1007-1013 Link Here
1007
      }
1019
      }
1008
    }
1020
    }
1009
1021
1010
    public static class Khazad extends HMacSHA384
1022
    public static class Khazad
1023
        extends HMacSHA384
1011
    {
1024
    {
1012
      public Khazad()
1025
      public Khazad()
1013
      {
1026
      {
Lines 1015-1021 Link Here
1015
      }
1028
      }
1016
    }
1029
    }
1017
1030
1018
    public static class Serpent extends HMacSHA384
1031
    public static class Serpent
1032
        extends HMacSHA384
1019
    {
1033
    {
1020
      public Serpent()
1034
      public Serpent()
1021
      {
1035
      {
Lines 1023-1029 Link Here
1023
      }
1037
      }
1024
    }
1038
    }
1025
1039
1026
    public static class Square extends HMacSHA384
1040
    public static class Square
1041
        extends HMacSHA384
1027
    {
1042
    {
1028
      public Square()
1043
      public Square()
1029
      {
1044
      {
Lines 1031-1037 Link Here
1031
      }
1046
      }
1032
    }
1047
    }
1033
1048
1034
    public static class TripleDES extends HMacSHA384
1049
    public static class TripleDES
1050
        extends HMacSHA384
1035
    {
1051
    {
1036
      public TripleDES()
1052
      public TripleDES()
1037
      {
1053
      {
Lines 1039-1045 Link Here
1039
      }
1055
      }
1040
    }
1056
    }
1041
1057
1042
    public static class Twofish extends HMacSHA384
1058
    public static class Twofish
1059
        extends HMacSHA384
1043
    {
1060
    {
1044
      public Twofish()
1061
      public Twofish()
1045
      {
1062
      {
Lines 1048-1059 Link Here
1048
    }
1065
    }
1049
  }
1066
  }
1050
1067
1051
  public static class HMacSHA512 extends PBES2
1068
  public static class HMacSHA512
1069
      extends PBES2
1052
  {
1070
  {
1053
1054
    // Constructor(s)
1055
    // ---------------------------------------------------------------------
1056
1057
    public HMacSHA512(String cipher, int blockLen)
1071
    public HMacSHA512(String cipher, int blockLen)
1058
    {
1072
    {
1059
      super(cipher, blockLen, "HMAC-SHA-512");
1073
      super(cipher, blockLen, "HMAC-SHA-512");
Lines 1064-1073 Link Here
1064
      super(cipher, "HMAC-SHA-512");
1078
      super(cipher, "HMAC-SHA-512");
1065
    }
1079
    }
1066
1080
1067
    // Inner classe(s)
1081
    public static class AES
1068
    // ======================================================================
1082
        extends HMacSHA512
1069
1070
    public static class AES extends HMacSHA512
1071
    {
1083
    {
1072
      public AES()
1084
      public AES()
1073
      {
1085
      {
Lines 1075-1081 Link Here
1075
      }
1087
      }
1076
    }
1088
    }
1077
1089
1078
    public static class Anubis extends HMacSHA512
1090
    public static class Anubis
1091
        extends HMacSHA512
1079
    {
1092
    {
1080
      public Anubis()
1093
      public Anubis()
1081
      {
1094
      {
Lines 1083-1089 Link Here
1083
      }
1096
      }
1084
    }
1097
    }
1085
1098
1086
    public static class Blowfish extends HMacSHA512
1099
    public static class Blowfish
1100
        extends HMacSHA512
1087
    {
1101
    {
1088
      public Blowfish()
1102
      public Blowfish()
1089
      {
1103
      {
Lines 1091-1097 Link Here
1091
      }
1105
      }
1092
    }
1106
    }
1093
1107
1094
    public static class Cast5 extends HMacSHA512
1108
    public static class Cast5
1109
        extends HMacSHA512
1095
    {
1110
    {
1096
      public Cast5()
1111
      public Cast5()
1097
      {
1112
      {
Lines 1099-1105 Link Here
1099
      }
1114
      }
1100
    }
1115
    }
1101
1116
1102
    public static class DES extends HMacSHA512
1117
    public static class DES
1118
        extends HMacSHA512
1103
    {
1119
    {
1104
      public DES()
1120
      public DES()
1105
      {
1121
      {
Lines 1107-1113 Link Here
1107
      }
1123
      }
1108
    }
1124
    }
1109
1125
1110
    public static class Khazad extends HMacSHA512
1126
    public static class Khazad
1127
        extends HMacSHA512
1111
    {
1128
    {
1112
      public Khazad()
1129
      public Khazad()
1113
      {
1130
      {
Lines 1115-1121 Link Here
1115
      }
1132
      }
1116
    }
1133
    }
1117
1134
1118
    public static class Serpent extends HMacSHA512
1135
    public static class Serpent
1136
        extends HMacSHA512
1119
    {
1137
    {
1120
      public Serpent()
1138
      public Serpent()
1121
      {
1139
      {
Lines 1123-1129 Link Here
1123
      }
1141
      }
1124
    }
1142
    }
1125
1143
1126
    public static class Square extends HMacSHA512
1144
    public static class Square
1145
        extends HMacSHA512
1127
    {
1146
    {
1128
      public Square()
1147
      public Square()
1129
      {
1148
      {
Lines 1131-1137 Link Here
1131
      }
1150
      }
1132
    }
1151
    }
1133
1152
1134
    public static class TripleDES extends HMacSHA512
1153
    public static class TripleDES
1154
        extends HMacSHA512
1135
    {
1155
    {
1136
      public TripleDES()
1156
      public TripleDES()
1137
      {
1157
      {
Lines 1139-1145 Link Here
1139
      }
1159
      }
1140
    }
1160
    }
1141
1161
1142
    public static class Twofish extends HMacSHA512
1162
    public static class Twofish
1163
        extends HMacSHA512
1143
    {
1164
    {
1144
      public Twofish()
1165
      public Twofish()
1145
      {
1166
      {
Lines 1148-1159 Link Here
1148
    }
1169
    }
1149
  }
1170
  }
1150
1171
1151
  public static class HMacTiger extends PBES2
1172
  public static class HMacTiger
1173
      extends PBES2
1152
  {
1174
  {
1153
1154
    // Constructor(s)
1155
    // ---------------------------------------------------------------------
1156
1157
    public HMacTiger(String cipher, int blockLen)
1175
    public HMacTiger(String cipher, int blockLen)
1158
    {
1176
    {
1159
      super(cipher, blockLen, "HMAC-TIGER");
1177
      super(cipher, blockLen, "HMAC-TIGER");
Lines 1164-1173 Link Here
1164
      super(cipher, "HMAC-TIGER");
1182
      super(cipher, "HMAC-TIGER");
1165
    }
1183
    }
1166
1184
1167
    // Inner classe(s)
1185
    public static class AES
1168
    // ======================================================================
1186
        extends HMacTiger
1169
1170
    public static class AES extends HMacTiger
1171
    {
1187
    {
1172
      public AES()
1188
      public AES()
1173
      {
1189
      {
Lines 1175-1181 Link Here
1175
      }
1191
      }
1176
    }
1192
    }
1177
1193
1178
    public static class Anubis extends HMacTiger
1194
    public static class Anubis
1195
        extends HMacTiger
1179
    {
1196
    {
1180
      public Anubis()
1197
      public Anubis()
1181
      {
1198
      {
Lines 1183-1189 Link Here
1183
      }
1200
      }
1184
    }
1201
    }
1185
1202
1186
    public static class Blowfish extends HMacTiger
1203
    public static class Blowfish
1204
        extends HMacTiger
1187
    {
1205
    {
1188
      public Blowfish()
1206
      public Blowfish()
1189
      {
1207
      {
Lines 1191-1197 Link Here
1191
      }
1209
      }
1192
    }
1210
    }
1193
1211
1194
    public static class Cast5 extends HMacTiger
1212
    public static class Cast5
1213
        extends HMacTiger
1195
    {
1214
    {
1196
      public Cast5()
1215
      public Cast5()
1197
      {
1216
      {
Lines 1199-1205 Link Here
1199
      }
1218
      }
1200
    }
1219
    }
1201
1220
1202
    public static class DES extends HMacTiger
1221
    public static class DES
1222
        extends HMacTiger
1203
    {
1223
    {
1204
      public DES()
1224
      public DES()
1205
      {
1225
      {
Lines 1207-1213 Link Here
1207
      }
1227
      }
1208
    }
1228
    }
1209
1229
1210
    public static class Khazad extends HMacTiger
1230
    public static class Khazad
1231
        extends HMacTiger
1211
    {
1232
    {
1212
      public Khazad()
1233
      public Khazad()
1213
      {
1234
      {
Lines 1215-1221 Link Here
1215
      }
1236
      }
1216
    }
1237
    }
1217
1238
1218
    public static class Serpent extends HMacTiger
1239
    public static class Serpent
1240
        extends HMacTiger
1219
    {
1241
    {
1220
      public Serpent()
1242
      public Serpent()
1221
      {
1243
      {
Lines 1223-1229 Link Here
1223
      }
1245
      }
1224
    }
1246
    }
1225
1247
1226
    public static class Square extends HMacTiger
1248
    public static class Square
1249
        extends HMacTiger
1227
    {
1250
    {
1228
      public Square()
1251
      public Square()
1229
      {
1252
      {
Lines 1231-1237 Link Here
1231
      }
1254
      }
1232
    }
1255
    }
1233
1256
1234
    public static class TripleDES extends HMacTiger
1257
    public static class TripleDES
1258
        extends HMacTiger
1235
    {
1259
    {
1236
      public TripleDES()
1260
      public TripleDES()
1237
      {
1261
      {
Lines 1239-1245 Link Here
1239
      }
1263
      }
1240
    }
1264
    }
1241
1265
1242
    public static class Twofish extends HMacTiger
1266
    public static class Twofish
1267
        extends HMacTiger
1243
    {
1268
    {
1244
      public Twofish()
1269
      public Twofish()
1245
      {
1270
      {
Lines 1248-1259 Link Here
1248
    }
1273
    }
1249
  }
1274
  }
1250
1275
1251
  public static class HMacWhirlpool extends PBES2
1276
  public static class HMacWhirlpool
1277
      extends PBES2
1252
  {
1278
  {
1253
1254
    // Constructor(s)
1255
    // ----------------------------------------------------------------------
1256
1257
    public HMacWhirlpool(String cipher, int blockLen)
1279
    public HMacWhirlpool(String cipher, int blockLen)
1258
    {
1280
    {
1259
      super(cipher, blockLen, "HMAC-WHIRLPOOL");
1281
      super(cipher, blockLen, "HMAC-WHIRLPOOL");
Lines 1264-1273 Link Here
1264
      super(cipher, "HMAC-WHIRLPOOL");
1286
      super(cipher, "HMAC-WHIRLPOOL");
1265
    }
1287
    }
1266
1288
1267
    // Inner classe(s)
1289
    public static class AES
1268
    // ======================================================================
1290
        extends HMacWhirlpool
1269
1270
    public static class AES extends HMacWhirlpool
1271
    {
1291
    {
1272
      public AES()
1292
      public AES()
1273
      {
1293
      {
Lines 1275-1281 Link Here
1275
      }
1295
      }
1276
    }
1296
    }
1277
1297
1278
    public static class Anubis extends HMacWhirlpool
1298
    public static class Anubis
1299
        extends HMacWhirlpool
1279
    {
1300
    {
1280
      public Anubis()
1301
      public Anubis()
1281
      {
1302
      {
Lines 1283-1289 Link Here
1283
      }
1304
      }
1284
    }
1305
    }
1285
1306
1286
    public static class Blowfish extends HMacWhirlpool
1307
    public static class Blowfish
1308
        extends HMacWhirlpool
1287
    {
1309
    {
1288
      public Blowfish()
1310
      public Blowfish()
1289
      {
1311
      {
Lines 1291-1297 Link Here
1291
      }
1313
      }
1292
    }
1314
    }
1293
1315
1294
    public static class Cast5 extends HMacWhirlpool
1316
    public static class Cast5
1317
        extends HMacWhirlpool
1295
    {
1318
    {
1296
      public Cast5()
1319
      public Cast5()
1297
      {
1320
      {
Lines 1299-1305 Link Here
1299
      }
1322
      }
1300
    }
1323
    }
1301
1324
1302
    public static class DES extends HMacWhirlpool
1325
    public static class DES
1326
        extends HMacWhirlpool
1303
    {
1327
    {
1304
      public DES()
1328
      public DES()
1305
      {
1329
      {
Lines 1307-1313 Link Here
1307
      }
1331
      }
1308
    }
1332
    }
1309
1333
1310
    public static class Khazad extends HMacWhirlpool
1334
    public static class Khazad
1335
        extends HMacWhirlpool
1311
    {
1336
    {
1312
      public Khazad()
1337
      public Khazad()
1313
      {
1338
      {
Lines 1315-1321 Link Here
1315
      }
1340
      }
1316
    }
1341
    }
1317
1342
1318
    public static class Serpent extends HMacWhirlpool
1343
    public static class Serpent
1344
        extends HMacWhirlpool
1319
    {
1345
    {
1320
      public Serpent()
1346
      public Serpent()
1321
      {
1347
      {
Lines 1323-1329 Link Here
1323
      }
1349
      }
1324
    }
1350
    }
1325
1351
1326
    public static class Square extends HMacWhirlpool
1352
    public static class Square
1353
        extends HMacWhirlpool
1327
    {
1354
    {
1328
      public Square()
1355
      public Square()
1329
      {
1356
      {
Lines 1331-1337 Link Here
1331
      }
1358
      }
1332
    }
1359
    }
1333
1360
1334
    public static class TripleDES extends HMacWhirlpool
1361
    public static class TripleDES
1362
        extends HMacWhirlpool
1335
    {
1363
    {
1336
      public TripleDES()
1364
      public TripleDES()
1337
      {
1365
      {
Lines 1339-1345 Link Here
1339
      }
1367
      }
1340
    }
1368
    }
1341
1369
1342
    public static class Twofish extends HMacWhirlpool
1370
    public static class Twofish
1371
        extends HMacWhirlpool
1343
    {
1372
    {
1344
      public Twofish()
1373
      public Twofish()
1345
      {
1374
      {
(-)cipher/RijndaelSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the Rijndael <i>Service Provider Interface</i>
44
 * The implementation of the Rijndael <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class RijndaelSpi extends CipherAdapter
47
public final class RijndaelSpi
48
    extends CipherAdapter
48
{
49
{
49
50
  // Constructors.
51
  // --------------------------------------------------------------------
52
53
  public RijndaelSpi()
50
  public RijndaelSpi()
54
  {
51
  {
55
    super(Registry.RIJNDAEL_CIPHER, 16);
52
    super(Registry.RIJNDAEL_CIPHER, 16);
(-)cipher/SerpentSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the Serpent <i>Service Provider Interface</i>
44
 * The implementation of the Serpent <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class SerpentSpi extends CipherAdapter
47
public final class SerpentSpi
48
    extends CipherAdapter
48
{
49
{
49
50
  // Constructors.
51
  // --------------------------------------------------------------------
52
53
  public SerpentSpi()
50
  public SerpentSpi()
54
  {
51
  {
55
    super(Registry.SERPENT_CIPHER);
52
    super(Registry.SERPENT_CIPHER);
(-)cipher/SquareSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the Square <i>Service Provider Interface</i>
44
 * The implementation of the Square <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class SquareSpi extends CipherAdapter
47
public final class SquareSpi
48
    extends CipherAdapter
48
{
49
{
49
50
  // Constructors.
51
  // --------------------------------------------------------------------
52
53
  public SquareSpi()
50
  public SquareSpi()
54
  {
51
  {
55
    super(Registry.SQUARE_CIPHER);
52
    super(Registry.SQUARE_CIPHER);
(-)cipher/TripleDESSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the Triple-DES <i>Service Provider Interface</i>
44
 * The implementation of the Triple-DES <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class TripleDESSpi extends CipherAdapter
47
public final class TripleDESSpi
48
    extends CipherAdapter
48
{
49
{
49
50
  // Constructors.
51
  // --------------------------------------------------------------------
52
53
  public TripleDESSpi()
50
  public TripleDESSpi()
54
  {
51
  {
55
    super(Registry.TRIPLEDES_CIPHER);
52
    super(Registry.TRIPLEDES_CIPHER);
(-)cipher/TwofishSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the Twofish <i>Service Provider Interface</i>
44
 * The implementation of the Twofish <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class TwofishSpi extends CipherAdapter
47
public final class TwofishSpi
48
    extends CipherAdapter
48
{
49
{
49
50
  // Constructors.
51
  // --------------------------------------------------------------------
52
53
  public TwofishSpi()
50
  public TwofishSpi()
54
  {
51
  {
55
    super(Registry.TWOFISH_CIPHER);
52
    super(Registry.TWOFISH_CIPHER);
(-)key/AnubisKeyGeneratorImpl.java (-7 / +4 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class AnubisKeyGeneratorImpl extends SecretKeyGeneratorImpl
43
public class AnubisKeyGeneratorImpl
44
    extends SecretKeyGeneratorImpl
44
{
45
{
45
46
  public AnubisKeyGeneratorImpl()
46
  // Constructors.
47
  // -------------------------------------------------------------------------
48
49
  public AnubisKeyGeneratorImpl ()
50
  {
47
  {
51
    super (Registry.ANUBIS_CIPHER);
48
    super(Registry.ANUBIS_CIPHER);
52
  }
49
  }
53
}
50
}
(-)key/AnubisSecretKeyFactoryImpl.java (-1 / +2 lines)
Lines 38-44 Link Here
38
38
39
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
40
40
41
public class AnubisSecretKeyFactoryImpl extends SecretKeyFactoryImpl
41
public class AnubisSecretKeyFactoryImpl
42
    extends SecretKeyFactoryImpl
42
{
43
{
43
  public AnubisSecretKeyFactoryImpl()
44
  public AnubisSecretKeyFactoryImpl()
44
  {
45
  {
(-)key/BlowfishKeyGeneratorImpl.java (-7 / +4 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class BlowfishKeyGeneratorImpl extends SecretKeyGeneratorImpl
43
public class BlowfishKeyGeneratorImpl
44
    extends SecretKeyGeneratorImpl
44
{
45
{
45
46
  public BlowfishKeyGeneratorImpl()
46
  // Constructors.
47
  // -------------------------------------------------------------------------
48
49
  public BlowfishKeyGeneratorImpl ()
50
  {
47
  {
51
    super (Registry.BLOWFISH_CIPHER);
48
    super(Registry.BLOWFISH_CIPHER);
52
  }
49
  }
53
}
50
}
(-)key/BlowfishSecretKeyFactoryImpl.java (-1 / +2 lines)
Lines 38-44 Link Here
38
38
39
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
40
40
41
public class BlowfishSecretKeyFactoryImpl extends SecretKeyFactoryImpl
41
public class BlowfishSecretKeyFactoryImpl
42
    extends SecretKeyFactoryImpl
42
{
43
{
43
  public BlowfishSecretKeyFactoryImpl()
44
  public BlowfishSecretKeyFactoryImpl()
44
  {
45
  {
(-)key/Cast5KeyGeneratorImpl.java (-7 / +4 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class Cast5KeyGeneratorImpl extends SecretKeyGeneratorImpl
43
public class Cast5KeyGeneratorImpl
44
    extends SecretKeyGeneratorImpl
44
{
45
{
45
46
  public Cast5KeyGeneratorImpl()
46
  // Constructors.
47
  // -------------------------------------------------------------------------
48
49
  public Cast5KeyGeneratorImpl ()
50
  {
47
  {
51
    super (Registry.CAST5_CIPHER);
48
    super(Registry.CAST5_CIPHER);
52
  }
49
  }
53
}
50
}
(-)key/Cast5SecretKeyFactoryImpl.java (-1 / +2 lines)
Lines 38-44 Link Here
38
38
39
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
40
40
41
public class Cast5SecretKeyFactoryImpl extends SecretKeyFactoryImpl
41
public class Cast5SecretKeyFactoryImpl
42
    extends SecretKeyFactoryImpl
42
{
43
{
43
  public Cast5SecretKeyFactoryImpl()
44
  public Cast5SecretKeyFactoryImpl()
44
  {
45
  {
(-)key/DESKeyGeneratorImpl.java (-18 / +13 lines)
Lines 35-40 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
Lines 43-73 Link Here
43
import javax.crypto.SecretKey;
44
import javax.crypto.SecretKey;
44
import javax.crypto.spec.SecretKeySpec;
45
import javax.crypto.spec.SecretKeySpec;
45
46
46
public class DESKeyGeneratorImpl extends SecretKeyGeneratorImpl
47
public class DESKeyGeneratorImpl
48
    extends SecretKeyGeneratorImpl
47
{
49
{
48
50
  public DESKeyGeneratorImpl()
49
  // Constructors.
50
  // -------------------------------------------------------------------------
51
52
  public DESKeyGeneratorImpl ()
53
  {
51
  {
54
    super (Registry.DES_CIPHER);
52
    super(Registry.DES_CIPHER);
55
  }
53
  }
56
54
57
  // Instance methods.
55
  protected SecretKey engineGenerateKey()
58
  // -------------------------------------------------------------------------
59
60
  protected SecretKey engineGenerateKey ()
61
  {
56
  {
62
    if (!init)
57
    if (! init)
63
      throw new IllegalStateException ("not initialized");
58
      throw new IllegalStateException("not initialized");
64
    byte[] buf = new byte [currentKeySize];
59
    byte[] buf = new byte[currentKeySize];
65
    do
60
    do
66
      {
61
      {
67
        random.nextBytes (buf);
62
        random.nextBytes(buf);
68
      }
63
      }
69
    while (DES.isWeak (buf) || DES.isSemiWeak (buf));
64
    while (DES.isWeak(buf) || DES.isSemiWeak(buf));
70
    DES.adjustParity (buf, 0);
65
    DES.adjustParity(buf, 0);
71
    return new SecretKeySpec (buf, algorithm);
66
    return new SecretKeySpec(buf, algorithm);
72
  }
67
  }
73
}
68
}
(-)key/DESSecretKeyFactoryImpl.java (-13 / +15 lines)
Lines 35-40 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import java.security.InvalidKeyException;
41
import java.security.InvalidKeyException;
Lines 45-80 Link Here
45
import javax.crypto.spec.DESKeySpec;
46
import javax.crypto.spec.DESKeySpec;
46
import javax.crypto.spec.SecretKeySpec;
47
import javax.crypto.spec.SecretKeySpec;
47
48
48
public class DESSecretKeyFactoryImpl extends SecretKeyFactoryImpl
49
public class DESSecretKeyFactoryImpl
50
    extends SecretKeyFactoryImpl
49
{
51
{
50
52
51
  public DESSecretKeyFactoryImpl()
53
  public DESSecretKeyFactoryImpl()
52
  {
54
  {
53
  }
55
  }
54
56
55
  protected SecretKey engineGenerateSecret (KeySpec spec)
57
  protected SecretKey engineGenerateSecret(KeySpec spec)
56
    throws InvalidKeySpecException
58
      throws InvalidKeySpecException
57
  {
59
  {
58
    if (spec instanceof DESKeySpec)
60
    if (spec instanceof DESKeySpec)
59
      return new SecretKeySpec (((DESKeySpec) spec).getKey(), "DES");
61
      return new SecretKeySpec(((DESKeySpec) spec).getKey(), "DES");
60
    return super.engineGenerateSecret (spec);
62
    return super.engineGenerateSecret(spec);
61
  }
63
  }
62
64
63
  protected KeySpec engineGetKeySpec (SecretKey key, Class spec)
65
  protected KeySpec engineGetKeySpec(SecretKey key, Class spec)
64
    throws InvalidKeySpecException
66
      throws InvalidKeySpecException
65
  {
67
  {
66
    if (spec.isAssignableFrom (DESKeySpec.class))
68
    if (spec.isAssignableFrom(DESKeySpec.class))
67
      try
69
      try
68
        {
70
        {
69
          return new DESKeySpec (key.getEncoded());
71
          return new DESKeySpec(key.getEncoded());
70
        }
72
        }
71
      catch (InvalidKeyException ike)
73
      catch (InvalidKeyException ike)
72
        {
74
        {
73
          InvalidKeySpecException ikse = new InvalidKeySpecException
75
          InvalidKeySpecException ikse = new InvalidKeySpecException(
74
            ("can't create DES key spec");
76
              "can't create DES key spec");
75
          ikse.initCause (ike);
77
          ikse.initCause(ike);
76
          throw ikse;
78
          throw ikse;
77
        }
79
        }
78
    return super.engineGetKeySpec (key, spec);
80
    return super.engineGetKeySpec(key, spec);
79
  }
81
  }
80
}
82
}
(-)key/DESedeSecretKeyFactoryImpl.java (-13 / +15 lines)
Lines 35-40 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import java.security.InvalidKeyException;
41
import java.security.InvalidKeyException;
Lines 45-80 Link Here
45
import javax.crypto.spec.DESedeKeySpec;
46
import javax.crypto.spec.DESedeKeySpec;
46
import javax.crypto.spec.SecretKeySpec;
47
import javax.crypto.spec.SecretKeySpec;
47
48
48
public class DESedeSecretKeyFactoryImpl extends SecretKeyFactoryImpl
49
public class DESedeSecretKeyFactoryImpl
50
    extends SecretKeyFactoryImpl
49
{
51
{
50
52
51
  public DESedeSecretKeyFactoryImpl()
53
  public DESedeSecretKeyFactoryImpl()
52
  {
54
  {
53
  }
55
  }
54
56
55
  protected SecretKey engineGenerateSecret (KeySpec spec)
57
  protected SecretKey engineGenerateSecret(KeySpec spec)
56
    throws InvalidKeySpecException
58
      throws InvalidKeySpecException
57
  {
59
  {
58
    if (spec instanceof DESedeKeySpec)
60
    if (spec instanceof DESedeKeySpec)
59
      return new SecretKeySpec (((DESedeKeySpec) spec).getKey(), "DESede");
61
      return new SecretKeySpec(((DESedeKeySpec) spec).getKey(), "DESede");
60
    return super.engineGenerateSecret (spec);
62
    return super.engineGenerateSecret(spec);
61
  }
63
  }
62
64
63
  protected KeySpec engineGetKeySpec (SecretKey key, Class spec)
65
  protected KeySpec engineGetKeySpec(SecretKey key, Class spec)
64
    throws InvalidKeySpecException
66
      throws InvalidKeySpecException
65
  {
67
  {
66
    if (spec.equals (DESedeKeySpec.class))
68
    if (spec.equals(DESedeKeySpec.class))
67
      try
69
      try
68
        {
70
        {
69
          return new DESedeKeySpec (key.getEncoded());
71
          return new DESedeKeySpec(key.getEncoded());
70
        }
72
        }
71
      catch (InvalidKeyException ike)
73
      catch (InvalidKeyException ike)
72
        {
74
        {
73
          InvalidKeySpecException ikse = new InvalidKeySpecException
75
          InvalidKeySpecException ikse = new InvalidKeySpecException(
74
            ("can't create DESede key spec");
76
              "can't create DESede key spec");
75
          ikse.initCause (ike);
77
          ikse.initCause(ike);
76
          throw ikse;
78
          throw ikse;
77
        }
79
        }
78
    return super.engineGetKeySpec (key, spec);
80
    return super.engineGetKeySpec(key, spec);
79
  }
81
  }
80
}
82
}
(-)key/KhazadKeyGeneratorImpl.java (-7 / +5 lines)
Lines 35-52 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
41
42
42
public class KhazadKeyGeneratorImpl extends SecretKeyGeneratorImpl
43
public class KhazadKeyGeneratorImpl
44
    extends SecretKeyGeneratorImpl
43
{
45
{
44
46
  public KhazadKeyGeneratorImpl()
45
  // Constructors.
46
  // -------------------------------------------------------------------------
47
48
  public KhazadKeyGeneratorImpl ()
49
  {
47
  {
50
    super (Registry.KHAZAD_CIPHER);
48
    super(Registry.KHAZAD_CIPHER);
51
  }
49
  }
52
}
50
}
(-)key/KhazadSecretKeyFactoryImpl.java (-1 / +3 lines)
Lines 35-43 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
public class KhazadSecretKeyFactoryImpl extends SecretKeyFactoryImpl
41
public class KhazadSecretKeyFactoryImpl
42
    extends SecretKeyFactoryImpl
41
{
43
{
42
  public KhazadSecretKeyFactoryImpl()
44
  public KhazadSecretKeyFactoryImpl()
43
  {
45
  {
(-)key/RijndaelKeyGeneratorImpl.java (-7 / +5 lines)
Lines 35-52 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
41
42
42
public class RijndaelKeyGeneratorImpl extends SecretKeyGeneratorImpl
43
public class RijndaelKeyGeneratorImpl
44
    extends SecretKeyGeneratorImpl
43
{
45
{
44
46
  public RijndaelKeyGeneratorImpl()
45
  // Constructors.
46
  // -------------------------------------------------------------------------
47
48
  public RijndaelKeyGeneratorImpl ()
49
  {
47
  {
50
    super (Registry.RIJNDAEL_CIPHER);
48
    super(Registry.RIJNDAEL_CIPHER);
51
  }
49
  }
52
}
50
}
(-)key/RijndaelSecretKeyFactoryImpl.java (-1 / +3 lines)
Lines 35-43 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
public class RijndaelSecretKeyFactoryImpl extends SecretKeyFactoryImpl
41
public class RijndaelSecretKeyFactoryImpl
42
    extends SecretKeyFactoryImpl
41
{
43
{
42
  public RijndaelSecretKeyFactoryImpl()
44
  public RijndaelSecretKeyFactoryImpl()
43
  {
45
  {
(-)key/SecretKeyFactoryImpl.java (-17 / +17 lines)
Lines 35-40 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import java.security.InvalidKeyException;
41
import java.security.InvalidKeyException;
Lines 45-87 Link Here
45
import javax.crypto.SecretKeyFactorySpi;
46
import javax.crypto.SecretKeyFactorySpi;
46
import javax.crypto.spec.SecretKeySpec;
47
import javax.crypto.spec.SecretKeySpec;
47
48
48
public abstract class SecretKeyFactoryImpl extends SecretKeyFactorySpi
49
public abstract class SecretKeyFactoryImpl
50
    extends SecretKeyFactorySpi
49
{
51
{
50
52
51
  protected SecretKeyFactoryImpl()
53
  protected SecretKeyFactoryImpl()
52
  {
54
  {
53
  }
55
  }
54
56
55
  protected SecretKey engineGenerateSecret (KeySpec spec)
57
  protected SecretKey engineGenerateSecret(KeySpec spec)
56
    throws InvalidKeySpecException
58
      throws InvalidKeySpecException
57
  {
59
  {
58
    if (spec instanceof SecretKeySpec)
60
    if (spec instanceof SecretKeySpec)
59
      return (SecretKey) spec;
61
      return (SecretKey) spec;
60
    throw new InvalidKeySpecException ("unknown key spec: " +
62
    throw new InvalidKeySpecException("unknown key spec: "
61
                                       spec.getClass().getName());
63
                                      + spec.getClass().getName());
62
  }
64
  }
63
65
64
  protected KeySpec engineGetKeySpec (SecretKey key, Class spec)
66
  protected KeySpec engineGetKeySpec(SecretKey key, Class spec)
65
    throws InvalidKeySpecException
67
      throws InvalidKeySpecException
66
  {
68
  {
67
    if (spec.equals (SecretKeySpec.class))
69
    if (spec.equals(SecretKeySpec.class))
68
      {
70
      {
69
        if (key instanceof SecretKeySpec)
71
        if (key instanceof SecretKeySpec)
70
          return (KeySpec) key;
72
          return (KeySpec) key;
71
        else
73
        else
72
          return new SecretKeySpec (key.getEncoded(), key.getAlgorithm());
74
          return new SecretKeySpec(key.getEncoded(), key.getAlgorithm());
73
      }
75
      }
74
    throw new InvalidKeySpecException ("unsupported key spec: " +
76
    throw new InvalidKeySpecException("unsupported key spec: " + spec.getName());
75
                                       spec.getName());
76
  }
77
  }
77
78
78
  protected SecretKey engineTranslateKey (SecretKey key)
79
  protected SecretKey engineTranslateKey(SecretKey key)
79
    throws InvalidKeyException
80
      throws InvalidKeyException
80
  {
81
  {
81
    if (!"RAW".equals (key.getFormat()))
82
    if (! "RAW".equals(key.getFormat()))
82
      throw new InvalidKeyException ("only raw keys are supported");
83
      throw new InvalidKeyException("only raw keys are supported");
83
84
    // SecretKeySpec is good enough for our purposes.
84
    // SecretKeySpec is good enough for our purposes.
85
    return new SecretKeySpec (key.getEncoded(), key.getAlgorithm());
85
    return new SecretKeySpec(key.getEncoded(), key.getAlgorithm());
86
  }
86
  }
87
}
87
}
(-)key/SecretKeyGeneratorImpl.java (-33 / +23 lines)
Lines 35-40 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import gnu.javax.crypto.cipher.CipherFactory;
41
import gnu.javax.crypto.cipher.CipherFactory;
Lines 53-64 Link Here
53
import javax.crypto.SecretKey;
54
import javax.crypto.SecretKey;
54
import javax.crypto.spec.SecretKeySpec;
55
import javax.crypto.spec.SecretKeySpec;
55
56
56
public class SecretKeyGeneratorImpl extends KeyGeneratorSpi
57
public class SecretKeyGeneratorImpl
58
    extends KeyGeneratorSpi
57
{
59
{
58
59
  // Fields.
60
  // -------------------------------------------------------------------------
61
62
  protected final int defaultKeySize;
60
  protected final int defaultKeySize;
63
  protected final List keySizes;
61
  protected final List keySizes;
64
  protected final String algorithm;
62
  protected final String algorithm;
Lines 66-120 Link Here
66
  protected int currentKeySize;
64
  protected int currentKeySize;
67
  protected SecureRandom random;
65
  protected SecureRandom random;
68
66
69
  // Constructors.
67
  protected SecretKeyGeneratorImpl(final String algorithm)
70
  // -------------------------------------------------------------------------
71
72
  protected SecretKeyGeneratorImpl (final String algorithm)
73
  {
68
  {
74
    this.algorithm = algorithm;
69
    this.algorithm = algorithm;
75
    IBlockCipher cipher = CipherFactory.getInstance (algorithm);
70
    IBlockCipher cipher = CipherFactory.getInstance(algorithm);
76
    if (cipher == null)
71
    if (cipher == null)
77
      throw new IllegalArgumentException ("no such cipher: "+algorithm);
72
      throw new IllegalArgumentException("no such cipher: " + algorithm);
78
    defaultKeySize = cipher.defaultKeySize ();
73
    defaultKeySize = cipher.defaultKeySize();
79
    keySizes = new LinkedList();
74
    keySizes = new LinkedList();
80
    for (Iterator it = cipher.keySizes (); it.hasNext (); )
75
    for (Iterator it = cipher.keySizes(); it.hasNext();)
81
      {
76
      keySizes.add(it.next());
82
        keySizes.add (it.next ());
83
      }
84
    init = false;
77
    init = false;
85
  }
78
  }
86
79
87
  // Instance methods.
80
  protected SecretKey engineGenerateKey()
88
  // -------------------------------------------------------------------------
89
90
  protected SecretKey engineGenerateKey ()
91
  {
81
  {
92
    if (!init)
82
    if (! init)
93
      throw new IllegalStateException ("not initialized");
83
      throw new IllegalStateException("not initialized");
94
    byte[] buf = new byte [currentKeySize];
84
    byte[] buf = new byte[currentKeySize];
95
    random.nextBytes (buf);
85
    random.nextBytes(buf);
96
    return new SecretKeySpec (buf, algorithm);
86
    return new SecretKeySpec(buf, algorithm);
97
  }
87
  }
98
88
99
  protected void engineInit (AlgorithmParameterSpec params, SecureRandom random)
89
  protected void engineInit(AlgorithmParameterSpec params, SecureRandom random)
100
    throws InvalidAlgorithmParameterException
90
      throws InvalidAlgorithmParameterException
101
  {
91
  {
102
    throw new InvalidAlgorithmParameterException (algorithm +
92
    throw new InvalidAlgorithmParameterException(
103
      " does not support algorithm paramaters");
93
        algorithm + " does not support algorithm paramaters");
104
  }
94
  }
105
95
106
  protected void engineInit (int keySize, SecureRandom random)
96
  protected void engineInit(int keySize, SecureRandom random)
107
  {
97
  {
108
    keySize >>>= 3; // Use bytes.
98
    keySize >>>= 3; // Use bytes.
109
    if (! keySizes.contains(Integer.valueOf(keySize)))
99
    if (! keySizes.contains(Integer.valueOf(keySize)))
110
      throw new InvalidParameterException ("unsupported key size: " + keySize);
100
      throw new InvalidParameterException("unsupported key size: " + keySize);
111
    currentKeySize = keySize;
101
    currentKeySize = keySize;
112
    this.random = random;
102
    this.random = random;
113
    init = true;
103
    init = true;
114
  }
104
  }
115
105
116
  protected void engineInit (SecureRandom random)
106
  protected void engineInit(SecureRandom random)
117
  {
107
  {
118
    engineInit (defaultKeySize << 3, random);
108
    engineInit(defaultKeySize << 3, random);
119
  }
109
  }
120
}
110
}
(-)key/SerpentKeyGeneratorImpl.java (-7 / +5 lines)
Lines 35-52 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
41
42
42
public class SerpentKeyGeneratorImpl extends SecretKeyGeneratorImpl
43
public class SerpentKeyGeneratorImpl
44
    extends SecretKeyGeneratorImpl
43
{
45
{
44
46
  public SerpentKeyGeneratorImpl()
45
  // Constructors.
46
  // -------------------------------------------------------------------------
47
48
  public SerpentKeyGeneratorImpl ()
49
  {
47
  {
50
    super (Registry.SERPENT_CIPHER);
48
    super(Registry.SERPENT_CIPHER);
51
  }
49
  }
52
}
50
}
(-)key/SerpentSecretKeyFactoryImpl.java (-1 / +3 lines)
Lines 35-43 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
public class SerpentSecretKeyFactoryImpl extends SecretKeyFactoryImpl
41
public class SerpentSecretKeyFactoryImpl
42
    extends SecretKeyFactoryImpl
41
{
43
{
42
  public SerpentSecretKeyFactoryImpl()
44
  public SerpentSecretKeyFactoryImpl()
43
  {
45
  {
(-)key/SquareKeyGeneratorImpl.java (-7 / +5 lines)
Lines 35-52 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
41
42
42
public class SquareKeyGeneratorImpl extends SecretKeyGeneratorImpl
43
public class SquareKeyGeneratorImpl
44
    extends SecretKeyGeneratorImpl
43
{
45
{
44
46
  public SquareKeyGeneratorImpl()
45
  // Constructors.
46
  // -------------------------------------------------------------------------
47
48
  public SquareKeyGeneratorImpl ()
49
  {
47
  {
50
    super (Registry.SQUARE_CIPHER);
48
    super(Registry.SQUARE_CIPHER);
51
  }
49
  }
52
}
50
}
(-)key/SquareSecretKeyFactoryImpl.java (-1 / +3 lines)
Lines 35-43 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
public class SquareSecretKeyFactoryImpl extends SecretKeyFactoryImpl
41
public class SquareSecretKeyFactoryImpl
42
    extends SecretKeyFactoryImpl
41
{
43
{
42
  public SquareSecretKeyFactoryImpl()
44
  public SquareSecretKeyFactoryImpl()
43
  {
45
  {
(-)key/TripleDESKeyGeneratorImpl.java (-7 / +5 lines)
Lines 35-52 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
41
42
42
public class TripleDESKeyGeneratorImpl extends SecretKeyGeneratorImpl
43
public class TripleDESKeyGeneratorImpl
44
    extends SecretKeyGeneratorImpl
43
{
45
{
44
46
  public TripleDESKeyGeneratorImpl()
45
  // Constructors.
46
  // -------------------------------------------------------------------------
47
48
  public TripleDESKeyGeneratorImpl ()
49
  {
47
  {
50
    super (Registry.TRIPLEDES_CIPHER);
48
    super(Registry.TRIPLEDES_CIPHER);
51
  }
49
  }
52
}
50
}
(-)key/TwofishKeyGeneratorImpl.java (-7 / +5 lines)
Lines 35-52 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
41
42
42
public class TwofishKeyGeneratorImpl extends SecretKeyGeneratorImpl
43
public class TwofishKeyGeneratorImpl
44
    extends SecretKeyGeneratorImpl
43
{
45
{
44
46
  public TwofishKeyGeneratorImpl()
45
  // Constructors.
46
  // -------------------------------------------------------------------------
47
48
  public TwofishKeyGeneratorImpl ()
49
  {
47
  {
50
    super (Registry.TWOFISH_CIPHER);
48
    super(Registry.TWOFISH_CIPHER);
51
  }
49
  }
52
}
50
}
(-)key/TwofishSecretKeyFactoryImpl.java (-1 / +3 lines)
Lines 35-43 Link Here
35
obligated to do so.  If you do not wish to do so, delete this
35
obligated to do so.  If you do not wish to do so, delete this
36
exception statement from your version.  */
36
exception statement from your version.  */
37
37
38
38
package gnu.javax.crypto.jce.key;
39
package gnu.javax.crypto.jce.key;
39
40
40
public class TwofishSecretKeyFactoryImpl extends SecretKeyFactoryImpl
41
public class TwofishSecretKeyFactoryImpl
42
    extends SecretKeyFactoryImpl
41
{
43
{
42
  public TwofishSecretKeyFactoryImpl()
44
  public TwofishSecretKeyFactoryImpl()
43
  {
45
  {
(-)keyring/GnuKeyring.java (-4 / +6 lines)
Lines 419-426 Link Here
419
    int usage = in.read();
419
    int usage = in.read();
420
    in.reset();
420
    in.reset();
421
    if (usage != GnuPrivateKeyring.USAGE)
421
    if (usage != GnuPrivateKeyring.USAGE)
422
      throw new MalformedKeyringException("Was expecting a private keyring but got a wrong USAGE: "
422
      throw new MalformedKeyringException(
423
                                          + Integer.toBinaryString(usage));
423
          "Was expecting a private keyring but got a wrong USAGE: "
424
          + Integer.toBinaryString(usage));
424
    HashMap attr = new HashMap();
425
    HashMap attr = new HashMap();
425
    attr.put(IKeyring.KEYRING_DATA_IN, in);
426
    attr.put(IKeyring.KEYRING_DATA_IN, in);
426
    attr.put(IKeyring.KEYRING_PASSWORD, password);
427
    attr.put(IKeyring.KEYRING_PASSWORD, password);
Lines 451-458 Link Here
451
    int usage = in.read();
452
    int usage = in.read();
452
    in.reset();
453
    in.reset();
453
    if (usage != GnuPublicKeyring.USAGE)
454
    if (usage != GnuPublicKeyring.USAGE)
454
      throw new MalformedKeyringException("Was expecting a public keyring but got a wrong USAGE: "
455
      throw new MalformedKeyringException(
455
                                          + Integer.toBinaryString(usage));
456
          "Was expecting a public keyring but got a wrong USAGE: "
457
          + Integer.toBinaryString(usage));
456
    HashMap attr = new HashMap();
458
    HashMap attr = new HashMap();
457
    attr.put(IKeyring.KEYRING_DATA_IN, in);
459
    attr.put(IKeyring.KEYRING_DATA_IN, in);
458
    attr.put(IKeyring.KEYRING_PASSWORD, password);
460
    attr.put(IKeyring.KEYRING_PASSWORD, password);
(-)mac/HMacHavalSpi.java (-17 / +4 lines)
Lines 37-67 Link Here
37
37
38
38
39
package gnu.javax.crypto.jce.mac;
39
package gnu.javax.crypto.jce.mac;
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
41
42
42
/**
43
/**
43
 * The implementation of the HMAC-HAVAL <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-HAVAL <i>Service Provider Interface</i>
44
 * (<b>SPI</b>) Adapter.
45
 * (<b>SPI</b>) Adapter.
45
 *
46
 * @version Revision: $
47
 */
46
 */
48
public class HMacHavalSpi extends MacAdapter
47
public class HMacHavalSpi
48
    extends MacAdapter
49
{
49
{
50
51
  // Constants and variables
52
  // -------------------------------------------------------------------------
53
54
  // Constructor(s)
55
  // -------------------------------------------------------------------------
56
57
  public HMacHavalSpi()
50
  public HMacHavalSpi()
58
  {
51
  {
59
    super(Registry.HMAC_NAME_PREFIX + Registry.HAVAL_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.HAVAL_HASH);
60
  }
53
  }
61
54
}
62
  // Class methods
63
  // -------------------------------------------------------------------------
64
65
  // Instance methods
66
  // -------------------------------------------------------------------------
67
}
(-)mac/HMacMD2Spi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the HMAC-MD2 <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-MD2 <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class HMacMD2Spi extends MacAdapter
47
public final class HMacMD2Spi
48
    extends MacAdapter
48
{
49
{
49
50
  // Constructors.
51
  // -----------------------------------------------------------------------
52
53
  public HMacMD2Spi()
50
  public HMacMD2Spi()
54
  {
51
  {
55
    super(Registry.HMAC_NAME_PREFIX + Registry.MD2_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.MD2_HASH);
(-)mac/HMacMD4Spi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the HMAC-MD4 <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-MD4 <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class HMacMD4Spi extends MacAdapter
47
public final class HMacMD4Spi
48
    extends MacAdapter
48
{
49
{
49
50
  // Constructors.
51
  // -----------------------------------------------------------------------
52
53
  public HMacMD4Spi()
50
  public HMacMD4Spi()
54
  {
51
  {
55
    super(Registry.HMAC_NAME_PREFIX + Registry.MD4_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.MD4_HASH);
(-)mac/HMacMD5Spi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the HMAC-MD5 <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-MD5 <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class HMacMD5Spi extends MacAdapter
47
public final class HMacMD5Spi
48
    extends MacAdapter
48
{
49
{
49
50
  // Constructors.
51
  // -----------------------------------------------------------------------
52
53
  public HMacMD5Spi()
50
  public HMacMD5Spi()
54
  {
51
  {
55
    super(Registry.HMAC_NAME_PREFIX + Registry.MD5_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.MD5_HASH);
(-)mac/HMacRipeMD128Spi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the HMAC-RIPEMD-128 <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-RIPEMD-128 <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class HMacRipeMD128Spi extends MacAdapter
47
public final class HMacRipeMD128Spi
48
    extends MacAdapter
48
{
49
{
49
50
  // Constructors.
51
  // -----------------------------------------------------------------------
52
53
  public HMacRipeMD128Spi()
50
  public HMacRipeMD128Spi()
54
  {
51
  {
55
    super(Registry.HMAC_NAME_PREFIX + Registry.RIPEMD128_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.RIPEMD128_HASH);
(-)mac/HMacRipeMD160Spi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the HMAC-RIPEMD-160 <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-RIPEMD-160 <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class HMacRipeMD160Spi extends MacAdapter
47
public final class HMacRipeMD160Spi
48
    extends MacAdapter
48
{
49
{
49
50
  // Constructors.
51
  // -----------------------------------------------------------------------
52
53
  public HMacRipeMD160Spi()
50
  public HMacRipeMD160Spi()
54
  {
51
  {
55
    super(Registry.HMAC_NAME_PREFIX + Registry.RIPEMD160_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.RIPEMD160_HASH);
(-)mac/HMacSHA160Spi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the HMAC-SHA-160 <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-SHA-160 <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class HMacSHA160Spi extends MacAdapter
47
public final class HMacSHA160Spi
48
    extends MacAdapter
48
{
49
{
49
50
  // Constructors.
51
  // -----------------------------------------------------------------------
52
53
  public HMacSHA160Spi()
50
  public HMacSHA160Spi()
54
  {
51
  {
55
    super(Registry.HMAC_NAME_PREFIX + Registry.SHA160_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.SHA160_HASH);
(-)mac/HMacSHA256Spi.java (-16 / +5 lines)
Lines 37-65 Link Here
37
37
38
38
39
package gnu.javax.crypto.jce.mac;
39
package gnu.javax.crypto.jce.mac;
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
41
42
42
/**
43
/**
43
 * <p>The implementation of the HMAC-SHA-256 <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-SHA-256 <i>Service Provider Interface</i>
44
 * (<b>SPI</b>) adapter.</p>
45
 * (<b>SPI</b>) adapter.
45
 */
46
 */
46
public final class HMacSHA256Spi extends MacAdapter
47
public final class HMacSHA256Spi
48
    extends MacAdapter
47
{
49
{
48
49
  // Constants and variables
50
  // -------------------------------------------------------------------------
51
52
  // Constructor(s)
53
  // -----------------------------------------------------------------------
54
55
  public HMacSHA256Spi()
50
  public HMacSHA256Spi()
56
  {
51
  {
57
    super(Registry.HMAC_NAME_PREFIX + Registry.SHA256_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.SHA256_HASH);
58
  }
53
  }
59
60
  // Class methods
61
  // -------------------------------------------------------------------------
62
63
  // Instance methods
64
  // -------------------------------------------------------------------------
65
}
54
}
(-)mac/HMacSHA384Spi.java (-16 / +5 lines)
Lines 37-65 Link Here
37
37
38
38
39
package gnu.javax.crypto.jce.mac;
39
package gnu.javax.crypto.jce.mac;
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
41
42
42
/**
43
/**
43
 * <p>The implementation of the HMAC-SHA-384 <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-SHA-384 <i>Service Provider Interface</i>
44
 * (<b>SPI</b>) adapter.</p>
45
 * (<b>SPI</b>) adapter.
45
 */
46
 */
46
public class HMacSHA384Spi extends MacAdapter
47
public class HMacSHA384Spi
48
    extends MacAdapter
47
{
49
{
48
49
  // Constants and variables
50
  // -------------------------------------------------------------------------
51
52
  // Constructor(s)
53
  // -----------------------------------------------------------------------
54
55
  public HMacSHA384Spi()
50
  public HMacSHA384Spi()
56
  {
51
  {
57
    super(Registry.HMAC_NAME_PREFIX + Registry.SHA384_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.SHA384_HASH);
58
  }
53
  }
59
60
  // Class methods
61
  // -------------------------------------------------------------------------
62
63
  // Instance methods
64
  // -------------------------------------------------------------------------
65
}
54
}
(-)mac/HMacSHA512Spi.java (-16 / +5 lines)
Lines 37-65 Link Here
37
37
38
38
39
package gnu.javax.crypto.jce.mac;
39
package gnu.javax.crypto.jce.mac;
40
40
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
41
42
42
/**
43
/**
43
 * <p>The implementation of the HMAC-SHA-512 <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-SHA-512 <i>Service Provider Interface</i>
44
 * (<b>SPI</b>) adapter.</p>
45
 * (<b>SPI</b>) adapter.
45
 */
46
 */
46
public class HMacSHA512Spi extends MacAdapter
47
public class HMacSHA512Spi
48
    extends MacAdapter
47
{
49
{
48
49
  // Constants and variables
50
  // -------------------------------------------------------------------------
51
52
  // Constructor(s)
53
  // -----------------------------------------------------------------------
54
55
  public HMacSHA512Spi()
50
  public HMacSHA512Spi()
56
  {
51
  {
57
    super(Registry.HMAC_NAME_PREFIX + Registry.SHA512_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.SHA512_HASH);
58
  }
53
  }
59
60
  // Class methods
61
  // -------------------------------------------------------------------------
62
63
  // Instance methods
64
  // -------------------------------------------------------------------------
65
}
54
}
(-)mac/HMacTigerSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the Tiger <i>Service Provider Interface</i>
44
 * The implementation of the Tiger <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class HMacTigerSpi extends MacAdapter
47
public final class HMacTigerSpi
48
    extends MacAdapter
48
{
49
{
49
50
  // Constructors.
51
  // -----------------------------------------------------------------------
52
53
  public HMacTigerSpi()
50
  public HMacTigerSpi()
54
  {
51
  {
55
    super(Registry.HMAC_NAME_PREFIX + Registry.TIGER_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.TIGER_HASH);
(-)mac/HMacWhirlpoolSpi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the HMAC-Whirlpool <i>Service Provider Interface</i>
44
 * The implementation of the HMAC-Whirlpool <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class HMacWhirlpoolSpi extends MacAdapter
47
public final class HMacWhirlpoolSpi
48
    extends MacAdapter
48
{
49
{
49
50
  // Constructors.
51
  // -----------------------------------------------------------------------
52
53
  public HMacWhirlpoolSpi()
50
  public HMacWhirlpoolSpi()
54
  {
51
  {
55
    super(Registry.HMAC_NAME_PREFIX + Registry.WHIRLPOOL_HASH);
52
    super(Registry.HMAC_NAME_PREFIX + Registry.WHIRLPOOL_HASH);
(-)mac/MacAdapter.java (-31 / +13 lines)
Lines 50-81 Link Here
50
import javax.crypto.MacSpi;
50
import javax.crypto.MacSpi;
51
51
52
/**
52
/**
53
 * <p>The implementation of a generic {@link javax.crypto.Mac} adapter class
53
 * The implementation of a generic {@link javax.crypto.Mac} adapter class to
54
 * to wrap GNU Crypto MAC instances.</p>
54
 * wrap GNU MAC instances.
55
 *
55
 * <p>
56
 * <p>This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
56
 * This class defines the <i>Service Provider Interface</i> (<b>SPI</b>) for
57
 * the {@link javax.crypto.Mac} class, which provides the functionality of a
57
 * the {@link javax.crypto.Mac} class, which provides the functionality of a
58
 * message authentication code algorithm, such as the <i>Hashed Message
58
 * message authentication code algorithm, such as the <i>Hashed Message
59
 * Authentication Code</i> (<b>HMAC</b>) algorithms.</p>
59
 * Authentication Code</i> (<b>HMAC</b>) algorithms.
60
 */
60
 */
61
class MacAdapter extends MacSpi implements Cloneable
61
class MacAdapter
62
    extends MacSpi
63
    implements Cloneable
62
{
64
{
63
64
  // Constants and variables
65
  // -----------------------------------------------------------------------
66
67
  /** Our MAC instance. */
65
  /** Our MAC instance. */
68
  protected IMac mac;
66
  protected IMac mac;
69
70
  /** Our MAC attributes. */
67
  /** Our MAC attributes. */
71
  protected Map attributes;
68
  protected Map attributes;
72
69
73
  // Constructor(s)
74
  // -----------------------------------------------------------------------
75
76
  /**
70
  /**
77
   * <p>Creates a new Mac instance for the given name.</p>
71
   * Creates a new Mac instance for the given name.
78
   *
72
   * 
79
   * @param name The name of the mac to create.
73
   * @param name The name of the mac to create.
80
   */
74
   */
81
  protected MacAdapter(String name)
75
  protected MacAdapter(String name)
Lines 88-94 Link Here
88
   * Private constructor for cloning purposes.
82
   * Private constructor for cloning purposes.
89
   * 
83
   * 
90
   * @param mac a clone of the internal {@link IMac} instance.
84
   * @param mac a clone of the internal {@link IMac} instance.
91
   * @param attributes a clone of the current {@link Map} of attributes. 
85
   * @param attributes a clone of the current {@link Map} of attributes.
92
   */
86
   */
93
  private MacAdapter(IMac mac, Map attributes)
87
  private MacAdapter(IMac mac, Map attributes)
94
  {
88
  {
Lines 98-118 Link Here
98
    this.attributes = attributes;
92
    this.attributes = attributes;
99
  }
93
  }
100
94
101
  // Class methods
102
  // -----------------------------------------------------------------------
103
104
  // Instance methods
105
  // -----------------------------------------------------------------------
106
107
  // Cloneable interface implementation ------------------------------------
108
109
  public Object clone() throws CloneNotSupportedException
95
  public Object clone() throws CloneNotSupportedException
110
  {
96
  {
111
    return new MacAdapter((IMac) mac.clone(), new HashMap(attributes));
97
    return new MacAdapter((IMac) mac.clone(), new HashMap(attributes));
112
  }
98
  }
113
99
114
  // Instance methods implementing javax.crypto.MacSpi ---------------------
115
116
  protected byte[] engineDoFinal()
100
  protected byte[] engineDoFinal()
117
  {
101
  {
118
    byte[] result = mac.digest();
102
    byte[] result = mac.digest();
Lines 128-137 Link Here
128
  protected void engineInit(Key key, AlgorithmParameterSpec params)
112
  protected void engineInit(Key key, AlgorithmParameterSpec params)
129
      throws InvalidKeyException, InvalidAlgorithmParameterException
113
      throws InvalidKeyException, InvalidAlgorithmParameterException
130
  {
114
  {
131
    if (!key.getFormat().equalsIgnoreCase("RAW"))
115
    if (! key.getFormat().equalsIgnoreCase("RAW"))
132
      {
116
      throw new InvalidKeyException("unknown key format " + key.getFormat());
133
        throw new InvalidKeyException("unknown key format " + key.getFormat());
134
      }
135
    attributes.put(IMac.MAC_KEY_MATERIAL, key.getEncoded());
117
    attributes.put(IMac.MAC_KEY_MATERIAL, key.getEncoded());
136
    mac.reset();
118
    mac.reset();
137
    mac.init(attributes);
119
    mac.init(attributes);
(-)mac/OMacAnubisImpl.java (-6 / +3 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class OMacAnubisImpl extends MacAdapter
43
public class OMacAnubisImpl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  public OMacAnubisImpl()
46
  public OMacAnubisImpl()
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + Registry.ANUBIS_CIPHER);
48
    super(Registry.OMAC_PREFIX + Registry.ANUBIS_CIPHER);
52
  }
49
  }
53
}
50
}
(-)mac/OMacBlowfishImpl.java (-6 / +3 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class OMacBlowfishImpl extends MacAdapter
43
public class OMacBlowfishImpl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  public OMacBlowfishImpl()
46
  public OMacBlowfishImpl()
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + Registry.BLOWFISH_CIPHER);
48
    super(Registry.OMAC_PREFIX + Registry.BLOWFISH_CIPHER);
52
  }
49
  }
53
}
50
}
(-)mac/OMacCast5Impl.java (-6 / +3 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class OMacCast5Impl extends MacAdapter
43
public class OMacCast5Impl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  public OMacCast5Impl()
46
  public OMacCast5Impl()
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + Registry.CAST5_CIPHER);
48
    super(Registry.OMAC_PREFIX + Registry.CAST5_CIPHER);
52
  }
49
  }
53
}
50
}
(-)mac/OMacDESImpl.java (-6 / +3 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class OMacDESImpl extends MacAdapter
43
public class OMacDESImpl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  public OMacDESImpl()
46
  public OMacDESImpl()
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + Registry.DES_CIPHER);
48
    super(Registry.OMAC_PREFIX + Registry.DES_CIPHER);
52
  }
49
  }
53
}
50
}
(-)mac/OMacImpl.java (-19 / +23 lines)
Lines 40-60 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public abstract class OMacImpl extends MacAdapter
43
public abstract class OMacImpl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  protected OMacImpl(String name)
46
  protected OMacImpl(String name)
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + name);
48
    super(Registry.OMAC_PREFIX + name);
52
  }
49
  }
53
50
54
  // Inner classes.
51
  public class Anubis
55
  // -------------------------------------------------------------------------
52
      extends OMacImpl
56
57
  public class Anubis extends OMacImpl
58
  {
53
  {
59
    public Anubis()
54
    public Anubis()
60
    {
55
    {
Lines 62-68 Link Here
62
    }
57
    }
63
  }
58
  }
64
59
65
  public class Blowfish extends OMacImpl
60
  public class Blowfish
61
      extends OMacImpl
66
  {
62
  {
67
    public Blowfish()
63
    public Blowfish()
68
    {
64
    {
Lines 70-76 Link Here
70
    }
66
    }
71
  }
67
  }
72
68
73
  public class Cast5 extends OMacImpl
69
  public class Cast5
70
      extends OMacImpl
74
  {
71
  {
75
    public Cast5()
72
    public Cast5()
76
    {
73
    {
Lines 78-84 Link Here
78
    }
75
    }
79
  }
76
  }
80
77
81
  public class DES extends OMacImpl
78
  public class DES
79
      extends OMacImpl
82
  {
80
  {
83
    public DES()
81
    public DES()
84
    {
82
    {
Lines 86-92 Link Here
86
    }
84
    }
87
  }
85
  }
88
86
89
  public class Khazad extends OMacImpl
87
  public class Khazad
88
      extends OMacImpl
90
  {
89
  {
91
    public Khazad()
90
    public Khazad()
92
    {
91
    {
Lines 94-100 Link Here
94
    }
93
    }
95
  }
94
  }
96
95
97
  public class Rijndael extends OMacImpl
96
  public class Rijndael
97
      extends OMacImpl
98
  {
98
  {
99
    public Rijndael()
99
    public Rijndael()
100
    {
100
    {
Lines 102-108 Link Here
102
    }
102
    }
103
  }
103
  }
104
104
105
  public class Serpent extends OMacImpl
105
  public class Serpent
106
      extends OMacImpl
106
  {
107
  {
107
    public Serpent()
108
    public Serpent()
108
    {
109
    {
Lines 110-116 Link Here
110
    }
111
    }
111
  }
112
  }
112
113
113
  public class Square extends OMacImpl
114
  public class Square
115
      extends OMacImpl
114
  {
116
  {
115
    public Square()
117
    public Square()
116
    {
118
    {
Lines 118-124 Link Here
118
    }
120
    }
119
  }
121
  }
120
122
121
  public class TripleDES extends OMacImpl
123
  public class TripleDES
124
      extends OMacImpl
122
  {
125
  {
123
    public TripleDES()
126
    public TripleDES()
124
    {
127
    {
Lines 126-136 Link Here
126
    }
129
    }
127
  }
130
  }
128
131
129
  public class Twofish extends OMacImpl
132
  public class Twofish
133
      extends OMacImpl
130
  {
134
  {
131
    public Twofish()
135
    public Twofish()
132
    {
136
    {
133
      super(Registry.TWOFISH_CIPHER);
137
      super(Registry.TWOFISH_CIPHER);
134
    }
138
    }
135
  }
139
  }
136
}
140
}
(-)mac/OMacKhazadImpl.java (-6 / +3 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class OMacKhazadImpl extends MacAdapter
43
public class OMacKhazadImpl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  public OMacKhazadImpl()
46
  public OMacKhazadImpl()
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + Registry.KHAZAD_CIPHER);
48
    super(Registry.OMAC_PREFIX + Registry.KHAZAD_CIPHER);
52
  }
49
  }
53
}
50
}
(-)mac/OMacRijndaelImpl.java (-6 / +3 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class OMacRijndaelImpl extends MacAdapter
43
public class OMacRijndaelImpl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  public OMacRijndaelImpl()
46
  public OMacRijndaelImpl()
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + Registry.RIJNDAEL_CIPHER);
48
    super(Registry.OMAC_PREFIX + Registry.RIJNDAEL_CIPHER);
52
  }
49
  }
53
}
50
}
(-)mac/OMacSerpentImpl.java (-6 / +3 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class OMacSerpentImpl extends MacAdapter
43
public class OMacSerpentImpl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  public OMacSerpentImpl()
46
  public OMacSerpentImpl()
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + Registry.SERPENT_CIPHER);
48
    super(Registry.OMAC_PREFIX + Registry.SERPENT_CIPHER);
52
  }
49
  }
53
}
50
}
(-)mac/OMacSquareImpl.java (-6 / +3 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class OMacSquareImpl extends MacAdapter
43
public class OMacSquareImpl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  public OMacSquareImpl()
46
  public OMacSquareImpl()
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + Registry.SQUARE_CIPHER);
48
    super(Registry.OMAC_PREFIX + Registry.SQUARE_CIPHER);
52
  }
49
  }
53
}
50
}
(-)mac/OMacTripleDESImpl.java (-6 / +3 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class OMacTripleDESImpl extends MacAdapter
43
public class OMacTripleDESImpl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  public OMacTripleDESImpl()
46
  public OMacTripleDESImpl()
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + Registry.TRIPLEDES_CIPHER);
48
    super(Registry.OMAC_PREFIX + Registry.TRIPLEDES_CIPHER);
52
  }
49
  }
53
}
50
}
(-)mac/OMacTwofishImpl.java (-6 / +3 lines)
Lines 40-53 Link Here
40
40
41
import gnu.java.security.Registry;
41
import gnu.java.security.Registry;
42
42
43
public class OMacTwofishImpl extends MacAdapter
43
public class OMacTwofishImpl
44
    extends MacAdapter
44
{
45
{
45
46
  // Constructor.
47
  // -------------------------------------------------------------------------
48
49
  public OMacTwofishImpl()
46
  public OMacTwofishImpl()
50
  {
47
  {
51
    super(Registry.OMAC_PREFIX + Registry.TWOFISH_CIPHER);
48
    super(Registry.OMAC_PREFIX + Registry.TWOFISH_CIPHER);
52
  }
49
  }
53
}
50
}
(-)mac/TMMH16Spi.java (-12 / +4 lines)
Lines 51-77 Link Here
51
 * The implementation of the TMMH16 <i>Service Provider Interface</i>
51
 * The implementation of the TMMH16 <i>Service Provider Interface</i>
52
 * (<b>SPI</b>) adapter.
52
 * (<b>SPI</b>) adapter.
53
 */
53
 */
54
public final class TMMH16Spi extends MacAdapter
54
public final class TMMH16Spi
55
    extends MacAdapter
55
{
56
{
56
57
  // Constructors.
58
  // -----------------------------------------------------------------------
59
60
  public TMMH16Spi()
57
  public TMMH16Spi()
61
  {
58
  {
62
    super(Registry.TMMH16);
59
    super(Registry.TMMH16);
63
  }
60
  }
64
61
65
  // Instance methods overriding MacAdapter.
66
  // -----------------------------------------------------------------------
67
68
  protected void engineInit(Key key, AlgorithmParameterSpec params)
62
  protected void engineInit(Key key, AlgorithmParameterSpec params)
69
      throws InvalidKeyException, InvalidAlgorithmParameterException
63
      throws InvalidKeyException, InvalidAlgorithmParameterException
70
  {
64
  {
71
    if (!(params instanceof TMMHParameterSpec))
65
    if (! (params instanceof TMMHParameterSpec))
72
      {
66
      throw new InvalidAlgorithmParameterException();
73
        throw new InvalidAlgorithmParameterException();
74
      }
75
    TMMHParameterSpec spec = (TMMHParameterSpec) params;
67
    TMMHParameterSpec spec = (TMMHParameterSpec) params;
76
    attributes.put(TMMH16.TAG_LENGTH, spec.getTagLength());
68
    attributes.put(TMMH16.TAG_LENGTH, spec.getTagLength());
77
    attributes.put(TMMH16.KEYSTREAM, spec.getKeystream());
69
    attributes.put(TMMH16.KEYSTREAM, spec.getKeystream());
(-)mac/UHash32Spi.java (-5 / +2 lines)
Lines 44-55 Link Here
44
 * The implementation of the UHash-32 <i>Service Provider Interface</i>
44
 * The implementation of the UHash-32 <i>Service Provider Interface</i>
45
 * (<b>SPI</b>) adapter.
45
 * (<b>SPI</b>) adapter.
46
 */
46
 */
47
public final class UHash32Spi extends MacAdapter
47
public final class UHash32Spi
48
    extends MacAdapter
48
{
49
{
49
50
  // Constructors.
51
  // -----------------------------------------------------------------------
52
53
  public UHash32Spi()
50
  public UHash32Spi()
54
  {
51
  {
55
    super(Registry.UHASH32);
52
    super(Registry.UHASH32);
(-)mac/UMac32Spi.java (-16 / +6 lines)
Lines 51-82 Link Here
51
 * The implementation of the UMAC-32 <i>Service Provider Interface</i>
51
 * The implementation of the UMAC-32 <i>Service Provider Interface</i>
52
 * (<b>SPI</b>) adapter.
52
 * (<b>SPI</b>) adapter.
53
 */
53
 */
54
public final class UMac32Spi extends MacAdapter
54
public final class UMac32Spi
55
    extends MacAdapter
55
{
56
{
56
57
  // Constructors.
58
  // -----------------------------------------------------------------------
59
60
  public UMac32Spi()
57
  public UMac32Spi()
61
  {
58
  {
62
    super(Registry.UMAC32);
59
    super(Registry.UMAC32);
63
  }
60
  }
64
61
65
  // Instance methods overriding MacAdapter.
66
  // -----------------------------------------------------------------------
67
68
  protected void engineInit(Key key, AlgorithmParameterSpec params)
62
  protected void engineInit(Key key, AlgorithmParameterSpec params)
69
      throws InvalidKeyException, InvalidAlgorithmParameterException
63
      throws InvalidKeyException, InvalidAlgorithmParameterException
70
  {
64
  {
71
    if (!(params instanceof UMac32ParameterSpec))
65
    if (! (params instanceof UMac32ParameterSpec))
72
      {
66
      throw new InvalidAlgorithmParameterException();
73
        throw new InvalidAlgorithmParameterException();
74
      }
75
    if (params != null)
67
    if (params != null)
76
      {
68
      attributes.put(UMac32.NONCE_MATERIAL,
77
        attributes.put(UMac32.NONCE_MATERIAL,
69
                     ((UMac32ParameterSpec) params).getNonce());
78
                       ((UMac32ParameterSpec) params).getNonce());
79
      }
80
    try
70
    try
81
      {
71
      {
82
        super.engineInit(key, null);
72
        super.engineInit(key, null);
(-)params/BlockCipherParameters.java (-104 / +33 lines)
Lines 48-85 Link Here
48
import java.security.spec.InvalidParameterSpecException;
48
import java.security.spec.InvalidParameterSpecException;
49
49
50
/**
50
/**
51
 * An implementation of algorithm parameters for the GNU Crypto block
51
 * An implementation of algorithm parameters for the GNU block ciphers. This
52
 * ciphers. This encompasses the cipher's block size, its key size, and
52
 * encompasses the cipher's block size, its key size, and an optional
53
 * an optional initialization vector (IV).
53
 * initialization vector (IV).
54
 */
54
 */
55
public class BlockCipherParameters extends AlgorithmParametersSpi
55
public class BlockCipherParameters
56
    extends AlgorithmParametersSpi
56
{
57
{
57
58
  /** The underlying block cipher specification. */
58
  // Constants and variables.
59
  // -----------------------------------------------------------------------
60
61
  /**
62
   * The underlying block cipher specification.
63
   */
64
  protected BlockCipherParameterSpec cipherSpec;
59
  protected BlockCipherParameterSpec cipherSpec;
65
66
  private static final String DEFAULT_FORMAT = "ASN.1";
60
  private static final String DEFAULT_FORMAT = "ASN.1";
67
61
68
  // Instance methods implementing AlgorithmParametersSpi.
69
  // -----------------------------------------------------------------------
70
71
  /**
62
  /**
72
   * Return these parameters encoded in ASN.1 (DER).
63
   * Return these parameters encoded in ASN.1 (DER).
73
   *
64
   * <p>
74
   * <p>For GNU Crypto block ciphers we will define these parameters as
65
   * For GNU block ciphers we will define these parameters as
75
   *
66
   * <pre>
76
   * <blockquote>
67
   * BlockCipherParameters ::= SEQUENCE {
77
   * <pre>BlockCipherParameters ::= SEQUENCE {
68
   *    blockSize            INTEGER,
78
   *   blockSize            INTEGER,
69
   *    keySize              INTEGER,
79
   *   keySize              INTEGER,
70
   *    initializationVector OCTET STRING OPTIONAL }
80
   *   initializationVector OCTET STRING OPTIONAL }</pre>
71
   * </pre>
81
   * </blockquote>
72
   * 
82
   *
83
   * @return The parameters, encoded an an ASN.1 DER sequence.
73
   * @return The parameters, encoded an an ASN.1 DER sequence.
84
   * @throws java.io.IOException If encoding these parameters fails.
74
   * @throws java.io.IOException If encoding these parameters fails.
85
   */
75
   */
Lines 90-193 Link Here
90
80
91
  protected byte[] engineGetEncoded(String format) throws IOException
81
  protected byte[] engineGetEncoded(String format) throws IOException
92
  {
82
  {
93
    if (!format.equalsIgnoreCase(DEFAULT_FORMAT)
83
    if (! format.equalsIgnoreCase(DEFAULT_FORMAT)
94
        && !format.equalsIgnoreCase("asn1"))
84
        && ! format.equalsIgnoreCase("asn1"))
95
      {
85
      throw new IOException("unknown format \"" + format + "\"");
96
        throw new IOException("unknown format \"" + format + "\"");
97
      }
98
    // This is probably a bad idea.
99
    /*
100
     int len = 12 + ((cipherSpec.getIV() != null)
101
     ? cipherSpec.getIV().length + 2 : 0);
102
     ByteArrayOutputStream out = new ByteArrayOutputStream();
103
     out.write(0x30);
104
     out.write(len);
105
     out.write(0x02);
106
     out.write(4);
107
     out.write(cipherSpec.getBlockSize() >>> 24 & 0xff);
108
     out.write(cipherSpec.getBlockSize() >>> 16 & 0xff);
109
     out.write(cipherSpec.getBlockSize() >>>  8 & 0xff);
110
     out.write(cipherSpec.getBlockSize() & 0xff);
111
     out.write(0x02);
112
     out.write(4);
113
     out.write(cipherSpec.getKeySize() >>> 24 & 0xff);
114
     out.write(cipherSpec.getKeySize() >>> 16 & 0xff);
115
     out.write(cipherSpec.getKeySize() >>>  8 & 0xff);
116
     out.write(cipherSpec.getKeySize() & 0xff);
117
     if (cipherSpec.getIV() != null) {
118
     out.write(0x04);
119
     len = cipherSpec.getIV().length;
120
     out.write(len & 0xff);
121
     out.write(cipherSpec.getIV());
122
     }
123
     out.write(0); out.write(0);
124
     return out.toByteArray();*/
125
    DERWriter writer = new DERWriter();
86
    DERWriter writer = new DERWriter();
87
    int cipherBlockSize = cipherSpec.getBlockSize();
88
    int cipherKeySize = cipherSpec.getKeySize();
89
    byte[] iv = cipherSpec.getIV();
126
    return writer.joinarrays(
90
    return writer.joinarrays(
127
                             writer.writeBigInteger(BigInteger.valueOf(cipherSpec.getBlockSize())),
91
        writer.writeBigInteger(BigInteger.valueOf(cipherBlockSize)),
128
                             writer.writeBigInteger(BigInteger.valueOf(cipherSpec.getKeySize())),
92
        writer.writeBigInteger(BigInteger.valueOf(cipherKeySize)),
129
                             (cipherSpec.getIV() != null) ? writer.writeBigInteger(new BigInteger(
93
        (iv != null) ? writer.writeBigInteger(new BigInteger(iv))
130
                                                                                                  cipherSpec.getIV()))
94
                     : new byte[0]);
131
                                                         : new byte[0]);
132
  }
95
  }
133
96
134
  protected void engineInit(AlgorithmParameterSpec spec)
97
  protected void engineInit(AlgorithmParameterSpec spec)
135
      throws InvalidParameterSpecException
98
      throws InvalidParameterSpecException
136
  {
99
  {
137
    if (spec instanceof BlockCipherParameterSpec)
100
    if (spec instanceof BlockCipherParameterSpec)
138
      {
101
      cipherSpec = (BlockCipherParameterSpec) spec;
139
        cipherSpec = (BlockCipherParameterSpec) spec;
140
      }
141
    else
102
    else
142
      {
103
      throw new InvalidParameterSpecException();
143
        throw new InvalidParameterSpecException();
144
      }
145
  }
104
  }
146
105
147
  protected void engineInit(byte[] encoded, String format) throws IOException
106
  protected void engineInit(byte[] encoded, String format) throws IOException
148
  {
107
  {
149
    if (!format.equalsIgnoreCase(DEFAULT_FORMAT)
108
    if (! format.equalsIgnoreCase(DEFAULT_FORMAT)
150
        && !format.equalsIgnoreCase("ASN1"))
109
        && ! format.equalsIgnoreCase("ASN1"))
151
      {
110
      throw new IOException("invalid format: only accepts ASN.1");
152
        throw new IOException("invalid format: only accepts ASN.1");
153
      }
154
    engineInit(encoded);
111
    engineInit(encoded);
155
  }
112
  }
156
113
157
  protected void engineInit(byte[] encoded) throws IOException
114
  protected void engineInit(byte[] encoded) throws IOException
158
  {
115
  {
159
    // This is probably an equally bad idea.
160
    /*if (encoded[0] != 0x30) {
161
     throw new IOException("malformed ASN.1 sequence");
162
     }
163
     if (encoded[2] != 0x02 || encoded[3] != 4) {
164
     throw new IOException("malformed ASN.1 sequence");
165
     }
166
     int blockSize = encoded[4] << 24 | encoded[5] << 16
167
     | encoded[6] <<  8 | encoded[7];
168
     if (encoded[8] != 0x02 || encoded[9] != 4) {
169
     throw new IOException("malformed ASN.1 sequence");
170
     }
171
     int keySize = encoded[10] << 24 | encoded[11] << 16
172
     | encoded[12] <<  8 | encoded[13];
173
     if (encoded[14] == 0x04) {
174
     int len = encoded[15] & 0xff;
175
     byte[] iv = new byte[len];
176
     System.arraycopy(encoded, 16, iv, 0, len);
177
     cipherSpec = new BlockCipherParameterSpec(iv, blockSize, keySize);
178
     } else if (encoded[14] == 0) {
179
     cipherSpec = new BlockCipherParameterSpec(blockSize, keySize);
180
     } else {
181
     throw new IOException("malformed ASN.1 sequence");
182
     }*/
183
    DERReader reader = new DERReader(encoded);
116
    DERReader reader = new DERReader(encoded);
184
    int bs = reader.getBigInteger().intValue();
117
    int bs = reader.getBigInteger().intValue();
185
    int ks = reader.getBigInteger().intValue();
118
    int ks = reader.getBigInteger().intValue();
186
    byte[] iv = null;
119
    byte[] iv = null;
187
    if (reader.hasMorePrimitives())
120
    if (reader.hasMorePrimitives())
188
      {
121
      iv = reader.getBigInteger().toByteArray();
189
        iv = reader.getBigInteger().toByteArray();
190
      }
191
    cipherSpec = new BlockCipherParameterSpec(iv, bs, ks);
122
    cipherSpec = new BlockCipherParameterSpec(iv, bs, ks);
192
    System.out.println(cipherSpec);
123
    System.out.println(cipherSpec);
193
  }
124
  }
Lines 196-204 Link Here
196
      throws InvalidParameterSpecException
127
      throws InvalidParameterSpecException
197
  {
128
  {
198
    if (c.isInstance(cipherSpec))
129
    if (c.isInstance(cipherSpec))
199
      {
130
      return cipherSpec;
200
        return cipherSpec;
201
      }
202
    throw new InvalidParameterSpecException();
131
    throw new InvalidParameterSpecException();
203
  }
132
  }
204
133
Lines 206-209 Link Here
206
  {
135
  {
207
    return cipherSpec.toString();
136
    return cipherSpec.toString();
208
  }
137
  }
209
}
138
}
(-)params/DEREncodingException.java (-2 / +3 lines)
Lines 38-44 Link Here
38
38
39
package gnu.javax.crypto.jce.params;
39
package gnu.javax.crypto.jce.params;
40
40
41
class DEREncodingException extends java.io.IOException
41
class DEREncodingException
42
    extends java.io.IOException
42
{
43
{
43
44
44
  public DEREncodingException()
45
  public DEREncodingException()
Lines 50-53 Link Here
50
  {
51
  {
51
    super(msg);
52
    super(msg);
52
  }
53
  }
53
}
54
}
(-)params/DERReader.java (-28 / +7 lines)
Lines 43-57 Link Here
43
class DERReader
43
class DERReader
44
{
44
{
45
  byte source[];
45
  byte source[];
46
47
  int pos;
46
  int pos;
48
49
  static final int UNIVERSAL = 1;
47
  static final int UNIVERSAL = 1;
50
51
  static final int APPLICATION = 2;
48
  static final int APPLICATION = 2;
52
53
  static final int CONTEXT_SPECIFIC = 3;
49
  static final int CONTEXT_SPECIFIC = 3;
54
55
  static final int PRIVATE = 4;
50
  static final int PRIVATE = 4;
56
51
57
  public DERReader()
52
  public DERReader()
Lines 86-138 Link Here
86
    return new BigInteger(getPrimitive());
81
    return new BigInteger(getPrimitive());
87
  }
82
  }
88
83
89
  //Reads Primitive, definite-length method
84
  // Reads Primitive, definite-length method
90
  private byte[] getPrimitive() throws DEREncodingException
85
  private byte[] getPrimitive() throws DEREncodingException
91
  {
86
  {
92
    int tmp = pos;
87
    int tmp = pos;
93
88
    // Read Identifier
94
    //Read Identifier
95
    byte identifier = source[tmp++];
89
    byte identifier = source[tmp++];
96
    if ((0x20 & identifier) != 0)
90
    if ((0x20 & identifier) != 0)
97
      throw new DEREncodingException();
91
      throw new DEREncodingException();
98
    int type = translateLeadIdentifierByte(identifier);
92
    int type = translateLeadIdentifierByte(identifier);
99
    //System.out.println("Type: " + type);
93
    // get tag
100
101
    //get tag
102
    int tag = (0x1f & identifier);
94
    int tag = (0x1f & identifier);
103
    //if( tag == 0x1f)
95
    // get length
104
    //	tag = getIdentifier(tmp);
96
    byte len = source[tmp]; // may be length of length parameter
105
    //System.out.println("Tag: " + tag);
106
107
    //get length
108
    byte len = source[tmp]; //may be length of length parameter
109
    long length = 0x7f & len;
97
    long length = 0x7f & len;
110
    int i;
98
    int i;
111
    if ((0x80 & len) != 0)
99
    if ((0x80 & len) != 0)
112
      {
100
      {
113
        //System.out.println("Extra Long Length");
114
        len &= 0x7f;
101
        len &= 0x7f;
115
        //System.out.println("Length of Length: " + len);
102
        // get length here
116
        //get length here
117
        length = 0;
103
        length = 0;
118
        for (i = 0; i < len; i++)
104
        for (i = 0; i < len; i++)
119
          {
105
          {
120
            tmp++;
106
            tmp++;
121
            length <<= 8;
107
            length <<= 8;
122
            length += (source[tmp] < 0) ? (256 + source[tmp]) : source[tmp];
108
            length += (source[tmp] < 0) ? (256 + source[tmp]) : source[tmp];
123
            //System.out.println("Length of Length: " + length);
124
          }
109
          }
125
        tmp++;
110
        tmp++;
126
      }
111
      }
127
    else
112
    else
128
      tmp++;
113
      tmp++;
129
114
130
    /*System.out.println("Position: " + tmp);
131
     System.out.println("Length: " + length);
132
     for( i = 0; i < 10; i++)
133
     System.out.print(source[tmp + i] + " ");
134
     System.out.println();*/
135
136
    byte tmpb[] = new byte[(int) length];
115
    byte tmpb[] = new byte[(int) length];
137
    System.arraycopy(source, tmp, tmpb, 0, (int) length);
116
    System.arraycopy(source, tmp, tmpb, 0, (int) length);
138
    pos = (int) (tmp + length);
117
    pos = (int) (tmp + length);
Lines 157-160 Link Here
157
      tpos++;
136
      tpos++;
158
    return tpos;
137
    return tpos;
159
  }
138
  }
160
}
139
}
(-)params/DERWriter.java (-20 / +9 lines)
Lines 43-53 Link Here
43
class DERWriter
43
class DERWriter
44
{
44
{
45
  static final int UNIVERSAL = 1;
45
  static final int UNIVERSAL = 1;
46
47
  static final int APPLICATION = 2;
46
  static final int APPLICATION = 2;
48
49
  static final int CONTEXT_SPECIFIC = 3;
47
  static final int CONTEXT_SPECIFIC = 3;
50
51
  static final int PRIVATE = 4;
48
  static final int PRIVATE = 4;
52
49
53
  public DERWriter()
50
  public DERWriter()
Lines 56-62 Link Here
56
53
57
  public byte[] writeBigInteger(BigInteger i)
54
  public byte[] writeBigInteger(BigInteger i)
58
  {
55
  {
59
    return writePrimitive(0x02, UNIVERSAL,
56
    return writePrimitive(0x02,
57
                          UNIVERSAL,
60
                          (int) Math.ceil((double) i.bitLength() / 8),
58
                          (int) Math.ceil((double) i.bitLength() / 8),
61
                          i.toByteArray());
59
                          i.toByteArray());
62
  }
60
  }
Lines 71-77 Link Here
71
  public byte[] joinarrays(byte a[], byte b[])
69
  public byte[] joinarrays(byte a[], byte b[])
72
  {
70
  {
73
    byte d[] = new byte[a.length + b.length];
71
    byte d[] = new byte[a.length + b.length];
74
    System.arraycopy(a, 0, d, 0, a.length);
72
    System.arraycopy(a, 0, d, 0,        a.length);
75
    System.arraycopy(b, 0, d, a.length, b.length);
73
    System.arraycopy(b, 0, d, a.length, b.length);
76
    return d;
74
    return d;
77
  }
75
  }
Lines 92-98 Link Here
92
      {
90
      {
93
        int count = (int) (Math.log(identifier) / Math.log(256));
91
        int count = (int) (Math.log(identifier) / Math.log(256));
94
        b = new byte[count + 1];
92
        b = new byte[count + 1];
95
        b[0] = (byte) (translateLeadIdentifierByte(identifierencoding) | 0x1f);
93
        b[0] = (byte)(translateLeadIdentifierByte(identifierencoding) | 0x1f);
96
        int i;
94
        int i;
97
        for (i = 1; i < (count + 1); i++)
95
        for (i = 1; i < (count + 1); i++)
98
          {
96
          {
Lines 100-113 Link Here
100
            b[i] |= 0x80;
98
            b[i] |= 0x80;
101
          }
99
          }
102
        b[i - 1] ^= 0x80;
100
        b[i - 1] ^= 0x80;
103
        //System.out.println("Identifier1: " + b[0]);
104
        return b;
101
        return b;
105
      }
102
      }
106
    else
103
    else
107
      {
104
      {
108
        b = new byte[1];
105
        b = new byte[1];
109
        b[0] = (byte) ((translateLeadIdentifierByte(identifierencoding) | (byte) (identifier & 0x1f)) & 0xdf);
106
        b[0] = (byte)((translateLeadIdentifierByte(identifierencoding)
110
        //System.out.println("Identifier2: " + b[0]);
107
             | (byte)(identifier & 0x1f)) & 0xdf);
111
        return b;
108
        return b;
112
      }
109
      }
113
  }
110
  }
Lines 130-154 Link Here
130
    if (length > 127)
127
    if (length > 127)
131
      {
128
      {
132
        int count = (int) Math.ceil(Math.log(length) / Math.log(256));
129
        int count = (int) Math.ceil(Math.log(length) / Math.log(256));
133
        //System.out.println("Length byte count: " + count);
134
        b = new byte[count + 1];
130
        b = new byte[count + 1];
135
        b[0] = (byte) ((count & 0x7f) | 0x80);
131
        b[0] = (byte)((count & 0x7f) | 0x80);
136
        for (int i = 1; i < (count + 1); i++)
132
        for (int i = 1; i < (count + 1); i++)
137
          {
133
          b[i] = (byte) (length >>> (8 * (count - i)));
138
            b[i] = (byte) (length >>> (8 * (count - i)));
139
            //System.out.println("Length1 byte1: " + (length >>> (8 * ( count - i) )));
140
            //System.out.println("Length1 byte2: " + b[i]);
141
          }
142
143
        //System.out.println("Length1: " + length);
144
        return b;
134
        return b;
145
      }
135
      }
146
    else
136
    else
147
      {
137
      {
148
        b = new byte[1];
138
        b = new byte[1];
149
        b[0] = (byte) (length & 0x7f);
139
        b[0] = (byte) (length & 0x7f);
150
        //System.out.println("Length2: " + length);
151
        return b;
140
        return b;
152
      }
141
      }
153
  }
142
  }
154
}
143
}
(-)prng/ARCFourRandomSpi.java (-26 / +7 lines)
Lines 48-71 Link Here
48
import java.util.HashMap;
48
import java.util.HashMap;
49
49
50
/**
50
/**
51
 * Implementation of the <i>Service Provider Interface</i> (<b>SPI</b>)
51
 * Implementation of the <i>Service Provider Interface</i> (<b>SPI</b>) for
52
 * for the ARCFOUR keystream generator.
52
 * the ARCFOUR keystream generator.
53
 */
53
 */
54
public class ARCFourRandomSpi extends SecureRandomSpi
54
public class ARCFourRandomSpi
55
    extends SecureRandomSpi
55
{
56
{
56
57
  // Constants and variables
58
  // -------------------------------------------------------------------------
59
60
  /** Our underlying prng instance. */
57
  /** Our underlying prng instance. */
61
  private IRandom adaptee;
58
  private IRandom adaptee;
62
63
  /** Have we been initialized? */
59
  /** Have we been initialized? */
64
  private boolean virgin;
60
  private boolean virgin;
65
61
66
  // Constructor(s)
67
  // -------------------------------------------------------------------------
68
69
  /**
62
  /**
70
   * Default 0-arguments constructor.
63
   * Default 0-arguments constructor.
71
   */
64
   */
Lines 76-95 Link Here
76
    virgin = true;
69
    virgin = true;
77
  }
70
  }
78
71
79
  // Class methods
80
  // -------------------------------------------------------------------------
81
82
  // Instance methods
83
  // -------------------------------------------------------------------------
84
85
  // java.security.SecureRandomSpi interface implementation ------------------
86
87
  public byte[] engineGenerateSeed(int numBytes)
72
  public byte[] engineGenerateSeed(int numBytes)
88
  {
73
  {
89
    if (numBytes < 1)
74
    if (numBytes < 1)
90
      {
75
      return new byte[0];
91
        return new byte[0];
92
      }
93
    byte[] result = new byte[numBytes];
76
    byte[] result = new byte[numBytes];
94
    this.engineNextBytes(result);
77
    this.engineNextBytes(result);
95
    return result;
78
    return result;
Lines 98-106 Link Here
98
  public void engineNextBytes(byte[] bytes)
81
  public void engineNextBytes(byte[] bytes)
99
  {
82
  {
100
    if (virgin)
83
    if (virgin)
101
      {
84
      this.engineSetSeed(new byte[0]);
102
        this.engineSetSeed(new byte[0]);
103
      }
104
    try
85
    try
105
      {
86
      {
106
        adaptee.nextBytes(bytes, 0, bytes.length);
87
        adaptee.nextBytes(bytes, 0, bytes.length);
Lines 117-120 Link Here
117
    adaptee.init(attributes);
98
    adaptee.init(attributes);
118
    virgin = false;
99
    virgin = false;
119
  }
100
  }
120
}
101
}
(-)prng/CSPRNGSpi.java (-26 / +9 lines)
Lines 46-65 Link Here
46
import java.security.SecureRandomSpi;
46
import java.security.SecureRandomSpi;
47
47
48
/**
48
/**
49
 * The implementation of the continuously-seeded SecureRandom
49
 * The implementation of the continuously-seeded SecureRandom <i>Service
50
 * <i>Service Provider Interface</i> (<b>SPI</b>) adapter.<p>
50
 * Provider Interface</i> (<b>SPI</b>) adapter.
51
 */
51
 */
52
public class CSPRNGSpi extends SecureRandomSpi
52
public class CSPRNGSpi
53
    extends SecureRandomSpi
53
{
54
{
54
55
  // Constants and variables
56
  // -------------------------------------------------------------------------
57
58
  private final IRandom adaptee;
55
  private final IRandom adaptee;
59
56
60
  // Constructor(s)
61
  // -------------------------------------------------------------------------
62
63
  public CSPRNGSpi() throws ClassNotFoundException, MalformedURLException,
57
  public CSPRNGSpi() throws ClassNotFoundException, MalformedURLException,
64
      NumberFormatException
58
      NumberFormatException
65
  {
59
  {
Lines 68-87 Link Here
68
    adaptee = CSPRNG.getSystemInstance();
62
    adaptee = CSPRNG.getSystemInstance();
69
  }
63
  }
70
64
71
  // Instance methods
72
  // -------------------------------------------------------------------------
73
74
  protected byte[] engineGenerateSeed(final int count)
65
  protected byte[] engineGenerateSeed(final int count)
75
  {
66
  {
76
    if (count < 0)
67
    if (count < 0)
77
      {
68
      throw new IllegalArgumentException("count must be nonnegative");
78
        throw new IllegalArgumentException("count must be nonnegative");
79
      }
80
    byte[] buf = new byte[count];
69
    byte[] buf = new byte[count];
81
    if (count == 0)
70
    if (count == 0)
82
      {
71
      return buf;
83
        return buf;
84
      }
85
    engineNextBytes(buf);
72
    engineNextBytes(buf);
86
    return buf;
73
    return buf;
87
  }
74
  }
Lines 89-97 Link Here
89
  protected void engineNextBytes(final byte[] buffer)
76
  protected void engineNextBytes(final byte[] buffer)
90
  {
77
  {
91
    if (buffer == null)
78
    if (buffer == null)
92
      {
79
      throw new NullPointerException();
93
        throw new NullPointerException();
94
      }
95
    try
80
    try
96
      {
81
      {
97
        adaptee.nextBytes(buffer, 0, buffer.length);
82
        adaptee.nextBytes(buffer, 0, buffer.length);
Lines 105-113 Link Here
105
  protected void engineSetSeed(final byte[] seed)
90
  protected void engineSetSeed(final byte[] seed)
106
  {
91
  {
107
    if (seed == null)
92
    if (seed == null)
108
      {
93
      throw new NullPointerException();
109
        throw new NullPointerException();
110
      }
111
    adaptee.addRandomBytes(seed, 0, seed.length);
94
    adaptee.addRandomBytes(seed, 0, seed.length);
112
  }
95
  }
113
}
96
}
(-)prng/FortunaImpl.java (-12 / +14 lines)
Lines 40-63 Link Here
40
40
41
import gnu.java.security.prng.LimitReachedException;
41
import gnu.java.security.prng.LimitReachedException;
42
import gnu.javax.crypto.prng.Fortuna;
42
import gnu.javax.crypto.prng.Fortuna;
43
43
import java.security.SecureRandomSpi;
44
import java.security.SecureRandomSpi;
44
import java.util.Collections;
45
import java.util.Collections;
45
46
46
public final class FortunaImpl extends SecureRandomSpi
47
public final class FortunaImpl
48
    extends SecureRandomSpi
47
{
49
{
48
  private final Fortuna adaptee;
50
  private final Fortuna adaptee;
49
51
50
  public FortunaImpl ()
52
  public FortunaImpl()
51
  {
53
  {
52
    adaptee = new Fortuna ();
54
    adaptee = new Fortuna();
53
    adaptee.init (Collections.singletonMap (Fortuna.SEED, new byte[0]));
55
    adaptee.init(Collections.singletonMap(Fortuna.SEED, new byte[0]));
54
  }
56
  }
55
  
57
56
  protected void engineSetSeed (byte[] seed)
58
  protected void engineSetSeed(byte[] seed)
57
  {
59
  {
58
    synchronized (adaptee)
60
    synchronized (adaptee)
59
      {
61
      {
60
        adaptee.addRandomBytes (seed);
62
        adaptee.addRandomBytes(seed);
61
      }
63
      }
62
  }
64
  }
63
65
Lines 67-85 Link Here
67
      {
69
      {
68
        try
70
        try
69
          {
71
          {
70
            adaptee.nextBytes (buffer);
72
            adaptee.nextBytes(buffer);
71
          }
73
          }
72
        catch (LimitReachedException shouldNotHappen)
74
        catch (LimitReachedException shouldNotHappen)
73
          {
75
          {
74
            throw new Error (shouldNotHappen);
76
            throw new Error(shouldNotHappen);
75
          }
77
          }
76
      }
78
      }
77
  }
79
  }
78
80
79
  protected byte[] engineGenerateSeed (int numbytes)
81
  protected byte[] engineGenerateSeed(int numbytes)
80
  {
82
  {
81
    byte[] seed = new byte[numbytes];
83
    byte[] seed = new byte[numbytes];
82
    engineNextBytes (seed);
84
    engineNextBytes(seed);
83
    return seed;
85
    return seed;
84
  }
86
  }
85
}
87
}
(-)prng/ICMRandomSpi.java (-35 / +11 lines)
Lines 51-63 Link Here
51
import java.util.logging.Logger;
51
import java.util.logging.Logger;
52
52
53
/**
53
/**
54
 * <p>An <em>Adapter</em> class around {@link ICMGenerator} to allow using this
54
 * An <em>Adapter</em> class around {@link ICMGenerator} to allow using this
55
 * algorithm as a JCE {@link java.security.SecureRandom}.</p>
55
 * algorithm as a JCE {@link java.security.SecureRandom}.
56
 */
56
 */
57
public class ICMRandomSpi extends SecureRandomSpi
57
public class ICMRandomSpi
58
    extends SecureRandomSpi
58
{
59
{
59
  private static final Logger log = Logger.getLogger(ICMRandomSpi.class.getName());
60
  private static final Logger log = Logger.getLogger(ICMRandomSpi.class.getName());
60
  /** Class-wide prng to generate random material for the underlying prng.*/
61
  /** Class-wide prng to generate random material for the underlying prng. */
61
  private static final ICMGenerator prng; // blank final
62
  private static final ICMGenerator prng; // blank final
62
  static
63
  static
63
    {
64
    {
Lines 68-91 Link Here
68
  // error messages
69
  // error messages
69
  private static final String MSG = "Exception while setting up an "
70
  private static final String MSG = "Exception while setting up an "
70
                                    + Registry.ICM_PRNG + " SPI: ";
71
                                    + Registry.ICM_PRNG + " SPI: ";
71
72
  private static final String RETRY = "Retry...";
72
  private static final String RETRY = "Retry...";
73
74
  private static final String LIMIT_REACHED_MSG = "Limit reached: ";
73
  private static final String LIMIT_REACHED_MSG = "Limit reached: ";
75
76
  private static final String RESEED = "Re-seed...";
74
  private static final String RESEED = "Re-seed...";
77
78
  /** Our underlying prng instance. */
75
  /** Our underlying prng instance. */
79
  private ICMGenerator adaptee = new ICMGenerator();
76
  private ICMGenerator adaptee = new ICMGenerator();
80
77
81
  // Constructor(s)
82
  // -------------------------------------------------------------------------
83
84
  // default 0-arguments constructor
78
  // default 0-arguments constructor
85
79
86
  // Class methods
87
  // -------------------------------------------------------------------------
88
89
  private static void resetLocalPRNG()
80
  private static void resetLocalPRNG()
90
  {
81
  {
91
    if (Configuration.DEBUG)
82
    if (Configuration.DEBUG)
Lines 104-127 Link Here
104
    // choose a random value between 1 and aesBlockSize / 2
95
    // choose a random value between 1 and aesBlockSize / 2
105
    int limit = aesBlockSize / 2;
96
    int limit = aesBlockSize / 2;
106
    while (ndxLen < 1 || ndxLen > limit)
97
    while (ndxLen < 1 || ndxLen > limit)
107
      {
98
      ndxLen = rand.nextInt(limit + 1);
108
        ndxLen = rand.nextInt(limit + 1);
109
      }
110
    attributes.put(ICMGenerator.SEGMENT_INDEX_LENGTH, Integer.valueOf(ndxLen));
99
    attributes.put(ICMGenerator.SEGMENT_INDEX_LENGTH, Integer.valueOf(ndxLen));
111
    byte[] index = new byte[ndxLen];
100
    byte[] index = new byte[ndxLen];
112
    rand.nextBytes(index);
101
    rand.nextBytes(index);
113
    attributes.put(ICMGenerator.SEGMENT_INDEX, new BigInteger(1, index));
102
    attributes.put(ICMGenerator.SEGMENT_INDEX, new BigInteger(1, index));
114
115
    prng.setup(attributes);
103
    prng.setup(attributes);
116
    if (Configuration.DEBUG)
104
    if (Configuration.DEBUG)
117
      log.exiting(ICMRandomSpi.class.getName(), "resetLocalPRNG");
105
      log.exiting(ICMRandomSpi.class.getName(), "resetLocalPRNG");
118
  }
106
  }
119
107
120
  // Instance methods
121
  // -------------------------------------------------------------------------
122
123
  // java.security.SecureRandomSpi interface implementation ------------------
124
125
  public byte[] engineGenerateSeed(int numBytes)
108
  public byte[] engineGenerateSeed(int numBytes)
126
  {
109
  {
127
    if (Configuration.DEBUG)
110
    if (Configuration.DEBUG)
Lines 143-153 Link Here
143
  {
126
  {
144
    if (Configuration.DEBUG)
127
    if (Configuration.DEBUG)
145
      log.entering(this.getClass().getName(), "engineNextBytes");
128
      log.entering(this.getClass().getName(), "engineNextBytes");
146
    if (!adaptee.isInitialised())
129
    if (! adaptee.isInitialised())
147
      {
130
      this.engineSetSeed(new byte[0]);
148
        this.engineSetSeed(new byte[0]);
149
      }
150
151
    while (true)
131
    while (true)
152
      {
132
      {
153
        try
133
        try
Lines 179-185 Link Here
179
    materialLength += 16; // offset size
159
    materialLength += 16; // offset size
180
    materialLength += 8; // index size == half of an AES block
160
    materialLength += 8; // index size == half of an AES block
181
    byte[] material = new byte[materialLength];
161
    byte[] material = new byte[materialLength];
182
183
    // use as much as possible bytes from the seed
162
    // use as much as possible bytes from the seed
184
    int materialOffset = 0;
163
    int materialOffset = 0;
185
    int materialLeft = material.length;
164
    int materialLeft = material.length;
Lines 190-197 Link Here
190
        materialOffset += lenToCopy;
169
        materialOffset += lenToCopy;
191
        materialLeft -= lenToCopy;
170
        materialLeft -= lenToCopy;
192
      }
171
      }
193
    if (materialOffset > 0)
172
    if (materialOffset > 0) // generate the rest
194
      { // generate the rest
173
      {
195
        while (true)
174
        while (true)
196
          {
175
          {
197
            try
176
            try
Lines 213-222 Link Here
213
              }
192
              }
214
          }
193
          }
215
      }
194
      }
216
217
    // setup the underlying adaptee instance
195
    // setup the underlying adaptee instance
218
    HashMap attributes = new HashMap();
196
    HashMap attributes = new HashMap();
219
220
    // use AES cipher with 128-bit block size
197
    // use AES cipher with 128-bit block size
221
    attributes.put(ICMGenerator.CIPHER, Registry.AES_CIPHER);
198
    attributes.put(ICMGenerator.CIPHER, Registry.AES_CIPHER);
222
    // use an index the size of quarter of an AES block
199
    // use an index the size of quarter of an AES block
Lines 233-241 Link Here
233
    byte[] index = new byte[8];
210
    byte[] index = new byte[8];
234
    System.arraycopy(material, 32, index, 0, 8);
211
    System.arraycopy(material, 32, index, 0, 8);
235
    attributes.put(ICMGenerator.SEGMENT_INDEX, new BigInteger(1, index));
212
    attributes.put(ICMGenerator.SEGMENT_INDEX, new BigInteger(1, index));
236
237
    adaptee.init(attributes);
213
    adaptee.init(attributes);
238
    if (Configuration.DEBUG)
214
    if (Configuration.DEBUG)
239
      log.exiting(this.getClass().getName(), "engineSetSeed");
215
      log.exiting(this.getClass().getName(), "engineSetSeed");
240
  }
216
  }
241
}
217
}
(-)prng/UMacRandomSpi.java (-36 / +13 lines)
Lines 50-86 Link Here
50
import java.util.logging.Logger;
50
import java.util.logging.Logger;
51
51
52
/**
52
/**
53
 * <p>An <em>Adapter</em> class around {@link UMacGenerator} to allow using this
53
 * An <em>Adapter</em> class around {@link UMacGenerator} to allow using this
54
 * algorithm as a JCE {@link java.security.SecureRandom}.</p>
54
 * algorithm as a JCE {@link java.security.SecureRandom}.
55
 */
55
 */
56
public class UMacRandomSpi extends SecureRandomSpi
56
public class UMacRandomSpi
57
    extends SecureRandomSpi
57
{
58
{
58
  private static final Logger log = Logger.getLogger(UMacRandomSpi.class.getName());
59
  private static final Logger log = Logger.getLogger(UMacRandomSpi.class.getName());
59
  /** Class-wide prng to generate random material for the underlying prng.*/
60
  /** Class-wide prng to generate random material for the underlying prng. */
60
  private static final UMacGenerator prng; // blank final
61
  private static final UMacGenerator prng; // blank final
61
  static
62
  static
62
    {
63
    {
63
      prng = new UMacGenerator();
64
      prng = new UMacGenerator();
64
      resetLocalPRNG();
65
      resetLocalPRNG();
65
    }
66
    }
66
67
  // error messages
67
  // error messages
68
  private static final String MSG = "Exception while setting up a "
68
  private static final String MSG = "Exception while setting up a "
69
                                    + Registry.UMAC_PRNG + " SPI: ";
69
                                    + Registry.UMAC_PRNG + " SPI: ";
70
71
  private static final String RETRY = "Retry...";
70
  private static final String RETRY = "Retry...";
72
73
  /** Our underlying prng instance. */
71
  /** Our underlying prng instance. */
74
  private UMacGenerator adaptee = new UMacGenerator();
72
  private UMacGenerator adaptee = new UMacGenerator();
75
73
76
  // Constructor(s)
77
  // -------------------------------------------------------------------------
78
79
  // default 0-arguments constructor
74
  // default 0-arguments constructor
80
75
81
  // Class methods
82
  // -------------------------------------------------------------------------
83
84
  private static void resetLocalPRNG()
76
  private static void resetLocalPRNG()
85
  {
77
  {
86
    HashMap attributes = new HashMap();
78
    HashMap attributes = new HashMap();
Lines 91-111 Link Here
91
    attributes.put(IBlockCipher.KEY_MATERIAL, key);
83
    attributes.put(IBlockCipher.KEY_MATERIAL, key);
92
    int index = rand.nextInt() & 0xFF;
84
    int index = rand.nextInt() & 0xFF;
93
    attributes.put(UMacGenerator.INDEX, Integer.valueOf(index));
85
    attributes.put(UMacGenerator.INDEX, Integer.valueOf(index));
94
95
    prng.setup(attributes);
86
    prng.setup(attributes);
96
  }
87
  }
97
88
98
  // Instance methods
99
  // -------------------------------------------------------------------------
100
101
  // java.security.SecureRandomSpi interface implementation ------------------
102
103
  public byte[] engineGenerateSeed(int numBytes)
89
  public byte[] engineGenerateSeed(int numBytes)
104
  {
90
  {
105
    if (numBytes < 1)
91
    if (numBytes < 1)
106
      {
92
      return new byte[0];
107
        return new byte[0];
108
      }
109
    byte[] result = new byte[numBytes];
93
    byte[] result = new byte[numBytes];
110
    this.engineNextBytes(result);
94
    this.engineNextBytes(result);
111
    return result;
95
    return result;
Lines 113-123 Link Here
113
97
114
  public void engineNextBytes(byte[] bytes)
98
  public void engineNextBytes(byte[] bytes)
115
  {
99
  {
116
    if (!adaptee.isInitialised())
100
    if (! adaptee.isInitialised())
117
      {
101
      this.engineSetSeed(new byte[0]);
118
        this.engineSetSeed(new byte[0]);
119
      }
120
121
    while (true)
102
    while (true)
122
      {
103
      {
123
        try
104
        try
Lines 139-145 Link Here
139
    materialLength += 16; // key material size
120
    materialLength += 16; // key material size
140
    materialLength++; // index size
121
    materialLength++; // index size
141
    byte[] material = new byte[materialLength];
122
    byte[] material = new byte[materialLength];
142
143
    // use as much as possible bytes from the seed
123
    // use as much as possible bytes from the seed
144
    int materialOffset = 0;
124
    int materialOffset = 0;
145
    int materialLeft = material.length;
125
    int materialLeft = material.length;
Lines 150-157 Link Here
150
        materialOffset += lenToCopy;
130
        materialOffset += lenToCopy;
151
        materialLeft -= lenToCopy;
131
        materialLeft -= lenToCopy;
152
      }
132
      }
153
    if (materialOffset > 0)
133
    if (materialOffset > 0) // generate the rest
154
      { // generate the rest
134
      {
155
        while (true)
135
        while (true)
156
          {
136
          {
157
            try
137
            try
Lines 159-166 Link Here
159
                prng.nextBytes(material, materialOffset, materialLeft);
139
                prng.nextBytes(material, materialOffset, materialLeft);
160
                break;
140
                break;
161
              }
141
              }
162
            catch (IllegalStateException x)
142
            catch (IllegalStateException x) // should not happen
163
              { // should not happen
143
              {
164
                throw new InternalError(MSG + String.valueOf(x));
144
                throw new InternalError(MSG + String.valueOf(x));
165
              }
145
              }
166
            catch (LimitReachedException x)
146
            catch (LimitReachedException x)
Lines 173-182 Link Here
173
              }
153
              }
174
          }
154
          }
175
      }
155
      }
176
177
    // setup the underlying adaptee instance
156
    // setup the underlying adaptee instance
178
    HashMap attributes = new HashMap();
157
    HashMap attributes = new HashMap();
179
180
    // use AES cipher with 128-bit block size
158
    // use AES cipher with 128-bit block size
181
    attributes.put(UMacGenerator.CIPHER, Registry.AES_CIPHER);
159
    attributes.put(UMacGenerator.CIPHER, Registry.AES_CIPHER);
182
    // specify the key
160
    // specify the key
Lines 185-191 Link Here
185
    attributes.put(IBlockCipher.KEY_MATERIAL, key);
163
    attributes.put(IBlockCipher.KEY_MATERIAL, key);
186
    // use a 1-byte index
164
    // use a 1-byte index
187
    attributes.put(UMacGenerator.INDEX, Integer.valueOf(material[16] & 0xFF));
165
    attributes.put(UMacGenerator.INDEX, Integer.valueOf(material[16] & 0xFF));
188
189
    adaptee.init(attributes);
166
    adaptee.init(attributes);
190
  }
167
  }
191
}
168
}
(-)sig/DHKeyFactory.java (-21 / +8 lines)
Lines 79-85 Link Here
79
        BigInteger y = spec.getY();
79
        BigInteger y = spec.getY();
80
        return new GnuDHPublicKey(Registry.X509_ENCODING_ID, null, p, g, y);
80
        return new GnuDHPublicKey(Registry.X509_ENCODING_ID, null, p, g, y);
81
      }
81
      }
82
83
    if (keySpec instanceof X509EncodedKeySpec)
82
    if (keySpec instanceof X509EncodedKeySpec)
84
      {
83
      {
85
        X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec;
84
        X509EncodedKeySpec spec = (X509EncodedKeySpec) keySpec;
Lines 97-103 Link Here
97
            throw y;
96
            throw y;
98
          }
97
          }
99
      }
98
      }
100
101
    throw new InvalidKeySpecException("Unsupported (public) key specification");
99
    throw new InvalidKeySpecException("Unsupported (public) key specification");
102
  }
100
  }
103
101
Lines 112-118 Link Here
112
        BigInteger x = spec.getX();
110
        BigInteger x = spec.getX();
113
        return new GnuDHPrivateKey(Registry.PKCS8_ENCODING_ID, null, p, g, x);
111
        return new GnuDHPrivateKey(Registry.PKCS8_ENCODING_ID, null, p, g, x);
114
      }
112
      }
115
116
    if (keySpec instanceof PKCS8EncodedKeySpec)
113
    if (keySpec instanceof PKCS8EncodedKeySpec)
117
      {
114
      {
118
        PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec;
115
        PKCS8EncodedKeySpec spec = (PKCS8EncodedKeySpec) keySpec;
Lines 130-136 Link Here
130
            throw y;
127
            throw y;
131
          }
128
          }
132
      }
129
      }
133
134
    throw new InvalidKeySpecException("Unsupported (private) key specification");
130
    throw new InvalidKeySpecException("Unsupported (private) key specification");
135
  }
131
  }
136
132
Lines 147-153 Link Here
147
            BigInteger y = dssKey.getY();
143
            BigInteger y = dssKey.getY();
148
            return new DHPublicKeySpec(y, p, g);
144
            return new DHPublicKeySpec(y, p, g);
149
          }
145
          }
150
151
        if (keySpec.isAssignableFrom(X509EncodedKeySpec.class))
146
        if (keySpec.isAssignableFrom(X509EncodedKeySpec.class))
152
          {
147
          {
153
            if (key instanceof GnuDHPublicKey)
148
            if (key instanceof GnuDHPublicKey)
Lines 156-174 Link Here
156
                byte[] encoded = dhKey.getEncoded(Registry.X509_ENCODING_ID);
151
                byte[] encoded = dhKey.getEncoded(Registry.X509_ENCODING_ID);
157
                return new X509EncodedKeySpec(encoded);
152
                return new X509EncodedKeySpec(encoded);
158
              }
153
              }
159
160
            if (Registry.X509_ENCODING_SORT_NAME.equalsIgnoreCase(key.getFormat()))
154
            if (Registry.X509_ENCODING_SORT_NAME.equalsIgnoreCase(key.getFormat()))
161
              {
155
              {
162
                byte[] encoded = key.getEncoded();
156
                byte[] encoded = key.getEncoded();
163
                return new X509EncodedKeySpec(encoded);
157
                return new X509EncodedKeySpec(encoded);
164
              }
158
              }
165
159
            throw new InvalidKeySpecException(
166
            throw new InvalidKeySpecException("Wrong key type or unsupported (public) key specification");
160
                "Wrong key type or unsupported (public) key specification");
167
          }
161
          }
168
169
        throw new InvalidKeySpecException("Unsupported (public) key specification");
162
        throw new InvalidKeySpecException("Unsupported (public) key specification");
170
      }
163
      }
171
172
    if (key instanceof DHPrivateKey)
164
    if (key instanceof DHPrivateKey)
173
      {
165
      {
174
        if (keySpec.isAssignableFrom(DHPrivateKeySpec.class))
166
        if (keySpec.isAssignableFrom(DHPrivateKeySpec.class))
Lines 179-185 Link Here
179
            BigInteger x = dhKey.getX();
171
            BigInteger x = dhKey.getX();
180
            return new DHPrivateKeySpec(x, p, g);
172
            return new DHPrivateKeySpec(x, p, g);
181
          }
173
          }
182
183
        if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class))
174
        if (keySpec.isAssignableFrom(PKCS8EncodedKeySpec.class))
184
          {
175
          {
185
            if (key instanceof GnuDHPrivateKey)
176
            if (key instanceof GnuDHPrivateKey)
Lines 188-214 Link Here
188
                byte[] encoded = dhKey.getEncoded(Registry.PKCS8_ENCODING_ID);
179
                byte[] encoded = dhKey.getEncoded(Registry.PKCS8_ENCODING_ID);
189
                return new PKCS8EncodedKeySpec(encoded);
180
                return new PKCS8EncodedKeySpec(encoded);
190
              }
181
              }
191
192
            if (Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat()))
182
            if (Registry.PKCS8_ENCODING_SHORT_NAME.equalsIgnoreCase(key.getFormat()))
193
              {
183
              {
194
                byte[] encoded = key.getEncoded();
184
                byte[] encoded = key.getEncoded();
195
                return new PKCS8EncodedKeySpec(encoded);
185
                return new PKCS8EncodedKeySpec(encoded);
196
              }
186
              }
197
187
            throw new InvalidKeySpecException(
198
            throw new InvalidKeySpecException("Wrong key type or unsupported (private) key specification");
188
                "Wrong key type or unsupported (private) key specification");
199
          }
189
          }
200
190
        throw new InvalidKeySpecException(
201
        throw new InvalidKeySpecException("Unsupported (private) key specification");
191
            "Unsupported (private) key specification");
202
      }
192
      }
203
193
    throw new InvalidKeySpecException(
204
    throw new InvalidKeySpecException("Wrong key type or unsupported key specification");
194
        "Wrong key type or unsupported key specification");
205
  }
195
  }
206
196
207
  protected Key engineTranslateKey(Key key) throws InvalidKeyException
197
  protected Key engineTranslateKey(Key key) throws InvalidKeyException
208
  {
198
  {
209
    if ((key instanceof GnuDHPublicKey) || (key instanceof GnuDHPrivateKey))
199
    if ((key instanceof GnuDHPublicKey) || (key instanceof GnuDHPrivateKey))
210
      return key;
200
      return key;
211
212
    if (key instanceof DHPubl