dnsmasq: full: disable ipset support by default
[openwrt/staging/mkresin.git] / package / kernel / lantiq / ltq-deu / src / ifxmips_md5.c
index 11cb64799e900a3cfe1303fda6016f7d0fbed8a0..51782e0b6a4cb00786217eb23b598b8e8a027b8b 100644 (file)
 #define MD5_HASH_WORDS      4
 #define HASH_START   IFX_HASH_CON
 
-static spinlock_t lock;
-#define CRTCL_SECT_INIT        spin_lock_init(&lock)
-#define CRTCL_SECT_START       spin_lock_irqsave(&lock, flag)
-#define CRTCL_SECT_END         spin_unlock_irqrestore(&lock, flag)
-
 //#define CRYPTO_DEBUG
 #ifdef CRYPTO_DEBUG
 extern char debug_level;
@@ -86,18 +81,6 @@ struct md5_ctx {
 
 extern int disable_deudma;
 
-/*! \fn static u32 endian_swap(u32 input)
- *  \ingroup IFX_MD5_FUNCTIONS
- *  \brief perform dword level endian swap   
- *  \param input value of dword that requires to be swapped  
-*/ 
-static u32 endian_swap(u32 input)
-{
-    u8 *ptr = (u8 *)&input;
-    
-    return ((ptr[3] << 24) | (ptr[2] << 16) | (ptr[1] << 8) | ptr[0]);     
-}
-
 /*! \fn static void md5_transform(u32 *hash, u32 const *in)
  *  \ingroup IFX_MD5_FUNCTIONS
  *  \brief main interface to md5 hardware   
@@ -110,18 +93,20 @@ static void md5_transform(struct md5_ctx *mctx, u32 *hash, u32 const *in)
     volatile struct deu_hash_t *hashs = (struct deu_hash_t *) HASH_START;
     unsigned long flag;
 
-    CRTCL_SECT_START;
+    CRTCL_SECT_HASH_START;
+
+    MD5_HASH_INIT;
 
     if (mctx->started) { 
-        hashs->D1R = endian_swap(*((u32 *) hash + 0));
-       hashs->D2R = endian_swap(*((u32 *) hash + 1));
-        hashs->D3R = endian_swap(*((u32 *) hash + 2));
-        hashs->D4R = endian_swap(*((u32 *) hash + 3));
+        hashs->D1R = *((u32 *) hash + 0);
+        hashs->D2R = *((u32 *) hash + 1);
+        hashs->D3R = *((u32 *) hash + 2);
+        hashs->D4R = *((u32 *) hash + 3);
     }
 
     for (i = 0; i < 16; i++) {
-        hashs->MR = endian_swap(in[i]);
-//     printk("in[%d]: %08x\n", i, endian_swap(in[i]));
+        hashs->MR = in[i];
+//      printk("in[%d]: %08x\n", i, in[i]);
     };
 
     //wait for processing
@@ -129,14 +114,14 @@ static void md5_transform(struct md5_ctx *mctx, u32 *hash, u32 const *in)
         // this will not take long
     }
 
-    *((u32 *) hash + 0) = endian_swap (hashs->D1R);
-    *((u32 *) hash + 1) = endian_swap (hashs->D2R);
-    *((u32 *) hash + 2) = endian_swap (hashs->D3R);
-    *((u32 *) hash + 3) = endian_swap (hashs->D4R);
+    *((u32 *) hash + 0) = hashs->D1R;
+    *((u32 *) hash + 1) = hashs->D2R;
+    *((u32 *) hash + 2) = hashs->D3R;
+    *((u32 *) hash + 3) = hashs->D4R;
 
-    mctx->started = 1; 
+    CRTCL_SECT_HASH_END;
 
-    CRTCL_SECT_END;
+    mctx->started = 1;
 }
 
 /*! \fn static inline void md5_transform_helper(struct md5_ctx *ctx)
@@ -160,11 +145,6 @@ static int md5_init(struct shash_desc *desc)
     struct md5_ctx *mctx = shash_desc_ctx(desc);
     volatile struct deu_hash_t *hash = (struct deu_hash_t *) HASH_START;
 
-    hash->controlr.ENDI = 0;
-    hash->controlr.SM = 1;
-    hash->controlr.ALGO = 1;    // 1 = md5  0 = sha1
-    hash->controlr.INIT = 1;    // Initialize the hash operation by writing a '1' to the INIT bit.
-
     mctx->byte_count = 0;
     mctx->started = 0;
     return 0;
@@ -232,24 +212,12 @@ static int md5_final(struct shash_desc *desc, u8 *out)
     }
 
     memset(p, 0, padding);
-    mctx->block[14] = endian_swap(mctx->byte_count << 3);
-    mctx->block[15] = endian_swap(mctx->byte_count >> 29);
-
-#if 0
-    le32_to_cpu_array(mctx->block, (sizeof(mctx->block) -
-                      sizeof(u64)) / sizeof(u32));
-#endif
+    mctx->block[14] = le32_to_cpu(mctx->byte_count << 3);
+    mctx->block[15] = le32_to_cpu(mctx->byte_count >> 29);
 
     md5_transform(mctx, mctx->hash, mctx->block);                                                 
 
-    CRTCL_SECT_START;
-
-    *((u32 *) out + 0) = endian_swap (hashs->D1R);
-    *((u32 *) out + 1) = endian_swap (hashs->D2R);
-    *((u32 *) out + 2) = endian_swap (hashs->D3R);
-    *((u32 *) out + 3) = endian_swap (hashs->D4R);
-
-    CRTCL_SECT_END;
+    memcpy(out, mctx->hash, MD5_DIGEST_SIZE);
 
     // Wipe context
     memset(mctx, 0, sizeof(*mctx));
@@ -270,7 +238,7 @@ static struct shash_alg ifxdeu_md5_alg = {
                 .cra_name       =       "md5",
                 .cra_driver_name=       "ifxdeu-md5",
                 .cra_priority   =       300,
-                .cra_flags      =       CRYPTO_ALG_TYPE_HASH,
+                .cra_flags      =       CRYPTO_ALG_TYPE_HASH | CRYPTO_ALG_KERN_DRIVER_ONLY,
                 .cra_blocksize  =       MD5_HMAC_BLOCK_SIZE,
                 .cra_module     =       THIS_MODULE,
     }
@@ -288,8 +256,6 @@ int ifxdeu_init_md5 (void)
     if ((ret = crypto_register_shash(&ifxdeu_md5_alg)))
         goto md5_err;
 
-    CRTCL_SECT_INIT;
-
     printk (KERN_NOTICE "IFX DEU MD5 initialized%s.\n", disable_deudma ? "" : " (DMA)");
     return ret;
 
@@ -308,4 +274,3 @@ void ifxdeu_fini_md5 (void)
     crypto_unregister_shash(&ifxdeu_md5_alg);
 
 }
-