IKeyWrappingAlgorithm.java 6.7 KB

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