Store the length field of the encrypted key in network byte order
authorJohn Carr <jfc@mit.edu>
Fri, 6 Dec 1991 13:18:16 +0000 (13:18 +0000)
committerJohn Carr <jfc@mit.edu>
Fri, 6 Dec 1991 13:18:16 +0000 (13:18 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2195 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/kdb/decrypt_key.c
src/lib/kdb/encrypt_key.c

index d99156af427f7e2329c5089723e0b8c69b7c285a..811727b3559c2f5deec0a37db88dd328dfdbb2b7 100644 (file)
@@ -47,11 +47,11 @@ krb5_encrypt_block *eblock;
 const krb5_encrypted_keyblock *in;
 krb5_keyblock *out;
 {
+    int length;
     krb5_error_code retval;
 
     /* the encrypted version is stored as the unencrypted key length
-       (in host byte order), followed by the encrypted key.
-     */
+       (4 bytes, MSB first) followed by the encrypted key. */
     out->keytype = in->keytype;
     out->length = krb5_encrypt_size(in->length-sizeof(in->length),
                                    eblock->crypto_entry);
@@ -62,7 +62,11 @@ krb5_keyblock *out;
        return ENOMEM;
     }
     /* copy out the real length count */
-    memcpy((char *)&out->length, (char *)in->contents, sizeof(out->length));
+    length  = ((unsigned char *)in->contents)[0] << 24;
+    length += ((unsigned char *)in->contents)[1] << 16;
+    length += ((unsigned char *)in->contents)[2] << 8;
+    length += ((unsigned char *)in->contents)[3];
+    out->length = length;
 
     /* remember the contents of the encrypted version has a sizeof(in->length)
        integer length of the real embedded key, followed by the
index f50efc9cbb4bd0c005b11d2257a3788549869668..293e84dd3263f2fb2c6b95ce15b48808358a2d5e 100644 (file)
@@ -51,6 +51,7 @@ krb5_encrypted_keyblock *out;
 
     krb5_error_code retval;
     krb5_keyblock tmpin;
+    int length;
 
     out->keytype = in->keytype;
     out->length = krb5_encrypt_size(in->length, eblock->crypto_entry);
@@ -63,7 +64,14 @@ krb5_encrypted_keyblock *out;
        out->length = 0;
        return ENOMEM;
     }
-    memcpy((char *)tmpin.contents, (const char *)in->contents, tmpin.length);
+    /* Convert length from MSB first to host byte order for the encryption
+       routine.  Assumes sizeof (int) is 4. */
+    length = ((((unsigned char*)in->contents)[0] << 24) + 
+             (((unsigned char*)in->contents)[1] << 16) + 
+             (((unsigned char*)in->contents)[2] << 8) + 
+             ((unsigned char*)in->contents)[3]);
+    memcpy((char *)tmpin.contents, (const char *)&length, 4);
+    memcpy((char *)tmpin.contents + 4, (const char *)in->contents + 4, tmpin.length);
 
     out->length += sizeof(out->length);
     out->contents = (krb5_octet *)malloc(out->length);