8291509: Minor cleanup could be done in sun.security

Reviewed-by: weijun
This commit is contained in:
Mark Powers 2022-09-15 19:59:53 +00:00 committed by Weijun Wang
parent 6beeb8471c
commit 4cec141a90
298 changed files with 2650 additions and 3262 deletions

View file

@ -67,8 +67,7 @@ enum SSLCipher {
// exportable ciphers
@SuppressWarnings({"unchecked", "rawtypes"})
B_NULL("NULL", NULL_CIPHER, 0, 0, 0, 0, true, true,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new NullReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_NONE
@ -77,92 +76,77 @@ enum SSLCipher {
new NullReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_13
)
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new NullWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_NONE
),
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new NullWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_13
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new NullWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_NONE
),
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new NullWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_13
)
})),
@SuppressWarnings({"unchecked", "rawtypes"})
B_RC4_40(CIPHER_RC4, STREAM_CIPHER, 5, 16, 0, 0, true, true,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new StreamReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new StreamWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_RC2_40("RC2", BLOCK_CIPHER, 5, 16, 8, 0, false, true,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new StreamReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new StreamWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_DES_40(CIPHER_DES, BLOCK_CIPHER, 5, 8, 8, 0, true, true,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new T10BlockReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new T10BlockWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
)
})),
}),
// domestic strength ciphers
@SuppressWarnings({"unchecked", "rawtypes"})
B_RC4_128(CIPHER_RC4, STREAM_CIPHER, 16, 16, 0, 0, true, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new StreamReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_12
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new StreamWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_12
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_DES(CIPHER_DES, BLOCK_CIPHER, 8, 8, 8, 0, true, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new T10BlockReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
@ -171,9 +155,7 @@ enum SSLCipher {
new T11BlockReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_11
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new T10BlockWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
@ -182,12 +164,11 @@ enum SSLCipher {
new T11BlockWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_11
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_3DES(CIPHER_3DES, BLOCK_CIPHER, 24, 24, 8, 0, true, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new T10BlockReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
@ -196,9 +177,7 @@ enum SSLCipher {
new T11BlockReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_11_12
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new T10BlockWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
@ -207,29 +186,25 @@ enum SSLCipher {
new T11BlockWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_11_12
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_IDEA("IDEA", BLOCK_CIPHER, 16, 16, 8, 0, false, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
null,
ProtocolVersion.PROTOCOLS_TO_12
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
null,
ProtocolVersion.PROTOCOLS_TO_12
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_AES_128(CIPHER_AES, BLOCK_CIPHER, 16, 16, 16, 0, true, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new T10BlockReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
@ -238,9 +213,7 @@ enum SSLCipher {
new T11BlockReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_11_12
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new T10BlockWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
@ -249,12 +222,11 @@ enum SSLCipher {
new T11BlockWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_11_12
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_AES_256(CIPHER_AES, BLOCK_CIPHER, 32, 32, 16, 0, true, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new T10BlockReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
@ -263,9 +235,7 @@ enum SSLCipher {
new T11BlockReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_11_12
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new T10BlockWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_TO_10
@ -274,81 +244,67 @@ enum SSLCipher {
new T11BlockWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_11_12
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_AES_128_GCM(CIPHER_AES_GCM, AEAD_CIPHER, 16, 16, 12, 4, true, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new T12GcmReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_12
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new T12GcmWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_12
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_AES_256_GCM(CIPHER_AES_GCM, AEAD_CIPHER, 32, 32, 12, 4, true, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new T12GcmReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_12
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new T12GcmWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_12
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_AES_128_GCM_IV(CIPHER_AES_GCM, AEAD_CIPHER, 16, 16, 12, 0, true, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new T13GcmReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_13
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new T13GcmWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_13
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_AES_256_GCM_IV(CIPHER_AES_GCM, AEAD_CIPHER, 32, 32, 12, 0, true, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new T13GcmReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_13
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new T13GcmWriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_13
)
})),
}),
@SuppressWarnings({"unchecked", "rawtypes"})
B_CC20_P1305(CIPHER_CHACHA20_POLY1305, AEAD_CIPHER, 32, 32, 12,
12, true, false,
(Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
12, true, false, new Map.Entry[] {
new SimpleImmutableEntry<ReadCipherGenerator, ProtocolVersion[]>(
new T12CC20P1305ReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_12
@ -357,9 +313,7 @@ enum SSLCipher {
new T13CC20P1305ReadCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_13
)
}),
(Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[])(new Map.Entry[] {
}, new Map.Entry[] {
new SimpleImmutableEntry<WriteCipherGenerator, ProtocolVersion[]>(
new T12CC20P1305WriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_12
@ -368,7 +322,7 @@ enum SSLCipher {
new T13CC20P1305WriteCipherGenerator(),
ProtocolVersion.PROTOCOLS_OF_13
)
}));
});
// descriptive name including key size, e.g. AES/128
final String description;
@ -483,14 +437,14 @@ enum SSLCipher {
}
}
private SSLCipher(String transformation,
CipherType cipherType, int keySize,
int expandedKeySize, int ivSize,
int fixedIvSize, boolean allowed, boolean exportable,
Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[] readCipherGenerators,
Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[] writeCipherGenerators) {
SSLCipher(String transformation,
CipherType cipherType, int keySize,
int expandedKeySize, int ivSize,
int fixedIvSize, boolean allowed, boolean exportable,
Map.Entry<ReadCipherGenerator,
ProtocolVersion[]>[] readCipherGenerators,
Map.Entry<WriteCipherGenerator,
ProtocolVersion[]>[] writeCipherGenerators) {
this.transformation = transformation;
String[] splits = transformation.split("/");
this.algorithm = splits[0];
@ -1187,7 +1141,7 @@ enum SSLCipher {
int blockSize = cipher.getBlockSize();
if ((fragmentLen % blockSize) == 0) {
int minimal = tagLen + 1;
minimal = (minimal >= blockSize) ? minimal : blockSize;
minimal = Math.max(minimal, blockSize);
return (fragmentLen >= minimal);
}
@ -1466,7 +1420,7 @@ enum SSLCipher {
int blockSize = cipher.getBlockSize();
if ((fragmentLen % blockSize) == 0) {
int minimal = tagLen + 1;
minimal = (minimal >= blockSize) ? minimal : blockSize;
minimal = Math.max(minimal, blockSize);
minimal += blockSize;
return (fragmentLen >= minimal);