labs-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pque...@apache.org
Subject svn commit: r744730 - in /labs/orthrus/trunk: SConstruct include/private/context.h src/core.c src/md5.c
Date Sun, 15 Feb 2009 19:52:28 GMT
Author: pquerna
Date: Sun Feb 15 19:52:28 2009
New Revision: 744730

URL: http://svn.apache.org/viewvc?rev=744730&view=rev
Log:
Move md5 code into its own file, and start making a basic API for hash algorithms.

Added:
    labs/orthrus/trunk/src/md5.c   (with props)
Modified:
    labs/orthrus/trunk/SConstruct
    labs/orthrus/trunk/include/private/context.h
    labs/orthrus/trunk/src/core.c

Modified: labs/orthrus/trunk/SConstruct
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/SConstruct?rev=744730&r1=744729&r2=744730&view=diff
==============================================================================
--- labs/orthrus/trunk/SConstruct (original)
+++ labs/orthrus/trunk/SConstruct Sun Feb 15 19:52:28 2009
@@ -48,7 +48,8 @@
 
 lib = env.SharedLibrary(target='orthrus-%d' % (orthrus_major),
                         source = ['src/core.c', 'src/error.c', 
-                                  'src/hex.c', 'src/words.c'])
+                                  'src/hex.c', 'src/words.c',
+                                  'src/md5.c'])
 
 headers = env.Glob('include/*.h')
 

Modified: labs/orthrus/trunk/include/private/context.h
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/include/private/context.h?rev=744730&r1=744729&r2=744730&view=diff
==============================================================================
--- labs/orthrus/trunk/include/private/context.h (original)
+++ labs/orthrus/trunk/include/private/context.h Sun Feb 15 19:52:28 2009
@@ -28,10 +28,21 @@
   apr_pool_t *pool;
 };
 
+
+orthrus_error_t* orthrus__alg_md5_fold(const char *seed,
+                                       apr_size_t slen,
+                                       const char *pw,
+                                       apr_size_t pwlen,
+                                       orthrus_response_t *reply);
+
+orthrus_error_t* orthrus__alg_md5_cycle(apr_uint64_t sequence, 
+                                        orthrus_response_t *reply);
+
 void orthrus__format_hex(orthrus_response_t *reply, apr_pool_t *pool);
 void orthrus__format_words(orthrus_response_t *reply, apr_pool_t *pool);
 
 struct orthrus_response_t {
+  apr_pool_t *pool;
   apr_uint64_t reply;
   const char hex[(8 * 2) + 4 + 1];
   const char *words;

Modified: labs/orthrus/trunk/src/core.c
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/src/core.c?rev=744730&r1=744729&r2=744730&view=diff
==============================================================================
--- labs/orthrus/trunk/src/core.c (original)
+++ labs/orthrus/trunk/src/core.c Sun Feb 15 19:52:28 2009
@@ -17,8 +17,7 @@
 #include "orthrus.h"
 #include "private/context.h"
 #include "apr_strings.h"
-#include <ctype.h>
-#include "apr_md5.h"
+#include <ctype.h> /* for tolower */
 
 orthrus_error_t* orthrus_create(apr_pool_t *pool, orthrus_t **out_ort)
 {
@@ -52,6 +51,7 @@
                                    apr_size_t pwlen,
                                    apr_pool_t *pool)
 {
+  orthrus_error_t* err;
   apr_size_t slen;
   char *seed;
   orthrus_response_t *reply;
@@ -86,40 +86,24 @@
   }
 
   
-  /* TODO: Refactor algorithm's into separate functions/callbacks or something */
-  {
-    int i,j;
-    unsigned char digest[APR_MD5_DIGESTSIZE];
-    apr_md5_ctx_t md5;
-    
-    apr_md5_init(&md5);
-
-    apr_md5_update(&md5, seed, slen);
-    apr_md5_update(&md5, pw, pwlen);
-    
-    apr_md5_final(digest, &md5);
-
-    for (j = 0; j < 8; j++) {
-      digest[j] ^= digest[j+8];
-    }
-    
-    for (i = 0; i < sequence; i++) {
-      apr_md5_init(&md5);
-      apr_md5_update(&md5, &digest[0], 8);
-      apr_md5_final(digest, &md5);
-      for (j = 0; j < 8; j++) {
-        digest[j] ^= digest[j+8];
-      }
-    }
-
-    reply = apr_pcalloc(pool, sizeof(orthrus_response_t));
-
-    memcpy(&reply->reply, &digest[0], 8);
-    
-    orthrus__format_hex(reply, pool);
-    orthrus__format_words(reply, pool);
+  reply = apr_pcalloc(pool, sizeof(orthrus_response_t));
+
+  reply->pool = pool;
+  
+  err = orthrus__alg_md5_fold(seed, slen, pw, pwlen, reply);
+
+  if (err) {
+    return err;
   }
 
+  err = orthrus__alg_md5_cycle(sequence, reply);
+  if (err) {
+    return err;
+  }
+
+  orthrus__format_hex(reply, pool);
+  orthrus__format_words(reply, pool);
+  
   *out_reply = reply;
 
   return ORTHRUS_SUCCESS;

Added: labs/orthrus/trunk/src/md5.c
URL: http://svn.apache.org/viewvc/labs/orthrus/trunk/src/md5.c?rev=744730&view=auto
==============================================================================
--- labs/orthrus/trunk/src/md5.c (added)
+++ labs/orthrus/trunk/src/md5.c Sun Feb 15 19:52:28 2009
@@ -0,0 +1,68 @@
+/* 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 "orthrus.h"
+#include "private/context.h"
+#include "apr_md5.h"
+
+orthrus_error_t* orthrus__alg_md5_fold(const char *seed,
+                                       apr_size_t slen,
+                                       const char *pw,
+                                       apr_size_t pwlen,
+                                       orthrus_response_t *reply)
+{
+  int j;
+  unsigned char digest[APR_MD5_DIGESTSIZE];
+  apr_md5_ctx_t md5;
+
+  apr_md5_init(&md5);
+
+  apr_md5_update(&md5, seed, slen);
+  apr_md5_update(&md5, pw, pwlen);
+
+  apr_md5_final(digest, &md5);
+  
+  for (j = 0; j < 8; j++) {
+    digest[j] ^= digest[j+8];
+  }
+
+  memcpy(&reply->reply, &digest[0], 8);
+
+  return ORTHRUS_SUCCESS;
+}
+
+orthrus_error_t* orthrus__alg_md5_cycle(apr_uint64_t sequence, 
+                                        orthrus_response_t *reply)
+{
+  int i,j;
+  unsigned char digest[APR_MD5_DIGESTSIZE];
+  apr_md5_ctx_t md5;
+
+  memcpy(&digest[0], &reply->reply, 8);
+
+  for (i = 0; i < sequence; i++) {
+    apr_md5_init(&md5);
+    apr_md5_update(&md5, &digest[0], 8);
+    apr_md5_final(digest, &md5);
+    for (j = 0; j < 8; j++) {
+      digest[j] ^= digest[j+8];
+    }
+  }
+
+  memcpy(&reply->reply, &digest[0], 8);
+
+  return ORTHRUS_SUCCESS;
+}

Propchange: labs/orthrus/trunk/src/md5.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: labs/orthrus/trunk/src/md5.c
------------------------------------------------------------------------------
    svn:keywords = Date Revision Author HeadURL Id

Propchange: labs/orthrus/trunk/src/md5.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@labs.apache.org
For additional commands, e-mail: commits-help@labs.apache.org


Mime
View raw message