gnu.javax.crypto.kwa

Class BaseKeyWrappingAlgorithm

Implemented Interfaces:
IKeyWrappingAlgorithm
Known Direct Subclasses:
AESKeyWrap, TripleDESKeyWrap

public abstract class BaseKeyWrappingAlgorithm
extends Object
implements IKeyWrappingAlgorithm

A base class to facilitate implementation of concrete Key Wrapping Algorithms.

Field Summary

protected String
name
The canonical name of the key wrapping algorithm.

Fields inherited from interface gnu.javax.crypto.kwa.IKeyWrappingAlgorithm

INITIAL_VALUE, KEY_ENCRYPTION_KEY_MATERIAL, SOURCE_OF_RANDOMNESS

Constructor Summary

BaseKeyWrappingAlgorithm(String name)
Protected constructor.

Method Summary

protected abstract void
engineInit(Map<K,V> attributes)
protected abstract byte[]
engineUnwrap(byte[] in, int inOffset, int length)
protected abstract byte[]
engineWrap(byte[] in, int inOffset, int length)
protected PRNG
getDefaultPRNG()
void
init(Map<K,V> attributes)
Initializes this instance with the designated algorithm specific attributes.
String
name()
Returns the canonical name of this Key Wrapping Algorithm.
byte[]
unwrap(byte[] in, int inOffset, int length)
Unwraps the designated cipher text bytes.
int
unwrap(byte[] in, int inOffset, int length, byte[] out, int outOffset)
Unwraps the designated cipher text bytes.
byte[]
wrap(byte[] in, int inOffset, int length)
Wraps the designated plain text bytes.
int
wrap(byte[] in, int inOffset, int length, byte[] out, int outOffset)
Wraps the designated plain text bytes.

Methods inherited from class java.lang.Object

clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Details

name

protected String name
The canonical name of the key wrapping algorithm.

Constructor Details

BaseKeyWrappingAlgorithm

protected BaseKeyWrappingAlgorithm(String name)
Protected constructor.
Parameters:
name - the key wrapping algorithm canonical name.

Method Details

engineInit

protected abstract void engineInit(Map<K,V> attributes)
            throws InvalidKeyException

engineUnwrap

protected abstract byte[] engineUnwrap(byte[] in,
                                       int inOffset,
                                       int length)
            throws KeyUnwrappingException

engineWrap

protected abstract byte[] engineWrap(byte[] in,
                                     int inOffset,
                                     int length)

getDefaultPRNG

protected PRNG getDefaultPRNG()
Returns:
a strong pseudo-random number generator if/when needed.

init

public void init(Map<K,V> attributes)
            throws InvalidKeyException
Initializes this instance with the designated algorithm specific attributes.
Specified by:
init in interface IKeyWrappingAlgorithm
Parameters:
attributes - a map of name-to-value pairs the Key Wrapping Algorithm must use for its setup.
Throws:
InvalidKeyException - if an exception is encountered while seting up the Key Wrapping Algorithm keying material (KEK).

name

public String name()
Returns the canonical name of this Key Wrapping Algorithm.
Specified by:
name in interface IKeyWrappingAlgorithm
Returns:
the canonical name of this Key Wrapping Algorithm.

unwrap

public byte[] unwrap(byte[] in,
                     int inOffset,
                     int length)
            throws KeyUnwrappingException
Unwraps the designated cipher text bytes.
Specified by:
unwrap in interface IKeyWrappingAlgorithm
Parameters:
in - the input byte array containing the cipher text.
inOffset - the offset into in where the first byte of the cipher text (already wrapped key material) to unwrap is located.
length - the number of bytes to unwrap.
Returns:
a newly allocated byte array containing the plain text.
Throws:
KeyUnwrappingException - if after unwrapping the cipher text, the bytes at the begining did not match the initial value.

unwrap

public int unwrap(byte[] in,
                  int inOffset,
                  int length,
                  byte[] out,
                  int outOffset)
            throws ShortBufferException,
                   KeyUnwrappingException
Unwraps the designated cipher text bytes.
Specified by:
unwrap in interface IKeyWrappingAlgorithm
Parameters:
in - the input byte array containing the cipher text.
inOffset - the offset into in where the first byte of the cipher text (already wrapped key material) to unwrap is located.
length - the number of bytes to unwrap.
out - the output byte array where the unwrapped key material will be stored.
outOffset - the offset into out of the first unwrapped byte.
Returns:
the number of bytes of the unwrapped key material; i.e. the length, in out, starting from outOffset where the plain text (unwrapped key material) are stored.
Throws:
ShortBufferException - if the output buffer is not long enough to accomodate the number of bytes resulting from unwrapping the cipher text.
KeyUnwrappingException - if after unwrapping the cipher text, the bytes at the begining did not match the initial value.

wrap

public byte[] wrap(byte[] in,
                   int inOffset,
                   int length)
Wraps the designated plain text bytes.
Specified by:
wrap in interface IKeyWrappingAlgorithm
Parameters:
in - the input byte array containing the plain text.
inOffset - the offset into in where the first byte of the plain text (key material) to wrap is located.
length - the number of bytes to wrap.
Returns:
a newly allocated byte array containing the cipher text.

wrap

public int wrap(byte[] in,
                int inOffset,
                int length,
                byte[] out,
                int outOffset)
            throws ShortBufferException
Wraps the designated plain text bytes.
Specified by:
wrap in interface IKeyWrappingAlgorithm
Parameters:
in - the input byte array containing the plain text.
inOffset - the offset into in where the first byte of the plain text (key material) to wrap is located.
length - the number of bytes to wrap.
out - the output byte array where the wrapped key material will be stored.
outOffset - the offset into out of the first wrapped byte.
Returns:
the number of bytes of the wrapped key material; i.e. the length, in out, starting from outOffset where the cipher text (wrapped key material) are stored.
Throws:
ShortBufferException - if the output buffer is not long enough to accomodate the number of bytes resulting from wrapping the plain text.

BaseKeyWrappingAlgorithm.java -- FIXME: briefly describe file purpose Copyright (C) 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.