PR: 2297
[openssl.git] / crypto / aes / aes_wrap.c
index ba62b55a9f4c8f90341b49ce6bbf45ba8b033260..a9aebfe9b0c0496a133cf39c88863b202f685a16 100644 (file)
 #include <openssl/aes.h>
 #include <openssl/bio.h>
 
+static const unsigned char default_iv[] = {
+  0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6,
+};
+
 int AES_wrap_key(AES_KEY *key, const unsigned char *iv,
                unsigned char *out,
                const unsigned char *in, unsigned int inlen)
@@ -81,9 +85,9 @@ int AES_wrap_key(AES_KEY *key, const unsigned char *iv,
                        A[7] ^= (unsigned char)(t & 0xff);
                        if (t > 0xff)   
                                {
-                               A[6] ^= (unsigned char)((t & 0xff) >> 8);
-                               A[5] ^= (unsigned char)((t & 0xff) >> 16);
-                               A[4] ^= (unsigned char)((t & 0xff) >> 24);
+                               A[6] ^= (unsigned char)((t >> 8) & 0xff);
+                               A[5] ^= (unsigned char)((t >> 16) & 0xff);
+                               A[4] ^= (unsigned char)((t >> 24) & 0xff);
                                }
                        memcpy(R, B + 8, 8);
                        }
@@ -195,10 +199,6 @@ static const unsigned char key[] = {
   0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f
 };
 
-static const unsigned char default_iv[] = {
-  0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6, 0xA6,
-};
-
 static const unsigned char e1[] = {
   0x1f, 0xa6, 0x8b, 0x0a, 0x81, 0x12, 0xb4, 0x47,
   0xae, 0xf3, 0x4b, 0xd8, 0xfb, 0x5a, 0x7b, 0x82,