user.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package wire
  2. import (
  3. "crypto/md5"
  4. "io"
  5. )
  6. // WeakMD5PasswordHash hashes password and authKey for AIM v3.5-v4.7.
  7. //
  8. //goland:noinspection ALL
  9. func WeakMD5PasswordHash(pass, authKey string) []byte {
  10. hash := md5.New()
  11. io.WriteString(hash, authKey)
  12. io.WriteString(hash, pass)
  13. io.WriteString(hash, "AOL Instant Messenger (SM)")
  14. return hash.Sum(nil)
  15. }
  16. // StrongMD5PasswordHash hashes password and authKey for AIM v4.8+.
  17. //
  18. //goland:noinspection ALL
  19. func StrongMD5PasswordHash(pass, authKey string) []byte {
  20. top := md5.New()
  21. io.WriteString(top, pass)
  22. bottom := md5.New()
  23. io.WriteString(bottom, authKey)
  24. bottom.Write(top.Sum(nil))
  25. io.WriteString(bottom, "AOL Instant Messenger (SM)")
  26. return bottom.Sum(nil)
  27. }
  28. // RoastPassword toggles password obfuscation using a roasting algorithm for
  29. // AIM v1.0-v3.0 auth. The first call obfuscates the password, and the second
  30. // call de-obfuscates the password, and so on.
  31. func RoastPassword(roastedPass []byte) []byte {
  32. var roastTable = [16]byte{
  33. 0xF3, 0x26, 0x81, 0xC4, 0x39, 0x86, 0xDB, 0x92,
  34. 0x71, 0xA3, 0xB9, 0xE6, 0x53, 0x7A, 0x95, 0x7C,
  35. }
  36. clearPass := make([]byte, len(roastedPass))
  37. for i := range roastedPass {
  38. clearPass[i] = roastedPass[i] ^ roastTable[i%len(roastTable)]
  39. }
  40. return clearPass
  41. }