~ubuntu-branches/ubuntu/precise/krb5/precise-updates

« back to all changes in this revision

Viewing changes to src/lib/crypto/krb/arcfour/arcfour_s2k.c

  • Committer: Package Import Robot
  • Author(s): Sam Hartman
  • Date: 2011-12-01 19:34:41 UTC
  • mfrom: (28.1.14 sid)
  • Revision ID: package-import@ubuntu.com-20111201193441-9tipg3aru1jsidyv
Tags: 1.10+dfsg~alpha1-6
* Fix segfault with unknown hostnames in krb5_sname_to_principal,
  Closes: #650671
* Indicate that this library breaks libsmbclient versions that depend on
  krb5_locate_kdc, Closes: #650603, #650611

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
 
#include "k5-int.h"
3
 
#include "k5-utf8.h"
4
 
#include "rsa-md4.h"
5
 
#include "arcfour-int.h"
6
 
 
7
 
#if TARGET_OS_MAC && !defined(DEPEND)
8
 
#include <CoreFoundation/CFString.h>
9
 
#endif
10
 
 
11
 
krb5_error_code
12
 
krb5int_arcfour_string_to_key(const struct krb5_keytypes *ktp,
13
 
                              const krb5_data *string, const krb5_data *salt,
14
 
                              const krb5_data *params, krb5_keyblock *key)
15
 
{
16
 
    krb5_error_code err = 0;
17
 
    krb5_MD4_CTX md4_context;
18
 
    unsigned char *copystr;
19
 
    size_t copystrlen;
20
 
 
21
 
    if (params != NULL)
22
 
        return KRB5_ERR_BAD_S2K_PARAMS;
23
 
 
24
 
    if (key->length != 16)
25
 
        return (KRB5_BAD_MSIZE);
26
 
 
27
 
    /* We ignore salt per the Microsoft spec*/
28
 
 
29
 
    /* compute the space needed for the new string.
30
 
       Since the password must be stored in unicode, we need to increase
31
 
       that number by 2x.
32
 
    */
33
 
 
34
 
    err = krb5int_utf8cs_to_ucs2les(string->data, string->length, &copystr, &copystrlen);
35
 
    if (err)
36
 
        return err;
37
 
 
38
 
    /* the actual MD4 hash of the data */
39
 
    krb5int_MD4Init(&md4_context);
40
 
    krb5int_MD4Update(&md4_context, copystr, copystrlen);
41
 
    krb5int_MD4Final(&md4_context);
42
 
    memcpy(key->contents, md4_context.digest, 16);
43
 
 
44
 
#if 0
45
 
    /* test the string_to_key function */
46
 
    printf("Hash=");
47
 
    {
48
 
        int counter;
49
 
        for(counter=0;counter<16;counter++)
50
 
            printf("%02x", md4_context.digest[counter]);
51
 
        printf("\n");
52
 
    }
53
 
#endif /* 0 */
54
 
 
55
 
    /* Zero out the data behind us */
56
 
    memset(copystr, 0, copystrlen);
57
 
    memset(&md4_context, 0, sizeof(md4_context));
58
 
    free(copystr);
59
 
    return err;
60
 
}