]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/crypto/omap-sham.c
crypto: omap-sham - buffer handling fixes for hashing later
[karo-tx-linux.git] / drivers / crypto / omap-sham.c
index d0b16e5e4ee56acb3e5a4b02191198798f7ff918..ca9e48a19b15d1512978f3669129b73321994d35 100644 (file)
@@ -41,6 +41,7 @@
 #include <crypto/algapi.h>
 #include <crypto/sha.h>
 #include <crypto/hash.h>
+#include <crypto/hmac.h>
 #include <crypto/internal/hash.h>
 
 #define MD5_DIGEST_SIZE                        16
@@ -873,14 +874,21 @@ static int omap_sham_prepare_request(struct ahash_request *req, bool update)
        }
 
        if (hash_later) {
-               if (req->nbytes) {
-                       scatterwalk_map_and_copy(rctx->buffer, req->src,
-                                                req->nbytes - hash_later,
-                                                hash_later, 0);
-               } else {
+               int offset = 0;
+
+               if (hash_later > req->nbytes) {
                        memcpy(rctx->buffer, rctx->buffer + xmit_len,
-                              hash_later);
+                              hash_later - req->nbytes);
+                       offset = hash_later - req->nbytes;
                }
+
+               if (req->nbytes) {
+                       scatterwalk_map_and_copy(rctx->buffer + offset,
+                                                req->src,
+                                                offset + req->nbytes -
+                                                hash_later, hash_later, 0);
+               }
+
                rctx->bufcnt = hash_later;
        } else {
                rctx->bufcnt = 0;
@@ -1189,11 +1197,10 @@ static int omap_sham_update(struct ahash_request *req)
        if (!req->nbytes)
                return 0;
 
-       if (ctx->total + req->nbytes < ctx->buflen) {
+       if (ctx->bufcnt + req->nbytes <= ctx->buflen) {
                scatterwalk_map_and_copy(ctx->buffer + ctx->bufcnt, req->src,
                                         0, req->nbytes, 0);
                ctx->bufcnt += req->nbytes;
-               ctx->total += req->nbytes;
                return 0;
        }
 
@@ -1326,8 +1333,8 @@ static int omap_sham_setkey(struct crypto_ahash *tfm, const u8 *key,
                memcpy(bctx->opad, bctx->ipad, bs);
 
                for (i = 0; i < bs; i++) {
-                       bctx->ipad[i] ^= 0x36;
-                       bctx->opad[i] ^= 0x5c;
+                       bctx->ipad[i] ^= HMAC_IPAD_VALUE;
+                       bctx->opad[i] ^= HMAC_OPAD_VALUE;
                }
        }