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

TOMOYO Linux Cross Reference
Linux/arch/sparc/crypto/sha512_glue.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 ] ~

Diff markup

Differences between /arch/sparc/crypto/sha512_glue.c (Architecture m68k) and /arch/mips/crypto/sha512_glue.c (Architecture mips)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 
  2 /* Glue code for SHA512 hashing optimized for     
  3  *                                                
  4  * This is based largely upon crypto/sha512_ge    
  5  *                                                
  6  * Copyright (c) Jean-Luc Cooke <jlcooke@certa    
  7  * Copyright (c) Andrew McDonald <andrew@mcdon    
  8  * Copyright (c) 2003 Kyle McMartin <kyle@debi    
  9  */                                               
 10                                                   
 11 #define pr_fmt(fmt)     KBUILD_MODNAME ": " fm    
 12                                                   
 13 #include <crypto/internal/hash.h>                 
 14 #include <linux/init.h>                           
 15 #include <linux/module.h>                         
 16 #include <linux/mm.h>                             
 17 #include <linux/types.h>                          
 18 #include <crypto/sha2.h>                          
 19 #include <crypto/sha512_base.h>                   
 20                                                   
 21 #include <asm/pstate.h>                           
 22 #include <asm/elf.h>                              
 23                                                   
 24 #include "opcodes.h"                              
 25                                                   
 26 asmlinkage void sha512_sparc64_transform(u64 *    
 27                                          unsig    
 28                                                   
 29 static void __sha512_sparc64_update(struct sha    
 30                                     unsigned i    
 31 {                                                 
 32         unsigned int done = 0;                    
 33                                                   
 34         if ((sctx->count[0] += len) < len)        
 35                 sctx->count[1]++;                 
 36         if (partial) {                            
 37                 done = SHA512_BLOCK_SIZE - par    
 38                 memcpy(sctx->buf + partial, da    
 39                 sha512_sparc64_transform(sctx-    
 40         }                                         
 41         if (len - done >= SHA512_BLOCK_SIZE) {    
 42                 const unsigned int rounds = (l    
 43                                                   
 44                 sha512_sparc64_transform(sctx-    
 45                 done += rounds * SHA512_BLOCK_    
 46         }                                         
 47                                                   
 48         memcpy(sctx->buf, data + done, len - d    
 49 }                                                 
 50                                                   
 51 static int sha512_sparc64_update(struct shash_    
 52                                  unsigned int     
 53 {                                                 
 54         struct sha512_state *sctx = shash_desc    
 55         unsigned int partial = sctx->count[0]     
 56                                                   
 57         /* Handle the fast case right here */     
 58         if (partial + len < SHA512_BLOCK_SIZE)    
 59                 if ((sctx->count[0] += len) <     
 60                         sctx->count[1]++;         
 61                 memcpy(sctx->buf + partial, da    
 62         } else                                    
 63                 __sha512_sparc64_update(sctx,     
 64                                                   
 65         return 0;                                 
 66 }                                                 
 67                                                   
 68 static int sha512_sparc64_final(struct shash_d    
 69 {                                                 
 70         struct sha512_state *sctx = shash_desc    
 71         unsigned int i, index, padlen;            
 72         __be64 *dst = (__be64 *)out;              
 73         __be64 bits[2];                           
 74         static const u8 padding[SHA512_BLOCK_S    
 75                                                   
 76         /* Save number of bits */                 
 77         bits[1] = cpu_to_be64(sctx->count[0] <    
 78         bits[0] = cpu_to_be64(sctx->count[1] <    
 79                                                   
 80         /* Pad out to 112 mod 128 and append l    
 81         index = sctx->count[0] % SHA512_BLOCK_    
 82         padlen = (index < 112) ? (112 - index)    
 83                                                   
 84         /* We need to fill a whole block for _    
 85         if (padlen <= 112) {                      
 86                 if ((sctx->count[0] += padlen)    
 87                         sctx->count[1]++;         
 88                 memcpy(sctx->buf + index, padd    
 89         } else {                                  
 90                 __sha512_sparc64_update(sctx,     
 91         }                                         
 92         __sha512_sparc64_update(sctx, (const u    
 93                                                   
 94         /* Store state in digest */               
 95         for (i = 0; i < 8; i++)                   
 96                 dst[i] = cpu_to_be64(sctx->sta    
 97                                                   
 98         /* Wipe context */                        
 99         memset(sctx, 0, sizeof(*sctx));           
100                                                   
101         return 0;                                 
102 }                                                 
103                                                   
104 static int sha384_sparc64_final(struct shash_d    
105 {                                                 
106         u8 D[64];                                 
107                                                   
108         sha512_sparc64_final(desc, D);            
109                                                   
110         memcpy(hash, D, 48);                      
111         memzero_explicit(D, 64);                  
112                                                   
113         return 0;                                 
114 }                                                 
115                                                   
116 static struct shash_alg sha512 = {                
117         .digestsize     =       SHA512_DIGEST_    
118         .init           =       sha512_base_in    
119         .update         =       sha512_sparc64    
120         .final          =       sha512_sparc64    
121         .descsize       =       sizeof(struct     
122         .base           =       {                 
123                 .cra_name       =       "sha51    
124                 .cra_driver_name=       "sha51    
125                 .cra_priority   =       SPARC_    
126                 .cra_blocksize  =       SHA512    
127                 .cra_module     =       THIS_M    
128         }                                         
129 };                                                
130                                                   
131 static struct shash_alg sha384 = {                
132         .digestsize     =       SHA384_DIGEST_    
133         .init           =       sha384_base_in    
134         .update         =       sha512_sparc64    
135         .final          =       sha384_sparc64    
136         .descsize       =       sizeof(struct     
137         .base           =       {                 
138                 .cra_name       =       "sha38    
139                 .cra_driver_name=       "sha38    
140                 .cra_priority   =       SPARC_    
141                 .cra_blocksize  =       SHA384    
142                 .cra_module     =       THIS_M    
143         }                                         
144 };                                                
145                                                   
146 static bool __init sparc64_has_sha512_opcode(v    
147 {                                                 
148         unsigned long cfr;                        
149                                                   
150         if (!(sparc64_elf_hwcap & HWCAP_SPARC_    
151                 return false;                     
152                                                   
153         __asm__ __volatile__("rd %%asr26, %0"     
154         if (!(cfr & CFR_SHA512))                  
155                 return false;                     
156                                                   
157         return true;                              
158 }                                                 
159                                                   
160 static int __init sha512_sparc64_mod_init(void    
161 {                                                 
162         if (sparc64_has_sha512_opcode()) {        
163                 int ret = crypto_register_shas    
164                 if (ret < 0)                      
165                         return ret;               
166                                                   
167                 ret = crypto_register_shash(&s    
168                 if (ret < 0) {                    
169                         crypto_unregister_shas    
170                         return ret;               
171                 }                                 
172                                                   
173                 pr_info("Using sparc64 sha512     
174                 return 0;                         
175         }                                         
176         pr_info("sparc64 sha512 opcode not ava    
177         return -ENODEV;                           
178 }                                                 
179                                                   
180 static void __exit sha512_sparc64_mod_fini(voi    
181 {                                                 
182         crypto_unregister_shash(&sha384);         
183         crypto_unregister_shash(&sha512);         
184 }                                                 
185                                                   
186 module_init(sha512_sparc64_mod_init);             
187 module_exit(sha512_sparc64_mod_fini);             
188                                                   
189 MODULE_LICENSE("GPL");                            
190 MODULE_DESCRIPTION("SHA-384 and SHA-512 Secure    
191                                                   
192 MODULE_ALIAS_CRYPTO("sha384");                    
193 MODULE_ALIAS_CRYPTO("sha512");                    
194                                                   
195 #include "crop_devid.c"                           
196                                                   

~ [ 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