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

TOMOYO Linux Cross Reference
Linux/arch/riscv/crypto/aes-riscv64-zvkned-zvkb.S

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/riscv/crypto/aes-riscv64-zvkned-zvkb.S (Version linux-6.12-rc7) and /arch/alpha/crypto/aes-riscv64-zvkned-zvkb.S (Version linux-5.13.19)


  1 /* SPDX-License-Identifier: Apache-2.0 OR BSD-    
  2 //                                                
  3 // This file is dual-licensed, meaning that yo    
  4 // choice of either of the following two licen    
  5 //                                                
  6 // Copyright 2023 The OpenSSL Project Authors.    
  7 //                                                
  8 // Licensed under the Apache License 2.0 (the     
  9 // a copy in the file LICENSE in the source di    
 10 // https://www.openssl.org/source/license.html    
 11 //                                                
 12 // or                                             
 13 //                                                
 14 // Copyright (c) 2023, Jerry Shih <jerry.shih@s    
 15 // Copyright 2024 Google LLC                      
 16 // All rights reserved.                           
 17 //                                                
 18 // Redistribution and use in source and binary    
 19 // modification, are permitted provided that t    
 20 // are met:                                       
 21 // 1. Redistributions of source code must reta    
 22 //    notice, this list of conditions and the     
 23 // 2. Redistributions in binary form must repr    
 24 //    notice, this list of conditions and the     
 25 //    documentation and/or other materials pro    
 26 //                                                
 27 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT     
 28 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTI    
 29 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCH    
 30 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO     
 31 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIR    
 32 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGE    
 33 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS    
 34 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION)    
 35 // THEORY OF LIABILITY, WHETHER IN CONTRACT, S    
 36 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING    
 37 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE PO    
 38                                                   
 39 // The generated code of this file depends on     
 40 // - RV64I                                        
 41 // - RISC-V Vector ('V') with VLEN >= 128         
 42 // - RISC-V Vector AES block cipher extension     
 43 // - RISC-V Vector Cryptography Bit-manipulati    
 44                                                   
 45 #include <linux/linkage.h>                        
 46                                                   
 47 .text                                             
 48 .option arch, +zvkned, +zvkb                      
 49                                                   
 50 #include "aes-macros.S"                           
 51                                                   
 52 #define KEYP            a0                        
 53 #define INP             a1                        
 54 #define OUTP            a2                        
 55 #define LEN             a3                        
 56 #define IVP             a4                        
 57                                                   
 58 #define LEN32           a5                        
 59 #define VL_E32          a6                        
 60 #define VL_BLOCKS       a7                        
 61                                                   
 62 .macro  aes_ctr32_crypt keylen                    
 63         // LEN32 = number of blocks, rounded u    
 64         addi            t0, LEN, 15               
 65         srli            t0, t0, 4                 
 66         slli            LEN32, t0, 2              
 67                                                   
 68         // Create a mask that selects the last    
 69         // block.  This is the word that conta    
 70         li              t0, 0x88                  
 71         vsetvli         t1, zero, e8, m1, ta,     
 72         vmv.v.x         v0, t0                    
 73                                                   
 74         // Load the IV into v31.  The last 32-    
 75         vsetivli        zero, 4, e32, m1, ta,     
 76         vle32.v         v31, (IVP)                
 77                                                   
 78         // Convert the big-endian counter into    
 79         vsetivli        zero, 4, e32, m1, ta,     
 80         vrev8.v         v31, v31, v0.t            
 81                                                   
 82         // Splat the IV to v16 (with LMUL=4).     
 83         // maximum number of blocks that will     
 84         vsetvli         zero, LEN32, e32, m4,     
 85         vmv.v.i         v16, 0                    
 86         vaesz.vs        v16, v31                  
 87                                                   
 88         // v20 = [x, x, x, 0, x, x, x, 1, ...]    
 89         viota.m         v20, v0, v0.t             
 90         // v16 = [IV0, IV1, IV2, counter+0, IV    
 91         vsetvli         VL_E32, LEN32, e32, m4    
 92         vadd.vv         v16, v16, v20, v0.t       
 93                                                   
 94         j 2f                                      
 95 1:                                                
 96         // Set the number of blocks to process    
 97         // the length in 32-bit words, i.e. 4     
 98         vsetvli         VL_E32, LEN32, e32, m4    
 99                                                   
100         // Increment the counters by the numbe    
101         // previous iteration.                    
102         vadd.vx         v16, v16, VL_BLOCKS, v    
103 2:                                                
104         // Prepare the AES inputs into v24.       
105         vmv.v.v         v24, v16                  
106         vrev8.v         v24, v24, v0.t  // Con    
107                                                   
108         // Encrypt the AES inputs to create th    
109         aes_encrypt     v24, \keylen              
110                                                   
111         // XOR the data with the keystream.       
112         vsetvli         t0, LEN, e8, m4, ta, m    
113         vle8.v          v20, (INP)                
114         vxor.vv         v20, v20, v24             
115         vse8.v          v20, (OUTP)               
116                                                   
117         // Advance the pointers and update the    
118         add             INP, INP, t0              
119         add             OUTP, OUTP, t0            
120         sub             LEN, LEN, t0              
121         sub             LEN32, LEN32, VL_E32      
122         srli            VL_BLOCKS, VL_E32, 2      
123                                                   
124         // Repeat if more data remains.           
125         bnez            LEN, 1b                   
126                                                   
127         // Update *IVP to contain the next cou    
128         vsetivli        zero, 4, e32, m1, ta,     
129         vadd.vx         v16, v16, VL_BLOCKS, v    
130         vrev8.v         v16, v16, v0.t  // Con    
131         vse32.v         v16, (IVP)                
132                                                   
133         ret                                       
134 .endm                                             
135                                                   
136 // void aes_ctr32_crypt_zvkned_zvkb(const stru    
137 //                                  const u8 *    
138 //                                  u8 iv[16])    
139 SYM_FUNC_START(aes_ctr32_crypt_zvkned_zvkb)       
140         aes_begin       KEYP, 128f, 192f          
141         aes_ctr32_crypt 256                       
142 128:                                              
143         aes_ctr32_crypt 128                       
144 192:                                              
145         aes_ctr32_crypt 192                       
146 SYM_FUNC_END(aes_ctr32_crypt_zvkned_zvkb)         
                                                      

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