(SM4_Context ctx, byte[] input)
| 241 | } |
| 242 | |
| 243 | public byte[] sm4_crypt_ecb(SM4_Context ctx, byte[] input) throws Exception { |
| 244 | if (input == null) { |
| 245 | throw new Exception("input is null!"); |
| 246 | } |
| 247 | |
| 248 | if ((ctx.isPadding) && (ctx.mode == SM4_ENCRYPT)) { |
| 249 | input = padding(input, SM4_ENCRYPT); |
| 250 | } |
| 251 | |
| 252 | int length = input.length; |
| 253 | ByteArrayInputStream bins = new ByteArrayInputStream(input); |
| 254 | ByteArrayOutputStream bous = new ByteArrayOutputStream(); |
| 255 | for (; length > 0; length -= 16) { |
| 256 | byte[] in = new byte[16]; |
| 257 | byte[] out = new byte[16]; |
| 258 | bins.read(in); |
| 259 | sm4_one_round(ctx.sk, in, out); |
| 260 | bous.write(out); |
| 261 | } |
| 262 | |
| 263 | byte[] output = bous.toByteArray(); |
| 264 | if (ctx.isPadding && ctx.mode == SM4_DECRYPT) { |
| 265 | output = padding(output, SM4_DECRYPT); |
| 266 | } |
| 267 | bins.close(); |
| 268 | bous.close(); |
| 269 | return output; |
| 270 | } |
| 271 | |
| 272 | public byte[] sm4_crypt_cbc(SM4_Context ctx, byte[] iv, byte[] input) throws Exception { |
| 273 | if (iv == null || iv.length != 16) { |
no test coverage detected