root/arch/arm/crypto/sha1_neon_glue.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. sha1_neon_update
  2. sha1_neon_finup
  3. sha1_neon_final
  4. sha1_neon_mod_init
  5. sha1_neon_mod_fini

   1 // SPDX-License-Identifier: GPL-2.0-or-later
   2 /*
   3  * Glue code for the SHA1 Secure Hash Algorithm assembler implementation using
   4  * ARM NEON instructions.
   5  *
   6  * Copyright © 2014 Jussi Kivilinna <jussi.kivilinna@iki.fi>
   7  *
   8  * This file is based on sha1_generic.c and sha1_ssse3_glue.c:
   9  *  Copyright (c) Alan Smithee.
  10  *  Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
  11  *  Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
  12  *  Copyright (c) Mathias Krause <minipli@googlemail.com>
  13  *  Copyright (c) Chandramouli Narayanan <mouli@linux.intel.com>
  14  */
  15 
  16 #include <crypto/internal/hash.h>
  17 #include <crypto/internal/simd.h>
  18 #include <linux/init.h>
  19 #include <linux/module.h>
  20 #include <linux/mm.h>
  21 #include <linux/cryptohash.h>
  22 #include <linux/types.h>
  23 #include <crypto/sha.h>
  24 #include <crypto/sha1_base.h>
  25 #include <asm/neon.h>
  26 #include <asm/simd.h>
  27 
  28 #include "sha1.h"
  29 
  30 asmlinkage void sha1_transform_neon(void *state_h, const char *data,
  31                                     unsigned int rounds);
  32 
  33 static int sha1_neon_update(struct shash_desc *desc, const u8 *data,
  34                           unsigned int len)
  35 {
  36         struct sha1_state *sctx = shash_desc_ctx(desc);
  37 
  38         if (!crypto_simd_usable() ||
  39             (sctx->count % SHA1_BLOCK_SIZE) + len < SHA1_BLOCK_SIZE)
  40                 return sha1_update_arm(desc, data, len);
  41 
  42         kernel_neon_begin();
  43         sha1_base_do_update(desc, data, len,
  44                             (sha1_block_fn *)sha1_transform_neon);
  45         kernel_neon_end();
  46 
  47         return 0;
  48 }
  49 
  50 static int sha1_neon_finup(struct shash_desc *desc, const u8 *data,
  51                            unsigned int len, u8 *out)
  52 {
  53         if (!crypto_simd_usable())
  54                 return sha1_finup_arm(desc, data, len, out);
  55 
  56         kernel_neon_begin();
  57         if (len)
  58                 sha1_base_do_update(desc, data, len,
  59                                     (sha1_block_fn *)sha1_transform_neon);
  60         sha1_base_do_finalize(desc, (sha1_block_fn *)sha1_transform_neon);
  61         kernel_neon_end();
  62 
  63         return sha1_base_finish(desc, out);
  64 }
  65 
  66 static int sha1_neon_final(struct shash_desc *desc, u8 *out)
  67 {
  68         return sha1_neon_finup(desc, NULL, 0, out);
  69 }
  70 
  71 static struct shash_alg alg = {
  72         .digestsize     =       SHA1_DIGEST_SIZE,
  73         .init           =       sha1_base_init,
  74         .update         =       sha1_neon_update,
  75         .final          =       sha1_neon_final,
  76         .finup          =       sha1_neon_finup,
  77         .descsize       =       sizeof(struct sha1_state),
  78         .base           =       {
  79                 .cra_name               = "sha1",
  80                 .cra_driver_name        = "sha1-neon",
  81                 .cra_priority           = 250,
  82                 .cra_blocksize          = SHA1_BLOCK_SIZE,
  83                 .cra_module             = THIS_MODULE,
  84         }
  85 };
  86 
  87 static int __init sha1_neon_mod_init(void)
  88 {
  89         if (!cpu_has_neon())
  90                 return -ENODEV;
  91 
  92         return crypto_register_shash(&alg);
  93 }
  94 
  95 static void __exit sha1_neon_mod_fini(void)
  96 {
  97         crypto_unregister_shash(&alg);
  98 }
  99 
 100 module_init(sha1_neon_mod_init);
 101 module_exit(sha1_neon_mod_fini);
 102 
 103 MODULE_LICENSE("GPL");
 104 MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm, NEON accelerated");
 105 MODULE_ALIAS_CRYPTO("sha1");

/* [<][>][^][v][top][bottom][index][help] */