TS-1800: Add new hash function implementation of MD5

Project: http://git-wip-us.apache.org/repos/asf/trafficserver/repo
Commit: http://git-wip-us.apache.org/repos/asf/trafficserver/commit/524f8d75
Tree: http://git-wip-us.apache.org/repos/asf/trafficserver/tree/524f8d75
Diff: http://git-wip-us.apache.org/repos/asf/trafficserver/diff/524f8d75

Branch: refs/heads/master
Commit: 524f8d7579c53378053595d2428cc36ccb94273e
Parents: 709650e
Author: Phil Sorber <[email protected]>
Authored: Fri Aug 8 12:48:36 2014 -0600
Committer: Phil Sorber <[email protected]>
Committed: Fri Aug 8 16:05:35 2014 -0600

----------------------------------------------------------------------
 lib/ts/HashMD5.cc  | 69 +++++++++++++++++++++++++++++++++++++++++++++++++
 lib/ts/HashMD5.h   | 44 +++++++++++++++++++++++++++++++
 lib/ts/Makefile.am |  2 ++
 lib/ts/libts.h     |  1 +
 4 files changed, 116 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafficserver/blob/524f8d75/lib/ts/HashMD5.cc
----------------------------------------------------------------------
diff --git a/lib/ts/HashMD5.cc b/lib/ts/HashMD5.cc
new file mode 100644
index 0000000..c2607ad
--- /dev/null
+++ b/lib/ts/HashMD5.cc
@@ -0,0 +1,69 @@
+/** @file
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#include "HashMD5.h"
+
+ATSHashMD5::ATSHashMD5(void) {
+    EVP_DigestInit(&ctx, EVP_md5());
+    md_len = 0;
+    finalized = false;
+}
+
+void
+ATSHashMD5::update(const void *data, size_t len) {
+    if (!finalized) {
+        EVP_DigestUpdate(&ctx, data, len);
+    }
+}
+
+void
+ATSHashMD5::final(void) {
+    if (!finalized) {
+        EVP_DigestFinal_ex(&ctx, md_value, &md_len);
+        finalized = true;
+    }
+}
+
+const void *
+ATSHashMD5::get(void) const {
+    if (finalized) {
+        return (void *) md_value;
+    } else {
+        return NULL;
+    }
+}
+
+size_t
+ATSHashMD5::size(void) const {
+    return EVP_MD_CTX_size(&ctx);
+}
+
+void
+ATSHashMD5::clear(void) {
+    EVP_MD_CTX_cleanup(&ctx);
+    EVP_DigestInit(&ctx, EVP_md5());
+    md_len = 0;
+    finalized = false;
+}
+
+ATSHashMD5::~ATSHashMD5() {
+    EVP_MD_CTX_cleanup(&ctx);
+}

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/524f8d75/lib/ts/HashMD5.h
----------------------------------------------------------------------
diff --git a/lib/ts/HashMD5.h b/lib/ts/HashMD5.h
new file mode 100644
index 0000000..bcf2d0b
--- /dev/null
+++ b/lib/ts/HashMD5.h
@@ -0,0 +1,44 @@
+/** @file
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#ifndef __HASH_MD5_H__
+#define __HASH_MD5_H__
+
+#include "Hash.h"
+#include <openssl/evp.h>
+
+struct ATSHashMD5 : ATSHash {
+    ATSHashMD5(void);
+    void update(const void *data, size_t len);
+    void final(void);
+    const void *get(void) const;
+    size_t size(void) const;
+    void clear(void);
+    ~ATSHashMD5();
+
+private:
+    EVP_MD_CTX ctx;
+    unsigned char md_value[EVP_MAX_MD_SIZE];
+    unsigned int md_len;
+    bool finalized;
+};
+
+#endif

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/524f8d75/lib/ts/Makefile.am
----------------------------------------------------------------------
diff --git a/lib/ts/Makefile.am b/lib/ts/Makefile.am
index 25e357b..acc55d7 100644
--- a/lib/ts/Makefile.am
+++ b/lib/ts/Makefile.am
@@ -56,6 +56,8 @@ libtsutil_la_SOURCES = \
   Hash.h \
   HashFNV.cc \
   HashFNV.h \
+  HashMD5.cc \
+  HashMD5.h \
   HostLookup.cc \
   HostLookup.h \
   INK_MD5.h \

http://git-wip-us.apache.org/repos/asf/trafficserver/blob/524f8d75/lib/ts/libts.h
----------------------------------------------------------------------
diff --git a/lib/ts/libts.h b/lib/ts/libts.h
index 1e05251..164780a 100644
--- a/lib/ts/libts.h
+++ b/lib/ts/libts.h
@@ -83,6 +83,7 @@
 #include "EventNotify.h"
 #include "Hash.h"
 #include "HashFNV.h"
+#include "HashMD5.h"
 #include "I_Version.h"
 #include "InkPool.h"
 #include "List.h"

Reply via email to