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 /******************************************************************************/
32 #include "airpdcap_rijndael.h"
34 #include "airpdcap_debug.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.
44 AES_unwrap(UCHAR
*kek
, UINT16 key_len
, UCHAR
*cipher_text
, UINT16 cipher_len
, UCHAR
*output
)
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);
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
){
72 /* DEBUG_DUMP("a", a, 8); */
75 /* DEBUG_DUMP("a plus t", b, 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) */
86 /* DEBUG_DUMP("a", a, 8); */
87 /* DEBUG_DUMP("output", output, cipher_len - 8); */
93 /******************************************************************************/