Lines 38-48
Link Here
|
38 |
# include <openssl/des.h> |
38 |
# include <openssl/des.h> |
39 |
|
39 |
|
40 |
|
40 |
|
41 |
typedef DES_cblock des_key; |
41 |
typedef DES_cblock DES_key; |
42 |
typedef DES_cblock des_data_block; |
42 |
typedef DES_cblock DES_data_block; |
43 |
typedef DES_key_schedule des_context[1]; |
43 |
typedef DES_key_schedule DES_context[1]; |
44 |
#define des_failed(encrypted) 0 |
44 |
#define DES_failed(encrypted) 0 |
45 |
#define des_finish(key, schedule) |
45 |
#define DES_finish(key, schedule) |
46 |
|
46 |
|
47 |
#elif defined(HAVE_MOZNSS) |
47 |
#elif defined(HAVE_MOZNSS) |
48 |
/* |
48 |
/* |
Lines 53-74
typedef DES_key_schedule des_context[1];
Link Here
|
53 |
*/ |
53 |
*/ |
54 |
#define PROTYPES_H 1 |
54 |
#define PROTYPES_H 1 |
55 |
# include <nss/pk11pub.h> |
55 |
# include <nss/pk11pub.h> |
56 |
typedef PK11SymKey *des_key; |
56 |
typedef PK11SymKey *DES_key; |
57 |
typedef unsigned char des_data_block[8]; |
57 |
typedef unsigned char DES_data_block[8]; |
58 |
typedef PK11Context *des_context[1]; |
58 |
typedef PK11Context *DES_context[1]; |
59 |
#define DES_ENCRYPT CKA_ENCRYPT |
59 |
#define DES_ENCRYPT CKA_ENCRYPT |
60 |
|
60 |
|
61 |
#elif defined(HAVE_GNUTLS_GNUTLS_H) && !defined(DES_ENCRYPT) |
61 |
#elif defined(HAVE_GNUTLS_GNUTLS_H) && !defined(DES_ENCRYPT) |
62 |
# include <gcrypt.h> |
62 |
# include <gcrypt.h> |
63 |
static int gcrypt_init = 0; |
63 |
static int gcrypt_init = 0; |
64 |
|
64 |
|
65 |
typedef const void* des_key; |
65 |
typedef const void* DES_key; |
66 |
typedef unsigned char DES_cblock[8]; |
66 |
typedef unsigned char DES_cblock[8]; |
67 |
typedef des_cblock des_data_block; |
67 |
typedef DES_cblock DES_data_block; |
68 |
typedef int DES_key_schedule; /* unused */ |
68 |
typedef int DES_key_schedule; /* unused */ |
69 |
typedef DES_key_schedule des_context; /* unused */ |
69 |
typedef DES_key_schedule DES_context; /* unused */ |
70 |
#define des_failed(encrypted) 0 |
70 |
#define DES_failed(encrypted) 0 |
71 |
#define des_finish(key, schedule) |
71 |
#define DES_finish(key, schedule) |
72 |
|
72 |
|
73 |
#define DES_set_key_unchecked( key, key_sched ) \ |
73 |
#define DES_set_key_unchecked( key, key_sched ) \ |
74 |
gcry_cipher_setkey( hd, key, 8 ) |
74 |
gcry_cipher_setkey( hd, key, 8 ) |
Lines 684-690
static int chk_md5(
Link Here
|
684 |
* abstract away setting the parity. |
684 |
* abstract away setting the parity. |
685 |
*/ |
685 |
*/ |
686 |
static void |
686 |
static void |
687 |
des_set_key_and_parity( des_key *key, unsigned char *keyData) |
687 |
DES_set_key_and_parity( DES_key *key, unsigned char *keyData) |
688 |
{ |
688 |
{ |
689 |
memcpy(key, keyData, 8); |
689 |
memcpy(key, keyData, 8); |
690 |
DES_set_odd_parity( key ); |
690 |
DES_set_odd_parity( key ); |
Lines 697-703
des_set_key_and_parity( des_key *key, un
Link Here
|
697 |
* implement MozNSS wrappers for the openSSL calls |
697 |
* implement MozNSS wrappers for the openSSL calls |
698 |
*/ |
698 |
*/ |
699 |
static void |
699 |
static void |
700 |
des_set_key_and_parity( des_key *key, unsigned char *keyData) |
700 |
DES_set_key_and_parity( DES_key *key, unsigned char *keyData) |
701 |
{ |
701 |
{ |
702 |
SECItem keyDataItem; |
702 |
SECItem keyDataItem; |
703 |
PK11SlotInfo *slot; |
703 |
PK11SlotInfo *slot; |
Lines 719-725
des_set_key_and_parity( des_key *key, un
Link Here
|
719 |
} |
719 |
} |
720 |
|
720 |
|
721 |
static void |
721 |
static void |
722 |
DES_set_key_unchecked( des_key *key, des_context ctxt ) |
722 |
DES_set_key_unchecked( DES_key *key, DES_context ctxt ) |
723 |
{ |
723 |
{ |
724 |
ctxt[0] = NULL; |
724 |
ctxt[0] = NULL; |
725 |
|
725 |
|
Lines 732-768
DES_set_key_unchecked( des_key *key, des
Link Here
|
732 |
} |
732 |
} |
733 |
|
733 |
|
734 |
static void |
734 |
static void |
735 |
DES_ecb_encrypt( des_data_block *plain, des_data_block *encrypted, |
735 |
DES_ecb_encrypt( DES_data_block *plain, DES_data_block *encrypted, |
736 |
des_context ctxt, int op) |
736 |
DES_context ctxt, int op) |
737 |
{ |
737 |
{ |
738 |
SECStatus rv; |
738 |
SECStatus rv; |
739 |
int size; |
739 |
int size; |
740 |
|
740 |
|
741 |
if (ctxt[0] == NULL) { |
741 |
if (ctxt[0] == NULL) { |
742 |
/* need to fail here... */ |
742 |
/* need to fail here... */ |
743 |
memset(encrypted, 0, sizeof(des_data_block)); |
743 |
memset(encrypted, 0, sizeof(DES_data_block)); |
744 |
return; |
744 |
return; |
745 |
} |
745 |
} |
746 |
rv = PK11_CipherOp(ctxt[0], (unsigned char *)&encrypted[0], |
746 |
rv = PK11_CipherOp(ctxt[0], (unsigned char *)&encrypted[0], |
747 |
&size, sizeof(des_data_block), |
747 |
&size, sizeof(DES_data_block), |
748 |
(unsigned char *)&plain[0], sizeof(des_data_block)); |
748 |
(unsigned char *)&plain[0], sizeof(DES_data_block)); |
749 |
if (rv != SECSuccess) { |
749 |
if (rv != SECSuccess) { |
750 |
/* signal failure */ |
750 |
/* signal failure */ |
751 |
memset(encrypted, 0, sizeof(des_data_block)); |
751 |
memset(encrypted, 0, sizeof(DES_data_block)); |
752 |
return; |
752 |
return; |
753 |
} |
753 |
} |
754 |
return; |
754 |
return; |
755 |
} |
755 |
} |
756 |
|
756 |
|
757 |
static int |
757 |
static int |
758 |
des_failed(des_data_block *encrypted) |
758 |
DES_failed(DES_data_block *encrypted) |
759 |
{ |
759 |
{ |
760 |
static const des_data_block zero = { 0 }; |
760 |
static const DES_data_block zero = { 0 }; |
761 |
return memcmp(encrypted, zero, sizeof(zero)) == 0; |
761 |
return memcmp(encrypted, zero, sizeof(zero)) == 0; |
762 |
} |
762 |
} |
763 |
|
763 |
|
764 |
static void |
764 |
static void |
765 |
des_finish(des_key *key, des_context ctxt) |
765 |
DES_finish(DES_key *key, DES_context ctxt) |
766 |
{ |
766 |
{ |
767 |
if (*key) { |
767 |
if (*key) { |
768 |
PK11_FreeSymKey(*key); |
768 |
PK11_FreeSymKey(*key); |
Lines 837-843
des_finish(des_key *key, des_context ctx
Link Here
|
837 |
|
837 |
|
838 |
static void lmPasswd_to_key( |
838 |
static void lmPasswd_to_key( |
839 |
const char *lmPasswd, |
839 |
const char *lmPasswd, |
840 |
des_key *key) |
840 |
DES_key *key) |
841 |
{ |
841 |
{ |
842 |
const unsigned char *lpw = (const unsigned char *) lmPasswd; |
842 |
const unsigned char *lpw = (const unsigned char *) lmPasswd; |
843 |
unsigned char k[8]; |
843 |
unsigned char k[8]; |
Lines 852-858
static void lmPasswd_to_key(
Link Here
|
852 |
k[6] = ((lpw[5] & 0x3F) << 2) | (lpw[6] >> 6); |
852 |
k[6] = ((lpw[5] & 0x3F) << 2) | (lpw[6] >> 6); |
853 |
k[7] = ((lpw[6] & 0x7F) << 1); |
853 |
k[7] = ((lpw[6] & 0x7F) << 1); |
854 |
|
854 |
|
855 |
des_set_key_and_parity( key, k ); |
855 |
DES_set_key_and_parity( key, k ); |
856 |
} |
856 |
} |
857 |
|
857 |
|
858 |
static int chk_lanman( |
858 |
static int chk_lanman( |
Lines 863-872
static int chk_lanman(
Link Here
|
863 |
{ |
863 |
{ |
864 |
ber_len_t i; |
864 |
ber_len_t i; |
865 |
char UcasePassword[15]; |
865 |
char UcasePassword[15]; |
866 |
des_key key; |
866 |
DES_key key; |
867 |
des_context schedule; |
867 |
DES_context schedule; |
868 |
des_data_block StdText = "KGS!@#$%"; |
868 |
DES_data_block StdText = "KGS!@#$%"; |
869 |
des_data_block PasswordHash1, PasswordHash2; |
869 |
DES_data_block PasswordHash1, PasswordHash2; |
870 |
char PasswordHash[33], storedPasswordHash[33]; |
870 |
char PasswordHash[33], storedPasswordHash[33]; |
871 |
|
871 |
|
872 |
#if defined(HAVE_GNUTLS_GNUTLS_H) && !defined(DES_ENCRYPT) |
872 |
#if defined(HAVE_GNUTLS_GNUTLS_H) && !defined(DES_ENCRYPT) |
Lines 900-917
static int chk_lanman(
Link Here
|
900 |
DES_set_key_unchecked( &key, schedule ); |
900 |
DES_set_key_unchecked( &key, schedule ); |
901 |
DES_ecb_encrypt( &StdText, &PasswordHash1, schedule , DES_ENCRYPT ); |
901 |
DES_ecb_encrypt( &StdText, &PasswordHash1, schedule , DES_ENCRYPT ); |
902 |
|
902 |
|
903 |
if (des_failed(&PasswordHash1)) { |
903 |
if (DES_failed(&PasswordHash1)) { |
904 |
return LUTIL_PASSWD_ERR; |
904 |
return LUTIL_PASSWD_ERR; |
905 |
} |
905 |
} |
906 |
|
906 |
|
907 |
lmPasswd_to_key( &UcasePassword[7], &key ); |
907 |
lmPasswd_to_key( &UcasePassword[7], &key ); |
908 |
DES_set_key_unchecked( &key, schedule ); |
908 |
DES_set_key_unchecked( &key, schedule ); |
909 |
DES_ecb_encrypt( &StdText, &PasswordHash2, schedule , DES_ENCRYPT ); |
909 |
DES_ecb_encrypt( &StdText, &PasswordHash2, schedule , DES_ENCRYPT ); |
910 |
if (des_failed(&PasswordHash2)) { |
910 |
if (DES_failed(&PasswordHash2)) { |
911 |
return LUTIL_PASSWD_ERR; |
911 |
return LUTIL_PASSWD_ERR; |
912 |
} |
912 |
} |
913 |
|
913 |
|
914 |
des_finish( &key, schedule ); |
914 |
DES_finish( &key, schedule ); |
915 |
|
915 |
|
916 |
sprintf( PasswordHash, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", |
916 |
sprintf( PasswordHash, "%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x", |
917 |
PasswordHash1[0],PasswordHash1[1],PasswordHash1[2],PasswordHash1[3], |
917 |
PasswordHash1[0],PasswordHash1[1],PasswordHash1[2],PasswordHash1[3], |
Lines 1176-1185
static int hash_lanman(
Link Here
|
1176 |
|
1176 |
|
1177 |
ber_len_t i; |
1177 |
ber_len_t i; |
1178 |
char UcasePassword[15]; |
1178 |
char UcasePassword[15]; |
1179 |
des_key key; |
1179 |
DES_key key; |
1180 |
des_context schedule; |
1180 |
DES_context schedule; |
1181 |
des_data_block StdText = "KGS!@#$%"; |
1181 |
DES_data_block StdText = "KGS!@#$%"; |
1182 |
des_data_block PasswordHash1, PasswordHash2; |
1182 |
DES_data_block PasswordHash1, PasswordHash2; |
1183 |
char PasswordHash[33]; |
1183 |
char PasswordHash[33]; |
1184 |
|
1184 |
|
1185 |
#if defined(HAVE_GNUTLS_GNUTLS_H) && !defined(DES_ENCRYPT) |
1185 |
#if defined(HAVE_GNUTLS_GNUTLS_H) && !defined(DES_ENCRYPT) |