cipherrc4.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. #include <mp.h>
  12. #include <fcall.h>
  13. #include <thread.h>
  14. #include <9p.h>
  15. #include <libsec.h>
  16. #include "netssh.h"
  17. struct CipherState {
  18. RC4state state;
  19. };
  20. static CipherState*
  21. initrc4(Conn *c, int dir)
  22. {
  23. CipherState *cs;
  24. cs = emalloc9p(sizeof(CipherState));
  25. if(dir)
  26. setupRC4state(&cs->state, c->s2cek, 16);
  27. else
  28. setupRC4state(&cs->state, c->c2sek, 16);
  29. return cs;
  30. }
  31. static void
  32. encryptrc4(CipherState *cs, uint8_t *buf, int nbuf)
  33. {
  34. rc4(&cs->state, buf, nbuf);
  35. }
  36. static void
  37. decryptrc4(CipherState *cs, uint8_t *buf, int nbuf)
  38. {
  39. rc4(&cs->state, buf, nbuf);
  40. }
  41. Cipher cipherrc4 = {
  42. "arcfour",
  43. 8,
  44. initrc4,
  45. encryptrc4,
  46. decryptrc4,
  47. };