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