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

TOMOYO Linux Cross Reference
Linux/arch/powerpc/crypto/crc32c-vpmsum_glue.c

Version: ~ [ linux-6.12-rc7 ] ~ [ linux-6.11.7 ] ~ [ linux-6.10.14 ] ~ [ linux-6.9.12 ] ~ [ linux-6.8.12 ] ~ [ linux-6.7.12 ] ~ [ linux-6.6.60 ] ~ [ linux-6.5.13 ] ~ [ linux-6.4.16 ] ~ [ linux-6.3.13 ] ~ [ linux-6.2.16 ] ~ [ linux-6.1.116 ] ~ [ linux-6.0.19 ] ~ [ linux-5.19.17 ] ~ [ linux-5.18.19 ] ~ [ linux-5.17.15 ] ~ [ linux-5.16.20 ] ~ [ linux-5.15.171 ] ~ [ linux-5.14.21 ] ~ [ linux-5.13.19 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.229 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.285 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.323 ] ~ [ 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.12 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /arch/powerpc/crypto/crc32c-vpmsum_glue.c (Architecture sparc64) and /arch/i386/crypto/crc32c-vpmsum_glue.c (Architecture i386)


  1 // SPDX-License-Identifier: GPL-2.0-only            1 
  2 #include <linux/crc32.h>                          
  3 #include <crypto/internal/hash.h>                 
  4 #include <crypto/internal/simd.h>                 
  5 #include <linux/init.h>                           
  6 #include <linux/module.h>                         
  7 #include <linux/string.h>                         
  8 #include <linux/kernel.h>                         
  9 #include <linux/cpufeature.h>                     
 10 #include <asm/simd.h>                             
 11 #include <asm/switch_to.h>                        
 12                                                   
 13 #define CHKSUM_BLOCK_SIZE       1                 
 14 #define CHKSUM_DIGEST_SIZE      4                 
 15                                                   
 16 #define VMX_ALIGN               16                
 17 #define VMX_ALIGN_MASK          (VMX_ALIGN-1)     
 18                                                   
 19 #define VECTOR_BREAKPOINT       512               
 20                                                   
 21 u32 __crc32c_vpmsum(u32 crc, unsigned char con    
 22                                                   
 23 static u32 crc32c_vpmsum(u32 crc, unsigned cha    
 24 {                                                 
 25         unsigned int prealign;                    
 26         unsigned int tail;                        
 27                                                   
 28         if (len < (VECTOR_BREAKPOINT + VMX_ALI    
 29                 return __crc32c_le(crc, p, len    
 30                                                   
 31         if ((unsigned long)p & VMX_ALIGN_MASK)    
 32                 prealign = VMX_ALIGN - ((unsig    
 33                 crc = __crc32c_le(crc, p, prea    
 34                 len -= prealign;                  
 35                 p += prealign;                    
 36         }                                         
 37                                                   
 38         if (len & ~VMX_ALIGN_MASK) {              
 39                 preempt_disable();                
 40                 pagefault_disable();              
 41                 enable_kernel_altivec();          
 42                 crc = __crc32c_vpmsum(crc, p,     
 43                 disable_kernel_altivec();         
 44                 pagefault_enable();               
 45                 preempt_enable();                 
 46         }                                         
 47                                                   
 48         tail = len & VMX_ALIGN_MASK;              
 49         if (tail) {                               
 50                 p += len & ~VMX_ALIGN_MASK;       
 51                 crc = __crc32c_le(crc, p, tail    
 52         }                                         
 53                                                   
 54         return crc;                               
 55 }                                                 
 56                                                   
 57 static int crc32c_vpmsum_cra_init(struct crypt    
 58 {                                                 
 59         u32 *key = crypto_tfm_ctx(tfm);           
 60                                                   
 61         *key = ~0;                                
 62                                                   
 63         return 0;                                 
 64 }                                                 
 65                                                   
 66 /*                                                
 67  * Setting the seed allows arbitrary accumulat    
 68  * If your algorithm starts with ~0, then XOR     
 69  * the seed.                                      
 70  */                                               
 71 static int crc32c_vpmsum_setkey(struct crypto_    
 72                                unsigned int ke    
 73 {                                                 
 74         u32 *mctx = crypto_shash_ctx(hash);       
 75                                                   
 76         if (keylen != sizeof(u32))                
 77                 return -EINVAL;                   
 78         *mctx = le32_to_cpup((__le32 *)key);      
 79         return 0;                                 
 80 }                                                 
 81                                                   
 82 static int crc32c_vpmsum_init(struct shash_des    
 83 {                                                 
 84         u32 *mctx = crypto_shash_ctx(desc->tfm    
 85         u32 *crcp = shash_desc_ctx(desc);         
 86                                                   
 87         *crcp = *mctx;                            
 88                                                   
 89         return 0;                                 
 90 }                                                 
 91                                                   
 92 static int crc32c_vpmsum_update(struct shash_d    
 93                                unsigned int le    
 94 {                                                 
 95         u32 *crcp = shash_desc_ctx(desc);         
 96                                                   
 97         *crcp = crc32c_vpmsum(*crcp, data, len    
 98                                                   
 99         return 0;                                 
100 }                                                 
101                                                   
102 static int __crc32c_vpmsum_finup(u32 *crcp, co    
103                                 u8 *out)          
104 {                                                 
105         *(__le32 *)out = ~cpu_to_le32(crc32c_v    
106                                                   
107         return 0;                                 
108 }                                                 
109                                                   
110 static int crc32c_vpmsum_finup(struct shash_de    
111                               unsigned int len    
112 {                                                 
113         return __crc32c_vpmsum_finup(shash_des    
114 }                                                 
115                                                   
116 static int crc32c_vpmsum_final(struct shash_de    
117 {                                                 
118         u32 *crcp = shash_desc_ctx(desc);         
119                                                   
120         *(__le32 *)out = ~cpu_to_le32p(crcp);     
121                                                   
122         return 0;                                 
123 }                                                 
124                                                   
125 static int crc32c_vpmsum_digest(struct shash_d    
126                                unsigned int le    
127 {                                                 
128         return __crc32c_vpmsum_finup(crypto_sh    
129                                      out);        
130 }                                                 
131                                                   
132 static struct shash_alg alg = {                   
133         .setkey         = crc32c_vpmsum_setkey    
134         .init           = crc32c_vpmsum_init,     
135         .update         = crc32c_vpmsum_update    
136         .final          = crc32c_vpmsum_final,    
137         .finup          = crc32c_vpmsum_finup,    
138         .digest         = crc32c_vpmsum_digest    
139         .descsize       = sizeof(u32),            
140         .digestsize     = CHKSUM_DIGEST_SIZE,     
141         .base           = {                       
142                 .cra_name               = "crc    
143                 .cra_driver_name        = "crc    
144                 .cra_priority           = 200,    
145                 .cra_flags              = CRYP    
146                 .cra_blocksize          = CHKS    
147                 .cra_ctxsize            = size    
148                 .cra_module             = THIS    
149                 .cra_init               = crc3    
150         }                                         
151 };                                                
152                                                   
153 static int __init crc32c_vpmsum_mod_init(void)    
154 {                                                 
155         if (!cpu_has_feature(CPU_FTR_ARCH_207S    
156                 return -ENODEV;                   
157                                                   
158         return crypto_register_shash(&alg);       
159 }                                                 
160                                                   
161 static void __exit crc32c_vpmsum_mod_fini(void    
162 {                                                 
163         crypto_unregister_shash(&alg);            
164 }                                                 
165                                                   
166 module_cpu_feature_match(PPC_MODULE_FEATURE_VE    
167 module_exit(crc32c_vpmsum_mod_fini);              
168                                                   
169 MODULE_AUTHOR("Anton Blanchard <anton@samba.or    
170 MODULE_DESCRIPTION("CRC32C using vector polyno    
171 MODULE_LICENSE("GPL");                            
172 MODULE_ALIAS_CRYPTO("crc32c");                    
173 MODULE_ALIAS_CRYPTO("crc32c-vpmsum");             
174                                                   

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