Frames | No Frames |
1: /* IKeyWrappingAlgorithm.java -- FIXME: briefly describe file purpose 2: Copyright (C) 2006 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package gnu.javax.crypto.kwa; 40: 41: import java.security.InvalidKeyException; 42: import java.security.SecureRandom; 43: import java.util.Map; 44: 45: import javax.crypto.ShortBufferException; 46: 47: /** 48: * Constants and visible methods available to all GNU Key Wrapping Algorithm 49: * implementations. 50: */ 51: public interface IKeyWrappingAlgorithm 52: { 53: /** 54: * Name of the property, in the attributes map, that references the Key 55: * Wrapping Algorithm KEK (Key Encryption Key) material. The object referenced 56: * by this property is a byte array containing the keying material for the 57: * underlying block cipher. 58: */ 59: String KEY_ENCRYPTION_KEY_MATERIAL = "gnu.crypto.kwa.kek"; 60: /** 61: * Name of the property, in the attributes map, that references the Initial 62: * Value (IV) material. The object referenced by this property is a byte array 63: * containing the initial integrity check register value. 64: */ 65: String INITIAL_VALUE = "gnu.crypto.kwa.iv"; 66: /** 67: * Property name of an optional {@link SecureRandom} instance to use. The 68: * default is to use a {@link gnu.java.security.util.PRNG} instance. 69: */ 70: String SOURCE_OF_RANDOMNESS = "gnu.crypto.kwa.prng"; 71: 72: /** 73: * Returns the canonical name of this Key Wrapping Algorithm. 74: * 75: * @return the canonical name of this Key Wrapping Algorithm. 76: */ 77: String name(); 78: 79: /** 80: * Initializes this instance with the designated algorithm specific 81: * attributes. 82: * 83: * @param attributes a map of name-to-value pairs the Key Wrapping Algorithm 84: * must use for its setup. 85: * @throws InvalidKeyException if an exception is encountered while seting up 86: * the Key Wrapping Algorithm keying material (KEK). 87: */ 88: void init(Map attributes) throws InvalidKeyException; 89: 90: /** 91: * Wraps the designated plain text bytes. 92: * 93: * @param in the input byte array containing the plain text. 94: * @param inOffset the offset into <code>in</code> where the first byte of 95: * the plain text (key material) to wrap is located. 96: * @param length the number of bytes to wrap. 97: * @param out the output byte array where the wrapped key material will be 98: * stored. 99: * @param outOffset the offset into <code>out</code> of the first wrapped 100: * byte. 101: * @return the number of bytes of the wrapped key material; i.e. the length, 102: * in <code>out</code>, starting from <code>outOffset</code> 103: * where the cipher text (wrapped key material) are stored. 104: * @throws ShortBufferException if the output buffer is not long enough to 105: * accomodate the number of bytes resulting from wrapping the plain 106: * text. 107: */ 108: int wrap(byte[] in, int inOffset, int length, byte[] out, int outOffset) 109: throws ShortBufferException; 110: 111: /** 112: * Wraps the designated plain text bytes. 113: * 114: * @param in the input byte array containing the plain text. 115: * @param inOffset the offset into <code>in</code> where the first byte of 116: * the plain text (key material) to wrap is located. 117: * @param length the number of bytes to wrap. 118: * @return a newly allocated byte array containing the cipher text. 119: */ 120: byte[] wrap(byte[] in, int inOffset, int length); 121: 122: /** 123: * Unwraps the designated cipher text bytes. 124: * 125: * @param in the input byte array containing the cipher text. 126: * @param inOffset the offset into <code>in</code> where the first byte of 127: * the cipher text (already wrapped key material) to unwrap is 128: * located. 129: * @param length the number of bytes to unwrap. 130: * @param out the output byte array where the unwrapped key material will be 131: * stored. 132: * @param outOffset the offset into <code>out</code> of the first unwrapped 133: * byte. 134: * @return the number of bytes of the unwrapped key material; i.e. the length, 135: * in <code>out</code>, starting from <code>outOffset</code> 136: * where the plain text (unwrapped key material) are stored. 137: * @throws ShortBufferException if the output buffer is not long enough to 138: * accomodate the number of bytes resulting from unwrapping the 139: * cipher text. 140: * @throws KeyUnwrappingException if after unwrapping the cipher text, the 141: * bytes at the begining did not match the initial value. 142: */ 143: int unwrap(byte[] in, int inOffset, int length, byte[] out, int outOffset) 144: throws ShortBufferException, KeyUnwrappingException; 145: 146: /** 147: * Unwraps the designated cipher text bytes. 148: * 149: * @param in the input byte array containing the cipher text. 150: * @param inOffset the offset into <code>in</code> where the first byte of 151: * the cipher text (already wrapped key material) to unwrap is 152: * located. 153: * @param length the number of bytes to unwrap. 154: * @return a newly allocated byte array containing the plain text. 155: * @throws KeyUnwrappingException if after unwrapping the cipher text, the 156: * bytes at the begining did not match the initial value. 157: */ 158: byte[] unwrap(byte[] in, int inOffset, int length) 159: throws KeyUnwrappingException; 160: }