增加init/update/digest/finish长数据操作

This commit is contained in:
junj2.liang 2022-09-01 18:01:57 +08:00
parent 2f95b9eb39
commit c60d9421a7

View File

@ -14,7 +14,7 @@ public class SydApiSM4 {
private boolean is_finished = false; private boolean is_finished = false;
private byte[] dataResult = new byte[0]; private byte[] dataResult = new byte[0];
ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[1]); ByteBuffer sourceWrap = ByteBuffer.wrap(new byte[0]);
public SydApiSM4(SydApi api, int iKeyIndex, int endeFlag) { public SydApiSM4(SydApi api, int iKeyIndex, int endeFlag) {
@ -59,9 +59,9 @@ public class SydApiSM4 {
bufferResult.put(bytes1); bufferResult.put(bytes1);
sourceWrap = bufferResult; sourceWrap = bufferResult;
} }
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
iPkgNum = 2; iPkgNum = 2;
return api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag); return bytes;
} else { } else {
if (16 > pcData.length + sourceWrap.array().length) { if (16 > pcData.length + sourceWrap.array().length) {
@ -75,7 +75,9 @@ public class SydApiSM4 {
bufferResult.put(sourceWrap.array()); bufferResult.put(sourceWrap.array());
bufferResult.put(pcData); bufferResult.put(pcData);
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult); byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
return api.SYD_SM4_LongData(iKeyIndex, bytes, iPkgNum, iFlag); byte[] bytes1 = api.SYD_SM4_LongData(iKeyIndex, bytes, iPkgNum, iFlag);
iPkgNum = 2;
return bytes1;
} else { } else {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength); ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
bufferResult.put(sourceWrap.array()); bufferResult.put(sourceWrap.array());
@ -92,8 +94,10 @@ public class SydApiSM4 {
ByteBuffer bufferResults = ByteBuffer.allocate(remainder); ByteBuffer bufferResults = ByteBuffer.allocate(remainder);
bufferResults.put(bytes1); bufferResults.put(bytes1);
sourceWrap = bufferResults; sourceWrap = bufferResults;
byte[] bytes2 = api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
iPkgNum = 2; iPkgNum = 2;
return api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag); return bytes2;
} }
} }
} }
@ -106,9 +110,10 @@ public class SydApiSM4 {
dataResult = bytes; dataResult = bytes;
byte[] bytes1 = new byte[pcData.length-16]; byte[] bytes1 = new byte[pcData.length-16];
System.arraycopy(pcData,length*16,bytes,0,16); System.arraycopy(pcData,length*16,bytes,0,16);
System.arraycopy(pcData,1,bytes1,0,pcData.length-16); System.arraycopy(pcData,0,bytes1,0,pcData.length-16);
byte[] bytes2 = api.SYD_SM4_LongData(iKeyIndex, bytes1, iPkgNum, iFlag);
iPkgNum = 2; iPkgNum = 2;
return api.SYD_SM4_LongData(iKeyIndex,bytes1,iPkgNum,iFlag); return bytes2;
} }
} }
@ -126,14 +131,11 @@ public class SydApiSM4 {
if (iFlag == 0){ if (iFlag == 0){
ByteBuffer buffer = ByteBuffer.allocate(dataResult.length+sourceWrap.array().length);
buffer.put(dataResult);
buffer.put(sourceWrap.array());
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex,dataResult, iPkgNum, iFlag); byte[] bytes = api.SYD_SM4_LongData(iKeyIndex,dataResult, iPkgNum, iFlag);
sourceWrap = null; sourceWrap = null;
return bytes; return bytes;
} }
byte[] bytes = api.SYD_SM4_LongData(iKeyIndex,dataResult, iPkgNum, iFlag); byte[] bytes = api.SYD_SM4_LongData(iKeyIndex,sourceWrap.array(), iPkgNum, iFlag);
sourceWrap = null; sourceWrap = null;
return bytes; return bytes;
} }