tree: https://gitee.com/openeuler/kernel.git OLK-6.6 head: 13706c950ff941dc015e16f76812077f9861e378 commit: b0381d106c64a4e0d4e737badd78e7d15aa917f1 [13458/13930] crypto: ccp: Support SM2 algorithm for hygon ccp. config: x86_64-randconfig-123-20240913 (https://download.01.org/0day-ci/archive/20240913/202409131819.BdjMPTsH-lkp@i...) compiler: clang version 18.1.8 (https://github.com/llvm/llvm-project 3b5b5c1ec4a3095ab096dd780e84d7ab81f3d7ff) reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20240913/202409131819.BdjMPTsH-lkp@i...)
If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot lkp@intel.com | Closes: https://lore.kernel.org/oe-kbuild-all/202409131819.BdjMPTsH-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:127:25: sparse: sparse: cast to restricted __be64
drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:128:25: sparse: sparse: cast to restricted __be64 drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:146:25: sparse: sparse: cast to restricted __be64 drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:147:25: sparse: sparse: cast to restricted __be64
drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:150:22: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long [usertype] @@ got restricted __be64 [usertype] @@
drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:150:22: sparse: expected unsigned long long [usertype] drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:150:22: sparse: got restricted __be64 [usertype] drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:171:25: sparse: sparse: cast to restricted __be64 drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:173:22: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned long long [usertype] @@ got restricted __be64 [usertype] @@ drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:173:22: sparse: expected unsigned long long [usertype] drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:173:22: sparse: got restricted __be64 [usertype]
drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:202:25: sparse: sparse: cast to restricted __be32
drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:208:33: sparse: sparse: cast to restricted __be32
drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:212:32: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] @@ got restricted __be32 [usertype] @@
drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:212:32: sparse: expected unsigned int [usertype] drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:212:32: sparse: got restricted __be32 [usertype] drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:215:24: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] @@ got restricted __be32 [usertype] @@ drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:215:24: sparse: expected unsigned int [usertype] drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:215:24: sparse: got restricted __be32 [usertype] drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:296:28: sparse: sparse: cast to restricted __be64 drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:582:24: sparse: sparse: incorrect type in assignment (different base types) @@ expected unsigned int [usertype] @@ got restricted __be32 [usertype] @@ drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:582:24: sparse: expected unsigned int [usertype] drivers/crypto/ccp/ccp-crypto-sm2-hygon.c:582:24: sparse: got restricted __be32 [usertype] drivers/crypto/ccp/ccp-crypto-sm2-hygon.c: note: in included file (through include/linux/module.h): include/linux/list.h:83:21: sparse: sparse: self-comparison always evaluates to true
vim +127 drivers/crypto/ccp/ccp-crypto-sm2-hygon.c
115 116 /* Return: 117 * 1: a > b 118 * -1: a < b 119 * 0: a = b 120 */ 121 static int ccp_sm2_fp_cmp(const u64 *a, const u64 *b, u32 count) 122 { 123 u64 a_cpu, b_cpu; 124 u32 i; 125 126 for (i = 0; i < count; i++) {
127 a_cpu = be64_to_cpu(a[i]);
128 b_cpu = be64_to_cpu(b[i]); 129 if (a_cpu > b_cpu) 130 return 1; 131 else if (a_cpu < b_cpu) 132 return -1; 133 } 134 135 return 0; 136 } 137 138 /* a = a + b */ 139 static void ccp_sm2_fp_add(u64 *a, const u64 *b, u32 count) 140 { 141 u64 a_cpu, b_cpu, c_cpu, d_cpu; 142 u32 carry = 0; 143 s32 i; 144 145 for (i = count - 1; i >= 0; i--) {
146 a_cpu = be64_to_cpu(a[i]);
147 b_cpu = be64_to_cpu(b[i]); 148 c_cpu = a_cpu + b_cpu; 149 d_cpu = c_cpu + carry;
150 a[i] = cpu_to_be64(d_cpu);
151 152 if (c_cpu < a_cpu) 153 carry = 1; 154 else if (carry && !d_cpu) 155 carry = 1; 156 else 157 carry = 0; 158 } 159 } 160 161 /* a = -a */ 162 static void ccp_sm2_fp_neg(u64 *a, u32 count) 163 { 164 u64 a_cpu, c_cpu; 165 s32 i; 166 167 for (i = 0; i <= count - 1; i++) 168 a[i] = ~a[i]; 169 170 for (i = count - 1; i >= 0; i--) { 171 a_cpu = be64_to_cpu(a[i]); 172 c_cpu = a_cpu + 1; 173 a[i] = cpu_to_be64(c_cpu); 174 175 if (a_cpu < c_cpu) 176 break; 177 } 178 } 179 180 /* a = a - b */ 181 static void ccp_sm2_fp_sub(u64 *a, u64 *b, u32 count) 182 { 183 ccp_sm2_fp_neg(b, count); 184 ccp_sm2_fp_add(a, b, count); 185 } 186 187 /* a and tmp must be 64B, b and c must be 32B 188 * a = b * c 189 */ 190 static void ccp_sm2_fp_mmul32(u8 *a, const u32 *b, const u32 *c, u8 *tmp) 191 { 192 u64 b_cpu, c_cpu, m_cpu; 193 u32 rem_cpu; 194 u32 *base, *m_cur; 195 int i, j, iter; 196 197 memset(a, 0, CCP_SM2_MMUL_LEN); 198 199 iter = 7; 200 base = (u32 *)(tmp + CCP_SM2_MMUL_LEN - sizeof(u32)); 201 for (i = iter; i >= 0; i--) {
202 b_cpu = be32_to_cpu(b[i]);
203 memset(tmp, 0, CCP_SM2_MMUL_LEN); 204 205 rem_cpu = 0; 206 m_cur = base; 207 for (j = iter; j >= 0; j--) { 208 c_cpu = be32_to_cpu(c[j]); 209 210 m_cpu = b_cpu * c_cpu + rem_cpu; 211 rem_cpu = (u32)(m_cpu >> 32);
212 *m_cur = cpu_to_be32((u32)(m_cpu));
213 m_cur--; 214 } 215 *m_cur = cpu_to_be32(rem_cpu); 216 ccp_sm2_fp_add((u64 *)a, (u64 *)tmp, 217 CCP_SM2_MMUL_LEN / sizeof(u64)); 218 219 base--; 220 } 221 } 222