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

TOMOYO Linux Cross Reference
Linux/arch/powerpc/crypto/sha1.c

Version: ~ [ linux-6.11-rc3 ] ~ [ linux-6.10.4 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.45 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.104 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.164 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.223 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.281 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.319 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.336 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.337 ] ~ [ linux-4.4.302 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.9 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 // SPDX-License-Identifier: GPL-2.0-or-later
  2 /*
  3  * Cryptographic API.
  4  *
  5  * powerpc implementation of the SHA1 Secure Hash Algorithm.
  6  *
  7  * Derived from cryptoapi implementation, adapted for in-place
  8  * scatterlist interface.
  9  *
 10  * Derived from "crypto/sha1.c"
 11  * Copyright (c) Alan Smithee.
 12  * Copyright (c) Andrew McDonald <andrew@mcdonald.org.uk>
 13  * Copyright (c) Jean-Francois Dive <jef@linuxbe.org>
 14  */
 15 #include <crypto/internal/hash.h>
 16 #include <linux/init.h>
 17 #include <linux/module.h>
 18 #include <linux/mm.h>
 19 #include <linux/types.h>
 20 #include <crypto/sha1.h>
 21 #include <crypto/sha1_base.h>
 22 #include <asm/byteorder.h>
 23 
 24 void powerpc_sha_transform(u32 *state, const u8 *src);
 25 
 26 static int powerpc_sha1_update(struct shash_desc *desc, const u8 *data,
 27                                unsigned int len)
 28 {
 29         struct sha1_state *sctx = shash_desc_ctx(desc);
 30         unsigned int partial, done;
 31         const u8 *src;
 32 
 33         partial = sctx->count & 0x3f;
 34         sctx->count += len;
 35         done = 0;
 36         src = data;
 37 
 38         if ((partial + len) > 63) {
 39 
 40                 if (partial) {
 41                         done = -partial;
 42                         memcpy(sctx->buffer + partial, data, done + 64);
 43                         src = sctx->buffer;
 44                 }
 45 
 46                 do {
 47                         powerpc_sha_transform(sctx->state, src);
 48                         done += 64;
 49                         src = data + done;
 50                 } while (done + 63 < len);
 51 
 52                 partial = 0;
 53         }
 54         memcpy(sctx->buffer + partial, src, len - done);
 55 
 56         return 0;
 57 }
 58 
 59 
 60 /* Add padding and return the message digest. */
 61 static int powerpc_sha1_final(struct shash_desc *desc, u8 *out)
 62 {
 63         struct sha1_state *sctx = shash_desc_ctx(desc);
 64         __be32 *dst = (__be32 *)out;
 65         u32 i, index, padlen;
 66         __be64 bits;
 67         static const u8 padding[64] = { 0x80, };
 68 
 69         bits = cpu_to_be64(sctx->count << 3);
 70 
 71         /* Pad out to 56 mod 64 */
 72         index = sctx->count & 0x3f;
 73         padlen = (index < 56) ? (56 - index) : ((64+56) - index);
 74         powerpc_sha1_update(desc, padding, padlen);
 75 
 76         /* Append length */
 77         powerpc_sha1_update(desc, (const u8 *)&bits, sizeof(bits));
 78 
 79         /* Store state in digest */
 80         for (i = 0; i < 5; i++)
 81                 dst[i] = cpu_to_be32(sctx->state[i]);
 82 
 83         /* Wipe context */
 84         memset(sctx, 0, sizeof *sctx);
 85 
 86         return 0;
 87 }
 88 
 89 static int powerpc_sha1_export(struct shash_desc *desc, void *out)
 90 {
 91         struct sha1_state *sctx = shash_desc_ctx(desc);
 92 
 93         memcpy(out, sctx, sizeof(*sctx));
 94         return 0;
 95 }
 96 
 97 static int powerpc_sha1_import(struct shash_desc *desc, const void *in)
 98 {
 99         struct sha1_state *sctx = shash_desc_ctx(desc);
100 
101         memcpy(sctx, in, sizeof(*sctx));
102         return 0;
103 }
104 
105 static struct shash_alg alg = {
106         .digestsize     =       SHA1_DIGEST_SIZE,
107         .init           =       sha1_base_init,
108         .update         =       powerpc_sha1_update,
109         .final          =       powerpc_sha1_final,
110         .export         =       powerpc_sha1_export,
111         .import         =       powerpc_sha1_import,
112         .descsize       =       sizeof(struct sha1_state),
113         .statesize      =       sizeof(struct sha1_state),
114         .base           =       {
115                 .cra_name       =       "sha1",
116                 .cra_driver_name=       "sha1-powerpc",
117                 .cra_blocksize  =       SHA1_BLOCK_SIZE,
118                 .cra_module     =       THIS_MODULE,
119         }
120 };
121 
122 static int __init sha1_powerpc_mod_init(void)
123 {
124         return crypto_register_shash(&alg);
125 }
126 
127 static void __exit sha1_powerpc_mod_fini(void)
128 {
129         crypto_unregister_shash(&alg);
130 }
131 
132 module_init(sha1_powerpc_mod_init);
133 module_exit(sha1_powerpc_mod_fini);
134 
135 MODULE_LICENSE("GPL");
136 MODULE_DESCRIPTION("SHA1 Secure Hash Algorithm");
137 
138 MODULE_ALIAS_CRYPTO("sha1");
139 MODULE_ALIAS_CRYPTO("sha1-powerpc");
140 

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

kernel.org | git.kernel.org | LWN.net | Project Home | 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.

sflogo.php