~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/s390/crypto/sha1_s390.c

Version: ~ [ linux-4.19-rc7 ] ~ [ linux-4.18.12 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.74 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.131 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.159 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.123 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.59 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-3.9.11 ] ~ [ linux-3.8.13 ] ~ [ linux-3.7.10 ] ~ [ linux-3.6.11 ] ~ [ linux-3.5.7 ] ~ [ linux-3.4.113 ] ~ [ linux-3.3.8 ] ~ [ linux-3.2.102 ] ~ [ linux-3.1.10 ] ~ [ linux-3.0.101 ] ~ [ linux-2.6.39.4 ] ~ [ linux-2.6.38.8 ] ~ [ linux-2.6.37.6 ] ~ [ linux-2.6.36.4 ] ~ [ linux-2.6.35.14 ] ~ [ linux-2.6.34.15 ] ~ [ linux-2.6.33.20 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.31.14 ] ~ [ linux-2.6.30.10 ] ~ [ linux-2.6.29.6 ] ~ [ linux-2.6.28.10 ] ~ [ linux-2.6.27.62 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0+
  2 /*
  3  * Cryptographic API.
  4  *
  5  * s390 implementation of the SHA1 Secure Hash Algorithm.
  6  *
  7  * Derived from cryptoapi implementation, adapted for in-place
  8  * scatterlist interface.  Originally based on the public domain
  9  * implementation written by Steve Reid.
 10  *
 11  * s390 Version:
 12  *   Copyright IBM Corp. 2003, 2007
 13  *   Author(s): Thomas Spatzier
 14  *              Jan Glauber (jan.glauber@de.ibm.com)
 15  *
 16  * Derived from "crypto/sha1_generic.c"
 17  *   Copyright (c) Alan Smithee.
 18  *   Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
 19  *   Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
 20  */
 21 #include <crypto/internal/hash.h>
 22 #include <linux/init.h>
 23 #include <linux/module.h>
 24 #include <linux/cpufeature.h>
 25 #include <crypto/sha.h>
 26 #include <asm/cpacf.h>
 27 
 28 #include "sha.h"
 29 
 30 static int sha1_init(struct shash_desc *desc)
 31 {
 32         struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
 33 
 34         sctx->state[0] = SHA1_H0;
 35         sctx->state[1] = SHA1_H1;
 36         sctx->state[2] = SHA1_H2;
 37         sctx->state[3] = SHA1_H3;
 38         sctx->state[4] = SHA1_H4;
 39         sctx->count = 0;
 40         sctx->func = CPACF_KIMD_SHA_1;
 41 
 42         return 0;
 43 }
 44 
 45 static int sha1_export(struct shash_desc *desc, void *out)
 46 {
 47         struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
 48         struct sha1_state *octx = out;
 49 
 50         octx->count = sctx->count;
 51         memcpy(octx->state, sctx->state, sizeof(octx->state));
 52         memcpy(octx->buffer, sctx->buf, sizeof(octx->buffer));
 53         return 0;
 54 }
 55 
 56 static int sha1_import(struct shash_desc *desc, const void *in)
 57 {
 58         struct s390_sha_ctx *sctx = shash_desc_ctx(desc);
 59         const struct sha1_state *ictx = in;
 60 
 61         sctx->count = ictx->count;
 62         memcpy(sctx->state, ictx->state, sizeof(ictx->state));
 63         memcpy(sctx->buf, ictx->buffer, sizeof(ictx->buffer));
 64         sctx->func = CPACF_KIMD_SHA_1;
 65         return 0;
 66 }
 67 
 68 static struct shash_alg alg = {
 69         .digestsize     =       SHA1_DIGEST_SIZE,
 70         .init           =       sha1_init,
 71         .update         =       s390_sha_update,
 72         .final          =       s390_sha_final,
 73         .export         =       sha1_export,
 74         .import         =       sha1_import,
 75         .descsize       =       sizeof(struct s390_sha_ctx),
 76         .statesize      =       sizeof(struct sha1_state),
 77         .base           =       {
 78                 .cra_name       =       "sha1",
 79                 .cra_driver_name=       "sha1-s390",
 80                 .cra_priority   =       300,
 81                 .cra_blocksize  =       SHA1_BLOCK_SIZE,
 82                 .cra_module     =       THIS_MODULE,
 83         }
 84 };
 85 
 86 static int __init sha1_s390_init(void)
 87 {
 88         if (!cpacf_query_func(CPACF_KIMD, CPACF_KIMD_SHA_1))
 89                 return -EOPNOTSUPP;
 90         return crypto_register_shash(&alg);
 91 }
 92 
 93 static void __exit sha1_s390_fini(void)
 94 {
 95         crypto_unregister_shash(&alg);
 96 }
 97 
 98 module_cpu_feature_match(MSA, sha1_s390_init);
 99 module_exit(sha1_s390_fini);
100 
101 MODULE_ALIAS_CRYPTO("sha1");
102 MODULE_LICENSE("GPL");
103 MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
104 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp