cleanup: remove md5 helper functions
PATCH 1/1 cleanup: remove md5 helper functions
The MD5 wrapper functions were used in just a few places, which imho is not worth the extra code. Instead of using these wrappers, just use the generic md_ctx_*() functions directly.
The md5sum() function was only used for logging information that was not useful to a user; first the full options string would be printed, and later just the hash. That hash is less informative than the full string, so why print it at all?
Finally, also removed save_pulled_options_digest(). The two times it was called, it executed either one of the possible branches in the function, where one of these needed a comment to explain what passing NULL as newdigest is supposed to do...
--- src/openvpn/crypto.c | 58 -------------------------------------------------- src/openvpn/crypto.h | 20 ----------------- src/openvpn/errlevel.h | 1 - src/openvpn/init.c | 56 ++++++++++++++++++++++-------------------------- src/openvpn/openvpn.h | 6 +++--- src/openvpn/push.c | 9 ++++---- 6 files changed, 33 insertions(+), 117 deletions(-)
src/openvpn/crypto.c +0 -58
@@ -1335,62 +1335,4 @@ get_random() return l; } -/* -* md5 functions -*/ - -const char * -md5sum (uint8_t *buf,int len,int n_print_chars,struct gc_arena *gc) -{ -uint8_t digest[MD5_DIGEST_LENGTH ]; -const md_kt_t *md5_kt =md_kt_get ("MD5" ); - -md_full (md5_kt, buf, len, digest); - -return format_hex (digest,MD5_DIGEST_LENGTH , n_print_chars, gc); -} - -void -md5_state_init (struct md5_state *s) -{ -const md_kt_t *md5_kt =md_kt_get ("MD5" ); - -md_ctx_init (&s->ctx, md5_kt); -} - -void -md5_state_update (struct md5_state *s,void *data,size_t len) -{ -md_ctx_update (&s->ctx, data, len); -} - -void -md5_state_final (struct md5_state *s,struct md5_digest *out) -{ -md_ctx_final (&s->ctx, out->digest); -md_ctx_cleanup (&s->ctx); -} - -void -md5_digest_clear (struct md5_digest *digest) -{ -CLEAR (*digest); -} - -bool -md5_digest_defined (const struct md5_digest *digest) -{ -int i; -for (i =0 ; i <MD5_DIGEST_LENGTH ; ++i) -if (digest->digest[i]) -return true; -return false; -} - -bool -md5_digest_equal (const struct md5_digest *d1,const struct md5_digest *d2) -{ -return memcmp (d1->digest, d2->digest,MD5_DIGEST_LENGTH ) ==0 ; -} -#endif /* ENABLE_CRYPTO */
src/openvpn/crypto.h +0 -20
@@ -421,26 +421,6 @@ void get_tls_handshake_key (const struct key_type *key_type, const unsigned int flags);/* -* md5 functions -*/ - -struct md5_state { -md_ctx_t ctx; -}; - -struct md5_digest { -uint8_t digest [MD5_DIGEST_LENGTH ]; -}; - -const char *md5sum (uint8_t *buf,int len,int n_print_chars,struct gc_arena *gc); -void md5_state_init (struct md5_state *s); -void md5_state_update (struct md5_state *s,void *data,size_t len); -void md5_state_final (struct md5_state *s,struct md5_digest *out); -void md5_digest_clear (struct md5_digest *digest); -bool md5_digest_defined (const struct md5_digest *digest); -bool md5_digest_equal (const struct md5_digest *d1,const struct md5_digest *d2); - -/* * Inline functions */
src/openvpn/errlevel.h +0 -1
@@ -105,7 +105,6 @@#define D_X509_ATTR LOGLEV(4, 59, 0)/* show x509-track attributes on connection */ #define D_INIT_MEDIUM LOGLEV(4, 60, 0)/* show medium frequency init messages */ #define D_MTU_INFO LOGLEV(4, 61, 0)/* show terse MTU info */ -#define D_SHOW_OCC_HASH LOGLEV(4, 62, 0)/* show MD5 hash of option compatibility string */ #define D_PID_DEBUG_LOW LOGLEV(4, 63, 0)/* show low-freq packet-id debugging info */ #define D_PID_DEBUG_MEDIUM LOGLEV(4, 64, 0)/* show medium-freq packet-id debugging info */
src/openvpn/init.c +25 -31
94 lines not on this page · raw message
src/openvpn/openvpn.h +3 -3
@@ -202,7 +202,7 @@ struct context_1#endif /* if client mode, hash of option strings we pulled from server */ -struct md5_digest pulled_options_digest_save; +uint8_t pulled_options_digest_save[MD5_DIGEST_LENGTH ];/**< Hash of option strings received from the * remote OpenVPN server. Only used in * client-mode. */
@@ -467,8 +467,8 @@ struct context_2/* hash of pulled options, so we can compare when options change */ bool pulled_options_md5_init_done; -struct md5_state pulled_options_state; -struct md5_digest pulled_options_digest; +md_ctx_t pulled_options_state; +uint8_t pulled_options_digest[MD5_DIGEST_LENGTH ];struct event_timeout server_poll_interval;
src/openvpn/push.c +5 -4
@@ -465,7 +465,7 @@ process_incoming_push_msg (struct context *c,struct buffer buf_orig = buf;if (!c->c2.pulled_options_md5_init_done) { -md5_state_init (&c->c2.pulled_options_state); +md_ctx_init (&c->c2.pulled_options_state,md_kt_get ("MD5" )); c->c2.pulled_options_md5_init_done = true; }if (!c->c2.did_pre_pull_restore)
@@ -482,13 +482,14 @@ process_incoming_push_msg (struct context *c, {case 0 :case 1 : -md5_state_update (&c->c2.pulled_options_state,BPTR (&buf_orig),BLEN (&buf_orig)); -md5_state_final (&c->c2.pulled_options_state, &c->c2.pulled_options_digest); +md_ctx_update (&c->c2.pulled_options_state,BPTR (&buf_orig),BLEN (&buf_orig)); +md_ctx_final (&c->c2.pulled_options_state, c->c2.pulled_options_digest); +md_ctx_cleanup (&c->c2.pulled_options_state); c->c2.pulled_options_md5_init_done = false; ret =PUSH_MSG_REPLY ;break ;case 2 : -md5_state_update (&c->c2.pulled_options_state,BPTR (&buf_orig),BLEN (&buf_orig)); +md_ctx_update (&c->c2.pulled_options_state,BPTR (&buf_orig),BLEN (&buf_orig)); ret =PUSH_MSG_CONTINUATION ;break ; }
Signature · 1 line
2.1.4
ACK.
Your patch has been applied to the master branch.
commit 827de237860813d2859aaae3aca292d42a9c2a82
Author: Steffan Karger Date: Sun May 3 17:07:11 2015 +0200
cleanup: remove md5 helper functions
Signed-off-by: Steffan Karger <[email protected]...>
Acked-by: Gert Doering <[email protected]...>
Message-Id: <[email protected]...>
URL: http://article.gmane.org/gmane.network.openvpn.devel/9642
Signed-off-by: Gert Doering <[email protected]...>--
kind regards,
Gert Doering