Examples of Rijndael


Examples of freenet.crypt.ciphers.Rijndael

        PCFB_256_DECRYPT_PLAINTEXT, PCFB_256_DECRYPT_CIPHERTEXT);
  }

  private void checkKnownValues(int bits, byte[] key, byte[] iv, byte[] plaintext,
      byte[] ciphertext) throws UnsupportedCipherException {
    Rijndael cipher = new Rijndael(bits, bits);
    cipher.initialize(key);
    PCFBMode ctr = PCFBMode.create(cipher);
    ctr.reset(iv);
    byte[] output = new byte[plaintext.length];
    System.arraycopy(plaintext, 0, output, 0, plaintext.length);
    //ctr.blockEncipher(plaintext, 0, plaintext.length, output, 0);
View Full Code Here

Examples of freenet.crypt.ciphers.Rijndael

      byte[] plaintext, byte[] ciphertext)
      throws UnsupportedCipherException {
    for (int i = 0; i < 1024; i++) {
      long seed = mt.nextLong();

      Rijndael cipher = new Rijndael(bits, bits);
      cipher.initialize(key);
      PCFBMode ctr = PCFBMode.create(cipher);
      ctr.reset(iv);
      byte[] output = new byte[plaintext.length];
      MersenneTwister random = new MersenneTwister(seed);
      int ptr = 0;
View Full Code Here

Examples of freenet.crypt.ciphers.Rijndael

      byte[] iv = new byte[32];
      mt.nextBytes(plaintext);
      mt.nextBytes(key);
      mt.nextBytes(iv);
      // First encrypt as a block.
      Rijndael cipher = new Rijndael(256, 256);
      cipher.initialize(key);
      PCFBMode ctr = PCFBMode.create(cipher);
      ctr.reset(iv);
      byte[] ciphertext = new byte[plaintext.length];
      System.arraycopy(plaintext, 0, ciphertext, 0, ciphertext.length);
      //ctr.blockEncipher(plaintext, 0, plaintext.length, ciphertext, 0);
      ctr.blockEncipher(ciphertext, 0, ciphertext.length);
      // Now decrypt.
      ctr = PCFBMode.create(cipher);
      ctr.reset(iv);
      byte[] finalPlaintext = new byte[plaintext.length];
      System.arraycopy(ciphertext, 0, finalPlaintext, 0, ciphertext.length);
      //ctr.blockDecipher(ciphertext, 0, ciphertext.length, finalPlaintext, 0);
      ctr.blockDecipher(finalPlaintext, 0, finalPlaintext.length);
      assertTrue(Arrays.equals(finalPlaintext, plaintext));

      // Now encrypt again, in random pieces.
      cipher.initialize(key);
      ctr = PCFBMode.create(cipher);
      ctr.reset(iv);
      byte[] output = new byte[plaintext.length];

      MersenneTwister random = new MersenneTwister(mt.nextLong());
View Full Code Here

Examples of freenet.crypt.ciphers.Rijndael

      c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
      byte[] output = c.doFinal(plaintext);
      assertTrue(Arrays.equals(output, ciphertext));
    }

    Rijndael cipher = new Rijndael(bits, 128);
    cipher.initialize(key);
    CTRBlockCipher ctr = new CTRBlockCipher(cipher);
    ctr.init(iv);
    byte[] output = new byte[plaintext.length];
    ctr.processBytes(plaintext, 0, plaintext.length, output, 0);
    assertTrue(Arrays.equals(output, ciphertext));
View Full Code Here

Examples of freenet.crypt.ciphers.Rijndael

        c.doFinal(plaintext, 0, plaintext.length - inputPtr, output,
            outputPtr);
        assertTrue(Arrays.equals(output, ciphertext));
      }

      Rijndael cipher = new Rijndael(bits, 128);
      cipher.initialize(key);
      CTRBlockCipher ctr = new CTRBlockCipher(cipher);
      ctr.init(iv);
      byte[] output = new byte[plaintext.length];
      MersenneTwister random = new MersenneTwister(seed);
      int ptr = 0;
View Full Code Here

Examples of freenet.crypt.ciphers.Rijndael

      byte[] iv = new byte[16];
      mt.nextBytes(plaintext);
      mt.nextBytes(key);
      mt.nextBytes(iv);
      // First encrypt as a block.
      Rijndael cipher = new Rijndael(256, 128);
      cipher.initialize(key);
      CTRBlockCipher ctr = new CTRBlockCipher(cipher);
      ctr.init(iv);
      byte[] ciphertext = new byte[plaintext.length];
      ctr.processBytes(plaintext, 0, plaintext.length, ciphertext, 0);
      // Now decrypt.
      ctr = new CTRBlockCipher(cipher);
      ctr.init(iv);
      byte[] finalPlaintext = new byte[plaintext.length];
      ctr.processBytes(ciphertext, 0, ciphertext.length, finalPlaintext, 0);
      assertTrue(Arrays.equals(finalPlaintext, plaintext));
      if(TEST_JCA) {
        SecretKeySpec k = new SecretKeySpec(key, "AES");
        Cipher c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
        c.init(Cipher.ENCRYPT_MODE, k, new IvParameterSpec(iv));
        byte[] output = c.doFinal(plaintext);
        assertTrue(Arrays.equals(output, ciphertext));
        c = Cipher.getInstance("AES/CTR/NOPADDING", Rijndael.AesCtrProvider);
        c.init(Cipher.DECRYPT_MODE, k, new IvParameterSpec(iv));
        byte[] decrypted = c.doFinal(output);
        assertTrue(Arrays.equals(decrypted, plaintext));
      }
      // Now encrypt again, in random pieces.
      cipher.initialize(key);
      ctr = new CTRBlockCipher(cipher);
      ctr.init(iv);
      byte[] output = new byte[plaintext.length];
      MersenneTwister random = new MersenneTwister(mt.nextLong());
      int ptr = 0;
