cipherrc4.c 674 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "ssh.h"
  2. struct CipherState
  3. {
  4. RC4state enc;
  5. RC4state dec;
  6. };
  7. static CipherState*
  8. initrc4(Conn *c, int isserver)
  9. {
  10. CipherState *cs;
  11. cs = emalloc(sizeof(CipherState));
  12. if(isserver){
  13. setupRC4state(&cs->enc, c->sesskey, 16);
  14. setupRC4state(&cs->dec, c->sesskey+16, 16);
  15. }else{
  16. setupRC4state(&cs->dec, c->sesskey, 16);
  17. setupRC4state(&cs->enc, c->sesskey+16, 16);
  18. }
  19. return cs;
  20. }
  21. static void
  22. encryptrc4(CipherState *cs, uchar *buf, int nbuf)
  23. {
  24. rc4(&cs->enc, buf, nbuf);
  25. }
  26. static void
  27. decryptrc4(CipherState *cs, uchar *buf, int nbuf)
  28. {
  29. rc4(&cs->dec, buf, nbuf);
  30. }
  31. Cipher cipherrc4 =
  32. {
  33. SSH_CIPHER_RC4,
  34. "rc4",
  35. initrc4,
  36. encryptrc4,
  37. decryptrc4,
  38. };