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

This commit is contained in:
junj2.liang
2022-08-31 17:57:20 +08:00
parent 849c380dbe
commit 030849f754
2 changed files with 26 additions and 7 deletions
@@ -21,10 +21,10 @@ public class SydApiSM4 {
this.iKeyIndex = iKeyIndex;
}
public void update(byte[] pcData) {
public byte[] update(byte[] pcData) {
this.pcdataResult = pcData;
if (null == pcData || pcData.length == 0) {
return;
return new byte[0];
}
int plength = pcData.length;
if (is_finished) {
@@ -58,20 +58,22 @@ public class SydApiSM4 {
bufferResult.put(bytes1);
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);
} else {
if (16 > pcData.length + sourceWrap.array().length) {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
bufferResult.put(pcData);
sourceWrap = bufferResult;
return new byte[0];
} else if ((pcData.length + sourceWrap.array().length) % 16 == 0) {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
bufferResult.put(pcData);
byte[] bytes = SydSM4Mac.bytebuffer2ByteArray(bufferResult);
api.SYD_SM4_LongData(iKeyIndex, bytes, iPkgNum, iFlag);
return api.SYD_SM4_LongData(iKeyIndex, bytes, iPkgNum, iFlag);
} else {
ByteBuffer bufferResult = ByteBuffer.allocate(sourceWrap.array().length + plength);
bufferResult.put(SydSM4Mac.bytebuffer2ByteArray(sourceWrap));
@@ -88,8 +90,8 @@ public class SydApiSM4 {
ByteBuffer bufferResults = ByteBuffer.allocate(remainder);
bufferResults.put(bytes1);
sourceWrap = bufferResults;
api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
iPkgNum = 2;
return api.SYD_SM4_LongData(iKeyIndex, pcdataResult, iPkgNum, iFlag);
}
}
}