1   /* $RCSfile: OperationModeECB.java,v $
2    * $Revision: 1.6 $
3    * $Date: 2001/11/02 09:11:01 $
4    * $Author: uwe $
5    * $State: Exp $
6    *
7    * Created on August 18, 2001 4:53 PM
8    *
9    * Copyright (C) 2001 Uwe Guenther <uwe@cscc.de>
10   *
11   * This file is part of the jhbci JCE-ServiceProvider. The jhbci JCE-
12   * ServiceProvider is a library, written in JavaTM, that should be 
13   * used in HBCI banking applications (clients and may be servers),
14   * to do cryptographic operations.
15   *
16   * The jhbci library is free software; you can redistribute it and/or
17   * modify it under the terms of the GNU Lesser General Public
18   * License as published by the Free Software Foundation; either
19   * version 2.1 of the License, or (at your option) any later version.
20   *
21   * The jhbci library is distributed in the hope that it will be useful,
22   * but WITHOUT ANY WARRANTY; without even the implied warranty of
23   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
24   * Lesser General Public License for more details.
25   *
26   * You should have received a copy of the GNU Lesser General Public
27   * License along with this library; if not, write to the Free Software
28   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
29   *
30   */
31  
32  package de.cscc.crypto.provider;
33  
34  import javax.crypto.IllegalBlockSizeException;
35  import javax.crypto.ShortBufferException;
36  
37  /**
38   * DESCoreECBOperationMode Class.
39   *
40   * @author  <a href=mailto:uwe@cscc.de>Uwe G&uuml;nther</a>
41   * @version $Revision: 1.6 $
42   */
43  class OperationModeECB extends OperationMode {
44      
45      /**
46       * A BlockCipher object that will be used
47       * for this OperationMode algorithm.
48       */    
49      private BlockCipher cipher;
50  
51      /** Don't create a new OperationModeEBC with the default constructor. */
52      private OperationModeECB() {}
53      
54      /** 
55       * Creates new OperationModeECB with a Blockcipher and an Iv.
56       * @param cipher the cipher to wrap.
57       */
58      public OperationModeECB(BlockCipher cipher) {
59          this.cipher = cipher;
60      }    
61  
62      /** 
63       * Returns a string representation of the object. 
64       *
65       * @return  a string representation of the object.
66       */
67      public String toString() {
68          return "Cipher: [" + this.cipher + "]";
69      }
70      
71      /**
72       * Returns the algorithm specific block size in bytes. These block
73       * size will be processed if one encrypt or decrypt method runs.
74       * If you subclass these abstract class, you have to implement these
75       * method.
76       *
77       * @return the algorithm specific block size in bytes.
78       */
79      public int getBlockSize() {
80          return this.cipher.getBlockSize();
81      }
82      
83      /** 
84       * The abstract encryption operation. If you subclass these abstract class,
85       * you have to implement these method.
86       *
87       * If (input.length-inputOffset > getBlockSize()) we use only the first
88       * getBlockSize() bytes from the block.
89       *
90       * @param input the getBlockSize() long data block that will be encrypted.
91       * @param inputOffset the offset in input where the input starts.
92       * @param output the buffer for the result.
93       * @param outputOffset the offset in output where the result is stored.
94       * @throws IllegalBlockSizeException will be thrown, if the
95       *         deliverd byte array has a length lesser than getBlockSize().
96       * @throws ShortBufferException will be thrown, if the
97       *         output buffer byte array has a length lesser than getBlockSize().
98       * @return the number of bytes stored in output.
99       */
100     public int encrypt(byte[] input, int inputOffset, 
101                        byte[] output, int outputOffset) 
102             throws IllegalBlockSizeException, ShortBufferException {
103         return cipher.encrypt(input, inputOffset, output, outputOffset);
104     }
105     
106     /** 
107      * The abstract decryption operation. If you subclass these abstract class,
108      * you have to implement these method.
109      *
110      * If (input.length-inputOffset > getBlockSize()) we use only the first
111      * getBlockSize() bytes
112      * for the block.
113      *
114      * @param input the getBlockSize() long data block that will be decrypted.
115      * @param inputOffset the offset in input where the input starts.
116      * @param output the buffer for the result.
117      * @param outputOffset the offset in output where the result is stored.
118      * @throws IllegalBlockSizeException will be thrown, if the
119      *         deliverd byte array has a length lesser than getBlockSize().
120      * @throws ShortBufferException will be thrown, if the
121      *         output buffer byte array has a length lesser than getBlockSize().
122      * @return the number of bytes stored in output.
123      */
124     public int decrypt(byte[] input, int inputOffset, 
125                        byte[] output, int outputOffset) 
126             throws IllegalBlockSizeException, ShortBufferException {
127         return cipher.decrypt(input, inputOffset, output, outputOffset);
128     }
129     
130     /**
131      * Set an initialization vector (iv) as a deep copy.
132      * The iv have to getBlockSize() bytes long.
133      *
134      * @param iv the initialization vector (iv).
135      */    
136     public void setIv(byte[] iv) {
137         //Do nothing in ECB mode.
138     }
139     
140     /** 
141      * Returns a deep copy of the internal byte[] array,
142      * which contains the initialization vector (iv),
143      * or null of the mode does not need an iv.
144      * Such as ECB.
145      *
146      * @return a deep copy of the internal byte[] array,
147      * which contains the initialization vector (iv),
148      * or null of the mode does not need an iv.
149      */    
150     public byte[] getIv() {
151         return null;
152     }
153     
154     /** Set chaning vector to the initial iv value. */
155     public void resetToIv() {
156         //Do nothing in ECB mode. :)
157     }
158 }
159