1 16 17 package de.schlichtherle.crypto.io.raes; 18 19 import de.schlichtherle.crypto.io.CipherOutputStream; 20 21 import java.io.IOException ; 22 import java.io.OutputStream ; 23 24 import org.bouncycastle.crypto.BufferedBlockCipher; 25 import org.bouncycastle.crypto.Mac; 26 27 37 public abstract class RaesOutputStream 38 extends CipherOutputStream 39 implements RAES { 40 41 49 static void klac(final Mac klac, long length, final byte[] buf) { 50 for (int i = 0; i < 8; i++) { 51 klac.update((byte) length); 52 length >>= 8; 53 } 54 final int bufLen = klac.doFinal(buf, 0); 55 assert bufLen == buf.length; 56 } 57 58 82 public static RaesOutputStream getInstance( 83 final OutputStream out, 84 RaesParameters parameters) 85 throws NullPointerException , 86 IllegalArgumentException , 87 RaesParametersException, 88 IOException { 89 if (out == null) 90 throw new NullPointerException ("out"); 91 92 if (parameters == null) { 94 throw new RaesParametersException(); 95 } else if (parameters instanceof Type0RaesParameters) { 96 return new Type0RaesOutputStream(out, 97 (Type0RaesParameters) parameters); 98 } else if (parameters instanceof RaesParametersAgent) { 99 parameters = ((RaesParametersAgent) parameters).getParameters( 100 RaesParameters.class); 101 return getInstance(out, parameters); 102 } else { 103 throw new RaesParametersException(); 104 } 105 } 106 107 RaesOutputStream(OutputStream out, BufferedBlockCipher cipher) { 108 super(out, cipher); 109 } 110 111 115 public abstract int getKeySizeBits(); 116 } 117 | Popular Tags |