aes-wrap.c

Go to the documentation of this file.
00001 
00017 #include "includes.h"
00018 
00019 #include "common.h"
00020 #include "aes.h"
00021 
00032 int aes_wrap(const u8 *kek, int n, const u8 *plain, u8 *cipher)
00033 {
00034         u8 *a, *r, b[16];
00035         int i, j;
00036         void *ctx;
00037 
00038         a = cipher;
00039         r = cipher + 8;
00040 
00041         /* 1) Initialize variables. */
00042         os_memset(a, 0xa6, 8);
00043         os_memcpy(r, plain, 8 * n);
00044 
00045         ctx = aes_encrypt_init(kek, 16);
00046         if (ctx == NULL)
00047                 return -1;
00048 
00049         /* 2) Calculate intermediate values.
00050          * For j = 0 to 5
00051          *     For i=1 to n
00052          *         B = AES(K, A | R[i])
00053          *         A = MSB(64, B) ^ t where t = (n*j)+i
00054          *         R[i] = LSB(64, B)
00055          */
00056         for (j = 0; j <= 5; j++) {
00057                 r = cipher + 8;
00058                 for (i = 1; i <= n; i++) {
00059                         os_memcpy(b, a, 8);
00060                         os_memcpy(b + 8, r, 8);
00061                         aes_encrypt(ctx, b, b);
00062                         os_memcpy(a, b, 8);
00063                         a[7] ^= n * j + i;
00064                         os_memcpy(r, b + 8, 8);
00065                         r += 8;
00066                 }
00067         }
00068         aes_encrypt_deinit(ctx);
00069 
00070         /* 3) Output the results.
00071          *
00072          * These are already in @cipher due to the location of temporary
00073          * variables.
00074          */
00075 
00076         return 0;
00077 }
00078 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines

Generated on Sat Nov 21 23:16:50 2009 for hostapd by  doxygen 1.6.1