des_crypt.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * @(#)des_crypt.h 2.1 88/08/11 4.0 RPCSRC
  3. *
  4. * des_crypt.h, des library routine interface
  5. * Copyright (c) 2010, Oracle America, Inc.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are
  9. * met:
  10. *
  11. * * Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * * Redistributions in binary form must reproduce the above
  14. * copyright notice, this list of conditions and the following
  15. * disclaimer in the documentation and/or other materials
  16. * provided with the distribution.
  17. * * Neither the name of the "Oracle America, Inc." nor the names of its
  18. * contributors may be used to endorse or promote products derived
  19. * from this software without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  26. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  27. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  28. * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
  29. * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
  30. * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  31. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  32. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  33. */
  34. #ifndef __DES_CRYPT_H__
  35. #define __DES_CRYPT_H__ 1
  36. #include <features.h>
  37. __BEGIN_DECLS
  38. #define DES_MAXDATA 8192 /* max bytes encrypted in one call */
  39. #define DES_DIRMASK (1 << 0)
  40. #define DES_ENCRYPT (0*DES_DIRMASK) /* Encrypt */
  41. #define DES_DECRYPT (1*DES_DIRMASK) /* Decrypt */
  42. #define DES_DEVMASK (1 << 1)
  43. #define DES_HW (0*DES_DEVMASK) /* Use hardware device */
  44. #define DES_SW (1*DES_DEVMASK) /* Use software device */
  45. #define DESERR_NONE 0 /* succeeded */
  46. #define DESERR_NOHWDEVICE 1 /* succeeded, but hw device not available */
  47. #define DESERR_HWERROR 2 /* failed, hardware/driver error */
  48. #define DESERR_BADPARAM 3 /* failed, bad parameter to call */
  49. #define DES_FAILED(err) \
  50. ((err) > DESERR_NOHWDEVICE)
  51. /*
  52. * cbc_crypt()
  53. * ecb_crypt()
  54. *
  55. * Encrypt (or decrypt) len bytes of a buffer buf.
  56. * The length must be a multiple of eight.
  57. * The key should have odd parity in the low bit of each byte.
  58. * ivec is the input vector, and is updated to the new one (cbc only).
  59. * The mode is created by oring together the appropriate parameters.
  60. * DESERR_NOHWDEVICE is returned if DES_HW was specified but
  61. * there was no hardware to do it on (the data will still be
  62. * encrypted though, in software).
  63. */
  64. /*
  65. * Cipher Block Chaining mode
  66. */
  67. extern int cbc_crypt (char *__key, char *__buf, unsigned __len,
  68. unsigned __mode, char *__ivec) __THROW;
  69. /*
  70. * Electronic Code Book mode
  71. */
  72. extern int ecb_crypt (char *__key, char *__buf, unsigned __len,
  73. unsigned __mode) __THROW;
  74. /*
  75. * Set des parity for a key.
  76. * DES parity is odd and in the low bit of each byte
  77. */
  78. extern void des_setparity (char *__key) __THROW;
  79. __END_DECLS
  80. #endif