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

« back to all changes in this revision

Viewing changes to src/lib/crypto/nss/des/des_keys.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
/* lib/crypto/nss/des/des_keys.c - Key functions used by Kerberos code */
 
3
/*
 
4
 * Copyright (C) 2011 by the Massachusetts Institute of Technology.
 
5
 * All rights reserved.
 
6
 *
 
7
 * Export of this software from the United States of America may
 
8
 *   require a specific license from the United States Government.
 
9
 *   It is the responsibility of any person or organization contemplating
 
10
 *   export to obtain such a license before exporting.
 
11
 *
 
12
 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
 
13
 * distribute this software and its documentation for any purpose and
 
14
 * without fee is hereby granted, provided that the above copyright
 
15
 * notice appear in all copies and that both that copyright notice and
 
16
 * this permission notice appear in supporting documentation, and that
 
17
 * the name of M.I.T. not be used in advertising or publicity pertaining
 
18
 * to distribution of the software without specific, written prior
 
19
 * permission.  Furthermore if you modify this software you must label
 
20
 * your software as modified software and not distribute it in such a
 
21
 * fashion that it might be confused with the original M.I.T. software.
 
22
 * M.I.T. makes no representations about the suitability of
 
23
 * this software for any purpose.  It is provided "as is" without express
 
24
 * or implied warranty.
 
25
 */
 
26
 
 
27
#include "crypto_int.h"
 
28
 
 
29
/*
 
30
 * des_fixup_key_parity: Forces odd parity per byte; parity is bits
 
31
 *                       8,16,...64 in des order, implies 0, 8, 16, ...
 
32
 *                       vax order.
 
33
 */
 
34
#define smask(step) ((1<<step)-1)
 
35
#define pstep(x,step) (((x)&smask(step))^(((x)>>step)&smask(step)))
 
36
#define parity_char(x) pstep(pstep(pstep((x),4),2),1)
 
37
 
 
38
void
 
39
k5_des_fixup_key_parity(unsigned char *keybits)
 
40
{
 
41
    unsigned int i;
 
42
 
 
43
    for (i = 0; i < 8; i++) {
 
44
        keybits[i] &= 0xfe;
 
45
        keybits[i] |= 1^parity_char(keybits[i]);
 
46
    }
 
47
}
 
48
 
 
49
/* The following are the weak DES keys: */
 
50
static const unsigned char weak[16][8] = {
 
51
    /* Weak keys */
 
52
    {0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01},
 
53
    {0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe,0xfe},
 
54
    {0x1f,0x1f,0x1f,0x1f,0x0e,0x0e,0x0e,0x0e},
 
55
    {0xe0,0xe0,0xe0,0xe0,0xf1,0xf1,0xf1,0xf1},
 
56
 
 
57
    /* Semi-weak */
 
58
    {0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe},
 
59
    {0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01},
 
60
 
 
61
    {0x1f,0xe0,0x1f,0xe0,0x0e,0xf1,0x0e,0xf1},
 
62
    {0xe0,0x1f,0xe0,0x1f,0xf1,0x0e,0xf1,0x0e},
 
63
 
 
64
    {0x01,0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1},
 
65
    {0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1,0x01},
 
66
 
 
67
    {0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e,0xfe},
 
68
    {0xfe,0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e},
 
69
 
 
70
    {0x01,0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e},
 
71
    {0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e,0x01},
 
72
 
 
73
    {0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1,0xfe},
 
74
    {0xfe,0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1}
 
75
};
 
76
 
 
77
krb5_boolean
 
78
k5_des_is_weak_key(unsigned char *keybits)
 
79
{
 
80
    unsigned int i;
 
81
 
 
82
    for (i = 0; i < sizeof(weak) / 8; i++) {
 
83
        if (memcmp(weak[i], keybits, 8) == 0)
 
84
            return TRUE;
 
85
    }
 
86
    return FALSE;
 
87
}