des 3.5 KB

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