HACK: pinfo->private_data points to smb_info again
[wireshark-wip.git] / epan / crypt / airpdcap_rijndael.c
blob1f70c45e06d0522175583a4c147a969f325ce24e
1 /**
2 * airpdcap_rijndael.c
4 * $Id$
6 * @version 3.0 (December 2000)
8 * Optimised ANSI C code for the Rijndael cipher (now AES)
10 * @author Vincent Rijmen <vincent.rijmen@esat.kuleuven.ac.be>
11 * @author Antoon Bosselaers <antoon.bosselaers@esat.kuleuven.ac.be>
12 * @author Paulo Barreto <paulo.barreto@terra.com.br>
14 * This code is hereby placed in the public domain.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ''AS IS'' AND ANY EXPRESS
17 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
26 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 /******************************************************************************/
30 /* File includes */
31 /* */
32 #include "airpdcap_rijndael.h"
34 #include "airpdcap_debug.h"
35 #include <glib.h>
36 #include <wsutil/aes.h>
38 /* Based on RFC 3394 and NIST AES Key Wrap Specification pseudo-code.
40 This function is used to unwrap an encrypted AES key. One example of its use is
41 in the WPA-2 protocol to get the group key.
43 UCHAR
44 AES_unwrap(UCHAR *kek, UINT16 key_len, UCHAR *cipher_text, UINT16 cipher_len, UCHAR *output)
46 UCHAR a[8], b[16];
47 UCHAR *r;
48 UCHAR *c;
49 gint16 i, j, n;
50 rijndael_ctx ctx;
52 if (! kek || cipher_len < 16 || ! cipher_text || ! output) {
53 return 1; /* We don't do anything with the return value */
56 /* Initialize variables */
58 n = (cipher_len/8)-1; /* the algorithm works on 64-bits at a time */
59 memcpy(a, cipher_text, 8);
60 r = output;
61 c = cipher_text;
62 memcpy(r, c+8, cipher_len - 8);
64 /* Compute intermediate values */
66 for (j=5; j >= 0; --j){
67 r = output + (n - 1) * 8;
68 /* DEBUG_DUMP("r1", (r-8), 8); */
69 /* DEBUG_DUMP("r2", r, 8); */
70 for (i = n; i >= 1; --i){
71 UINT16 t = (n*j) + i;
72 /* DEBUG_DUMP("a", a, 8); */
73 memcpy(b, a, 8);
74 b[7] ^= t;
75 /* DEBUG_DUMP("a plus t", b, 8); */
76 memcpy(b+8, r, 8);
77 rijndael_set_key(&ctx, kek, key_len*8 /*bits*/);
78 rijndael_decrypt(&ctx, b, b); /* NOTE: we are using the same src and dst buffer. It's ok. */
79 /* DEBUG_DUMP("aes decrypt", b, 16) */
80 memcpy(a,b,8);
81 memcpy(r, b+8, 8);
82 r -= 8;
86 /* DEBUG_DUMP("a", a, 8); */
87 /* DEBUG_DUMP("output", output, cipher_len - 8); */
89 return 0;
92 /* */
93 /******************************************************************************/