~ubuntu-branches/ubuntu/lucid/wpasupplicant/lucid

« back to all changes in this revision

Viewing changes to crypto.c

  • Committer: Bazaar Package Importer
  • Author(s): Kyle McMartin
  • Date: 2005-02-15 00:51:28 UTC
  • Revision ID: james.westby@ubuntu.com-20050215005128-xr4m8owiunur2008
Tags: upstream-0.3.8
ImportĀ upstreamĀ versionĀ 0.3.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * WPA Supplicant / wrapper functions for libcrypto
 
3
 * Copyright (c) 2004-2005, Jouni Malinen <jkmaline@cc.hut.fi>
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License version 2 as
 
7
 * published by the Free Software Foundation.
 
8
 *
 
9
 * Alternatively, this software may be distributed under the terms of BSD
 
10
 * license.
 
11
 *
 
12
 * See README and COPYING for more details.
 
13
 */
 
14
 
 
15
#include <openssl/md4.h>
 
16
#include <openssl/des.h>
 
17
 
 
18
#include "common.h"
 
19
 
 
20
 
 
21
#if OPENSSL_VERSION_NUMBER < 0x00907000
 
22
#define DES_key_schedule des_key_schedule
 
23
#define DES_cblock des_cblock
 
24
#define DES_set_key(key, schedule) des_set_key((key), *(schedule))
 
25
#define DES_ecb_encrypt(input, output, ks, enc) \
 
26
        des_ecb_encrypt((input), (output), *(ks), (enc))
 
27
#endif /* openssl < 0.9.7 */
 
28
 
 
29
 
 
30
void md4_vector(size_t num_elem, const u8 *addr[], size_t *len, u8 *mac)
 
31
{
 
32
        MD4_CTX ctx;
 
33
        int i;
 
34
 
 
35
        MD4_Init(&ctx);
 
36
        for (i = 0; i < num_elem; i++)
 
37
                MD4_Update(&ctx, addr[i], len[i]);
 
38
        MD4_Final(mac, &ctx);
 
39
}
 
40
 
 
41
 
 
42
void md4(const u8 *addr, size_t len, u8 *mac)
 
43
{
 
44
        md4_vector(1, &addr, &len, mac);
 
45
}
 
46
 
 
47
 
 
48
/**
 
49
 * @clear: 8 octets (in)
 
50
 * @key: 7 octets (in) (no parity bits included)
 
51
 * @cypher: 8 octets (out)
 
52
 */
 
53
void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
 
54
{
 
55
        u8 pkey[8], next, tmp;
 
56
        int i;
 
57
        DES_key_schedule ks;
 
58
 
 
59
        /* Add parity bits to the key */
 
60
        next = 0;
 
61
        for (i = 0; i < 7; i++) {
 
62
                tmp = key[i];
 
63
                pkey[i] = (tmp >> i) | next | 1;
 
64
                next = tmp << (7 - i);
 
65
        }
 
66
        pkey[i] = next | 1;
 
67
 
 
68
        DES_set_key(&pkey, &ks);
 
69
        DES_ecb_encrypt((DES_cblock *) clear, (DES_cblock *) cypher, &ks,
 
70
                        DES_ENCRYPT);
 
71
}