1 /* $NetBSD: salt-des3.c,v 1.1.1.1 2011/04/13 18:15:37 elric Exp $ */
4 * Copyright (c) 1997 - 2008 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "krb5_locl.h"
38 #ifdef DES3_OLD_ENCTYPE
39 static krb5_error_code
40 DES3_string_to_key(krb5_context context
,
49 unsigned char tmp
[24];
53 len
= password
.length
+ salt
.saltvalue
.length
;
55 if(len
!= 0 && str
== NULL
) {
56 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
59 memcpy(str
, password
.data
, password
.length
);
60 memcpy(str
+ password
.length
, salt
.saltvalue
.data
, salt
.saltvalue
.length
);
63 DES_key_schedule s
[3];
66 ret
= _krb5_n_fold(str
, len
, tmp
, 24);
70 krb5_set_error_message(context
, ret
, N_("malloc: out of memory", ""));
74 for(i
= 0; i
< 3; i
++){
75 memcpy(keys
+ i
, tmp
+ i
* 8, sizeof(keys
[i
]));
76 DES_set_odd_parity(keys
+ i
);
77 if(DES_is_weak_key(keys
+ i
))
78 _krb5_xor(keys
+ i
, (const unsigned char*)"\0\0\0\0\0\0\0\xf0");
79 DES_set_key_unchecked(keys
+ i
, &s
[i
]);
81 memset(&ivec
, 0, sizeof(ivec
));
82 DES_ede3_cbc_encrypt(tmp
,
84 &s
[0], &s
[1], &s
[2], &ivec
, DES_ENCRYPT
);
85 memset(s
, 0, sizeof(s
));
86 memset(&ivec
, 0, sizeof(ivec
));
87 for(i
= 0; i
< 3; i
++){
88 memcpy(keys
+ i
, tmp
+ i
* 8, sizeof(keys
[i
]));
89 DES_set_odd_parity(keys
+ i
);
90 if(DES_is_weak_key(keys
+ i
))
91 _krb5_xor(keys
+ i
, (const unsigned char*)"\0\0\0\0\0\0\0\xf0");
93 memset(tmp
, 0, sizeof(tmp
));
95 key
->keytype
= enctype
;
96 krb5_data_copy(&key
->keyvalue
, keys
, sizeof(keys
));
97 memset(keys
, 0, sizeof(keys
));
104 static krb5_error_code
105 DES3_string_to_key_derived(krb5_context context
,
106 krb5_enctype enctype
,
113 size_t len
= password
.length
+ salt
.saltvalue
.length
;
117 if(len
!= 0 && s
== NULL
) {
118 krb5_set_error_message(context
, ENOMEM
, N_("malloc: out of memory", ""));
121 memcpy(s
, password
.data
, password
.length
);
122 memcpy(s
+ password
.length
, salt
.saltvalue
.data
, salt
.saltvalue
.length
);
123 ret
= krb5_string_to_key_derived(context
,
134 #ifdef DES3_OLD_ENCTYPE
135 struct salt_type _krb5_des3_salt
[] = {
145 struct salt_type _krb5_des3_salt_derived
[] = {
149 DES3_string_to_key_derived