1 /* Ref. RFC 3394 Advanced Encryption Standard (AES) Key Wrap Algorithm */
7 static uint64_t wrapmask(int n
)
12 return ((uint64_t)htonl(n
) << 32);
16 void aes128_unwrap(uint8_t key
[16], void* buf
, unsigned long len
)
25 aes128_init(&ae
, key
);
27 for(j
= 5; j
>= 0; j
--)
28 for(i
= n
; i
>= 1; i
--) {
29 R
[0] ^= wrapmask(n
*j
+ i
);
31 memcpy(B
+ 0, &R
[0], 8);
32 memcpy(B
+ 8, &R
[i
], 8);
34 aes128_decrypt(&ae
, B
);
36 memcpy(&R
[0], B
+ 0, 8);
37 memcpy(&R
[i
], B
+ 8, 8);