chacha 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. .TH CHACHA 2
  2. .SH NAME
  3. setupChachastate, chacha_setblock, chacha_encrypt, chacha_encrypt2 - chacha encryption
  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 setupChachastate(Chachastate *s, uchar key[],
  15. .B
  16. int keylen, uchar *nonce, int rounds)
  17. .PP
  18. .B
  19. void chacha_encrypt(uchar *data, int len, Chachastate *s)
  20. .PP
  21. .B
  22. void chacha_encrypt2(uchar *src, uchar *dst, int len, Chachastate *s)
  23. .PP
  24. .B
  25. void chacha_setblock(Chachastate *s, u32int blockno)
  26. .SH DESCRIPTION
  27. .PP
  28. Chacha is D J Berstein's symmetric stream cipher, as modified by RFC7539. It uses
  29. keys of 256 bits (128 bits is supported here for special purposes). It has an underlying block size of 64 bytes
  30. (named as constant
  31. .BR ChachaBsize ).
  32. It is a potential replacement for
  33. .IR rc4 (2).
  34. .PP
  35. .I SetupChachastate
  36. takes a reference to a
  37. .B Chachastate
  38. structure, a
  39. .I key
  40. of
  41. .I keylen
  42. bytes, which should normally be
  43. .BR ChachaKeylen ,
  44. a
  45. .I nonce
  46. or initialisation vector of
  47. .B ChachaIVlen
  48. bytes (set to all zeros if the argument is nil),
  49. and the number of
  50. .I rounds
  51. (set to the default of 20 if the argument is zero).
  52. With a keylength of 256 bits (32 bytes) and 20
  53. .IR rounds ,
  54. the function implements the Chacha20 encryption function of RFC7539.
  55. .PP
  56. .I Chacha_encrypt
  57. encrypts
  58. .I len
  59. bytes of
  60. .I buf
  61. in place using the
  62. .B Chachastate
  63. in
  64. .IR s .
  65. .I Len
  66. can be any byte length.
  67. Encryption and decryption are the same operation given the same starting state
  68. .IR s .
  69. .PP
  70. .I Chacha_encrypt2
  71. is similar, but encrypts
  72. .I len
  73. bytes of
  74. .I src
  75. into
  76. .I dst
  77. without modifying
  78. .IR src .
  79. .PP
  80. .I Chacha_setblock
  81. sets the Chacha block counter for the next encryption to
  82. .IR blockno ,
  83. allowing seeking in an encrypted stream.
  84. .SH SOURCE
  85. .B /sys/src/libsec
  86. .SH SEE ALSO
  87. .IR mp (2),
  88. .IR aes (2),
  89. .IR blowfish (2),
  90. .IR des (2),
  91. .IR dsa (2),
  92. .IR elgamal (2),
  93. .IR rc4 (2),
  94. .IR rsa (2),
  95. .IR sechash (2),
  96. .IR prime (2),
  97. .IR rand (2)