View Full Code Here

Examples of freenet.crypt.ciphers.Rijndael

      }

      // Implicit hash of data
      byte[] origDataHash = md256.digest(data);

      Rijndael aes;
      try {
        aes = new Rijndael(256, 256);
      } catch (UnsupportedCipherException e) {
        throw new Error("256/256 Rijndael not supported!");
      }

      // Encrypt data. Data encryption key = H(plaintext data).

      aes.initialize(origDataHash);
      PCFBMode pcfb = PCFBMode.create(aes, origDataHash);

      pcfb.blockEncipher(data, 0, data.length);

      byte[] encryptedDataHash = md256.digest(data);

      // Create headers

      byte[] headers = new byte[SSKBlock.TOTAL_HEADERS_LENGTH];
      // First two bytes = hash ID
      int x = 0;
      headers[x++] = (byte) (KeyBlock.HASH_SHA256 >> 8);
      headers[x++] = (byte) (KeyBlock.HASH_SHA256);
      // Then crypto ID
      headers[x++] = (byte) (Key.ALGO_AES_PCFB_256_SHA256 >> 8);
      headers[x++] = Key.ALGO_AES_PCFB_256_SHA256;
      // Then E(H(docname))
      // Copy to headers
      System.arraycopy(ehDocname, 0, headers, x, ehDocname.length);
      x += ehDocname.length;
      // Now the encrypted headers
      byte[] encryptedHeaders = Arrays.copyOf(origDataHash, SSKBlock.ENCRYPTED_HEADERS_LENGTH);
      int y = origDataHash.length;
      short len = (short) compressedData.length;
      if (asMetadata)
        len |= 32768;
      encryptedHeaders[y++] = (byte) (len >> 8);
      encryptedHeaders[y++] = (byte) len;
      encryptedHeaders[y++] = (byte) (compressionAlgo >> 8);
      encryptedHeaders[y++] = (byte) compressionAlgo;
      if (encryptedHeaders.length != y)
        throw new IllegalStateException("Have more bytes to generate encoding SSK");
      aes.initialize(cryptoKey);
      pcfb.reset(ehDocname);
      pcfb.blockEncipher(encryptedHeaders, 0, encryptedHeaders.length);
      System.arraycopy(encryptedHeaders, 0, headers, x, encryptedHeaders.length);
      x += encryptedHeaders.length;
      // Generate implicit overall hash.
View Full Code Here

Examples of freenet.crypt.ciphers.Rijndael

        // Overall hash already verified, so first job is to decrypt.
    if(key.cryptoAlgorithm != Key.ALGO_AES_PCFB_256_SHA256)
            throw new UnsupportedOperationException();
        BlockCipher cipher;
        try {
            cipher = new Rijndael(256, 256);
        } catch (UnsupportedCipherException e) {
            // FIXME - log this properly
            throw new Error(e);
        }
        byte[] cryptoKey = key.cryptoKey;
View Full Code Here

Examples of freenet.crypt.ciphers.Rijndael

        byte[] data = block.data;
      byte[] hash = Arrays.copyOfRange(headers, 2, 2+32);
        byte[] cryptoKey = key.cryptoKey;
        if(cryptoKey.length < Node.SYMMETRIC_KEY_LENGTH)
            throw new CHKDecodeException("Crypto key too short");
        Rijndael aes;
        try {
      aes = new Rijndael(256, 128);
    } catch (UnsupportedCipherException e) {
      // Impossible.
      throw new Error(e);
    }
    aes.initialize(cryptoKey);
        CTRBlockCipher cipher = new CTRBlockCipher(aes);
        cipher.init(hash, 0, 16);
        byte[] plaintext = new byte[data.length];
        cipher.processBytes(data, 0, data.length, plaintext, 0);
        byte[] lengthBytes = new byte[2];
View Full Code Here

Examples of freenet.crypt.ciphers.Rijndael

      if(blockHashAlgorithm == 0) cryptoAlgorithm = KeyBlock.HASH_SHA256;
      if(blockHashAlgorithm != KeyBlock.HASH_SHA256)
        throw new IllegalArgumentException("Unsupported block hash algorithm "+cryptoAlgorithm);
        header[0] = (byte)(blockHashAlgorithm >> 8);
        header[1] = (byte)(blockHashAlgorithm & 0xff);
        Rijndael aes;
    try {
      aes = new Rijndael(256, 128);
    } catch (UnsupportedCipherException e) {
      // Impossible
      throw new Error(e);
    }
        aes.initialize(encKey);
        CTRBlockCipher ctr = new CTRBlockCipher(aes);
        // CTR mode IV is only 16 bytes.
        // That's still plenty though. It will still be unique.
        ctr.init(hash, 0, 16);
        System.arraycopy(hash, 0, header, 2, hash.length);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.