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 */
4
* Copyright (C) 2011 by the Massachusetts Institute of Technology.
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.
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.
27
#include "crypto_int.h"
30
* des_fixup_key_parity: Forces odd parity per byte; parity is bits
31
* 8,16,...64 in des order, implies 0, 8, 16, ...
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)
39
k5_des_fixup_key_parity(unsigned char *keybits)
43
for (i = 0; i < 8; i++) {
45
keybits[i] |= 1^parity_char(keybits[i]);
49
/* The following are the weak DES keys: */
50
static const unsigned char weak[16][8] = {
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},
58
{0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe},
59
{0xfe,0x01,0xfe,0x01,0xfe,0x01,0xfe,0x01},
61
{0x1f,0xe0,0x1f,0xe0,0x0e,0xf1,0x0e,0xf1},
62
{0xe0,0x1f,0xe0,0x1f,0xf1,0x0e,0xf1,0x0e},
64
{0x01,0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1},
65
{0xe0,0x01,0xe0,0x01,0xf1,0x01,0xf1,0x01},
67
{0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e,0xfe},
68
{0xfe,0x1f,0xfe,0x1f,0xfe,0x0e,0xfe,0x0e},
70
{0x01,0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e},
71
{0x1f,0x01,0x1f,0x01,0x0e,0x01,0x0e,0x01},
73
{0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1,0xfe},
74
{0xfe,0xe0,0xfe,0xe0,0xfe,0xf1,0xfe,0xf1}
78
k5_des_is_weak_key(unsigned char *keybits)
82
for (i = 0; i < sizeof(weak) / 8; i++) {
83
if (memcmp(weak[i], keybits, 8) == 0)