8000 Add GMSSL support by Trisia · Pull Request #908 · bcgit/bc-java · GitHub
[go: up one dir, main page]

Skip to content

Add GMSSL support #908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
42d67ad
Added SM4 block encryption algorithm
Trisia Mar 5, 2021
7eab95d
Added SM3 hash hmac alg support
Trisia Mar 5, 2021
087209a
Add the algorithm identifier related to ECC_SM4_SM3
Trisia Mar 5, 2021
2423ca5
Added GMSSL related algorithm identifier analysis to Spi
Trisia Mar 5, 2021
c42b9cb
fix CipherSuiteInfo prefix check logic error
Trisia Mar 5, 2021
5529e58
debug client hello message
Trisia Mar 9, 2021
3a2c0d4
add sm2 key exchange process
Trisia Mar 10, 2021
f01c27c
add gm client key exchange impl
Trisia Mar 10, 2021
0c7a246
fix big BigInteger need set flag to process byte array signum
Trisia Mar 11, 2021
a26181e
TlsBlockCipher support gmssl struct encrypt and decrypt.
Trisia Mar 11, 2021
99b4d74
Merge pull request #1 from bcgit/master
Trisia Mar 11, 2021
e1ad060
change test site.
Trisia Mar 11, 2021
79e8066
implement server side gmssl SM2_SM4_SM3 suite develop.
Trisia Mar 12, 2021
92ca36c
add server version limit, if server dont have version of protocol the…
Trisia Mar 15, 2021
5dfe15e
change mock GMSSL CLient/Server to SimpleGMSSL public access.
Trisia Mar 16, 2021
45a747f
Add GM Simple Socket Factory.
Trisia Mar 16, 2021
1373192
Manually resolve merge conflicts
Trisia Mar 16, 2021
56d3167
Merge branch 'master' of https://github.com/bcgit/bc-java into bcgit-…
Trisia Mar 16, 2021
cf634a0
Merge branch 'bcgit-master'
Trisia Mar 16, 2021
b90aab1
Fix apache HttpClient get session null throw error.
Trisia Mar 17, 2021
a608f56
remove author tag
Trisia Mar 21, 2021
2c7bdad
修复了Alert 40 错误
Trisia Oct 20, 2021
621e688
格式调整
Trisia Oct 20, 2021
abfb039
Completed the GMSSL session.
Trisia Oct 23, 2021
fb72a85
remove debug info and change certificate parer method.
Trisia Oct 23, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added SM3 hash hmac alg support
  • Loading branch information
Trisia committed Mar 5, 2021
commit 7eab95d91323c8e4e125d16baabe2fd6ceeb07ee
10 changes: 10 additions & 0 deletions tls/src/main/java/org/bouncycastle/tls/HashAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public class HashAlgorithm
*/
public static final short Intrinsic = 8;

/*
* GMT 0024-2014 No value is specified,
* so a value is randomly specified here to avoid conflicts
*/
public static final short sm3 = 20;

public static String getName(short hashAlgorithm)
{
switch (hashAlgorithm)
Expand All @@ -38,6 +44,8 @@ public static String getName(short hashAlgorithm)
return "sha512";
case Intrinsic:
return "Intrinsic";
case sm3:
return "sm3";
default:
return "UNKNOWN";
}
Expand All @@ -54,6 +62,7 @@ public static int getOutputSize(short hashAlgorithm)
case sha224:
return 28;
case sha256:
case sm3:
return 32;
case sha384:
return 48;
Expand All @@ -79,6 +88,7 @@ public static boolean isRecognized(short hashAlgorithm)
switch (hashAlgorithm)
{
case md5:
case sm3:
case sha1:
case sha224:
case sha256:
Expand Down
9 changes: 9 additions & 0 deletions tls/src/main/java/org/bouncycastle/tls/MACAlgorithm.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ public class MACAlgorithm
public static final int hmac_sha384 = 4;
public static final int hmac_sha512 = 5;

/*
* GMT 0024-2014 No value is specified,
* so a value is randomly specified here to avoid conflicts
*/
public static final int hmac_sm3 = 20;

public static String getName(int macAlgorithm)
{
switch (macAlgorithm)
Expand All @@ -37,6 +43,8 @@ public static String getName(int macAlgorithm)
return "hmac_sha384";
case hmac_sha512:
return "hmac_sha512";
case hmac_sm3:
return "hmac_sm3";
default:
return "UNKNOWN";
}
Expand All @@ -56,6 +64,7 @@ public static boolean isHMAC(int macAlgorithm)
case hmac_sha256:
case hmac_sha384:
case hmac_sha512:
case hmac_sm3:
return true;
default:
return false;
Expand Down
2 changes: 2 additions & 0 deletions tls/src/main/java/org/bouncycastle/tls/TlsUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -1793,6 +1793,8 @@ public static short getHashAlgorithmForHMACAlgorithm(int macAlgorithm)
return HashAlgorithm.sha384;
case MACAlgorithm.hmac_sha512:
return HashAlgorithm.sha512;
case MACAlgorithm.hmac_sm3:
return HashAlgorithm.sm3;
default:
throw new IllegalArgumentException("specified MACAlgorithm not an HMAC: " + MACAlgorithm.getText(macAlgorithm));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.bouncycastle.crypto.digests.SHA256Digest;
import org.bouncycastle.crypto.digests.SHA384Digest;
import org.bouncycastle.crypto.digests.SHA512Digest;
import org.bouncycastle.crypto.digests.SM3Digest;
import org.bouncycastle.crypto.encodings.PKCS1Encoding;
import org.bouncycastle.crypto.engines.*;
import org.bouncycastle.crypto.macs.HMac;
Expand Down Expand Up @@ -157,7 +158,8 @@ public TlsCipher createCipher(TlsCryptoParameters cryptoParams, int encryptionAl
// NOTE: Ignores macAlgorithm
return createChaCha20Poly1305(cryptoParams);
case EncryptionAlgorithm.SM4_CBC:
return createSm4(cryptoParams, macAlgorithm);
// Chinese GMSSL SM4 mode
return createSM4Cipher(cryptoParams, macAlgorithm);
case EncryptionAlgorithm.NULL:
return createNullCipher(cryptoParams, macAlgorithm);
case EncryptionAlgorithm.SEED_CBC:
Expand Down Expand Up @@ -369,6 +371,8 @@ public Digest createDigest(short hashAlgorithm)
return new SHA384Digest();
case HashAlgorithm.sha512:
return new SHA512Digest();
case HashAlgorithm.sm3:
return new SM3Digest();
default:
throw new IllegalArgumentException("invalid HashAlgorithm: " + HashAlgorithm.getText(hashAlgorithm));
}
Expand Down Expand Up @@ -435,9 +439,10 @@ public static Digest cloneDigest(short hashAlgorithm, Digest hash)
}
}

protected TlsCipher createSm4(TlsCryptoParameters cryptoParams, int macAlgorithm)
protected TlsCipher createSM4Cipher(TlsCryptoParameters cryptoParams, int macAlgorithm)
throws IOException
{
// SM4 Block size 128bit => 16 byte
return new TlsBlockCipher(this, cryptoParams,
new BlockOperator(createSM4BlockCipher(), true),
new BlockOperator(createSM4BlockCipher(), false),
Expand Down
0