derekf pushed a commit to branch master.

http://git.enlightenment.org/core/enlightenment.git/commit/?id=d0b0f81fb761b85253b3617ce71dbb146fb88aa8

commit d0b0f81fb761b85253b3617ce71dbb146fb88aa8
Author: Derek Foreman <derekf@localhost.localdomain>
Date:   Wed Oct 12 05:36:31 2016 -0500

    teamwork: Use emile SHA1 functions
    
    Remove the SHA1 functions in the module in favour of the ones now present in
    EFL
---
 src/modules/Makefile_teamwork.mk  |   4 +-
 src/modules/teamwork/e_mod_main.c |  17 +----
 src/modules/teamwork/e_mod_main.h |   5 +-
 src/modules/teamwork/e_mod_tw.c   |   2 +-
 src/modules/teamwork/sha1.c       | 146 --------------------------------------
 src/modules/teamwork/sha1.h       |  54 --------------
 6 files changed, 8 insertions(+), 220 deletions(-)

diff --git a/src/modules/Makefile_teamwork.mk b/src/modules/Makefile_teamwork.mk
index 8abc04f..a157fc2 100644
--- a/src/modules/Makefile_teamwork.mk
+++ b/src/modules/Makefile_teamwork.mk
@@ -16,9 +16,7 @@ src_modules_teamwork_module_la_LDFLAGS = $(MOD_LDFLAGS)
 src_modules_teamwork_module_la_SOURCES = src/modules/teamwork/e_mod_main.c \
 src/modules/teamwork/e_mod_config.c \
 src/modules/teamwork/e_mod_main.h \
-src/modules/teamwork/e_mod_tw.c \
-src/modules/teamwork/sha1.c \
-src/modules/teamwork/sha1.h
+src/modules/teamwork/e_mod_tw.c
 
 if HAVE_WAYLAND
 src_modules_teamwork_module_la_SOURCES += \
diff --git a/src/modules/teamwork/e_mod_main.c 
b/src/modules/teamwork/e_mod_main.c
index ce24ef8..0be6ab4 100644
--- a/src/modules/teamwork/e_mod_main.c
+++ b/src/modules/teamwork/e_mod_main.c
@@ -1,5 +1,4 @@
 #include "e_mod_main.h"
-#include "sha1.h"
 
 EINTERN int _e_teamwork_log_dom = -1;
 EINTERN Mod *tw_mod = NULL;
@@ -30,23 +29,11 @@ _sha1_to_string(const unsigned char *hashout)
 }
 
 const char *
-sha1_encode(const unsigned char *data, size_t len)
+sha1_encode(const Eina_Binbuf *data)
 {
-   SHA_CTX2 ctx;
    unsigned char hashout[20];
-   unsigned char *buf;
 
-   if (EINA_UNLIKELY(len > 65000))
-     buf = malloc(len);
-   else
-     buf = alloca(len);
-   EINA_SAFETY_ON_NULL_RETURN_VAL(buf, NULL);
-   memcpy(buf, data, len);
-
-   SHA1_Init2(&ctx);
-   SHA1_Update2(&ctx, buf, len);
-   SHA1_Final2(hashout, &ctx);
-   if (EINA_UNLIKELY(len > 65000)) free(buf);
+   emile_binbuf_sha1(data, hashout);
    return _sha1_to_string(hashout);
 }
 
diff --git a/src/modules/teamwork/e_mod_main.h 
b/src/modules/teamwork/e_mod_main.h
index 9cb8695..e7f1d6a 100644
--- a/src/modules/teamwork/e_mod_main.h
+++ b/src/modules/teamwork/e_mod_main.h
@@ -1,6 +1,9 @@
 #ifndef E_MOD_MAIN_H
 #define E_MOD_MAIN_H
 
