2 * Copyright (c) 1997 - 2008 Kungliga Tekniska Högskolan
3 * (Royal Institute of Technology, Stockholm, Sweden).
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the Institute nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 #include "krb5_locl.h"
41 DES3_random_key(krb5_context context
,
44 DES_cblock
*k
= key
->keyvalue
.data
;
46 krb5_generate_random_block(k
, 3 * sizeof(DES_cblock
));
47 DES_set_odd_parity(&k
[0]);
48 DES_set_odd_parity(&k
[1]);
49 DES_set_odd_parity(&k
[2]);
50 } while(DES_is_weak_key(&k
[0]) ||
51 DES_is_weak_key(&k
[1]) ||
52 DES_is_weak_key(&k
[2]));
56 #ifdef DES3_OLD_ENCTYPE
57 static struct _krb5_key_type keytype_des3
= {
58 ETYPE_OLD_DES3_CBC_SHA1
,
62 sizeof(struct _krb5_evp_schedule
),
66 _krb5_DES3_random_to_key
,
72 static struct _krb5_key_type keytype_des3_derived
= {
73 ETYPE_OLD_DES3_CBC_SHA1
,
77 sizeof(struct _krb5_evp_schedule
),
80 _krb5_des3_salt_derived
,
81 _krb5_DES3_random_to_key
,
86 #ifdef DES3_OLD_ENCTYPE
87 static krb5_error_code
88 RSA_MD5_DES3_checksum(krb5_context context
,
89 struct _krb5_key_data
*key
,
95 return _krb5_des_checksum(context
, EVP_md5(), key
, data
, len
, C
);
98 static krb5_error_code
99 RSA_MD5_DES3_verify(krb5_context context
,
100 struct _krb5_key_data
*key
,
106 return _krb5_des_verify(context
, EVP_md5(), key
, data
, len
, C
);
109 struct _krb5_checksum_type _krb5_checksum_rsa_md5_des3
= {
110 CKSUMTYPE_RSA_MD5_DES3
,
114 F_KEYED
| F_CPROOF
| F_VARIANT
,
115 RSA_MD5_DES3_checksum
,
120 struct _krb5_checksum_type _krb5_checksum_hmac_sha1_des3
= {
121 CKSUMTYPE_HMAC_SHA1_DES3
,
125 F_KEYED
| F_CPROOF
| F_DERIVED
,
126 _krb5_SP_HMAC_SHA1_checksum
,
130 #ifdef DES3_OLD_ENCTYPE
131 struct _krb5_encryption_type _krb5_enctype_des3_cbc_md5
= {
138 &_krb5_checksum_rsa_md5
,
139 &_krb5_checksum_rsa_md5_des3
,
147 struct _krb5_encryption_type _krb5_enctype_des3_cbc_sha1
= {
153 &keytype_des3_derived
,
154 &_krb5_checksum_sha1
,
155 &_krb5_checksum_hmac_sha1_des3
,
162 #ifdef DES3_OLD_ENCTYPE
163 struct _krb5_encryption_type _krb5_enctype_old_des3_cbc_sha1
= {
164 ETYPE_OLD_DES3_CBC_SHA1
,
170 &_krb5_checksum_sha1
,
171 &_krb5_checksum_hmac_sha1_des3
,
179 struct _krb5_encryption_type _krb5_enctype_des3_cbc_none
= {
185 &keytype_des3_derived
,
186 &_krb5_checksum_none
,
195 _krb5_DES3_random_to_key(krb5_context context
,
200 unsigned char *x
= key
->keyvalue
.data
;
201 const u_char
*q
= data
;
205 memset(key
->keyvalue
.data
, 0, key
->keyvalue
.length
);
206 for (i
= 0; i
< 3; ++i
) {
208 for (j
= 0; j
< 7; ++j
) {
209 unsigned char b
= q
[7 * i
+ j
];
214 for (j
= 6; j
>= 0; --j
) {
215 foo
|= q
[7 * i
+ j
] & 1;
220 k
= key
->keyvalue
.data
;
221 for (i
= 0; i
< 3; i
++) {
222 DES_set_odd_parity(&k
[i
]);
223 if(DES_is_weak_key(&k
[i
]))
224 _krb5_xor(&k
[i
], (const unsigned char*)"\0\0\0\0\0\0\0\xf0");