cipherrc4.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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 "ssh.h"
  10. struct CipherState
  11. {
  12. RC4state enc;
  13. RC4state dec;
  14. };
  15. static CipherState*
  16. initrc4(Conn *c, int isserver)
  17. {
  18. CipherState *cs;
  19. cs = emalloc(sizeof(CipherState));
  20. if(isserver){
  21. setupRC4state(&cs->enc, c->sesskey, 16);
  22. setupRC4state(&cs->dec, c->sesskey+16, 16);
  23. }else{
  24. setupRC4state(&cs->dec, c->sesskey, 16);
  25. setupRC4state(&cs->enc, c->sesskey+16, 16);
  26. }
  27. return cs;
  28. }
  29. static void
  30. encryptrc4(CipherState *cs, uint8_t *buf, int nbuf)
  31. {
  32. rc4(&cs->enc, buf, nbuf);
  33. }
  34. static void
  35. decryptrc4(CipherState *cs, uint8_t *buf, int nbuf)
  36. {
  37. rc4(&cs->dec, buf, nbuf);
  38. }
  39. Cipher cipherrc4 =
  40. {
  41. SSH_CIPHER_RC4,
  42. "rc4",
  43. initrc4,
  44. encryptrc4,
  45. decryptrc4,
  46. };