1 /* IPSec VPN client compatible with Cisco equipment.
2 Copyright (C) 2004-2007 Maurice Massar
3 A bit reorganized in 2007 by Wolfram Sang
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
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.
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
32 #include "decrypt-utils.h"
35 static int hex2bin_c(unsigned int c
)
37 if ((c
>= '0')&&(c
<= '9'))
39 if ((c
>= 'A')&&(c
<= 'F'))
41 if ((c
>= 'a')&&(c
<= 'f'))
46 int hex2bin(const char *str
, char **bin
, int *len
)
54 for (i
= 0; str
[i
] != '\0'; i
++)
55 if (hex2bin_c(str
[i
]) == -1)
67 for (i
= 0; i
< l
; i
++)
68 p
[i
] = hex2bin_c(str
[i
*2]) << 4 | hex2bin_c(str
[i
*2+1]);
77 int deobfuscate(char *ct
, int len
, const char **resp
, char *reslenp
)
80 const char *h4
= ct
+ 20;
81 const char *enc
= ct
+ 40;
83 char ht
[20], h2
[20], h3
[20], key
[24];
96 gcry_md_hash_buffer(GCRY_MD_SHA1
, h2
, ht
, 20);
99 gcry_md_hash_buffer(GCRY_MD_SHA1
, h3
, ht
, 20);
102 memcpy(key
+20, h3
, 4);
103 /* who cares about parity anyway? */
105 gcry_md_hash_buffer(GCRY_MD_SHA1
, ht
, enc
, len
);
107 if (memcmp(h4
, ht
, 20) != 0)
114 gcry_cipher_open(&ctx
, GCRY_CIPHER_3DES
, GCRY_CIPHER_MODE_CBC
, 0);
115 gcry_cipher_setkey(ctx
, key
, 24);
116 gcry_cipher_setiv(ctx
, iv
, 8);
117 gcry_cipher_decrypt(ctx
, (unsigned char *)res
, len
, (unsigned char *)enc
, len
);
118 gcry_cipher_close(ctx
);
120 reslen
= len
- res
[len
-1];