Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Adjusted the array copy offset calculation in the SM4, SM4CTR, SM4GCM, and ZucCipher classes to return data within the correct range.
Commented out the SM2 certificate test code in JceTest to temporarily disable the test and avoid hard-coded path issues.
  • Loading branch information
liyongfei committed Sep 23, 2024
1 parent e3567cc commit 228f05a
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/main/java/org/gmssl/crypto/symmetric/SM4CBC.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected byte[] processUpdate(byte[] input, int inputOffset, int inputLen) {
}

int outLen = processUpdate(input, inputOffset, inputLen, outputByteArray, offset);
return Arrays.copyOfRange(outputByteArray,offset,offset + outLen);
return Arrays.copyOfRange(outputByteArray,offset-outLen,offset);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gmssl/crypto/symmetric/SM4CTR.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected byte[] processUpdate(byte[] input, int inputOffset, int inputLen) {
}

int outLen = processUpdate(input, inputOffset, inputLen, outputByteArray, offset);
return Arrays.copyOfRange(outputByteArray,offset,offset + outLen);
return Arrays.copyOfRange(outputByteArray,offset-outLen,offset);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gmssl/crypto/symmetric/SM4GCM.java
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ protected byte[] processUpdate(byte[] input, int inputOffset, int inputLen) {
}

int outLen = processUpdate(input, inputOffset, inputLen, outputByteArray, offset);
return Arrays.copyOfRange(outputByteArray,offset,offset + outLen);
return Arrays.copyOfRange(outputByteArray,offset-outLen,offset);
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/gmssl/crypto/symmetric/ZucCipher.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ protected byte[] engineUpdate(byte[] input, int inputOffset, int inputLen) {
}

int outLen = engineUpdate(input, inputOffset, inputLen, outputByteArray, offset);
return Arrays.copyOfRange(outputByteArray,offset,offset + outLen);
return Arrays.copyOfRange(outputByteArray,offset-outLen,offset);
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/org/gmssl/JceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ public void SM2_test() throws Exception{
@Test
public void sm2_certificate_test() throws Exception{
SM2Certificate sm2Cert = new SM2Certificate();
sm2Cert.importPem("D:\\cert.pem");
System.out.println("NotAfter:"+sm2Cert.getNotAfter());
//sm2Cert.importPem("D:\\cert.pem");
//System.out.println("NotAfter:"+sm2Cert.getNotAfter());
}

@Test
Expand Down

0 comments on commit 228f05a

Please sign in to comment.