~ubuntu-branches/ubuntu/vivid/wpasupplicant/vivid

« back to all changes in this revision

Viewing changes to crypto_gnutls.c

  • Committer: Bazaar Package Importer
  • Author(s): Kel Modderman
  • Date: 2008-03-12 20:03:04 UTC
  • mfrom: (1.1.10 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080312200304-4331y9wj46pdd34z
Tags: 0.6.3-1
* New upstream release.
* Drop patches applied upstream:
  - debian/patches/30_wpa_gui_qt4_eventhistoryui_rework.patch
  - debian/patches/31_wpa_gui_qt4_eventhistory_always_scrollbar.patch
  - debian/patches/32_wpa_gui_qt4_eventhistory_scroll_with_events.patch
  - debian/patches/40_dbus_ssid_data.patch
* Tidy up the clean target of debian/rules. Now that the madwifi headers are
  handled differently we no longer need to do any cleanup.
* Fix formatting error in debian/ifupdown/wpa_action.8 to make lintian
  quieter.
* Add patch to fix formatting errors in manpages build from sgml source. Use
  <emphasis> tags to hightlight keywords instead of surrounding them in
  strong quotes.
  - debian/patches/41_manpage_format_fixes.patch
* wpasupplicant binary package no longer suggests pcscd, guessnet, iproute
  or wireless-tools, nor does it recommend dhcp3-client. These are not
  needed.
* Add debian/patches/10_silence_siocsiwauth_icotl_failure.patch to disable
  ioctl failure messages that occur under normal conditions.
* Cherry pick two upstream git commits concerning the dbus interface:
  - debian/patches/11_avoid_dbus_version_namespace.patch
  - debian/patches/12_fix_potential_use_after_free.patch
* Add debian/patches/42_manpage_explain_available_drivers.patch to explain
  that not all of the driver backends are available in the provided
  wpa_supplicant binary, and that the canonical list of supported driver
  backends can be retrieved from the wpa_supplicant -h (help) output.
  (Closes: #466910)
* Add debian/patches/20_wpa_gui_qt4_disable_link_prl.patch to remove
  link_prl CONFIG compile flag added by qmake-qt4 >= 4.3.4-2 to avoid excess
  linking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * WPA Supplicant / wrapper functions for libgcrypt
3
 
 * Copyright (c) 2004-2005, Jouni Malinen <j@w1.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 "includes.h"
16
 
#include <gcrypt.h>
17
 
 
18
 
#include "common.h"
19
 
#include "crypto.h"
20
 
 
21
 
void md4_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
22
 
{
23
 
        gcry_md_hd_t hd;
24
 
        unsigned char *p;
25
 
        size_t i;
26
 
 
27
 
        if (gcry_md_open(&hd, GCRY_MD_MD4, 0) != GPG_ERR_NO_ERROR)
28
 
                return;
29
 
        for (i = 0; i < num_elem; i++)
30
 
                gcry_md_write(hd, addr[i], len[i]);
31
 
        p = gcry_md_read(hd, GCRY_MD_MD4);
32
 
        if (p)
33
 
                memcpy(mac, p, gcry_md_get_algo_dlen(GCRY_MD_MD4));
34
 
        gcry_md_close(hd);
35
 
}
36
 
 
37
 
 
38
 
void des_encrypt(const u8 *clear, const u8 *key, u8 *cypher)
39
 
{
40
 
        gcry_cipher_hd_t hd;
41
 
        u8 pkey[8], next, tmp;
42
 
        int i;
43
 
 
44
 
        /* Add parity bits to the key */
45
 
        next = 0;
46
 
        for (i = 0; i < 7; i++) {
47
 
                tmp = key[i];
48
 
                pkey[i] = (tmp >> i) | next | 1;
49
 
                next = tmp << (7 - i);
50
 
        }
51
 
        pkey[i] = next | 1;
52
 
 
53
 
        gcry_cipher_open(&hd, GCRY_CIPHER_DES, GCRY_CIPHER_MODE_ECB, 0);
54
 
        gcry_err_code(gcry_cipher_setkey(hd, pkey, 8));
55
 
        gcry_cipher_encrypt(hd, cypher, 8, clear, 8);
56
 
        gcry_cipher_close(hd);
57
 
}
58
 
 
59
 
 
60
 
#ifdef EAP_TLS_FUNCS
61
 
void md5_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
62
 
{
63
 
        gcry_md_hd_t hd;
64
 
        unsigned char *p;
65
 
        size_t i;
66
 
 
67
 
        if (gcry_md_open(&hd, GCRY_MD_MD5, 0) != GPG_ERR_NO_ERROR)
68
 
                return;
69
 
        for (i = 0; i < num_elem; i++)
70
 
                gcry_md_write(hd, addr[i], len[i]);
71
 
        p = gcry_md_read(hd, GCRY_MD_MD5);
72
 
        if (p)
73
 
                memcpy(mac, p, gcry_md_get_algo_dlen(GCRY_MD_MD5));
74
 
        gcry_md_close(hd);
75
 
}
76
 
 
77
 
 
78
 
void sha1_vector(size_t num_elem, const u8 *addr[], const size_t *len, u8 *mac)
79
 
{
80
 
        gcry_md_hd_t hd;
81
 
        unsigned char *p;
82
 
        size_t i;
83
 
 
84
 
        if (gcry_md_open(&hd, GCRY_MD_SHA1, 0) != GPG_ERR_NO_ERROR)
85
 
                return;
86
 
        for (i = 0; i < num_elem; i++)
87
 
                gcry_md_write(hd, addr[i], len[i]);
88
 
        p = gcry_md_read(hd, GCRY_MD_SHA1);
89
 
        if (p)
90
 
                memcpy(mac, p, gcry_md_get_algo_dlen(GCRY_MD_SHA1));
91
 
        gcry_md_close(hd);
92
 
}
93
 
 
94
 
 
95
 
int fips186_2_prf(const u8 *seed, size_t seed_len, u8 *x, size_t xlen)
96
 
{
97
 
        /* FIX: how to do this with libgcrypt? */
98
 
        return -1;
99
 
}
100
 
 
101
 
 
102
 
void * aes_encrypt_init(const u8 *key, size_t len)
103
 
{
104
 
        gcry_cipher_hd_t hd;
105
 
 
106
 
        if (gcry_cipher_open(&hd, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_ECB, 0) !=
107
 
            GPG_ERR_NO_ERROR) {
108
 
                printf("cipher open failed\n");
109
 
                return NULL;
110
 
        }
111
 
        if (gcry_cipher_setkey(hd, key, len) != GPG_ERR_NO_ERROR) {
112
 
                printf("setkey failed\n");
113
 
                gcry_cipher_close(hd);
114
 
                return NULL;
115
 
        }
116
 
 
117
 
        return hd;
118
 
}
119
 
 
120
 
 
121
 
void aes_encrypt(void *ctx, const u8 *plain, u8 *crypt)
122
 
{
123
 
        gcry_cipher_hd_t hd = ctx;
124
 
        gcry_cipher_encrypt(hd, crypt, 16, plain, 16);
125
 
}
126
 
 
127
 
 
128
 
void aes_encrypt_deinit(void *ctx)
129
 
{
130
 
        gcry_cipher_hd_t hd = ctx;
131
 
        gcry_cipher_close(hd);
132
 
}
133
 
 
134
 
 
135
 
void * aes_decrypt_init(const u8 *key, size_t len)
136
 
{
137
 
        gcry_cipher_hd_t hd;
138
 
 
139
 
        if (gcry_cipher_open(&hd, GCRY_CIPHER_AES, GCRY_CIPHER_MODE_ECB, 0) !=
140
 
            GPG_ERR_NO_ERROR)
141
 
                return NULL;
142
 
        if (gcry_cipher_setkey(hd, key, len) != GPG_ERR_NO_ERROR) {
143
 
                gcry_cipher_close(hd);
144
 
                return NULL;
145
 
        }
146
 
 
147
 
        return hd;
148
 
}
149
 
 
150
 
 
151
 
void aes_decrypt(void *ctx, const u8 *crypt, u8 *plain)
152
 
{
153
 
        gcry_cipher_hd_t hd = ctx;
154
 
        gcry_cipher_decrypt(hd, plain, 16, crypt, 16);
155
 
}
156
 
 
157
 
 
158
 
void aes_decrypt_deinit(void *ctx)
159
 
{
160
 
        gcry_cipher_hd_t hd = ctx;
161
 
        gcry_cipher_close(hd);
162
 
}
163
 
#endif /* EAP_TLS_FUNCS */