aboutsummaryrefslogtreecommitdiffstats
path: root/package/kernel/lantiq/ltq-deu/src/ifxmips_md5_hmac.c
diff options
context:
space:
mode:
authorDaniel Kestrel <kestrel1974@t-online.de>2021-06-05 23:46:58 +0200
committerHauke Mehrtens <hauke@hauke-m.de>2022-01-06 00:22:50 +0100
commit34a3eaf07f6a814d77cbdaa6c8a14604a37f7784 (patch)
tree2409d0dd9c716ea234f88f6eff6eaff98716799c /package/kernel/lantiq/ltq-deu/src/ifxmips_md5_hmac.c
parent87a19c9345db7554441dbd10f8c4460f6629c10a (diff)
downloadupstream-34a3eaf07f6a814d77cbdaa6c8a14604a37f7784.tar.gz
upstream-34a3eaf07f6a814d77cbdaa6c8a14604a37f7784.tar.bz2
upstream-34a3eaf07f6a814d77cbdaa6c8a14604a37f7784.zip
ltq-deu: changes for hash multithread callers and md5 endianess
The algorithms sha1, sha1_hmac and md5_hmac all use ENDI=1. The md5 algorithm uses ENDI=0 and the endian_swap methods to reverse the endianess switch by using user CPU time, which is unnecessary overhead. Danube and AR9 devices do not set endianess for SHA1, so is done for MD5. Furthermore the patch replaces endian_swap with le32_to_cpu for md5 and md5 hmac algorithms and removes endian_swap for them. The init functions initialize the algorithm in the hardware. The lock is not used to write to the control register. If another thread calls another hash algo before update or final, the result will be wrong. Therefore move the algorithm init to the lock protected sections in the transform or final methods. Setting the hw key for the hmac algorithms is now done from within the lock protected sections in their final methods. The lock protecting is removed from the _hmac_setkey_hw functions. In final for md5 and sha1 the lock section is removed, because all the work was already done in transform (which is called from final). As such only copying the hash to the output is required. MD5 and MD5_HMAC produce 16 byte hashes (4 DWORDS) only, therefor writing register D5R to the hash output is removed for MD5_HMAC. Signed-off-by: Daniel Kestrel <kestrel1974@t-online.de>
Diffstat (limited to 'package/kernel/lantiq/ltq-deu/src/ifxmips_md5_hmac.c')
-rw-r--r--package/kernel/lantiq/ltq-deu/src/ifxmips_md5_hmac.c26
1 files changed, 6 insertions, 20 deletions
diff --git a/package/kernel/lantiq/ltq-deu/src/ifxmips_md5_hmac.c b/package/kernel/lantiq/ltq-deu/src/ifxmips_md5_hmac.c
index 9cc6eb7a55..277879fbbb 100644
--- a/package/kernel/lantiq/ltq-deu/src/ifxmips_md5_hmac.c
+++ b/package/kernel/lantiq/ltq-deu/src/ifxmips_md5_hmac.c
@@ -86,18 +86,6 @@ static u32 temp[MD5_HMAC_DBN_TEMP_SIZE];
extern int disable_deudma;
-/*! \fn static u32 endian_swap(u32 input)
- * \ingroup IFX_MD5_HMAC_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_hmac_transform(struct crypto_tfm *tfm, u32 const *in)
* \ingroup IFX_MD5_HMAC_FUNCTIONS
* \brief save input block to context
@@ -128,7 +116,6 @@ static void md5_hmac_transform(struct shash_desc *desc, u32 const *in)
static int md5_hmac_setkey(struct crypto_shash *tfm, const u8 *key, unsigned int keylen)
{
struct md5_hmac_ctx *mctx = crypto_shash_ctx(tfm);
- volatile struct deu_hash_t *hash = (struct deu_hash_t *) HASH_START;
//printk("copying keys to context with length %d\n", keylen);
if (keylen > MAX_HASH_KEYLEN) {
@@ -137,7 +124,6 @@ static int md5_hmac_setkey(struct crypto_shash *tfm, const u8 *key, unsigned int
}
- hash->KIDX |= 0x80000000; // reset all 16 words of the key to '0'
memcpy(&mctx->key, key, keylen);
mctx->keylen = keylen;
@@ -156,13 +142,12 @@ static int md5_hmac_setkey(struct crypto_shash *tfm, const u8 *key, unsigned int
static int md5_hmac_setkey_hw(const u8 *key, unsigned int keylen)
{
volatile struct deu_hash_t *hash = (struct deu_hash_t *) HASH_START;
- unsigned long flag;
int i, j;
u32 *in_key = (u32 *)key;
//printk("\nsetkey keylen: %d\n key: ", keylen);
- CRTCL_SECT_HASH_START;
+ hash->KIDX |= 0x80000000; // reset all 16 words of the key to '0'
j = 0;
for (i = 0; i < keylen; i+=4)
{
@@ -172,7 +157,6 @@ static int md5_hmac_setkey_hw(const u8 *key, unsigned int keylen)
asm("sync");
j++;
}
- CRTCL_SECT_HASH_END;
return 0;
}
@@ -189,7 +173,6 @@ static int md5_hmac_init(struct shash_desc *desc)
mctx->dbn = 0; //dbn workaround
- md5_hmac_setkey_hw(mctx->key, mctx->keylen);
return 0;
}
@@ -260,13 +243,17 @@ static int md5_hmac_final(struct shash_desc *desc, u8 *out)
}
memset(p, 0, padding);
- mctx->block[14] = endian_swap((mctx->byte_count + 64) << 3); // need to add 512 bit of the IPAD operation
+ mctx->block[14] = le32_to_cpu((mctx->byte_count + 64) << 3); // need to add 512 bit of the IPAD operation
mctx->block[15] = 0x00000000;
md5_hmac_transform(desc, mctx->block);
CRTCL_SECT_HASH_START;
+ MD5_HASH_INIT;
+
+ md5_hmac_setkey_hw(mctx->key, mctx->keylen);
+
//printk("\ndbn = %d\n", mctx->dbn);
hashs->DBN = mctx->dbn;
asm("sync");
@@ -307,7 +294,6 @@ static int md5_hmac_final(struct shash_desc *desc, u8 *out)
*((u32 *) out + 1) = hashs->D2R;
*((u32 *) out + 2) = hashs->D3R;
*((u32 *) out + 3) = hashs->D4R;
- *((u32 *) out + 4) = hashs->D5R;
/* reset the context after we finish with the hash */
mctx->byte_count = 0;