diff options
author | Greg Hudson <ghudson@mit.edu> | 2014-03-25 10:52:38 -0400 |
---|---|---|
committer | Greg Hudson <ghudson@mit.edu> | 2014-03-25 18:08:21 -0400 |
commit | 7d87754d7d4c0398c0504f2cae0937c0d005a339 (patch) | |
tree | 0708dd95a82030ea987f0e444715998b5a48c664 /src/lib/crypto/krb | |
parent | 6b9e570a7e98470b806a26c5119e53b2145e2586 (diff) | |
download | krb5-7d87754d7d4c0398c0504f2cae0937c0d005a339.tar.gz krb5-7d87754d7d4c0398c0504f2cae0937c0d005a339.tar.xz krb5-7d87754d7d4c0398c0504f2cae0937c0d005a339.zip |
Modernize default_state.c
Use alloc_data() and empty_data() where appropriate. Keep mainline
logic to the left where possible. Name the output parameter of
krb5int_des_init_state with an _out suffix. Use a professional tone
in comments. Partly based on a patch from Alok Menghrajani.
Diffstat (limited to 'src/lib/crypto/krb')
-rw-r--r-- | src/lib/crypto/krb/crypto_int.h | 2 | ||||
-rw-r--r-- | src/lib/crypto/krb/default_state.c | 27 |
2 files changed, 11 insertions, 18 deletions
diff --git a/src/lib/crypto/krb/crypto_int.h b/src/lib/crypto/krb/crypto_int.h index c2c6344bc..c0541447a 100644 --- a/src/lib/crypto/krb/crypto_int.h +++ b/src/lib/crypto/krb/crypto_int.h @@ -364,7 +364,7 @@ int krb5int_crypto_init(void); /* DES default state initialization handler (used by module enc providers). */ krb5_error_code krb5int_des_init_state(const krb5_keyblock *key, krb5_keyusage keyusage, - krb5_data *new_state); + krb5_data *state_out); /* Default state cleanup handler (used by module enc providers). */ void krb5int_default_free_state(krb5_data *state); diff --git a/src/lib/crypto/krb/default_state.c b/src/lib/crypto/krb/default_state.c index 121244871..c7bfe323f 100644 --- a/src/lib/crypto/krb/default_state.c +++ b/src/lib/crypto/krb/default_state.c @@ -1,6 +1,6 @@ /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */ /* - * Copyright (C) 2001 by the Massachusetts Institute of Technology. + * Copyright (C) 2001, 2014 by the Massachusetts Institute of Technology. * All rights reserved. * * Export of this software from the United States of America may @@ -34,28 +34,21 @@ krb5_error_code krb5int_des_init_state(const krb5_keyblock *key, krb5_keyusage usage, - krb5_data *new_state) + krb5_data *state_out) { - new_state->length = 8; - new_state->data = (void *) malloc(8); - if (new_state->data) { - memset (new_state->data, 0, new_state->length); - /* We need to copy in the key for des-cbc-cr--ick, but that's how it works*/ - if (key->enctype == ENCTYPE_DES_CBC_CRC) { - memcpy (new_state->data, key->contents, new_state->length); - } - } else { + if (alloc_data(state_out, 8)) return ENOMEM; - } + + /* des-cbc-crc uses the key as the initial ivec. */ + if (key->enctype == ENCTYPE_DES_CBC_CRC) + memcpy(state_out->data, key->contents, state_out->length); + return 0; } void krb5int_default_free_state(krb5_data *state) { - if (state->data) { - free (state->data); - state-> data = NULL; - state->length = 0; - } + free(state->data); + *state = empty_data(); } |