From: John Carr Date: Sun, 23 Feb 1992 12:17:37 +0000 (+0000) Subject: sizeof (int) -> 4 bytes, because this is supposed to be a portable X-Git-Tag: krb5-1.0-beta2~235 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=13d9a51338239e37ee77f0b22cc784ee97fe822e;p=krb5.git sizeof (int) -> 4 bytes, because this is supposed to be a portable binary representation. Fix bug in writing length. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2227 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/kdb/encrypt_key.c b/src/lib/kdb/encrypt_key.c index 293e84dd3..c1a25783e 100644 --- a/src/lib/kdb/encrypt_key.c +++ b/src/lib/kdb/encrypt_key.c @@ -44,14 +44,15 @@ krb5_error_code krb5_kdb_encrypt_key(eblock, in, out) krb5_encrypt_block *eblock; const krb5_keyblock *in; -krb5_encrypted_keyblock *out; +register krb5_encrypted_keyblock *out; { - /* encrypted rep has the real (unencrypted) key length stored - along with the encrypted key */ + /* Encrypted rep has the real (unencrypted) key length stored + along with the encrypted key. The length is stored as a 4 + byte integer, MSB first. */ krb5_error_code retval; krb5_keyblock tmpin; - int length; + unsigned int length; out->keytype = in->keytype; out->length = krb5_encrypt_size(in->length, eblock->crypto_entry); @@ -64,14 +65,7 @@ krb5_encrypted_keyblock *out; out->length = 0; return ENOMEM; } - /* 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); + memcpy((char *)tmpin.contents, (const char *)in->contents, tmpin.length); out->length += sizeof(out->length); out->contents = (krb5_octet *)malloc(out->length); @@ -81,13 +75,15 @@ krb5_encrypted_keyblock *out; out->length = 0; return ENOMEM; } - /* copy in real length */ - memcpy((char *)out->contents, (const char *)&tmpin.length, - sizeof(out->length)); - /* and arrange for encrypted key */ + + length = tmpin.length; + ((char *)out->contents)[0] = length >> 24; + ((char *)out->contents)[1] = length >> 16; + ((char *)out->contents)[2] = length >> 8; + ((char *)out->contents)[3] = length; + retval = krb5_encrypt((krb5_pointer) tmpin.contents, - (krb5_pointer) (((char *) out->contents) + - sizeof(out->length)), + (krb5_pointer) ((char *) out->contents + 4), tmpin.length, eblock, 0); xfree(tmpin.contents); if (retval) { @@ -95,5 +91,6 @@ krb5_encrypted_keyblock *out; out->contents = 0; out->length = 0; } + return retval; }