aboutsummaryrefslogtreecommitdiffstats
path: root/package/kernel/lantiq/ltq-deu/src/ifxmips_sha1_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_sha1_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_sha1_hmac.c')
-rw-r--r--package/kernel/lantiq/ltq-deu/src/ifxmips_sha1_hmac.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/package/kernel/lantiq/ltq-deu/src/ifxmips_sha1_hmac.c b/package/kernel/lantiq/ltq-deu/src/ifxmips_sha1_hmac.c
index a1461e6e5b..cee0041e8f 100644
--- a/package/kernel/lantiq/ltq-deu/src/ifxmips_sha1_hmac.c
+++ b/package/kernel/lantiq/ltq-deu/src/ifxmips_sha1_hmac.c
@@ -119,7 +119,6 @@ static int sha1_hmac_transform(struct shash_desc *desc, u32 const *in)
static int sha1_hmac_setkey(struct crypto_shash *tfm, const u8 *key, unsigned int keylen)
{
struct sha1_hmac_ctx *sctx = crypto_shash_ctx(tfm);
- volatile struct deu_hash_t *hashs = (struct deu_hash_t *) HASH_START;
if (keylen > SHA1_HMAC_MAX_KEYLEN) {
printk("Key length exceeds maximum key length\n");
@@ -128,7 +127,6 @@ static int sha1_hmac_setkey(struct crypto_shash *tfm, const u8 *key, unsigned in
//printk("Setting keys of len: %d\n", keylen);
- hashs->KIDX |= 0x80000000; //reset keys back to 0
memcpy(&sctx->key, key, keylen);
sctx->keylen = keylen;
@@ -148,12 +146,11 @@ static int sha1_hmac_setkey_hw(const u8 *key, unsigned int keylen)
{
volatile struct deu_hash_t *hash = (struct deu_hash_t *) HASH_START;
int i, j;
- unsigned long flag;
u32 *in_key = (u32 *)key;
j = 0;
- CRTCL_SECT_HASH_START;
+ hash->KIDX |= 0x80000000; //reset keys back to 0
for (i = 0; i < keylen; i+=4)
{
hash->KIDX = j;
@@ -162,7 +159,6 @@ static int sha1_hmac_setkey_hw(const u8 *key, unsigned int keylen)
j++;
}
- CRTCL_SECT_HASH_END;
return 0;
}
@@ -177,7 +173,6 @@ static int sha1_hmac_init(struct shash_desc *desc)
//printk("debug ln: %d, fn: %s\n", __LINE__, __func__);
sctx->dbn = 0; //dbn workaround
- sha1_hmac_setkey_hw(sctx->key, sctx->keylen);
return 0;
}
@@ -261,6 +256,10 @@ static int sha1_hmac_final(struct shash_desc *desc, u8 *out)
sha1_hmac_update (desc, bits, sizeof bits);
CRTCL_SECT_HASH_START;
+
+ SHA_HASH_INIT;
+
+ sha1_hmac_setkey_hw(sctx->key, sctx->keylen);
hashs->DBN = sctx->dbn;