コード例 #1
0
  private void checkMask(int count, DerivationFunction kdf, byte[] seed, byte[] result) {
    byte[] data = new byte[result.length];

    kdf.init(new MGFParameters(seed));

    kdf.generateBytes(data, 0, data.length);

    if (!areEqual(result, data)) {
      fail("MGF1 failed generator test " + count);
    }
  }
コード例 #2
0
  protected SecretKey engineGenerateSecret(String algorithm) throws NoSuchAlgorithmException {
    byte[] secret = bigIntToBytes(result);

    if (kdf != null) {
      if (!algorithms.containsKey(algorithm)) {
        throw new NoSuchAlgorithmException("unknown algorithm encountered: " + algorithm);
      }

      int keySize = ((Integer) algorithms.get(algorithm)).intValue();

      DHKDFParameters params =
          new DHKDFParameters(new ASN1ObjectIdentifier(algorithm), keySize, secret);

      byte[] keyBytes = new byte[keySize / 8];
      kdf.init(params);
      kdf.generateBytes(keyBytes, 0, keyBytes.length);
      secret = keyBytes;
    } else {
      // TODO Should we be ensuring the key is the right length?
    }

    return new SecretKeySpec(secret, algorithm);
  }