+/* We want emil_binbuf_sha1 which is beta API */
+#define EFL_BETA_API_SUPPORT
+
 #include "e.h"
 
 /**
@@ -45,7 +48,7 @@ extern Teamwork_Config *tw_config;
 extern Mod *tw_mod;
 extern int _e_teamwork_log_dom;
 
-EINTERN const char *sha1_encode(const unsigned char *data, size_t len);
+EINTERN const char *sha1_encode(const Eina_Binbuf *data);
 
 EINTERN int e_tw_init(void);
 EINTERN void e_tw_shutdown(void);
diff --git a/src/modules/teamwork/e_mod_tw.c b/src/modules/teamwork/e_mod_tw.c
index dae03d5..5c5ea3b 100644
--- a/src/modules/teamwork/e_mod_tw.c
+++ b/src/modules/teamwork/e_mod_tw.c
@@ -671,7 +671,7 @@ tw_media_add(const char *url, Eina_Binbuf *buf, unsigned 
long long timestamp, Ei
    if (!media[video]) return -1;
    if (!tw_config->allowed_media_age) return 0; //disk caching disabled
 
-   sha1 = sha1_encode(eina_binbuf_string_get(buf), 
eina_binbuf_length_get(buf));
+   sha1 = sha1_encode(buf);
    DBG("Media: %s - %s", url, sha1);
 
    list = eet_list(media[video], url, &lsize);
diff --git a/src/modules/teamwork/sha1.c b/src/modules/teamwork/sha1.c
deleted file mode 100644
index 7a53fa7..0000000
--- a/src/modules/teamwork/sha1.c
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- *
- * The Original Code is SHA 180-1 Reference Implementation (Compact version)
- *
- * The Initial Developer of the Original Code is Paul Kocher of
- * Cryptography Research.  Portions created by Paul Kocher are
- * Copyright (C) 1995-9 by Cryptography Research, Inc.  All
- * Rights Reserved.
- *
- * Contributor(s):
- *
- *     Paul Kocher
- *
- */
-
-#include "sha1.h"
-
-static void shaHashBlock(SHA_CTX2 *ctx);
-
-void
-SHA1_Init2(SHA_CTX2 *ctx) {
-   int i;
-
-   ctx->lenW = 0;
-   ctx->sizeHi = ctx->sizeLo = 0;
-
-   /* Initialize H with the magic constants (see FIPS180 for constants)
-    */
-   ctx->H[0] = 0x67452301;
-   ctx->H[1] = 0xefcdab89;
-   ctx->H[2] = 0x98badcfe;
-   ctx->H[3] = 0x10325476;
-   ctx->H[4] = 0xc3d2e1f0;
-
-   for (i = 0; i < 80; i++)
-     ctx->W[i] = 0;
-}
-
-void
-SHA1_Update2(SHA_CTX2 *ctx,
-             void     *_dataIn,
-             int       len) {
-   unsigned char *dataIn = _dataIn;
-   int i;
-
-   /* Read the data into W and process blocks as they get full
-    */
-   for (i = 0; i < len; i++) {
-        ctx->W[ctx->lenW / 4] <<= 8;
-        ctx->W[ctx->lenW / 4] |= (unsigned int)dataIn[i];
-        if ((++ctx->lenW) % 64 == 0)
-          {
-             shaHashBlock(ctx);
-             ctx->lenW = 0;
-          }
-        ctx->sizeLo += 8;
-        ctx->sizeHi += (ctx->sizeLo < 8);
-     }
-}
-
-void
-SHA1_Final2(unsigned char hashout[20],
-            SHA_CTX2     *ctx) {
-   unsigned char pad0x80 = 0x80;
-   unsigned char pad0x00 = 0x00;
-   unsigned char padlen[8];
-   int i;
-
-   /* Pad with a binary 1 (e.g. 0x80), then zeroes, then length
-    */
-   padlen[0] = (unsigned char)((ctx->sizeHi >> 24) & 255);
-   padlen[1] = (unsigned char)((ctx->sizeHi >> 16) & 255);
-   padlen[2] = (unsigned char)((ctx->sizeHi >> 8) & 255);
-   padlen[3] = (unsigned char)((ctx->sizeHi >> 0) & 255);
-   padlen[4] = (unsigned char)((ctx->sizeLo >> 24) & 255);
-   padlen[5] = (unsigned char)((ctx->sizeLo >> 16) & 255);
-   padlen[6] = (unsigned char)((ctx->sizeLo >> 8) & 255);
-   padlen[7] = (unsigned char)((ctx->sizeLo >> 0) & 255);
-   SHA1_Update2(ctx, &pad0x80, 1);
-   while (ctx->lenW != 56)
-     SHA1_Update2(ctx, &pad0x00, 1);
-   SHA1_Update2(ctx, padlen, 8);
-
-   /* Output hash
-    */
-   for (i = 0; i < 20; i++) {
-        hashout[i] = (unsigned char)(ctx->H[i / 4] >> 24);
-        ctx->H[i / 4] <<= 8;
-     }
-
-   /*
-    *  Re-initialize the context (also zeroizes contents)
-    */
-   SHA1_Init2(ctx);
-}
-
-#define SHA_ROT(X, n) (((X) << (n)) | ((X) >> (32 - (n))))
-
-static void
-shaHashBlock(SHA_CTX2 *ctx) {
-   int t;
-   unsigned int A, B, C, D, E, TEMP;
-
-   for (t = 16; t <= 79; t++)
-     ctx->W[t] =
-       SHA_ROT(ctx->W[t - 3] ^ ctx->W[t - 8] ^ ctx->W[t - 14] ^ ctx->W[t - 
16], 1);
-
-   A = ctx->H[0];
-   B = ctx->H[1];
-   C = ctx->H[2];
-   D = ctx->H[3];
-   E = ctx->H[4];
-
-   for (t = 0; t <= 19; t++) {
-        TEMP = SHA_ROT(A, 5) + (((C ^ D) & B) ^ D) + E + ctx->W[t] + 
0x5a827999;
-        E = D; D = C; C = SHA_ROT(B, 30); B = A; A = TEMP;
-     }
-   for (t = 20; t <= 39; t++) {
-        TEMP = SHA_ROT(A, 5) + (B ^ C ^ D) + E + ctx->W[t] + 0x6ed9eba1;
-        E = D; D = C; C = SHA_ROT(B, 30); B = A; A = TEMP;
-     }
-   for (t = 40; t <= 59; t++) {
-        TEMP = SHA_ROT(A, 5) + ((B & C) | (D & (B | C))) + E + ctx->W[t] + 
0x8f1bbcdc;
-        E = D; D = C; C = SHA_ROT(B, 30); B = A; A = TEMP;
-     }
-   for (t = 60; t <= 79; t++) {
-        TEMP = SHA_ROT(A, 5) + (B ^ C ^ D) + E + ctx->W[t] + 0xca62c1d6;
-        E = D; D = C; C = SHA_ROT(B, 30); B = A; A = TEMP;
-     }
-
-   ctx->H[0] += A;
-   ctx->H[1] += B;
-   ctx->H[2] += C;
-   ctx->H[3] += D;
-   ctx->H[4] += E;
-}
-
diff --git a/src/modules/teamwork/sha1.h b/src/modules/teamwork/sha1.h
deleted file mode 100644
index 6ab295d..0000000
--- a/src/modules/teamwork/sha1.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * The contents of this file are subject to the Mozilla Public
- * License Version 1.1 (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.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS
- * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
- * implied. See the License for the specific language governing
- * rights and limitations under the License.
- *
- * The Original Code is SHA 180-1 Header File
- *
- * The Initial Developer of the Original Code is Paul Kocher of
- * Cryptography Research.  Portions created by Paul Kocher are
- * Copyright (C) 1995-9 by Cryptography Research, Inc.  All
- * Rights Reserved.
- *
- * Contributor(s):
- *
- *     Paul Kocher
- *
- * Alternatively, the contents of this file may be used under the
- * terms of the GNU General Public License Version 2 or later (the
- * "GPL"), in which case the provisions of the GPL are applicable
- * instead of those above.  If you wish to allow use of your
- * version of this file only under the terms of the GPL and not to
- * allow others to use your version of this file under the MPL,
- * indicate your decision by deleting the provisions above and
- * replace them with the notice and other provisions required by
- * the GPL.  If you do not delete the provisions above, a recipient
- * may use your version of this file under either the MPL or the
- * GPL.
- */
-
-#ifndef SHA_H
-#define SHA_H
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-typedef struct {
-  unsigned int H[5];
-  unsigned int W[80];
-  int lenW;
-  unsigned int sizeHi,sizeLo;
-} SHA_CTX2;
-
-void SHA1_Init2(SHA_CTX2 *ctx);
-void SHA1_Update2(SHA_CTX2 *ctx, void *dataIn, int len);
-void SHA1_Final2(unsigned char hashout[20], SHA_CTX2 *ctx);
-
-#endif

-- 


Reply via email to