des 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. .TH DES 2
  2. .SH NAME
  3. setupDESstate, des_key_setup, block_cipher, desCBCencrypt, desCBCdecrypt, desECBencrypt, desECBdecrypt, des3CBCencrypt, des3CBCdecrypt, des3ECBencrypt, des3ECBdecrypt, key_setup, des56to64, des64to56, setupDES3state, triple_block_cipher, - single and triple digital encryption standard
  4. .SH SYNOPSIS
  5. .B #include <u.h>
  6. .br
  7. .B #include <libc.h>
  8. .br
  9. .B #include <mp.h>
  10. .br
  11. .B #include <libsec.h>
  12. .PP
  13. .B
  14. void des_key_setup(uchar key[8], ulong schedule[32])
  15. .PP
  16. .B
  17. void block_cipher(ulong *schedule, uchar *data, int decrypting)
  18. .PP
  19. .B
  20. void setupDESstate(DESstate *s, uchar key[8], uchar *ivec)
  21. .PP
  22. .B
  23. void desCBCencrypt(uchar*, int, DESstate*)
  24. .PP
  25. .B
  26. void desCBCdecrypt(uchar*, int, DESstate*)
  27. .PP
  28. .B
  29. void desECBencrypt(uchar*, int, DESstate*)
  30. .PP
  31. .B
  32. void desECBdecrypt(uchar*, int, DESstate*)
  33. .PP
  34. .B
  35. void triple_block_cipher(ulong keys[3][32], uchar*, int)
  36. .PP
  37. .B
  38. void setupDES3state(DES3state *s, uchar key[3][8], uchar *ivec)
  39. .PP
  40. .B
  41. void des3CBCencrypt(uchar*, int, DES3state*)
  42. .PP
  43. .B
  44. void des3CBCdecrypt(uchar*, int, DES3state*)
  45. .PP
  46. .B
  47. void des3ECBencrypt(uchar*, int, DES3state*)
  48. .PP
  49. .B
  50. void des3ECBdecrypt(uchar*, int, DES3state*)
  51. .PP
  52. .B
  53. void key_setup(uchar[7], ulong[32])
  54. .PP
  55. .B
  56. void des56to64(uchar *k56, uchar *k64)
  57. .PP
  58. .B
  59. void des64to56(uchar *k64, uchar *k56)
  60. .SH DESCRIPTION
  61. .PP
  62. The Digital Encryption Standard (DES)
  63. is a shared key or symmetric encryption using either
  64. a 56 bit key for single DES or three 56 bit keys for triple des.
  65. The keys are encoded into 64 bits where every eight bit
  66. is parity.
  67. .PP
  68. The basic DES function,
  69. .IR block_cipher ,
  70. works on a block of 8 bytes, converting them in place.
  71. It takes a key schedule, a pointer to the block, and
  72. a flag indicating encrypting (0) or decrypting (1).
  73. The key schedule is created from the key using
  74. .IR des_key_setup .
  75. .PP
  76. Since it is a bit awkward,
  77. .I block_cipher
  78. is rarely called directly. Instead, one normally uses
  79. routines that encrypt larger buffers of data and
  80. which may chain the encryption state from one buffer
  81. to the next.
  82. These routines keep track of the state of the
  83. encryption using a
  84. .B DESstate
  85. structure that contains the key schedule and any chained
  86. state.
  87. .I SetupDESstate
  88. sets up the
  89. .B DESstate
  90. structure using the key and an 8 byte initialization vector.
  91. .PP
  92. Electronic code book, using
  93. .I desECBencrypt
  94. and
  95. .IR desECBdecrypt ,
  96. is the less secure mode. The encryption of each 8 bytes
  97. does not depend on the encryption of any other.
  98. Hence the encryption is a substitution
  99. cipher using 64 bit characters.
  100. .PP
  101. Cipher block chaining mode, using
  102. .I desCBCencrypt
  103. and
  104. .IR desCBCdecrypt ,
  105. is more secure. Every block encrypted depends on the initialization
  106. vector and all blocks encrypted before it.
  107. .PP
  108. For both CBC and ECB modes, a stream of data can be encrypted as
  109. multiple buffers. However, all buffers except the last must
  110. be a multiple of 8 bytes to ensure successful decryption of
  111. the stream.
  112. .PP
  113. There are equivalent triple DES functions for each of the
  114. DES functions.
  115. .PP
  116. In the past Plan 9 used a 56 bit or 7 byte
  117. format for DES keys. To be compatible with the rest
  118. of the world, we've abandoned this format.
  119. There are two functions:
  120. .I des56to64
  121. and
  122. .I des64to56
  123. to convert back and forth between the two formats.
  124. Also a key schedule can be set up from the 7 byte format
  125. using
  126. .IR key_setup .
  127. .PP
  128. .SH SOURCE
  129. .B /sys/src/libsec
  130. .SH SEE ALSO
  131. .IR mp (2),
  132. .IR aes (2),
  133. .IR blowfish (2),
  134. .IR dsa (2),
  135. .IR elgamal (2),
  136. .IR rc4 (2),
  137. .IR rsa (2),
  138. .IR sechash (2),
  139. .IR prime (2),
  140. .IR rand (2)