| 1 | /* |
| 2 | * Original hash funcions Copyright (C) Luigi Auriemma ([email protected]) |
| 3 | * Copyright (C) 2007 Pelish ([email protected]) |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
| 20 | #include "common/setup_before.h"cxx . . $ `<file>/src/common/setup_before.h`/ |
| 21 | #include "common/wolhash.h"cxx . . $ `<file>/src/common/wolhash.h`/ |
| 22 | |
| 23 | #include <cstdlib> |
| 24 | #include <cstring> |
| 25 | |
| 26 | #include "common/eventlog.h"cxx . . $ `<file>/src/common/eventlog.h`/ |
| 27 | #include "common/setup_after.h"cxx . . $ `<file>/src/common/setup_after.h`/ |
| 28 | |
| 29 | namespace pvpgncxx . . $ pvpgn/ |
| 30 | { |
| 31 | |
| 32 | |
| 33 | extern int wol_hashcxx . . $ pvpgn/wol_hash(2b6915b218ebe054).(t_wolhashcxx . . $ pvpgn/t_wolhash# * hashout, unsigned int size, void const * datain) { |
| 34 | unsigned char pwd1[9]; |
| 35 | unsigned char pwd2[9]; |
| 36 | unsigned char edx; |
| 37 | unsigned char esi; |
| 38 | unsigned char i; |
| 39 | unsigned char *p1; |
| 40 | unsigned char *p2; |
| 41 | |
| 42 | /** |
| 43 | * Original NOTE by Luigi Auriemma: |
| 44 | * Original algorithm starts at offset 0x0041d440 of wchat.dat of 4.221 US version |
| 45 | * The algorithm is one-way, so the encoded password can NOT be completely decoded! |
| 46 | */ |
| 47 | |
| 48 | if (size > 8) { |
| 49 | // ERROR1("Westwood passwords are max 8 bytes long: \"%.8s\"",size); |
| 50 | return -1; |
| 51 | } |
| 52 | |
| 53 | if (!datain) { |
| 54 | ERROR0cxx . . $ `src/common/eventlog.h:73:9`!("got NULL datain"); |
| 55 | return -1; |
| 56 | } |
| 57 | |
| 58 | stdcxx . . $ std/::memset(pwd1, 0, sizeof(pwd1)); |
| 59 | stdcxx . . $ std/::memset(pwd2, 0, sizeof(pwd2)); |
| 60 | stdcxx . . $ std/::memcpy(pwd1, datain, size); |
| 61 | |
| 62 | esi = size; |
| 63 | p1 = pwd1; |
| 64 | p2 = pwd2; |
| 65 | for (i = 0; i < size; i++) { |
| 66 | if (*p1 & 1) { |
| 67 | edx = *p1 << 1; |
| 68 | edx &= *(pwd1 + esi); |
| 69 | } |
| 70 | else { |
| 71 | edx = *p1 ^ *(pwd1 + esi); |
| 72 | } |
| 73 | *p2++ = edx; |
| 74 | esi--; |
| 75 | p1++; |
| 76 | } |
| 77 | |
| 78 | p1 = pwd1; |
| 79 | p2 = pwd2; |
| 80 | for (i = 0; i < 8; i++) { |
| 81 | edx = *p2++ & 0x3f; |
| 82 | *p1++ = WOL_HASH_CHARcxx . . $ `src/common/wolhash.h:29:9`![edx]; |
| 83 | } |
| 84 | |
| 85 | stdcxx . . $ std/::memcpy(hashout, pwd1, sizeof(pwd1)); |
| 86 | return 0; |
| 87 | } |
| 88 | |
| 89 | /*extern int wolhash_eq(t_wolhash const h1, t_wolhash const h2) |
| 90 | { |
| 91 | unsigned int i; |
| 92 | |
| 93 | if (!h1 || !h2) |
| 94 | { |
| 95 | eventlog(eventlog_level_error,__FUNCTION__,"got NULL hash"); |
| 96 | return -1; |
| 97 | } |
| 98 | |
| 99 | for (i=0; i<5; i++) |
| 100 | if (h1[i]!=h2[i]) |
| 101 | return 0; |
| 102 | |
| 103 | return 1; |
| 104 | }*/ |
| 105 | |
| 106 | } |
| 107 | |
| 108 | |
| 109 |