001 /** 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017 018 package org.apache.geronimo.util.crypto; 019 020 021 /** 022 * Block cipher engines are expected to conform to this interface. 023 */ 024 public interface BlockCipher 025 { 026 /** 027 * Initialise the cipher. 028 * 029 * @param forEncryption if true the cipher is initialised for 030 * encryption, if false for decryption. 031 * @param params the key and other data required by the cipher. 032 * @exception IllegalArgumentException if the params argument is 033 * inappropriate. 034 */ 035 public void init(boolean forEncryption, CipherParameters params) 036 throws IllegalArgumentException; 037 038 /** 039 * Return the name of the algorithm the cipher implements. 040 * 041 * @return the name of the algorithm the cipher implements. 042 */ 043 public String getAlgorithmName(); 044 045 /** 046 * Return the block size for this cipher (in bytes). 047 * 048 * @return the block size for this cipher in bytes. 049 */ 050 public int getBlockSize(); 051 052 /** 053 * Process one block of input from the array in and write it to 054 * the out array. 055 * 056 * @param in the array containing the input data. 057 * @param inOff offset into the in array the data starts at. 058 * @param out the array the output data will be copied into. 059 * @param outOff the offset into the out array the output will start at. 060 * @exception DataLengthException if there isn't enough data in in, or 061 * space in out. 062 * @exception IllegalStateException if the cipher isn't initialised. 063 * @return the number of bytes processed and produced. 064 */ 065 public int processBlock(byte[] in, int inOff, byte[] out, int outOff) 066 throws DataLengthException, IllegalStateException; 067 068 /** 069 * Reset the cipher. After resetting the cipher is in the same state 070 * as it was after the last init (if there was one). 071 */ 072 public void reset(); 073 }