IBlockCipherSpi.java 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /* IBlockCipherSpi.java --
  2. Copyright (C) 2001, 2002, 2006 Free Software Foundation, Inc.
  3. This file is a 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 of the License, or (at
  7. your option) 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; if not, write to the Free Software
  14. Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
  15. 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.cipher;
  32. import java.security.InvalidKeyException;
  33. import java.util.Iterator;
  34. /**
  35. * Package-private interface exposing mandatory methods to be implemented by
  36. * concrete {@link BaseCipher} sub-classes.
  37. */
  38. interface IBlockCipherSpi
  39. extends Cloneable
  40. {
  41. /**
  42. * Returns an {@link Iterator} over the supported block sizes. Each element
  43. * returned by this object is a {@link java.lang.Integer}.
  44. *
  45. * @return an <code>Iterator</code> over the supported block sizes.
  46. */
  47. Iterator blockSizes();
  48. /**
  49. * Returns an {@link Iterator} over the supported key sizes. Each element
  50. * returned by this object is a {@link java.lang.Integer}.
  51. *
  52. * @return an <code>Iterator</code> over the supported key sizes.
  53. */
  54. Iterator keySizes();
  55. /**
  56. * Expands a user-supplied key material into a session key for a designated
  57. * <i>block size</i>.
  58. *
  59. * @param k the user-supplied key material.
  60. * @param bs the desired block size in bytes.
  61. * @return an Object encapsulating the session key.
  62. * @exception IllegalArgumentException if the block size is invalid.
  63. * @exception InvalidKeyException if the key data is invalid.
  64. */
  65. Object makeKey(byte[] k, int bs) throws InvalidKeyException;
  66. /**
  67. * Encrypts exactly one block of plaintext.
  68. *
  69. * @param in the plaintext.
  70. * @param inOffset index of <code>in</code> from which to start considering
  71. * data.
  72. * @param out the ciphertext.
  73. * @param outOffset index of <code>out</code> from which to store the
  74. * result.
  75. * @param k the session key to use.
  76. * @param bs the block size to use.
  77. * @exception IllegalArgumentException if the block size is invalid.
  78. * @exception ArrayIndexOutOfBoundsException if there is not enough room in
  79. * either the plaintext or ciphertext buffers.
  80. */
  81. void encrypt(byte[] in, int inOffset, byte[] out, int outOffset, Object k,
  82. int bs);
  83. /**
  84. * Decrypts exactly one block of ciphertext.
  85. *
  86. * @param in the ciphertext.
  87. * @param inOffset index of <code>in</code> from which to start considering
  88. * data.
  89. * @param out the plaintext.
  90. * @param outOffset index of <code>out</code> from which to store the
  91. * result.
  92. * @param k the session key to use.
  93. * @param bs the block size to use.
  94. * @exception IllegalArgumentException if the block size is invalid.
  95. * @exception ArrayIndexOutOfBoundsException if there is not enough room in
  96. * either the plaintext or ciphertext buffers.
  97. */
  98. void decrypt(byte[] in, int inOffset, byte[] out, int outOffset, Object k,
  99. int bs);
  100. /**
  101. * A <i>correctness</i> test that consists of basic symmetric encryption /
  102. * decryption test(s) for all supported block and key sizes, as well as one
  103. * (1) variable key Known Answer Test (KAT).
  104. *
  105. * @return <code>true</code> if the implementation passes simple
  106. * <i>correctness</i> tests. Returns <code>false</code> otherwise.
  107. */
  108. boolean selfTest();
  109. }