xref: /freebsd/crypto/krb5/src/lib/crypto/krb/s2k_rc4.c (revision 7f2fe78b9dd5f51c821d771b63d2e096f6fd49e9)
1*7f2fe78bSCy Schubert /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2*7f2fe78bSCy Schubert #include "crypto_int.h"
3*7f2fe78bSCy Schubert #include "k5-utf8.h"
4*7f2fe78bSCy Schubert 
5*7f2fe78bSCy Schubert krb5_error_code
krb5int_arcfour_string_to_key(const struct krb5_keytypes * ktp,const krb5_data * string,const krb5_data * salt,const krb5_data * params,krb5_keyblock * key)6*7f2fe78bSCy Schubert krb5int_arcfour_string_to_key(const struct krb5_keytypes *ktp,
7*7f2fe78bSCy Schubert                               const krb5_data *string, const krb5_data *salt,
8*7f2fe78bSCy Schubert                               const krb5_data *params, krb5_keyblock *key)
9*7f2fe78bSCy Schubert {
10*7f2fe78bSCy Schubert     krb5_error_code err = 0;
11*7f2fe78bSCy Schubert     krb5_crypto_iov iov;
12*7f2fe78bSCy Schubert     krb5_data hash_out;
13*7f2fe78bSCy Schubert     char *utf8;
14*7f2fe78bSCy Schubert     unsigned char *copystr;
15*7f2fe78bSCy Schubert     size_t copystrlen;
16*7f2fe78bSCy Schubert 
17*7f2fe78bSCy Schubert     if (params != NULL)
18*7f2fe78bSCy Schubert         return KRB5_ERR_BAD_S2K_PARAMS;
19*7f2fe78bSCy Schubert 
20*7f2fe78bSCy Schubert     if (key->length != 16)
21*7f2fe78bSCy Schubert         return (KRB5_BAD_MSIZE);
22*7f2fe78bSCy Schubert 
23*7f2fe78bSCy Schubert     /* We ignore salt per the Microsoft spec. */
24*7f2fe78bSCy Schubert     utf8 = k5memdup0(string->data, string->length, &err);
25*7f2fe78bSCy Schubert     if (utf8 == NULL)
26*7f2fe78bSCy Schubert         return err;
27*7f2fe78bSCy Schubert     err = k5_utf8_to_utf16le(utf8, &copystr, &copystrlen);
28*7f2fe78bSCy Schubert     zapfree(utf8, string->length);
29*7f2fe78bSCy Schubert     if (err)
30*7f2fe78bSCy Schubert         return err;
31*7f2fe78bSCy Schubert 
32*7f2fe78bSCy Schubert     /* the actual MD4 hash of the data */
33*7f2fe78bSCy Schubert     iov.flags = KRB5_CRYPTO_TYPE_DATA;
34*7f2fe78bSCy Schubert     iov.data = make_data(copystr, copystrlen);
35*7f2fe78bSCy Schubert     hash_out = make_data(key->contents, key->length);
36*7f2fe78bSCy Schubert     err = krb5int_hash_md4.hash(&iov, 1, &hash_out);
37*7f2fe78bSCy Schubert 
38*7f2fe78bSCy Schubert     /* Zero out the data behind us */
39*7f2fe78bSCy Schubert     zapfree(copystr, copystrlen);
40*7f2fe78bSCy Schubert     return err;
41*7f2fe78bSCy Schubert }
42