8333364: Minor cleanup could be done in com.sun.crypto.provider

Reviewed-by: mullan, valeriep
This commit is contained in:
Mark Powers 2024-07-09 20:38:09 +00:00
parent 7e11fb7026
commit 1472124489
47 changed files with 313 additions and 367 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,19 +25,19 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.security.SecureRandom;
import java.security.InvalidParameterException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException; import java.security.InvalidParameterException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays; import java.util.Arrays;
import javax.crypto.KeyGeneratorSpi; import javax.crypto.KeyGeneratorSpi;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec; import javax.crypto.spec.SecretKeySpec;
import sun.security.util.SecurityProviderConstants; import sun.security.util.SecurityProviderConstants;
/** /**
* This class generates a AES key. * This class generates an AES key.
* *
* @author Valerie Peng * @author Valerie Peng
* *
@ -105,7 +105,7 @@ public final class AESKeyGenerator extends KeyGeneratorSpi {
* @return the new AES key * @return the new AES key
*/ */
protected SecretKey engineGenerateKey() { protected SecretKey engineGenerateKey() {
SecretKeySpec aesKey = null; SecretKeySpec aesKey;
if (this.random == null) { if (this.random == null) {
this.random = SunJCE.getRandom(); this.random = SunJCE.getRandom();

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,11 +25,11 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.util.Arrays; import java.security.InvalidAlgorithmParameterException;
import java.security.*; import java.security.InvalidKeyException;
import java.security.spec.*; import java.security.MessageDigest;
import javax.crypto.*; import javax.crypto.IllegalBlockSizeException;
import javax.crypto.spec.*;
import static com.sun.crypto.provider.KWUtil.*; import static com.sun.crypto.provider.KWUtil.*;
/** /**
@ -66,7 +66,7 @@ class AESKeyWrap extends FeedbackCipher {
@Override @Override
void save() { void save() {
throw new UnsupportedOperationException("save not supported"); throw new UnsupportedOperationException("save not supported");
}; }
/** /**
* Restores the content of this cipher to the previous saved one. * Restores the content of this cipher to the previous saved one.
@ -74,7 +74,7 @@ class AESKeyWrap extends FeedbackCipher {
@Override @Override
void restore() { void restore() {
throw new UnsupportedOperationException("restore not supported"); throw new UnsupportedOperationException("restore not supported");
}; }
/** /**
* Initializes the cipher in the specified mode with the given key * Initializes the cipher in the specified mode with the given key
@ -112,20 +112,20 @@ class AESKeyWrap extends FeedbackCipher {
@Override @Override
void reset() { void reset() {
throw new UnsupportedOperationException("reset not supported"); throw new UnsupportedOperationException("reset not supported");
}; }
// no support for multi-part encryption // no support for multipart encryption
@Override @Override
int encrypt(byte[] pt, int ptOfs, int ptLen, byte[] ct, int ctOfs) { int encrypt(byte[] pt, int ptOfs, int ptLen, byte[] ct, int ctOfs) {
throw new UnsupportedOperationException("multi-part not supported"); throw new UnsupportedOperationException("multipart not supported");
}; }
// no support for multi-part decryption // no support for multipart decryption
@Override @Override
int decrypt(byte[] ct, int ctOfs, int ctLen, byte[] pt, int ptOfs) { int decrypt(byte[] ct, int ctOfs, int ctLen, byte[] pt, int ptOfs) {
throw new UnsupportedOperationException("multi-part not supported"); throw new UnsupportedOperationException("multipart not supported");
}; }
/** /**
* Performs single-part encryption operation. * Performs single-part encryption operation.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,12 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.util.Arrays; import java.util.Arrays;
import java.util.HexFormat; import java.util.HexFormat;
import java.security.*; import javax.crypto.IllegalBlockSizeException;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import static com.sun.crypto.provider.KWUtil.*; import static com.sun.crypto.provider.KWUtil.*;
/** /**
@ -49,7 +49,7 @@ class AESKeyWrapPadded extends FeedbackCipher {
private static final byte[] PAD_BLK = new byte[SEMI_BLKSIZE - 1]; private static final byte[] PAD_BLK = new byte[SEMI_BLKSIZE - 1];
// set the first semiblock of dest with iv and inLen // set the first semi-block of dest with iv and inLen
private static void setIvAndLen(byte[] dest, byte[] iv, int inLen) { private static void setIvAndLen(byte[] dest, byte[] iv, int inLen) {
assert(dest.length >= SEMI_BLKSIZE) : "buffer needs at least 8 bytes"; assert(dest.length >= SEMI_BLKSIZE) : "buffer needs at least 8 bytes";
@ -60,7 +60,7 @@ class AESKeyWrapPadded extends FeedbackCipher {
dest[7] = (byte) (inLen & 0xFF); dest[7] = (byte) (inLen & 0xFF);
} }
// validate the recovered internal ivAndLen semiblock against iv and // validate the recovered internal ivAndLen semi-block against iv and
// return the recovered input length // return the recovered input length
private static int validateIV(byte[] ivAndLen, byte[] iv) private static int validateIV(byte[] ivAndLen, byte[] iv)
throws IllegalBlockSizeException { throws IllegalBlockSizeException {
@ -103,7 +103,7 @@ class AESKeyWrapPadded extends FeedbackCipher {
@Override @Override
void save() { void save() {
throw new UnsupportedOperationException("save not supported"); throw new UnsupportedOperationException("save not supported");
}; }
/** /**
* Restores the content of this cipher to the previous saved one. * Restores the content of this cipher to the previous saved one.
@ -111,7 +111,7 @@ class AESKeyWrapPadded extends FeedbackCipher {
@Override @Override
void restore() { void restore() {
throw new UnsupportedOperationException("restore not supported"); throw new UnsupportedOperationException("restore not supported");
}; }
/** /**
* Initializes the cipher in the specified mode with the given key * Initializes the cipher in the specified mode with the given key
@ -151,19 +151,19 @@ class AESKeyWrapPadded extends FeedbackCipher {
@Override @Override
void reset() { void reset() {
throw new UnsupportedOperationException("reset not supported"); throw new UnsupportedOperationException("reset not supported");
}; }
// no support for multi-part encryption // no support for multipart encryption
@Override @Override
int encrypt(byte[] pt, int ptOfs, int ptLen, byte[] ct, int ctOfs) { int encrypt(byte[] pt, int ptOfs, int ptLen, byte[] ct, int ctOfs) {
throw new UnsupportedOperationException("multi-part not supported"); throw new UnsupportedOperationException("multipart not supported");
}; }
// no support for multi-part decryption // no support for multipart decryption
@Override @Override
int decrypt(byte[] ct, int ctOfs, int ctLen, byte[] pt, int ptOfs) { int decrypt(byte[] ct, int ctOfs, int ctLen, byte[] pt, int ptOfs) {
throw new UnsupportedOperationException("multi-part not supported"); throw new UnsupportedOperationException("multipart not supported");
}; }
/** /**
* Performs single-part encryption operation. * Performs single-part encryption operation.
@ -199,7 +199,7 @@ class AESKeyWrapPadded extends FeedbackCipher {
} }
if (ptLen <= BLKSIZE) { if (ptLen <= BLKSIZE) {
// overwrite the first semiblock with iv and input length // overwrite the first semi-block with iv and input length
setIvAndLen(pt, iv, actualLen); setIvAndLen(pt, iv, actualLen);
embeddedCipher.encryptBlock(pt, 0, pt, 0); embeddedCipher.encryptBlock(pt, 0, pt, 0);
} else { } else {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -114,7 +114,7 @@ public sealed class ARCFOURCipher extends CipherSpi
// Modes do not make sense with stream ciphers, but allow ECB // Modes do not make sense with stream ciphers, but allow ECB
// see JCE spec. // see JCE spec.
protected void engineSetMode(String mode) throws NoSuchAlgorithmException { protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
if (mode.equalsIgnoreCase("ECB") == false) { if (!mode.equalsIgnoreCase("ECB")) {
throw new NoSuchAlgorithmException("Unsupported mode " + mode); throw new NoSuchAlgorithmException("Unsupported mode " + mode);
} }
} }
@ -123,7 +123,7 @@ public sealed class ARCFOURCipher extends CipherSpi
// see JCE spec. // see JCE spec.
protected void engineSetPadding(String padding) protected void engineSetPadding(String padding)
throws NoSuchPaddingException { throws NoSuchPaddingException {
if (padding.equalsIgnoreCase("NoPadding") == false) { if (!padding.equalsIgnoreCase("NoPadding")) {
throw new NoSuchPaddingException("Padding must be NoPadding"); throw new NoSuchPaddingException("Padding must be NoPadding");
} }
} }
@ -201,7 +201,7 @@ public sealed class ARCFOURCipher extends CipherSpi
if (!keyAlg.equals("RC4") && !keyAlg.equals("ARCFOUR")) { if (!keyAlg.equals("RC4") && !keyAlg.equals("ARCFOUR")) {
throw new InvalidKeyException("Not an ARCFOUR key: " + keyAlg); throw new InvalidKeyException("Not an ARCFOUR key: " + keyAlg);
} }
if ("RAW".equals(key.getFormat()) == false) { if (!"RAW".equals(key.getFormat())) {
throw new InvalidKeyException("Key encoding format must be RAW"); throw new InvalidKeyException("Key encoding format must be RAW");
} }
byte[] encodedKey = key.getEncoded(); byte[] encodedKey = key.getEncoded();

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -156,7 +156,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
*/ */
@Override @Override
protected void engineSetMode(String mode) throws NoSuchAlgorithmException { protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
if (mode.equalsIgnoreCase("None") == false) { if (!mode.equalsIgnoreCase("None")) {
throw new NoSuchAlgorithmException("Mode must be None"); throw new NoSuchAlgorithmException("Mode must be None");
} }
} }
@ -174,7 +174,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
@Override @Override
protected void engineSetPadding(String padding) protected void engineSetPadding(String padding)
throws NoSuchPaddingException { throws NoSuchPaddingException {
if (padding.equalsIgnoreCase("NoPadding") == false) { if (!padding.equalsIgnoreCase("NoPadding")) {
throw new NoSuchPaddingException("Padding must be NoPadding"); throw new NoSuchPaddingException("Padding must be NoPadding");
} }
} }
@ -326,7 +326,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
// We will ignore the secure random implementation and use the nonce // We will ignore the secure random implementation and use the nonce
// from the AlgorithmParameterSpec instead. // from the AlgorithmParameterSpec instead.
byte[] newNonce = null; byte[] newNonce;
switch (mode) { switch (mode) {
case MODE_NONE: case MODE_NONE:
if (!(params instanceof ChaCha20ParameterSpec)) { if (!(params instanceof ChaCha20ParameterSpec)) {
@ -360,7 +360,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
/** /**
* Initialize the engine using the {@code AlgorithmParameter} initialization * Initialize the engine using the {@code AlgorithmParameter} initialization
* format. This cipher does supports initialization with * format. This cipher supports initialization with
* {@code AlgorithmParameter} objects for ChaCha20-Poly1305 but not for * {@code AlgorithmParameter} objects for ChaCha20-Poly1305 but not for
* ChaCha20 as a simple stream cipher. In the latter case, it will throw * ChaCha20 as a simple stream cipher. In the latter case, it will throw
* an {@code InvalidAlgorithmParameterException} if the value is non-null. * an {@code InvalidAlgorithmParameterException} if the value is non-null.
@ -618,7 +618,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
* or if the key encoding format is not {@code RAW}. * or if the key encoding format is not {@code RAW}.
*/ */
private static byte[] getEncodedKey(Key key) throws InvalidKeyException { private static byte[] getEncodedKey(Key key) throws InvalidKeyException {
if ("RAW".equals(key.getFormat()) == false) { if (!"RAW".equals(key.getFormat())) {
throw new InvalidKeyException("Key encoding format must be RAW"); throw new InvalidKeyException("Key encoding format must be RAW");
} }
byte[] encodedKey = key.getEncoded(); byte[] encodedKey = key.getEncoded();
@ -675,7 +675,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
@Override @Override
protected int engineUpdate(byte[] in, int inOfs, int inLen, protected int engineUpdate(byte[] in, int inOfs, int inLen,
byte[] out, int outOfs) throws ShortBufferException { byte[] out, int outOfs) throws ShortBufferException {
int bytesUpdated = 0; int bytesUpdated;
try { try {
bytesUpdated = engine.doUpdate(in, inOfs, inLen, out, outOfs); bytesUpdated = engine.doUpdate(in, inOfs, inLen, out, outOfs);
} catch (KeyException ke) { } catch (KeyException ke) {
@ -691,10 +691,10 @@ abstract class ChaCha20Cipher extends CipherSpi {
* @param output ByteBuffer that will hold the resulting data. This * @param output ByteBuffer that will hold the resulting data. This
* must be large enough to hold the resulting data. * must be large enough to hold the resulting data.
* *
* @return the length in bytes of the data written into the {@code out} * @return the length in bytes of the data written into the {@code output}
* buffer. * buffer.
* *
* @throws ShortBufferException if the buffer {@code out} does not have * @throws ShortBufferException if the buffer {@code output} does not have
* enough space to hold the resulting data. * enough space to hold the resulting data.
*/ */
@Override @Override
@ -763,7 +763,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
protected int engineDoFinal(byte[] in, int inOfs, int inLen, byte[] out, protected int engineDoFinal(byte[] in, int inOfs, int inLen, byte[] out,
int outOfs) throws ShortBufferException, AEADBadTagException { int outOfs) throws ShortBufferException, AEADBadTagException {
int bytesUpdated = 0; int bytesUpdated;
try { try {
bytesUpdated = engine.doFinal(in, inOfs, inLen, out, outOfs); bytesUpdated = engine.doFinal(in, inOfs, inLen, out, outOfs);
} catch (KeyException ke) { } catch (KeyException ke) {
@ -785,6 +785,9 @@ abstract class ChaCha20Cipher extends CipherSpi {
* *
* @return the resulting plaintext or ciphertext bytes. * @return the resulting plaintext or ciphertext bytes.
* *
* @throws ShortBufferException if the buffer {@code output} does not have
* enough space to hold the resulting data.
*
* @throws AEADBadTagException if, during decryption, the provided tag * @throws AEADBadTagException if, during decryption, the provided tag
* does not match the calculated tag. * does not match the calculated tag.
*/ */
@ -947,12 +950,8 @@ abstract class ChaCha20Cipher extends CipherSpi {
* key and nonce into their proper locations. The counter field is not * key and nonce into their proper locations. The counter field is not
* set here. * set here.
* *
* @throws IllegalArgumentException if the key or nonce are not in
* their proper lengths (32 bytes for the key, 12 bytes for the
* nonce).
* @throws InvalidKeyException if the key does not support an encoded form.
*/ */
private void setInitialState() throws InvalidKeyException { private void setInitialState() {
// Apply constants to first 4 words // Apply constants to first 4 words
startState[0] = STATE_CONST_0; startState[0] = STATE_CONST_0;
startState[1] = STATE_CONST_1; startState[1] = STATE_CONST_1;
@ -1257,11 +1256,11 @@ abstract class ChaCha20Cipher extends CipherSpi {
* @param out the array to write the resulting tag into * @param out the array to write the resulting tag into
* @param outOff the offset to begin writing the data. * @param outOff the offset to begin writing the data.
* *
* @throws ShortBufferException if there is insufficient room to * @throws ProviderException if there is insufficient room to
* write the tag. * write the tag.
*/ */
private void authFinalizeData(byte[] data, int dataOff, int length, private void authFinalizeData(byte[] data, int dataOff, int length,
byte[] out, int outOff) throws ShortBufferException { byte[] out, int outOff) {
// Update with the final chunk of ciphertext, then pad to a // Update with the final chunk of ciphertext, then pad to a
// multiple of 16. // multiple of 16.
if (data != null) { if (data != null) {
@ -1300,7 +1299,7 @@ abstract class ChaCha20Cipher extends CipherSpi {
* @param dLen the length of the application data. * @param dLen the length of the application data.
* @param buf the buffer to write the two lengths into. * @param buf the buffer to write the two lengths into.
* *
* @note it is the caller's responsibility to provide an array large * @implNote it is the caller's responsibility to provide an array large
* enough to hold the two longs. * enough to hold the two longs.
*/ */
private void authWriteLengths(long aLen, long dLen, byte[] buf) { private void authWriteLengths(long aLen, long dLen, byte[] buf) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -206,8 +206,7 @@ public final class ChaCha20Poly1305Parameters extends AlgorithmParametersSpi {
protected String engineToString() { protected String engineToString() {
String LINE_SEP = System.lineSeparator(); String LINE_SEP = System.lineSeparator();
HexDumpEncoder encoder = new HexDumpEncoder(); HexDumpEncoder encoder = new HexDumpEncoder();
StringBuilder sb = new StringBuilder(LINE_SEP + "nonce:" + return LINE_SEP + "nonce:" +
LINE_SEP + "[" + encoder.encodeBuffer(nonce) + "]"); LINE_SEP + "[" + encoder.encodeBuffer(nonce) + "]";
return sb.toString();
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -180,7 +180,7 @@ class CipherBlockChaining extends FeedbackCipher {
* *
* <p>It is also the application's responsibility to make sure that * <p>It is also the application's responsibility to make sure that
* <code>init</code> has been called before this method is called. * <code>init</code> has been called before this method is called.
* (This check is omitted here, to avoid double checking.) * (This check is omitted here, to avoid double-checking.)
* *
* @param cipher the buffer with the input data to be decrypted * @param cipher the buffer with the input data to be decrypted
* @param cipherOffset the offset in <code>cipherOffset</code> * @param cipherOffset the offset in <code>cipherOffset</code>

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -67,7 +67,7 @@ final class CipherCore {
/* /*
* unit size (number of input bytes that can be processed at a time) * unit size (number of input bytes that can be processed at a time)
*/ */
private int unitBytes = 0; private int unitBytes;
/* /*
* index of the content size left in the buffer * index of the content size left in the buffer
@ -91,17 +91,17 @@ final class CipherCore {
* input bytes that are processed at a time is different from the block * input bytes that are processed at a time is different from the block
* size) * size)
*/ */
private int diffBlocksize = 0; private int diffBlocksize;
/* /*
* padding class * padding class
*/ */
private Padding padding = null; private Padding padding;
/* /*
* internal cipher engine * internal cipher engine
*/ */
private FeedbackCipher cipher = null; private FeedbackCipher cipher;
/* /*
* the cipher mode * the cipher mode
@ -136,7 +136,7 @@ final class CipherCore {
/* /*
* The buffer should be usable for all cipher mode and padding * The buffer should be usable for all cipher mode and padding
* schemes. Thus, it has to be at least (blockSize+1) for CTS. * schemes. Thus, it has to be at least (blockSize+1) for CTS.
* In decryption mode, it also hold the possible padding block. * In decryption mode, it also holds the possible padding block.
*/ */
buffer = new byte[blockSize*2]; buffer = new byte[blockSize*2];
@ -334,7 +334,7 @@ final class CipherCore {
if (cipherMode == ECB_MODE) { if (cipherMode == ECB_MODE) {
return null; return null;
} }
AlgorithmParameters params = null; AlgorithmParameters params;
AlgorithmParameterSpec spec; AlgorithmParameterSpec spec;
byte[] iv = getIV(); byte[] iv = getIV();
if (iv == null) { if (iv == null) {
@ -545,7 +545,7 @@ final class CipherCore {
*/ */
byte[] update(byte[] input, int inputOffset, int inputLen) { byte[] update(byte[] input, int inputOffset, int inputLen) {
byte[] output = null; byte[] output;
try { try {
output = new byte[getOutputSizeByOperation(inputLen, false)]; output = new byte[getOutputSizeByOperation(inputLen, false)];
int len = update(input, inputOffset, inputLen, output, int len = update(input, inputOffset, inputLen, output,
@ -930,8 +930,7 @@ final class CipherCore {
private int fillOutputBuffer(byte[] finalBuf, int finalOffset, private int fillOutputBuffer(byte[] finalBuf, int finalOffset,
byte[] output, int outOfs, int finalBufLen, byte[] input) byte[] output, int outOfs, int finalBufLen, byte[] input)
throws ShortBufferException, BadPaddingException, throws BadPaddingException, IllegalBlockSizeException {
IllegalBlockSizeException {
int len; int len;
try { try {
@ -967,7 +966,7 @@ final class CipherCore {
private int finalNoPadding(byte[] in, int inOfs, byte[] out, int outOfs, private int finalNoPadding(byte[] in, int inOfs, byte[] out, int outOfs,
int len) int len)
throws IllegalBlockSizeException, ShortBufferException { throws IllegalBlockSizeException {
if (in == null || len == 0) { if (in == null || len == 0) {
return 0; return 0;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,7 +26,6 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import javax.crypto.IllegalBlockSizeException; import javax.crypto.IllegalBlockSizeException;
import javax.crypto.ShortBufferException;
/** /**
* This class represents ciphers in cipher text stealing (CTS) mode. * This class represents ciphers in cipher text stealing (CTS) mode.
@ -153,7 +152,7 @@ final class CipherTextStealing extends CipherBlockChaining {
* *
* <p>It is also the application's responsibility to make sure that * <p>It is also the application's responsibility to make sure that
* <code>init</code> has been called before this method is called. * <code>init</code> has been called before this method is called.
* (This check is omitted here, to avoid double checking.) * (This check is omitted here, to avoid double-checking.)
* *
* @param cipher the buffer with the input data to be decrypted * @param cipher the buffer with the input data to be decrypted
* @param cipherOffset the offset in <code>cipherOffset</code> * @param cipherOffset the offset in <code>cipherOffset</code>

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -54,7 +54,7 @@ final class ConstructKeys {
private static final PublicKey constructPublicKey(byte[] encodedKey, private static final PublicKey constructPublicKey(byte[] encodedKey,
int ofs, int len, String encodedKeyAlgorithm) int ofs, int len, String encodedKeyAlgorithm)
throws InvalidKeyException, NoSuchAlgorithmException { throws InvalidKeyException, NoSuchAlgorithmException {
PublicKey key = null; PublicKey key;
byte[] keyBytes = (ofs == 0 && encodedKey.length == len) byte[] keyBytes = (ofs == 0 && encodedKey.length == len)
? encodedKey : Arrays.copyOfRange(encodedKey, ofs, ofs + len); ? encodedKey : Arrays.copyOfRange(encodedKey, ofs, ofs + len);
X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes); X509EncodedKeySpec keySpec = new X509EncodedKeySpec(keyBytes);
@ -88,7 +88,7 @@ final class ConstructKeys {
private static final PrivateKey constructPrivateKey(byte[] encodedKey, private static final PrivateKey constructPrivateKey(byte[] encodedKey,
int ofs, int len, String encodedKeyAlgorithm) int ofs, int len, String encodedKeyAlgorithm)
throws InvalidKeyException, NoSuchAlgorithmException { throws InvalidKeyException, NoSuchAlgorithmException {
PrivateKey key = null; PrivateKey key;
byte[] keyBytes = (ofs == 0 && encodedKey.length == len) byte[] keyBytes = (ofs == 0 && encodedKey.length == len)
? encodedKey : Arrays.copyOfRange(encodedKey, ofs, ofs + len); ? encodedKey : Arrays.copyOfRange(encodedKey, ofs, ofs + len);
PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(keyBytes);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -40,7 +40,7 @@ import java.security.InvalidKeyException;
*/ */
class DESCrypt extends SymmetricCipher implements DESConstants { class DESCrypt extends SymmetricCipher implements DESConstants {
private static final int s0p[] = { private static final int[] s0p = {
0x00410100, 0x00010000, 0x40400000, 0x40410100, 0x00400000, 0x00410100, 0x00010000, 0x40400000, 0x40410100, 0x00400000,
0x40010100, 0x40010000, 0x40400000, 0x40010100, 0x00410100, 0x40010100, 0x40010000, 0x40400000, 0x40010100, 0x00410100,
0x00410000, 0x40000100, 0x40400100, 0x00400000, 0x00000000, 0x00410000, 0x40000100, 0x40400100, 0x00400000, 0x00000000,
@ -56,7 +56,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
0x40000000, 0x40410000, 0x00000100, 0x40010100, 0x40000000, 0x40410000, 0x00000100, 0x40010100,
}; };
private static final int s1p[] = { private static final int[] s1p = {
0x08021002, 0x00000000, 0x00021000, 0x08020000, 0x08000002, 0x08021002, 0x00000000, 0x00021000, 0x08020000, 0x08000002,
0x00001002, 0x08001000, 0x00021000, 0x00001000, 0x08020002, 0x00001002, 0x08001000, 0x00021000, 0x00001000, 0x08020002,
0x00000002, 0x08001000, 0x00020002, 0x08021000, 0x08020000, 0x00000002, 0x08001000, 0x00020002, 0x08021000, 0x08020000,
@ -72,7 +72,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
0x08001002, 0x00000002, 0x08020000, 0x00021000, 0x08001002, 0x00000002, 0x08020000, 0x00021000,
}; };
private static final int s2p[] = { private static final int[] s2p = {
0x20800000, 0x00808020, 0x00000020, 0x20800020, 0x20008000, 0x20800000, 0x00808020, 0x00000020, 0x20800020, 0x20008000,
0x00800000, 0x20800020, 0x00008020, 0x00800020, 0x00008000, 0x00800000, 0x20800020, 0x00008020, 0x00800020, 0x00008000,
0x00808000, 0x20000000, 0x20808020, 0x20000020, 0x20000000, 0x00808000, 0x20000000, 0x20808020, 0x20000020, 0x20000000,
@ -88,7 +88,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
0x20800000, 0x20008020, 0x00000020, 0x00808000, 0x20800000, 0x20008020, 0x00000020, 0x00808000,
}; };
private static final int s3p[] = { private static final int[] s3p = {
0x00080201, 0x02000200, 0x00000001, 0x02080201, 0x00000000, 0x00080201, 0x02000200, 0x00000001, 0x02080201, 0x00000000,
0x02080000, 0x02000201, 0x00080001, 0x02080200, 0x02000001, 0x02080000, 0x02000201, 0x00080001, 0x02080200, 0x02000001,
0x02000000, 0x00000201, 0x02000001, 0x00080201, 0x00080000, 0x02000000, 0x00000201, 0x02000001, 0x00080201, 0x00080000,
@ -104,7 +104,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
0x00000201, 0x02000000, 0x02000001, 0x02080200, 0x00000201, 0x02000000, 0x02000001, 0x02080200,
}; };
private static final int s4p[] = { private static final int[] s4p = {
0x01000000, 0x00002000, 0x00000080, 0x01002084, 0x01002004, 0x01000000, 0x00002000, 0x00000080, 0x01002084, 0x01002004,
0x01000080, 0x00002084, 0x01002000, 0x00002000, 0x00000004, 0x01000080, 0x00002084, 0x01002000, 0x00002000, 0x00000004,
0x01000004, 0x00002080, 0x01000084, 0x01002004, 0x01002080, 0x01000004, 0x00002080, 0x01000084, 0x01002004, 0x01002080,
@ -120,7 +120,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
0x00000004, 0x00002084, 0x01002000, 0x01000004, 0x00000004, 0x00002084, 0x01002000, 0x01000004,
}; };
private static final int s5p[] = { private static final int[] s5p = {
0x10000008, 0x00040008, 0x00000000, 0x10040400, 0x00040008, 0x10000008, 0x00040008, 0x00000000, 0x10040400, 0x00040008,
0x00000400, 0x10000408, 0x00040000, 0x00000408, 0x10040408, 0x00000400, 0x10000408, 0x00040000, 0x00000408, 0x10040408,
0x00040400, 0x10000000, 0x10000400, 0x10000008, 0x10040000, 0x00040400, 0x10000000, 0x10000400, 0x10000008, 0x10040000,
@ -136,7 +136,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
0x10040000, 0x00000408, 0x00000008, 0x10040008, 0x10040000, 0x00000408, 0x00000008, 0x10040008,
}; };
private static final int s6p[] = { private static final int[] s6p = {
0x00000800, 0x00000040, 0x00200040, 0x80200000, 0x80200840, 0x00000800, 0x00000040, 0x00200040, 0x80200000, 0x80200840,
0x80000800, 0x00000840, 0x00000000, 0x00200000, 0x80200040, 0x80000800, 0x00000840, 0x00000000, 0x00200000, 0x80200040,
0x80000040, 0x00200800, 0x80000000, 0x00200840, 0x00200800, 0x80000040, 0x00200800, 0x80000000, 0x00200840, 0x00200800,
@ -152,7 +152,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
0x80200000, 0x00200840, 0x00200800, 0x80000800, 0x80200000, 0x00200840, 0x00200800, 0x80000800,
}; };
private static final int s7p[] = { private static final int[] s7p = {
0x04100010, 0x04104000, 0x00004010, 0x00000000, 0x04004000, 0x04100010, 0x04104000, 0x00004010, 0x00000000, 0x04004000,
0x00100010, 0x04100000, 0x04104010, 0x00000010, 0x04000000, 0x00100010, 0x04100000, 0x04104010, 0x00000010, 0x04000000,
0x00104000, 0x00004010, 0x00104010, 0x04004010, 0x04000010, 0x00104000, 0x00004010, 0x00104010, 0x04004010, 0x04000010,
@ -168,112 +168,112 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
0x04000000, 0x04100010, 0x00004000, 0x00104010, 0x04000000, 0x04100010, 0x00004000, 0x00104010,
}; };
private static final int permRight0[] = { private static final int[] permRight0 = {
0x00000000, 0x40000000, 0x00400000, 0x40400000, 0x00004000, 0x00000000, 0x40000000, 0x00400000, 0x40400000, 0x00004000,
0x40004000, 0x00404000, 0x40404000, 0x00000040, 0x40000040, 0x40004000, 0x00404000, 0x40404000, 0x00000040, 0x40000040,
0x00400040, 0x40400040, 0x00004040, 0x40004040, 0x00404040, 0x00400040, 0x40400040, 0x00004040, 0x40004040, 0x00404040,
0x40404040, 0x40404040,
}; };
private static final int permLeft1[] = { private static final int[] permLeft1 = {
0x00000000, 0x40000000, 0x00400000, 0x40400000, 0x00004000, 0x00000000, 0x40000000, 0x00400000, 0x40400000, 0x00004000,
0x40004000, 0x00404000, 0x40404000, 0x00000040, 0x40000040, 0x40004000, 0x00404000, 0x40404000, 0x00000040, 0x40000040,
0x00400040, 0x40400040, 0x00004040, 0x40004040, 0x00404040, 0x00400040, 0x40400040, 0x00004040, 0x40004040, 0x00404040,
0x40404040, 0x40404040,
}; };
private static final int permRight2[] = { private static final int[] permRight2 = {
0x00000000, 0x10000000, 0x00100000, 0x10100000, 0x00001000, 0x00000000, 0x10000000, 0x00100000, 0x10100000, 0x00001000,
0x10001000, 0x00101000, 0x10101000, 0x00000010, 0x10000010, 0x10001000, 0x00101000, 0x10101000, 0x00000010, 0x10000010,
0x00100010, 0x10100010, 0x00001010, 0x10001010, 0x00101010, 0x00100010, 0x10100010, 0x00001010, 0x10001010, 0x00101010,
0x10101010, 0x10101010,
}; };
private static final int permLeft3[] = { private static final int[] permLeft3 = {
0x00000000, 0x10000000, 0x00100000, 0x10100000, 0x00001000, 0x00000000, 0x10000000, 0x00100000, 0x10100000, 0x00001000,
0x10001000, 0x00101000, 0x10101000, 0x00000010, 0x10000010, 0x10001000, 0x00101000, 0x10101000, 0x00000010, 0x10000010,
0x00100010, 0x10100010, 0x00001010, 0x10001010, 0x00101010, 0x00100010, 0x10100010, 0x00001010, 0x10001010, 0x00101010,
0x10101010, 0x10101010,
}; };
private static final int permRight4[] = { private static final int[] permRight4 = {
0x00000000, 0x04000000, 0x00040000, 0x04040000, 0x00000400, 0x00000000, 0x04000000, 0x00040000, 0x04040000, 0x00000400,
0x04000400, 0x00040400, 0x04040400, 0x00000004, 0x04000004, 0x04000400, 0x00040400, 0x04040400, 0x00000004, 0x04000004,
0x00040004, 0x04040004, 0x00000404, 0x04000404, 0x00040404, 0x00040004, 0x04040004, 0x00000404, 0x04000404, 0x00040404,
0x04040404, 0x04040404,
}; };
private static final int permLeft5[] = { private static final int[] permLeft5 = {
0x00000000, 0x04000000, 0x00040000, 0x04040000, 0x00000400, 0x00000000, 0x04000000, 0x00040000, 0x04040000, 0x00000400,
0x04000400, 0x00040400, 0x04040400, 0x00000004, 0x04000004, 0x04000400, 0x00040400, 0x04040400, 0x00000004, 0x04000004,
0x00040004, 0x04040004, 0x00000404, 0x04000404, 0x00040404, 0x00040004, 0x04040004, 0x00000404, 0x04000404, 0x00040404,
0x04040404, 0x04040404,
}; };
private static final int permRight6[] = { private static final int[] permRight6 = {
0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100, 0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100,
0x01000100, 0x00010100, 0x01010100, 0x00000001, 0x01000001, 0x01000100, 0x00010100, 0x01010100, 0x00000001, 0x01000001,
0x00010001, 0x01010001, 0x00000101, 0x01000101, 0x00010101, 0x00010001, 0x01010001, 0x00000101, 0x01000101, 0x00010101,
0x01010101, 0x01010101,
}; };
private static final int permLeft7[] = { private static final int[] permLeft7 = {
0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100, 0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00000100,
0x01000100, 0x00010100, 0x01010100, 0x00000001, 0x01000001, 0x01000100, 0x00010100, 0x01010100, 0x00000001, 0x01000001,
0x00010001, 0x01010001, 0x00000101, 0x01000101, 0x00010101, 0x00010001, 0x01010001, 0x00000101, 0x01000101, 0x00010101,
0x01010101, 0x01010101,
}; };
private static final int permRight8[] = { private static final int[] permRight8 = {
0x00000000, 0x80000000, 0x00800000, 0x80800000, 0x00008000, 0x00000000, 0x80000000, 0x00800000, 0x80800000, 0x00008000,
0x80008000, 0x00808000, 0x80808000, 0x00000080, 0x80000080, 0x80008000, 0x00808000, 0x80808000, 0x00000080, 0x80000080,
0x00800080, 0x80800080, 0x00008080, 0x80008080, 0x00808080, 0x00800080, 0x80800080, 0x00008080, 0x80008080, 0x00808080,
0x80808080, 0x80808080,
}; };
private static final int permLeft9[] = { private static final int[] permLeft9 = {
0x00000000, 0x80000000, 0x00800000, 0x80800000, 0x00008000, 0x00000000, 0x80000000, 0x00800000, 0x80800000, 0x00008000,
0x80008000, 0x00808000, 0x80808000, 0x00000080, 0x80000080, 0x80008000, 0x00808000, 0x80808000, 0x00000080, 0x80000080,
0x00800080, 0x80800080, 0x00008080, 0x80008080, 0x00808080, 0x00800080, 0x80800080, 0x00008080, 0x80008080, 0x00808080,
0x80808080, 0x80808080,
}; };
private static final int permRightA[] = { private static final int[] permRightA = {
0x00000000, 0x20000000, 0x00200000, 0x20200000, 0x00002000, 0x00000000, 0x20000000, 0x00200000, 0x20200000, 0x00002000,
0x20002000, 0x00202000, 0x20202000, 0x00000020, 0x20000020, 0x20002000, 0x00202000, 0x20202000, 0x00000020, 0x20000020,
0x00200020, 0x20200020, 0x00002020, 0x20002020, 0x00202020, 0x00200020, 0x20200020, 0x00002020, 0x20002020, 0x00202020,
0x20202020, 0x20202020,
}; };
private static final int permLeftB[] = { private static final int[] permLeftB = {
0x00000000, 0x20000000, 0x00200000, 0x20200000, 0x00002000, 0x00000000, 0x20000000, 0x00200000, 0x20200000, 0x00002000,
0x20002000, 0x00202000, 0x20202000, 0x00000020, 0x20000020, 0x20002000, 0x00202000, 0x20202000, 0x00000020, 0x20000020,
0x00200020, 0x20200020, 0x00002020, 0x20002020, 0x00202020, 0x00200020, 0x20200020, 0x00002020, 0x20002020, 0x00202020,
0x20202020, 0x20202020,
}; };
private static final int permRightC[] = { private static final int[] permRightC = {
0x00000000, 0x08000000, 0x00080000, 0x08080000, 0x00000800, 0x00000000, 0x08000000, 0x00080000, 0x08080000, 0x00000800,
0x08000800, 0x00080800, 0x08080800, 0x00000008, 0x08000008, 0x08000800, 0x00080800, 0x08080800, 0x00000008, 0x08000008,
0x00080008, 0x08080008, 0x00000808, 0x08000808, 0x00080808, 0x00080008, 0x08080008, 0x00000808, 0x08000808, 0x00080808,
0x08080808, 0x08080808,
}; };
private static final int permLeftD[] = { private static final int[] permLeftD = {
0x00000000, 0x08000000, 0x00080000, 0x08080000, 0x00000800, 0x00000000, 0x08000000, 0x00080000, 0x08080000, 0x00000800,
0x08000800, 0x00080800, 0x08080800, 0x00000008, 0x08000008, 0x08000800, 0x00080800, 0x08080800, 0x00000008, 0x08000008,
0x00080008, 0x08080008, 0x00000808, 0x08000808, 0x00080808, 0x00080008, 0x08080008, 0x00000808, 0x08000808, 0x00080808,
0x08080808, 0x08080808,
}; };
private static final int permRightE[] = { private static final int[] permRightE = {
0x00000000, 0x02000000, 0x00020000, 0x02020000, 0x00000200, 0x00000000, 0x02000000, 0x00020000, 0x02020000, 0x00000200,
0x02000200, 0x00020200, 0x02020200, 0x00000002, 0x02000002, 0x02000200, 0x00020200, 0x02020200, 0x00000002, 0x02000002,
0x00020002, 0x02020002, 0x00000202, 0x02000202, 0x00020202, 0x00020002, 0x02020002, 0x00000202, 0x02000202, 0x00020202,
0x02020202, 0x02020202,
}; };
private static final int permLeftF[] = { private static final int[] permLeftF = {
0x00000000, 0x02000000, 0x00020000, 0x02020000, 0x00000200, 0x00000000, 0x02000000, 0x00020000, 0x02020000, 0x00000200,
0x02000200, 0x00020200, 0x02020200, 0x00000002, 0x02000002, 0x02000200, 0x00020200, 0x02020200, 0x00000002, 0x02000002,
0x00020002, 0x02020002, 0x00000202, 0x02000202, 0x00020202, 0x00020002, 0x02020002, 0x00000202, 0x02000202, 0x00020202,
@ -283,224 +283,224 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
/* /*
* Initial Permutation * Initial Permutation
*/ */
private static final int initPermLeft0[] = { private static final int[] initPermLeft0 = {
0x00000000, 0x00008000, 0x00000000, 0x00008000, 0x00000080, 0x00000000, 0x00008000, 0x00000000, 0x00008000, 0x00000080,
0x00008080, 0x00000080, 0x00008080, 0x00000000, 0x00008000, 0x00008080, 0x00000080, 0x00008080, 0x00000000, 0x00008000,
0x00000000, 0x00008000, 0x00000080, 0x00008080, 0x00000080, 0x00000000, 0x00008000, 0x00000080, 0x00008080, 0x00000080,
0x00008080, 0x00008080,
}; };
private static final int initPermRight0[] = { private static final int[] initPermRight0 = {
0x00000000, 0x00000000, 0x00008000, 0x00008000, 0x00000000, 0x00000000, 0x00000000, 0x00008000, 0x00008000, 0x00000000,
0x00000000, 0x00008000, 0x00008000, 0x00000080, 0x00000080, 0x00000000, 0x00008000, 0x00008000, 0x00000080, 0x00000080,
0x00008080, 0x00008080, 0x00000080, 0x00000080, 0x00008080, 0x00008080, 0x00008080, 0x00000080, 0x00000080, 0x00008080,
0x00008080, 0x00008080,
}; };
private static final int initPermLeft1[] = { private static final int[] initPermLeft1 = {
0x00000000, 0x80000000, 0x00000000, 0x80000000, 0x00800000, 0x00000000, 0x80000000, 0x00000000, 0x80000000, 0x00800000,
0x80800000, 0x00800000, 0x80800000, 0x00000000, 0x80000000, 0x80800000, 0x00800000, 0x80800000, 0x00000000, 0x80000000,
0x00000000, 0x80000000, 0x00800000, 0x80800000, 0x00800000, 0x00000000, 0x80000000, 0x00800000, 0x80800000, 0x00800000,
0x80800000, 0x80800000,
}; };
private static final int initPermRight1[] = { private static final int[] initPermRight1 = {
0x00000000, 0x00000000, 0x80000000, 0x80000000, 0x00000000, 0x00000000, 0x00000000, 0x80000000, 0x80000000, 0x00000000,
0x00000000, 0x80000000, 0x80000000, 0x00800000, 0x00800000, 0x00000000, 0x80000000, 0x80000000, 0x00800000, 0x00800000,
0x80800000, 0x80800000, 0x00800000, 0x00800000, 0x80800000, 0x80800000, 0x80800000, 0x00800000, 0x00800000, 0x80800000,
0x80800000, 0x80800000,
}; };
private static final int initPermLeft2[] = { private static final int[] initPermLeft2 = {
0x00000000, 0x00004000, 0x00000000, 0x00004000, 0x00000040, 0x00000000, 0x00004000, 0x00000000, 0x00004000, 0x00000040,
0x00004040, 0x00000040, 0x00004040, 0x00000000, 0x00004000, 0x00004040, 0x00000040, 0x00004040, 0x00000000, 0x00004000,
0x00000000, 0x00004000, 0x00000040, 0x00004040, 0x00000040, 0x00000000, 0x00004000, 0x00000040, 0x00004040, 0x00000040,
0x00004040, 0x00004040,
}; };
private static final int initPermRight2[] = { private static final int[] initPermRight2 = {
0x00000000, 0x00000000, 0x00004000, 0x00004000, 0x00000000, 0x00000000, 0x00000000, 0x00004000, 0x00004000, 0x00000000,
0x00000000, 0x00004000, 0x00004000, 0x00000040, 0x00000040, 0x00000000, 0x00004000, 0x00004000, 0x00000040, 0x00000040,
0x00004040, 0x00004040, 0x00000040, 0x00000040, 0x00004040, 0x00004040, 0x00004040, 0x00000040, 0x00000040, 0x00004040,
0x00004040, 0x00004040,
}; };
private static final int initPermLeft3[] = { private static final int[] initPermLeft3 = {
0x00000000, 0x40000000, 0x00000000, 0x40000000, 0x00400000, 0x00000000, 0x40000000, 0x00000000, 0x40000000, 0x00400000,
0x40400000, 0x00400000, 0x40400000, 0x00000000, 0x40000000, 0x40400000, 0x00400000, 0x40400000, 0x00000000, 0x40000000,
0x00000000, 0x40000000, 0x00400000, 0x40400000, 0x00400000, 0x00000000, 0x40000000, 0x00400000, 0x40400000, 0x00400000,
0x40400000, 0x40400000,
}; };
private static final int initPermRight3[] = { private static final int[] initPermRight3 = {
0x00000000, 0x00000000, 0x40000000, 0x40000000, 0x00000000, 0x00000000, 0x00000000, 0x40000000, 0x40000000, 0x00000000,
0x00000000, 0x40000000, 0x40000000, 0x00400000, 0x00400000, 0x00000000, 0x40000000, 0x40000000, 0x00400000, 0x00400000,
0x40400000, 0x40400000, 0x00400000, 0x00400000, 0x40400000, 0x40400000, 0x40400000, 0x00400000, 0x00400000, 0x40400000,
0x40400000, 0x40400000,
}; };
private static final int initPermLeft4[] = { private static final int[] initPermLeft4 = {
0x00000000, 0x00002000, 0x00000000, 0x00002000, 0x00000020, 0x00000000, 0x00002000, 0x00000000, 0x00002000, 0x00000020,
0x00002020, 0x00000020, 0x00002020, 0x00000000, 0x00002000, 0x00002020, 0x00000020, 0x00002020, 0x00000000, 0x00002000,
0x00000000, 0x00002000, 0x00000020, 0x00002020, 0x00000020, 0x00000000, 0x00002000, 0x00000020, 0x00002020, 0x00000020,
0x00002020, 0x00002020,
}; };
private static final int initPermRight4[] = { private static final int[] initPermRight4 = {
0x00000000, 0x00000000, 0x00002000, 0x00002000, 0x00000000, 0x00000000, 0x00000000, 0x00002000, 0x00002000, 0x00000000,
0x00000000, 0x00002000, 0x00002000, 0x00000020, 0x00000020, 0x00000000, 0x00002000, 0x00002000, 0x00000020, 0x00000020,
0x00002020, 0x00002020, 0x00000020, 0x00000020, 0x00002020, 0x00002020, 0x00002020, 0x00000020, 0x00000020, 0x00002020,
0x00002020, 0x00002020,
}; };
private static final int initPermLeft5[] = { private static final int[] initPermLeft5 = {
0x00000000, 0x20000000, 0x00000000, 0x20000000, 0x00200000, 0x00000000, 0x20000000, 0x00000000, 0x20000000, 0x00200000,
0x20200000, 0x00200000, 0x20200000, 0x00000000, 0x20000000, 0x20200000, 0x00200000, 0x20200000, 0x00000000, 0x20000000,
0x00000000, 0x20000000, 0x00200000, 0x20200000, 0x00200000, 0x00000000, 0x20000000, 0x00200000, 0x20200000, 0x00200000,
0x20200000, 0x20200000,
}; };
private static final int initPermRight5[] = { private static final int[] initPermRight5 = {
0x00000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000, 0x00000000, 0x00000000, 0x20000000, 0x20000000, 0x00000000,
0x00000000, 0x20000000, 0x20000000, 0x00200000, 0x00200000, 0x00000000, 0x20000000, 0x20000000, 0x00200000, 0x00200000,
0x20200000, 0x20200000, 0x00200000, 0x00200000, 0x20200000, 0x20200000, 0x20200000, 0x00200000, 0x00200000, 0x20200000,
0x20200000, 0x20200000,
}; };
private static final int initPermLeft6[] = { private static final int[] initPermLeft6 = {
0x00000000, 0x00001000, 0x00000000, 0x00001000, 0x00000010, 0x00000000, 0x00001000, 0x00000000, 0x00001000, 0x00000010,
0x00001010, 0x00000010, 0x00001010, 0x00000000, 0x00001000, 0x00001010, 0x00000010, 0x00001010, 0x00000000, 0x00001000,
0x00000000, 0x00001000, 0x00000010, 0x00001010, 0x00000010, 0x00000000, 0x00001000, 0x00000010, 0x00001010, 0x00000010,
0x00001010, 0x00001010,
}; };
private static final int initPermRight6[] = { private static final int[] initPermRight6 = {
0x00000000, 0x00000000, 0x00001000, 0x00001000, 0x00000000, 0x00000000, 0x00000000, 0x00001000, 0x00001000, 0x00000000,
0x00000000, 0x00001000, 0x00001000, 0x00000010, 0x00000010, 0x00000000, 0x00001000, 0x00001000, 0x00000010, 0x00000010,
0x00001010, 0x00001010, 0x00000010, 0x00000010, 0x00001010, 0x00001010, 0x00001010, 0x00000010, 0x00000010, 0x00001010,
0x00001010, 0x00001010,
}; };
private static final int initPermLeft7[] = { private static final int[] initPermLeft7 = {
0x00000000, 0x10000000, 0x00000000, 0x10000000, 0x00100000, 0x00000000, 0x10000000, 0x00000000, 0x10000000, 0x00100000,
0x10100000, 0x00100000, 0x10100000, 0x00000000, 0x10000000, 0x10100000, 0x00100000, 0x10100000, 0x00000000, 0x10000000,
0x00000000, 0x10000000, 0x00100000, 0x10100000, 0x00100000, 0x00000000, 0x10000000, 0x00100000, 0x10100000, 0x00100000,
0x10100000, 0x10100000,
}; };
private static final int initPermRight7[] = { private static final int[] initPermRight7 = {
0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x00000000, 0x00000000, 0x00000000, 0x10000000, 0x10000000, 0x00000000,
0x00000000, 0x10000000, 0x10000000, 0x00100000, 0x00100000, 0x00000000, 0x10000000, 0x10000000, 0x00100000, 0x00100000,
0x10100000, 0x10100000, 0x00100000, 0x00100000, 0x10100000, 0x10100000, 0x10100000, 0x00100000, 0x00100000, 0x10100000,
0x10100000, 0x10100000,
}; };
private static final int initPermLeft8[] = { private static final int[] initPermLeft8 = {
0x00000000, 0x00000800, 0x00000000, 0x00000800, 0x00000008, 0x00000000, 0x00000800, 0x00000000, 0x00000800, 0x00000008,
0x00000808, 0x00000008, 0x00000808, 0x00000000, 0x00000800, 0x00000808, 0x00000008, 0x00000808, 0x00000000, 0x00000800,
0x00000000, 0x00000800, 0x00000008, 0x00000808, 0x00000008, 0x00000000, 0x00000800, 0x00000008, 0x00000808, 0x00000008,
0x00000808, 0x00000808,
}; };
private static final int initPermRight8[] = { private static final int[] initPermRight8 = {
0x00000000, 0x00000000, 0x00000800, 0x00000800, 0x00000000, 0x00000000, 0x00000000, 0x00000800, 0x00000800, 0x00000000,
0x00000000, 0x00000800, 0x00000800, 0x00000008, 0x00000008, 0x00000000, 0x00000800, 0x00000800, 0x00000008, 0x00000008,
0x00000808, 0x00000808, 0x00000008, 0x00000008, 0x00000808, 0x00000808, 0x00000808, 0x00000008, 0x00000008, 0x00000808,
0x00000808, 0x00000808,
}; };
private static final int initPermLeft9[] = { private static final int[] initPermLeft9 = {
0x00000000, 0x08000000, 0x00000000, 0x08000000, 0x00080000, 0x00000000, 0x08000000, 0x00000000, 0x08000000, 0x00080000,
0x08080000, 0x00080000, 0x08080000, 0x00000000, 0x08000000, 0x08080000, 0x00080000, 0x08080000, 0x00000000, 0x08000000,
0x00000000, 0x08000000, 0x00080000, 0x08080000, 0x00080000, 0x00000000, 0x08000000, 0x00080000, 0x08080000, 0x00080000,
0x08080000, 0x08080000,
}; };
private static final int initPermRight9[] = { private static final int[] initPermRight9 = {
0x00000000, 0x00000000, 0x08000000, 0x08000000, 0x00000000, 0x00000000, 0x00000000, 0x08000000, 0x08000000, 0x00000000,
0x00000000, 0x08000000, 0x08000000, 0x00080000, 0x00080000, 0x00000000, 0x08000000, 0x08000000, 0x00080000, 0x00080000,
0x08080000, 0x08080000, 0x00080000, 0x00080000, 0x08080000, 0x08080000, 0x08080000, 0x00080000, 0x00080000, 0x08080000,
0x08080000, 0x08080000,
}; };
private static final int initPermLeftA[] = { private static final int[] initPermLeftA = {
0x00000000, 0x00000400, 0x00000000, 0x00000400, 0x00000004, 0x00000000, 0x00000400, 0x00000000, 0x00000400, 0x00000004,
0x00000404, 0x00000004, 0x00000404, 0x00000000, 0x00000400, 0x00000404, 0x00000004, 0x00000404, 0x00000000, 0x00000400,
0x00000000, 0x00000400, 0x00000004, 0x00000404, 0x00000004, 0x00000000, 0x00000400, 0x00000004, 0x00000404, 0x00000004,
0x00000404, 0x00000404,
}; };
private static final int initPermRightA[] = { private static final int[] initPermRightA = {
0x00000000, 0x00000000, 0x00000400, 0x00000400, 0x00000000, 0x00000000, 0x00000000, 0x00000400, 0x00000400, 0x00000000,
0x00000000, 0x00000400, 0x00000400, 0x00000004, 0x00000004, 0x00000000, 0x00000400, 0x00000400, 0x00000004, 0x00000004,
0x00000404, 0x00000404, 0x00000004, 0x00000004, 0x00000404, 0x00000404, 0x00000404, 0x00000004, 0x00000004, 0x00000404,
0x00000404, 0x00000404,
}; };
private static final int initPermLeftB[] = { private static final int[] initPermLeftB = {
0x00000000, 0x04000000, 0x00000000, 0x04000000, 0x00040000, 0x00000000, 0x04000000, 0x00000000, 0x04000000, 0x00040000,
0x04040000, 0x00040000, 0x04040000, 0x00000000, 0x04000000, 0x04040000, 0x00040000, 0x04040000, 0x00000000, 0x04000000,
0x00000000, 0x04000000, 0x00040000, 0x04040000, 0x00040000, 0x00000000, 0x04000000, 0x00040000, 0x04040000, 0x00040000,
0x04040000, 0x04040000,
}; };
private static final int initPermRightB[] = { private static final int[] initPermRightB = {
0x00000000, 0x00000000, 0x04000000, 0x04000000, 0x00000000, 0x00000000, 0x00000000, 0x04000000, 0x04000000, 0x00000000,
0x00000000, 0x04000000, 0x04000000, 0x00040000, 0x00040000, 0x00000000, 0x04000000, 0x04000000, 0x00040000, 0x00040000,
0x04040000, 0x04040000, 0x00040000, 0x00040000, 0x04040000, 0x04040000, 0x04040000, 0x00040000, 0x00040000, 0x04040000,
0x04040000, 0x04040000,
}; };
private static final int initPermLeftC[] = { private static final int[] initPermLeftC = {
0x00000000, 0x00000200, 0x00000000, 0x00000200, 0x00000002, 0x00000000, 0x00000200, 0x00000000, 0x00000200, 0x00000002,
0x00000202, 0x00000002, 0x00000202, 0x00000000, 0x00000200, 0x00000202, 0x00000002, 0x00000202, 0x00000000, 0x00000200,
0x00000000, 0x00000200, 0x00000002, 0x00000202, 0x00000002, 0x00000000, 0x00000200, 0x00000002, 0x00000202, 0x00000002,
0x00000202, 0x00000202,
}; };
private static final int initPermRightC[] = { private static final int[] initPermRightC = {
0x00000000, 0x00000000, 0x00000200, 0x00000200, 0x00000000, 0x00000000, 0x00000000, 0x00000200, 0x00000200, 0x00000000,
0x00000000, 0x00000200, 0x00000200, 0x00000002, 0x00000002, 0x00000000, 0x00000200, 0x00000200, 0x00000002, 0x00000002,
0x00000202, 0x00000202, 0x00000002, 0x00000002, 0x00000202, 0x00000202, 0x00000202, 0x00000002, 0x00000002, 0x00000202,
0x00000202, 0x00000202,
}; };
private static final int initPermLeftD[] = { private static final int[] initPermLeftD = {
0x00000000, 0x02000000, 0x00000000, 0x02000000, 0x00020000, 0x00000000, 0x02000000, 0x00000000, 0x02000000, 0x00020000,
0x02020000, 0x00020000, 0x02020000, 0x00000000, 0x02000000, 0x02020000, 0x00020000, 0x02020000, 0x00000000, 0x02000000,
0x00000000, 0x02000000, 0x00020000, 0x02020000, 0x00020000, 0x00000000, 0x02000000, 0x00020000, 0x02020000, 0x00020000,
0x02020000, 0x02020000,
}; };
private static final int initPermRightD[] = { private static final int[] initPermRightD = {
0x00000000, 0x00000000, 0x02000000, 0x02000000, 0x00000000, 0x00000000, 0x00000000, 0x02000000, 0x02000000, 0x00000000,
0x00000000, 0x02000000, 0x02000000, 0x00020000, 0x00020000, 0x00000000, 0x02000000, 0x02000000, 0x00020000, 0x00020000,
0x02020000, 0x02020000, 0x00020000, 0x00020000, 0x02020000, 0x02020000, 0x02020000, 0x00020000, 0x00020000, 0x02020000,
0x02020000, 0x02020000,
}; };
private static final int initPermLeftE[] = { private static final int[] initPermLeftE = {
0x00000000, 0x00000100, 0x00000000, 0x00000100, 0x00000001, 0x00000000, 0x00000100, 0x00000000, 0x00000100, 0x00000001,
0x00000101, 0x00000001, 0x00000101, 0x00000000, 0x00000100, 0x00000101, 0x00000001, 0x00000101, 0x00000000, 0x00000100,
0x00000000, 0x00000100, 0x00000001, 0x00000101, 0x00000001, 0x00000000, 0x00000100, 0x00000001, 0x00000101, 0x00000001,
0x00000101, 0x00000101,
}; };
private static final int initPermRightE[] = { private static final int[] initPermRightE = {
0x00000000, 0x00000000, 0x00000100, 0x00000100, 0x00000000, 0x00000000, 0x00000000, 0x00000100, 0x00000100, 0x00000000,
0x00000000, 0x00000100, 0x00000100, 0x00000001, 0x00000001, 0x00000000, 0x00000100, 0x00000100, 0x00000001, 0x00000001,
0x00000101, 0x00000101, 0x00000001, 0x00000001, 0x00000101, 0x00000101, 0x00000101, 0x00000001, 0x00000001, 0x00000101,
0x00000101, 0x00000101,
}; };
private static final int initPermLeftF[] = { private static final int[] initPermLeftF = {
0x00000000, 0x01000000, 0x00000000, 0x01000000, 0x00010000, 0x00000000, 0x01000000, 0x00000000, 0x01000000, 0x00010000,
0x01010000, 0x00010000, 0x01010000, 0x00000000, 0x01000000, 0x01010000, 0x00010000, 0x01010000, 0x00000000, 0x01000000,
0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00010000, 0x00000000, 0x01000000, 0x00010000, 0x01010000, 0x00010000,
0x01010000, 0x01010000,
}; };
private static final int initPermRightF[] = { private static final int[] initPermRightF = {
0x00000000, 0x00000000, 0x01000000, 0x01000000, 0x00000000, 0x00000000, 0x00000000, 0x01000000, 0x01000000, 0x00000000,
0x00000000, 0x01000000, 0x01000000, 0x00010000, 0x00010000, 0x00000000, 0x01000000, 0x01000000, 0x00010000, 0x00010000,
0x01010000, 0x01010000, 0x00010000, 0x00010000, 0x01010000, 0x01010000, 0x01010000, 0x00010000, 0x00010000, 0x01010000,
@ -586,7 +586,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
void cipherBlock(byte[] in, int inOffset, byte[] out, int outOffset) { void cipherBlock(byte[] in, int inOffset, byte[] out, int outOffset) {
byte key[]; byte[] key;
int temp; int temp;
int i, j; int i, j;
int offset; int offset;
@ -638,7 +638,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
} }
private static void perm(int left, int right, private static void perm(int left, int right,
byte out[], int offset) { byte[] out, int offset) {
int low, high, temp; int low, high, temp;
temp = left; temp = left;
@ -687,7 +687,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
} }
private static int initialPermutationLeft(byte block[], int offset) { private static int initialPermutationLeft(byte[] block, int offset) {
int l; int l;
l = initPermLeft1[block[offset] & 0xf]; l = initPermLeft1[block[offset] & 0xf];
@ -709,7 +709,7 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
return l; return l;
} }
private static int initialPermutationRight(byte block[], int offset) { private static int initialPermutationRight(byte[] block, int offset) {
int l; int l;
l = initPermRight1[block[offset] & 0xf]; l = initPermRight1[block[offset] & 0xf];
@ -731,9 +731,9 @@ class DESCrypt extends SymmetricCipher implements DESConstants {
return l; return l;
} }
void expandKey(byte key[]) { void expandKey(byte[] key) {
int octet; int octet;
byte ek[] = new byte[128]; byte[] ek = new byte[128];
octet = key[0]; octet = key[0];
if ((octet & 0x80) != 0) { if ((octet & 0x80) != 0) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -104,7 +104,7 @@ public final class DESKeyFactory extends SecretKeyFactorySpi {
try { try {
if ((key instanceof SecretKey) if ((key != null)
&& (key.getAlgorithm().equalsIgnoreCase("DES")) && (key.getAlgorithm().equalsIgnoreCase("DES"))
&& (key.getFormat().equalsIgnoreCase("RAW"))) { && (key.getFormat().equalsIgnoreCase("RAW"))) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -103,7 +103,7 @@ public final class DESedeKeyFactory extends SecretKeyFactorySpi {
throws InvalidKeySpecException { throws InvalidKeySpecException {
try { try {
if ((key instanceof SecretKey) if ((key != null)
&& (key.getAlgorithm().equalsIgnoreCase("DESede")) && (key.getAlgorithm().equalsIgnoreCase("DESede"))
&& (key.getFormat().equalsIgnoreCase("RAW"))) { && (key.getFormat().equalsIgnoreCase("RAW"))) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -130,7 +130,7 @@ public final class DESedeKeyGenerator extends KeyGeneratorSpi {
java.util.Arrays.fill(tmpkey, (byte)0x00); java.util.Arrays.fill(tmpkey, (byte)0x00);
} }
DESedeKey desEdeKey = null; DESedeKey desEdeKey;
try { try {
desEdeKey = new DESedeKey(rawkey); desEdeKey = new DESedeKey(rawkey);
} catch (InvalidKeyException ike) { } catch (InvalidKeyException ike) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -137,13 +137,13 @@ public final class DESedeWrapCipher extends CipherSpi {
*/ */
protected int engineGetOutputSize(int inputLen) { protected int engineGetOutputSize(int inputLen) {
// can only return an upper-limit if not initialized yet. // can only return an upper-limit if not initialized yet.
int result = 0; int result;
if (decrypting) { if (decrypting) {
result = inputLen - 16; // CHECKSUM_LEN + IV_LEN; result = inputLen - 16; // CHECKSUM_LEN + IV_LEN;
} else { } else {
result = Math.addExact(inputLen, 16); result = Math.addExact(inputLen, 16);
} }
return (result < 0? 0:result); return (Math.max(result, 0));
} }
/** /**
@ -210,7 +210,7 @@ public final class DESedeWrapCipher extends CipherSpi {
AlgorithmParameterSpec params, AlgorithmParameterSpec params,
SecureRandom random) SecureRandom random)
throws InvalidKeyException, InvalidAlgorithmParameterException { throws InvalidKeyException, InvalidAlgorithmParameterException {
byte[] currIv = null; byte[] currIv;
if (opmode == Cipher.WRAP_MODE) { if (opmode == Cipher.WRAP_MODE) {
decrypting = false; decrypting = false;
if (params == null) { if (params == null) {
@ -380,7 +380,7 @@ public final class DESedeWrapCipher extends CipherSpi {
/** /**
* Returns the parameters used with this cipher. * Returns the parameters used with this cipher.
* Note that null maybe returned if this cipher does not use any * Note that null maybe returned if this cipher does not use any
* parameters or when it has not be set, e.g. initialized with * parameters or when it has not been set, e.g. initialized with
* UNWRAP_MODE but wrapped key data has not been given. * UNWRAP_MODE but wrapped key data has not been given.
* *
* @return the parameters used with this cipher; can be null. * @return the parameters used with this cipher; can be null.
@ -556,9 +556,8 @@ public final class DESedeWrapCipher extends CipherSpi {
buffer2, 0); buffer2, 0);
int keyValLen = buffer2.length - CHECKSUM_LEN; int keyValLen = buffer2.length - CHECKSUM_LEN;
byte[] cks = getChecksum(buffer2, 0, keyValLen); byte[] cks = getChecksum(buffer2, 0, keyValLen);
int offset = keyValLen;
for (int i = 0; i < CHECKSUM_LEN; i++) { for (int i = 0; i < CHECKSUM_LEN; i++) {
if (buffer2[offset + i] != cks[i]) { if (buffer2[keyValLen + i] != cks[i]) {
throw new InvalidKeyException("Checksum comparison failed"); throw new InvalidKeyException("Checksum comparison failed");
} }
} }
@ -588,7 +587,7 @@ public final class DESedeWrapCipher extends CipherSpi {
return getChecksum(in, 0, in.length); return getChecksum(in, 0, in.length);
} }
private static final byte[] getChecksum(byte[] in, int offset, int len) { private static final byte[] getChecksum(byte[] in, int offset, int len) {
MessageDigest md = null; MessageDigest md;
try { try {
md = MessageDigest.getInstance("SHA1"); md = MessageDigest.getInstance("SHA1");
} catch (NoSuchAlgorithmException nsae) { } catch (NoSuchAlgorithmException nsae) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2023, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -24,21 +24,23 @@
*/ */
package com.sun.crypto.provider; package com.sun.crypto.provider;
import sun.security.jca.JCAUtil;
import sun.security.ssl.HKDF;
import sun.security.util.*;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.IOException; import java.io.IOException;
import java.math.BigInteger; import java.math.BigInteger;
import java.nio.charset.StandardCharsets;
import java.security.*; import java.security.*;
import java.security.interfaces.*; import java.security.interfaces.ECKey;
import java.security.interfaces.ECPublicKey;
import java.security.interfaces.XECKey;
import java.security.interfaces.XECPublicKey;
import java.security.spec.*; import java.security.spec.*;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import javax.crypto.*;
import javax.crypto.spec.SecretKeySpec;
import sun.security.jca.JCAUtil;
import sun.security.ssl.HKDF;
import sun.security.util.*;
// Implementing DHKEM defined inside https://www.rfc-editor.org/rfc/rfc9180.html, // Implementing DHKEM defined inside https://www.rfc-editor.org/rfc/rfc9180.html,
// without the AuthEncap and AuthDecap functions // without the AuthEncap and AuthDecap functions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,23 +25,15 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.util.*;
import java.lang.*;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.AccessController; import java.security.*;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.PrivilegedAction;
import java.security.ProviderException;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidKeySpecException; import java.util.Arrays;
import javax.crypto.KeyAgreementSpi; import javax.crypto.KeyAgreementSpi;
import javax.crypto.ShortBufferException;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import javax.crypto.spec.*; import javax.crypto.ShortBufferException;
import javax.crypto.spec.DHParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import sun.security.util.KeyUtil; import sun.security.util.KeyUtil;
@ -180,7 +172,7 @@ extends KeyAgreementSpi {
* @param key the key for this phase. For example, in the case of * @param key the key for this phase. For example, in the case of
* Diffie-Hellman between 2 parties, this would be the other party's * Diffie-Hellman between 2 parties, this would be the other party's
* Diffie-Hellman public key. * Diffie-Hellman public key.
* @param lastPhase flag which indicates whether or not this is the last * @param lastPhase flag which indicates if this is the last
* phase of this key agreement. * phase of this key agreement.
* *
* @return the (intermediate) key resulting from this phase, or null if * @return the (intermediate) key resulting from this phase, or null if
@ -227,7 +219,7 @@ extends KeyAgreementSpi {
// intermediate secret, in which case we wrap it into a // intermediate secret, in which case we wrap it into a
// Diffie-Hellman public key object and return it. // Diffie-Hellman public key object and return it.
generateSecret = true; generateSecret = true;
if (lastPhase == false) { if (!lastPhase) {
byte[] intermediate = engineGenerateSecret(); byte[] intermediate = engineGenerateSecret();
return new DHPublicKey(new BigInteger(1, intermediate), return new DHPublicKey(new BigInteger(1, intermediate),
init_p, init_g); init_p, init_g);
@ -293,7 +285,7 @@ extends KeyAgreementSpi {
protected int engineGenerateSecret(byte[] sharedSecret, int offset) protected int engineGenerateSecret(byte[] sharedSecret, int offset)
throws IllegalStateException, ShortBufferException throws IllegalStateException, ShortBufferException
{ {
if (generateSecret == false) { if (!generateSecret) {
throw new IllegalStateException throw new IllegalStateException
("Key agreement has not been completed yet"); ("Key agreement has not been completed yet");
} }
@ -413,9 +405,7 @@ extends KeyAgreementSpi {
int keysize = secret.length; int keysize = secret.length;
if (keysize >= BlowfishConstants.BLOWFISH_MAX_KEYSIZE) if (keysize >= BlowfishConstants.BLOWFISH_MAX_KEYSIZE)
keysize = BlowfishConstants.BLOWFISH_MAX_KEYSIZE; keysize = BlowfishConstants.BLOWFISH_MAX_KEYSIZE;
SecretKeySpec skey = new SecretKeySpec(secret, 0, keysize, return new SecretKeySpec(secret, 0, keysize, "Blowfish");
"Blowfish");
return skey;
} else if (algorithm.equalsIgnoreCase("AES")) { } else if (algorithm.equalsIgnoreCase("AES")) {
// AES // AES
int keysize = secret.length; int keysize = secret.length;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -28,11 +28,10 @@ package com.sun.crypto.provider;
import java.math.BigInteger; import java.math.BigInteger;
import java.security.*; import java.security.*;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException;
import javax.crypto.spec.DHParameterSpec; import javax.crypto.spec.DHParameterSpec;
import javax.crypto.spec.DHGenParameterSpec;
import sun.security.provider.ParameterCache; import sun.security.provider.ParameterCache;
import static sun.security.util.SecurityProviderConstants.DEF_DH_KEY_SIZE; import static sun.security.util.SecurityProviderConstants.DEF_DH_KEY_SIZE;
import static sun.security.util.SecurityProviderConstants.getDefDHPrivateExpSize; import static sun.security.util.SecurityProviderConstants.getDefDHPrivateExpSize;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -27,9 +27,9 @@ package com.sun.crypto.provider;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.ProviderException; import java.security.ProviderException;
import sun.security.util.ArrayUtil;
import java.util.Objects;
import jdk.internal.vm.annotation.IntrinsicCandidate; import jdk.internal.vm.annotation.IntrinsicCandidate;
import sun.security.util.ArrayUtil;
/** /**
* This class represents ciphers in electronic codebook (ECB) mode. * This class represents ciphers in electronic codebook (ECB) mode.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -157,7 +157,7 @@ abstract class FeedbackCipher {
*/ */
int encryptFinal(byte[] plain, int plainOffset, int plainLen, int encryptFinal(byte[] plain, int plainOffset, int plainLen,
byte[] cipher, int cipherOffset) byte[] cipher, int cipherOffset)
throws IllegalBlockSizeException, ShortBufferException { throws IllegalBlockSizeException {
return encrypt(plain, plainOffset, plainLen, cipher, cipherOffset); return encrypt(plain, plainOffset, plainLen, cipher, cipherOffset);
} }
/** /**
@ -199,7 +199,7 @@ abstract class FeedbackCipher {
*/ */
int decryptFinal(byte[] cipher, int cipherOffset, int cipherLen, int decryptFinal(byte[] cipher, int cipherOffset, int cipherLen,
byte[] plain, int plainOffset) byte[] plain, int plainOffset)
throws IllegalBlockSizeException, ShortBufferException { throws IllegalBlockSizeException {
return decrypt(cipher, cipherOffset, cipherLen, plain, plainOffset); return decrypt(cipher, cipherOffset, cipherLen, plain, plainOffset);
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -79,8 +79,7 @@ final class GCTR extends CounterMode implements GCM {
ByteBuffer buf = ByteBuffer.wrap(counter, counter.length - 4, 4); ByteBuffer buf = ByteBuffer.wrap(counter, counter.length - 4, 4);
buf.order(ByteOrder.BIG_ENDIAN); buf.order(ByteOrder.BIG_ENDIAN);
long ctr32 = 0xFFFFFFFFL & buf.getInt(); long ctr32 = 0xFFFFFFFFL & buf.getInt();
long blocksLeft = (1L << 32) - ctr32; return (1L << 32) - ctr32;
return blocksLeft;
} }
private void checkBlock() { private void checkBlock() {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -190,9 +190,8 @@ final class GHASH implements Cloneable, GCM {
// If ct is a direct bytebuffer, send it directly to the intrinsic // If ct is a direct bytebuffer, send it directly to the intrinsic
if (ct.isDirect()) { if (ct.isDirect()) {
int processed = inLen;
processBlocksDirect(ct, inLen); processBlocksDirect(ct, inLen);
return processed; return inLen;
} else if (!ct.isReadOnly()) { } else if (!ct.isReadOnly()) {
// If a non-read only heap bytebuffer, use the array update method // If a non-read only heap bytebuffer, use the array update method
int processed = update(ct.array(), int processed = update(ct.array(),
@ -273,7 +272,7 @@ final class GHASH implements Cloneable, GCM {
/* /*
* This is an intrinsified method. The method's argument list must match * This is an intrinsified method. The method's argument list must match
* the hotspot signature. This method and methods called by it, cannot * the hotspot signature. This method and methods called by it, cannot
* throw exceptions or allocate arrays as it will breaking intrinsics * throw exceptions or allocate arrays as it will break intrinsics.
*/ */
@IntrinsicCandidate @IntrinsicCandidate
private static void processBlocks(byte[] data, int inOfs, int blocks, private static void processBlocks(byte[] data, int inOfs, int blocks,

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2013, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,38 +25,24 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import jdk.internal.access.JavaNioAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.Unsafe;
import sun.nio.ch.DirectBuffer;
import sun.security.jca.JCAUtil;
import sun.security.util.ArrayUtil;
import javax.crypto.AEADBadTagException;
import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.CipherSpi;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.crypto.ShortBufferException;
import javax.crypto.spec.GCMParameterSpec;
import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle; import java.lang.invoke.VarHandle;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.ByteOrder; import java.nio.ByteOrder;
import java.security.AlgorithmParameters; import java.security.*;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.Key;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.security.ProviderException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException; import java.security.spec.InvalidParameterSpecException;
import java.util.Arrays; import java.util.Arrays;
import javax.crypto.*;
import javax.crypto.spec.GCMParameterSpec;
import jdk.internal.access.JavaNioAccess;
import jdk.internal.access.SharedSecrets;
import jdk.internal.misc.Unsafe;
import jdk.internal.vm.annotation.IntrinsicCandidate; import jdk.internal.vm.annotation.IntrinsicCandidate;
import sun.nio.ch.DirectBuffer;
import sun.security.jca.JCAUtil;
import sun.security.util.ArrayUtil;
/** /**
* This class represents ciphers in GaloisCounter (GCM) mode. * This class represents ciphers in GaloisCounter (GCM) mode.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2020, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,16 +25,12 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.util.Arrays;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.security.*;
import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays;
import javax.crypto.MacSpi; import javax.crypto.MacSpi;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import java.security.*;
import java.security.spec.*;
import sun.security.x509.AlgorithmId;
/** /**
* This class constitutes the core of HMAC-<MD> algorithms, where * This class constitutes the core of HMAC-<MD> algorithms, where
@ -87,8 +83,7 @@ abstract class HmacCore extends MacSpi implements Cloneable {
break; break;
} }
} }
} catch (NoSuchAlgorithmException nsae) { } catch (NoSuchAlgorithmException ignored) {
continue;
} }
} }
if (md == null) { if (md == null) {
@ -169,7 +164,7 @@ abstract class HmacCore extends MacSpi implements Cloneable {
* @param input the input byte to be processed. * @param input the input byte to be processed.
*/ */
protected void engineUpdate(byte input) { protected void engineUpdate(byte input) {
if (first == true) { if (first) {
// compute digest for 1st pass; start with inner pad // compute digest for 1st pass; start with inner pad
md.update(k_ipad); md.update(k_ipad);
first = false; first = false;
@ -187,8 +182,8 @@ abstract class HmacCore extends MacSpi implements Cloneable {
* @param offset the offset in <code>input</code> where the input starts. * @param offset the offset in <code>input</code> where the input starts.
* @param len the number of bytes to process. * @param len the number of bytes to process.
*/ */
protected void engineUpdate(byte input[], int offset, int len) { protected void engineUpdate(byte[] input, int offset, int len) {
if (first == true) { if (first) {
// compute digest for 1st pass; start with inner pad // compute digest for 1st pass; start with inner pad
md.update(k_ipad); md.update(k_ipad);
first = false; first = false;
@ -205,7 +200,7 @@ abstract class HmacCore extends MacSpi implements Cloneable {
* @param input the input byte buffer. * @param input the input byte buffer.
*/ */
protected void engineUpdate(ByteBuffer input) { protected void engineUpdate(ByteBuffer input) {
if (first == true) { if (first) {
// compute digest for 1st pass; start with inner pad // compute digest for 1st pass; start with inner pad
md.update(k_ipad); md.update(k_ipad);
first = false; first = false;
@ -221,7 +216,7 @@ abstract class HmacCore extends MacSpi implements Cloneable {
* @return the HMAC result. * @return the HMAC result.
*/ */
protected byte[] engineDoFinal() { protected byte[] engineDoFinal() {
if (first == true) { if (first) {
// compute digest for 1st pass; start with inner pad // compute digest for 1st pass; start with inner pad
md.update(k_ipad); md.update(k_ipad);
} else { } else {
@ -250,7 +245,7 @@ abstract class HmacCore extends MacSpi implements Cloneable {
* HMAC was initialized with. * HMAC was initialized with.
*/ */
protected void engineReset() { protected void engineReset() {
if (first == false) { if (!first) {
md.reset(); md.reset();
first = true; first = true;
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,7 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.nio.ByteBuffer; import java.security.NoSuchAlgorithmException;
import javax.crypto.MacSpi;
import javax.crypto.SecretKey;
import java.security.*;
import java.security.spec.*;
/** /**
* This is an implementation of the HMAC-MD5 algorithm. * This is an implementation of the HMAC-MD5 algorithm.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,9 +25,8 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.security.SecureRandom;
import java.security.InvalidParameterException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays; import java.util.Arrays;
import javax.crypto.KeyGeneratorSpi; import javax.crypto.KeyGeneratorSpi;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2012, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,12 +25,7 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.nio.ByteBuffer; import java.security.NoSuchAlgorithmException;
import javax.crypto.MacSpi;
import javax.crypto.SecretKey;
import java.security.*;
import java.security.spec.*;
/** /**
* This is an implementation of the HMAC-SHA1 algorithm. * This is an implementation of the HMAC-SHA1 algorithm.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1999, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,9 +25,8 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.security.SecureRandom;
import java.security.InvalidParameterException;
import java.security.InvalidAlgorithmParameterException; import java.security.InvalidAlgorithmParameterException;
import java.security.SecureRandom;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays; import java.util.Arrays;
import javax.crypto.KeyGeneratorSpi; import javax.crypto.KeyGeneratorSpi;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -119,7 +119,6 @@ final class ISO10126Padding implements Padding {
* @return the length of the padding * @return the length of the padding
*/ */
public int padLength(int len) { public int padLength(int len) {
int paddingOctet = blockSize - (len % blockSize); return blockSize - (len % blockSize);
return paddingOctet;
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -75,7 +75,7 @@ public final class JceKeyStore extends KeyStoreSpi {
Date date; // the creation date of this entry Date date; // the creation date of this entry
byte[] protectedKey; byte[] protectedKey;
Certificate[] chain; Certificate[] chain;
}; }
// Secret key // Secret key
private static final class SecretKeyEntry { private static final class SecretKeyEntry {
@ -93,7 +93,7 @@ public final class JceKeyStore extends KeyStoreSpi {
private static final class TrustedCertEntry { private static final class TrustedCertEntry {
Date date; // the creation date of this entry Date date; // the creation date of this entry
Certificate cert; Certificate cert;
}; }
/** /**
* Private keys and certificates are stored in a hashtable. * Private keys and certificates are stored in a hashtable.
@ -119,7 +119,7 @@ public final class JceKeyStore extends KeyStoreSpi {
public Key engineGetKey(String alias, char[] password) public Key engineGetKey(String alias, char[] password)
throws NoSuchAlgorithmException, UnrecoverableKeyException throws NoSuchAlgorithmException, UnrecoverableKeyException
{ {
Key key = null; Key key;
Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH)); Object entry = entries.get(alias.toLowerCase(Locale.ENGLISH));
@ -652,7 +652,7 @@ public final class JceKeyStore extends KeyStoreSpi {
* the keystore (such as deleting or modifying key or * the keystore (such as deleting or modifying key or
* certificate entries). * certificate entries).
*/ */
byte digest[] = md.digest(); byte[] digest = md.digest();
dos.write(digest); dos.write(digest);
dos.flush(); dos.flush();
@ -691,8 +691,8 @@ public final class JceKeyStore extends KeyStoreSpi {
MessageDigest md = null; MessageDigest md = null;
CertificateFactory cf = null; CertificateFactory cf = null;
Hashtable<String, CertificateFactory> cfs = null; Hashtable<String, CertificateFactory> cfs = null;
ByteArrayInputStream bais = null; ByteArrayInputStream bais;
byte[] encoded = null; byte[] encoded;
int trustedKeyCount = 0, privateKeyCount = 0, secretKeyCount = 0; int trustedKeyCount = 0, privateKeyCount = 0, secretKeyCount = 0;
if (stream == null) if (stream == null)

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2021, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,10 +26,6 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.util.Arrays; import java.util.Arrays;
import java.security.*;
import java.security.spec.*;
import javax.crypto.*;
import javax.crypto.spec.*;
/** /**
* This class acts as the base class for AES KeyWrap algorithms as defined * This class acts as the base class for AES KeyWrap algorithms as defined
@ -58,7 +54,7 @@ class KWUtil {
("Invalid data length for W: " + inLen); ("Invalid data length for W: " + inLen);
assert(icvIn.length == SEMI_BLKSIZE) : "Invalid ICV buffer size"; assert(icvIn.length == SEMI_BLKSIZE) : "Invalid ICV buffer size";
// overwrite the first block of in with the icv semiblock // overwrite the first block of in with the icv semi-block
System.arraycopy(icvIn, 0, in, 0, SEMI_BLKSIZE); System.arraycopy(icvIn, 0, in, 0, SEMI_BLKSIZE);
int n = inLen / SEMI_BLKSIZE - 1; int n = inLen / SEMI_BLKSIZE - 1;
@ -93,7 +89,7 @@ class KWUtil {
* data until the initial value and padding bytes are verified. * data until the initial value and padding bytes are verified.
* @param in input bytes, i.e. the to-be-processed data * @param in input bytes, i.e. the to-be-processed data
* @param inLen length of the to-be-processed bytes * @param inLen length of the to-be-processed bytes
* @param ivOut buffer for holding the recovered ICV semiblock * @param ivOut buffer for holding the recovered ICV semi-block
* @param cipher the initialized cipher object used * @param cipher the initialized cipher object used
* @return the recovered data length, i.e. {@code (inLen - icvOut.length)} * @return the recovered data length, i.e. {@code (inLen - icvOut.length)}
*/ */

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1998, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1998, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -98,7 +98,7 @@ final class KeyProtector {
iterationCount > MAX_ITERATION_COUNT) { iterationCount > MAX_ITERATION_COUNT) {
iterationCount = DEFAULT_ITERATION_COUNT; iterationCount = DEFAULT_ITERATION_COUNT;
} }
} catch (NumberFormatException e) {} } catch (NumberFormatException ignored) {}
} }
ITERATION_COUNT = iterationCount; ITERATION_COUNT = iterationCount;
} }
@ -369,7 +369,7 @@ final class KeyProtector {
sKey = new PBEKey(pbeKeySpec, "PBEWithMD5AndTripleDES"); sKey = new PBEKey(pbeKeySpec, "PBEWithMD5AndTripleDES");
pbeKeySpec.clearPassword(); pbeKeySpec.clearPassword();
SealedObjectForKeyProtector soForKeyProtector = null; SealedObjectForKeyProtector soForKeyProtector;
if (!(so instanceof SealedObjectForKeyProtector)) { if (!(so instanceof SealedObjectForKeyProtector)) {
soForKeyProtector = new SealedObjectForKeyProtector(so); soForKeyProtector = new SealedObjectForKeyProtector(so);
} else { } else {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2004, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2004, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -285,7 +285,7 @@ abstract class KeyWrapCipher extends CipherSpi {
padLen = SEMI_BLKSIZE - n; padLen = SEMI_BLKSIZE - n;
} }
} }
// then add the first semiblock and padLen to result // then add the first semi-block and padLen to result
result = Math.addExact(result, SEMI_BLKSIZE + padLen); result = Math.addExact(result, SEMI_BLKSIZE + padLen);
} else { } else {
result = inLen - SEMI_BLKSIZE; result = inLen - SEMI_BLKSIZE;
@ -339,7 +339,7 @@ abstract class KeyWrapCipher extends CipherSpi {
protected void engineInit(int opmode, Key key, SecureRandom random) protected void engineInit(int opmode, Key key, SecureRandom random)
throws InvalidKeyException { throws InvalidKeyException {
try { try {
implInit(opmode, key, (byte[])null, random); implInit(opmode, key, null, random);
} catch (InvalidAlgorithmParameterException iae) { } catch (InvalidAlgorithmParameterException iae) {
// should never happen // should never happen
throw new AssertionError(iae); throw new AssertionError(iae);
@ -394,9 +394,9 @@ abstract class KeyWrapCipher extends CipherSpi {
byte[] iv = null; byte[] iv = null;
if (params != null) { if (params != null) {
try { try {
AlgorithmParameterSpec spec = IvParameterSpec spec =
params.getParameterSpec(IvParameterSpec.class); params.getParameterSpec(IvParameterSpec.class);
iv = ((IvParameterSpec)spec).getIV(); iv = spec.getIV();
} catch (InvalidParameterSpecException ispe) { } catch (InvalidParameterSpecException ispe) {
throw new InvalidAlgorithmParameterException( throw new InvalidAlgorithmParameterException(
"Only IvParameterSpec is accepted"); "Only IvParameterSpec is accepted");
@ -462,7 +462,7 @@ abstract class KeyWrapCipher extends CipherSpi {
if (inLen <= 0) return; if (inLen <= 0) return;
if (opmode == Cipher.ENCRYPT_MODE && dataIdx == 0) { if (opmode == Cipher.ENCRYPT_MODE && dataIdx == 0) {
// the first semiblock is for iv, store data after it // the first semi-block is for iv, store data after it
dataIdx = SEMI_BLKSIZE; dataIdx = SEMI_BLKSIZE;
} }
store(in, inOfs, inLen); store(in, inOfs, inLen);
@ -595,8 +595,8 @@ abstract class KeyWrapCipher extends CipherSpi {
} }
// helper routine for in-place encryption. // helper routine for in-place encryption.
// 'inBuf' = semiblock | plain text | extra bytes if padding is used // 'inBuf' = semi-block | plain text | extra bytes if padding is used
// 'inLen' = semiblock length + plain text length // 'inLen' = semi-block length + plain text length
private int helperEncrypt(byte[] inBuf, int inLen) private int helperEncrypt(byte[] inBuf, int inLen)
throws IllegalBlockSizeException, ShortBufferException { throws IllegalBlockSizeException, ShortBufferException {
@ -646,7 +646,7 @@ abstract class KeyWrapCipher extends CipherSpi {
*/ */
@Override @Override
protected AlgorithmParameters engineGetParameters() { protected AlgorithmParameters engineGetParameters() {
AlgorithmParameters params = null; AlgorithmParameters params;
byte[] iv = cipher.getIV(); byte[] iv = cipher.getIV();
if (iv == null) { if (iv == null) {
@ -711,7 +711,7 @@ abstract class KeyWrapCipher extends CipherSpi {
// output size is known, allocate output buffer // output size is known, allocate output buffer
byte[] out = new byte[engineGetOutputSize(encoded.length)]; byte[] out = new byte[engineGetOutputSize(encoded.length)];
// reserve the first semiblock and do not write data // reserve the first semi-block and do not write data
int len = SEMI_BLKSIZE; int len = SEMI_BLKSIZE;
System.arraycopy(encoded, 0, out, len, encoded.length); System.arraycopy(encoded, 0, out, len, encoded.length);
len += encoded.length; len += encoded.length;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -225,11 +225,9 @@ public final class OAEPParameters extends AlgorithmParametersSpi {
} }
protected String engineToString() { protected String engineToString() {
StringBuilder sb = new StringBuilder(); return "MD: " + mdName + "\n" +
sb.append("MD: " + mdName + "\n"); "MGF: MGF1" + mgfSpec.getDigestAlgorithm() + "\n" +
sb.append("MGF: MGF1" + mgfSpec.getDigestAlgorithm() + "\n"); "PSource: PSpecified " +
sb.append("PSource: PSpecified " + (p.length == 0 ? "" : Debug.toHexString(new BigInteger(p))) + "\n";
(p.length==0? "":Debug.toHexString(new BigInteger(p))) + "\n");
return sb.toString();
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -53,7 +53,7 @@ final class OutputFeedback extends FeedbackCipher {
private final byte[] register; private final byte[] register;
/* /*
* number of bytes for each stream unit, defaults to the blocksize * number of bytes for each stream unit, defaults to the block size
* of the embedded cipher * of the embedded cipher
*/ */
private final int numBytes; private final int numBytes;

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -261,7 +261,7 @@ abstract class PBEKeyFactory extends SecretKeyFactorySpi {
*/ */
protected KeySpec engineGetKeySpec(SecretKey key, Class<?> keySpecCl) protected KeySpec engineGetKeySpec(SecretKey key, Class<?> keySpecCl)
throws InvalidKeySpecException { throws InvalidKeySpecException {
if ((key instanceof SecretKey) if ((key != null)
&& (validTypes.contains(key.getAlgorithm().toUpperCase(Locale.ENGLISH))) && (validTypes.contains(key.getAlgorithm().toUpperCase(Locale.ENGLISH)))
&& (key.getFormat().equalsIgnoreCase("RAW"))) { && (key.getFormat().equalsIgnoreCase("RAW"))) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2002, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2002, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -161,7 +161,7 @@ final class PBES1Core {
* does not use any parameters. * does not use any parameters.
*/ */
AlgorithmParameters getParameters() { AlgorithmParameters getParameters() {
AlgorithmParameters params = null; AlgorithmParameters params;
if (salt == null) { if (salt == null) {
salt = new byte[8]; salt = new byte[8];
SunJCE.getRandom().nextBytes(salt); SunJCE.getRandom().nextBytes(salt);
@ -303,7 +303,7 @@ final class PBES1Core {
// Concatenate the output from each digest round with the // Concatenate the output from each digest round with the
// password, and use the result as the input to the next digest // password, and use the result as the input to the next digest
// operation. // operation.
byte[] toBeHashed = null; byte[] toBeHashed;
result = new byte[DESedeKeySpec.DES_EDE_KEY_LEN + result = new byte[DESedeKeySpec.DES_EDE_KEY_LEN +
DESConstants.DES_BLOCK_SIZE]; DESConstants.DES_BLOCK_SIZE];
for (i = 0; i < 2; i++) { for (i = 0; i < 2; i++) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2012, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2012, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -131,8 +131,8 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
PBES2Parameters(String pbes2AlgorithmName) throws NoSuchAlgorithmException { PBES2Parameters(String pbes2AlgorithmName) throws NoSuchAlgorithmException {
int and; int and;
String kdfAlgo = null; String kdfAlgo;
String cipherAlgo = null; String cipherAlgo;
// Extract the KDF and encryption algorithm names // Extract the KDF and encryption algorithm names
this.pbes2AlgorithmName = pbes2AlgorithmName; this.pbes2AlgorithmName = pbes2AlgorithmName;
@ -210,9 +210,6 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
protected void engineInit(byte[] encoded) protected void engineInit(byte[] encoded)
throws IOException throws IOException
{ {
String kdfAlgo = null;
String cipherAlgo = null;
DerValue pBES2_params = new DerValue(encoded); DerValue pBES2_params = new DerValue(encoded);
if (pBES2_params.tag != DerValue.tag_Sequence) { if (pBES2_params.tag != DerValue.tag_Sequence) {
throw new IOException("PBE parameter parsing error: " throw new IOException("PBE parameter parsing error: "
@ -231,16 +228,15 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
kdf = pBES2_params.data.getDerValue(); kdf = pBES2_params.data.getDerValue();
} }
kdfAlgo = parseKDF(kdf); String kdfAlgo = parseKDF(kdf);
if (pBES2_params.tag != DerValue.tag_Sequence) { if (pBES2_params.tag != DerValue.tag_Sequence) {
throw new IOException("PBE parameter parsing error: " throw new IOException("PBE parameter parsing error: "
+ "not an ASN.1 SEQUENCE tag"); + "not an ASN.1 SEQUENCE tag");
} }
cipherAlgo = parseES(pBES2_params.data.getDerValue()); String cipherAlgo = parseES(pBES2_params.data.getDerValue());
this.pbes2AlgorithmName = new StringBuilder().append("PBEWith") this.pbes2AlgorithmName = "PBEWith" + kdfAlgo + "And" + cipherAlgo;
.append(kdfAlgo).append("And").append(cipherAlgo).toString();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -305,7 +301,7 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private String parseES(DerValue encryptionScheme) throws IOException { private String parseES(DerValue encryptionScheme) throws IOException {
String cipherAlgo = null; String cipherAlgo;
cipherAlgo_OID = encryptionScheme.data.getOID(); cipherAlgo_OID = encryptionScheme.data.getOID();
if (aes128CBC_OID.equals(cipherAlgo_OID)) { if (aes128CBC_OID.equals(cipherAlgo_OID)) {
@ -399,7 +395,7 @@ abstract class PBES2Parameters extends AlgorithmParametersSpi {
/* /*
* Returns a formatted string describing the parameters. * Returns a formatted string describing the parameters.
* *
* The algorithn name pattern is: "PBEWith<prf>And<encryption>" * The algorithm name pattern is: "PBEWith<prf>And<encryption>"
* where <prf> is one of: HmacSHA1, HmacSHA224, HmacSHA256, HmacSHA384, * where <prf> is one of: HmacSHA1, HmacSHA224, HmacSHA256, HmacSHA384,
* HmacSHA512, HmacSHA512/224, or HmacSHA512/256 and <encryption> is * HmacSHA512, HmacSHA512/224, or HmacSHA512/256 and <encryption> is
* AES with a keysize suffix. * AES with a keysize suffix.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -25,26 +25,29 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.io.*; import java.io.IOException;
import java.lang.ref.Reference; import java.io.InvalidObjectException;
import java.io.ObjectInputStream;
import java.io.ObjectStreamException;
import java.lang.ref.Cleaner; import java.lang.ref.Cleaner;
import java.lang.ref.Reference;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.CharBuffer; import java.nio.CharBuffer;
import java.util.Arrays;
import java.util.Locale;
import java.security.MessageDigest;
import java.security.KeyRep;
import java.security.GeneralSecurityException; import java.security.GeneralSecurityException;
import java.security.KeyRep;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.security.spec.InvalidKeySpecException; import java.security.spec.InvalidKeySpecException;
import java.util.Arrays;
import java.util.Locale;
import javax.crypto.Mac; import javax.crypto.Mac;
import javax.crypto.SecretKey; import javax.crypto.SecretKey;
import javax.crypto.spec.PBEKeySpec; import javax.crypto.spec.PBEKeySpec;
import static java.nio.charset.StandardCharsets.UTF_8;
import jdk.internal.ref.CleanerFactory; import jdk.internal.ref.CleanerFactory;
import static java.nio.charset.StandardCharsets.UTF_8;
/** /**
* This class represents a PBE key derived using PBKDF2 defined * This class represents a PBE key derived using PBKDF2 defined
* in PKCS#5 v2.0. meaning that * in PKCS#5 v2.0. meaning that

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -61,7 +61,7 @@ abstract class PBMAC1Core extends HmacCore {
} }
private static PBKDF2Core getKDFImpl(String algo) { private static PBKDF2Core getKDFImpl(String algo) {
PBKDF2Core kdf = null; PBKDF2Core kdf;
switch(algo) { switch(algo) {
case "HmacSHA1": case "HmacSHA1":
kdf = new PBKDF2Core.HmacSHA1(); kdf = new PBKDF2Core.HmacSHA1();

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 1997, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -120,7 +120,6 @@ final class PKCS5Padding implements Padding {
* @return the length of the padding * @return the length of the padding
*/ */
public int padLength(int len) { public int padLength(int len) {
int paddingOctet = blockSize - (len % blockSize); return blockSize - (len % blockSize);
return paddingOctet;
} }
} }

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,16 +26,18 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.security.Key;
import java.security.InvalidKeyException; import java.security.InvalidKeyException;
import java.security.Key;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.util.Arrays; import java.util.Arrays;
import java.util.Objects; import java.util.Objects;
import sun.security.util.math.*;
import sun.security.util.math.intpoly.*;
import jdk.internal.vm.annotation.IntrinsicCandidate;
import jdk.internal.vm.annotation.ForceInline; import jdk.internal.vm.annotation.ForceInline;
import jdk.internal.vm.annotation.IntrinsicCandidate;
import sun.security.util.math.IntegerFieldModuloP;
import sun.security.util.math.IntegerModuloP;
import sun.security.util.math.MutableIntegerModuloP;
import sun.security.util.math.intpoly.IntegerPolynomial1305;
/** /**
* This class represents the Poly1305 function defined in RFC 7539. * This class represents the Poly1305 function defined in RFC 7539.

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2007, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -108,7 +108,7 @@ final class RC2Crypt extends SymmetricCipher {
static void checkKey(String algorithm, int keyLength) static void checkKey(String algorithm, int keyLength)
throws InvalidKeyException { throws InvalidKeyException {
if (algorithm.equals("RC2") == false) { if (!algorithm.equals("RC2")) {
throw new InvalidKeyException("Key algorithm must be RC2"); throw new InvalidKeyException("Key algorithm must be RC2");
} }
if ((keyLength < 5) || (keyLength > 128)) { if ((keyLength < 5) || (keyLength > 128)) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -33,6 +33,7 @@ import java.security.interfaces.*;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import java.security.spec.InvalidParameterSpecException; import java.security.spec.InvalidParameterSpecException;
import java.security.spec.MGF1ParameterSpec; import java.security.spec.MGF1ParameterSpec;
import java.util.Objects;
import javax.crypto.*; import javax.crypto.*;
import javax.crypto.spec.PSource; import javax.crypto.spec.PSource;
@ -126,7 +127,7 @@ public final class RSACipher extends CipherSpi {
// modes do not make sense for RSA, but allow ECB // modes do not make sense for RSA, but allow ECB
// see JCE spec // see JCE spec
protected void engineSetMode(String mode) throws NoSuchAlgorithmException { protected void engineSetMode(String mode) throws NoSuchAlgorithmException {
if (mode.equalsIgnoreCase("ECB") == false) { if (!mode.equalsIgnoreCase("ECB")) {
throw new NoSuchAlgorithmException("Unsupported mode " + mode); throw new NoSuchAlgorithmException("Unsupported mode " + mode);
} }
} }
@ -468,7 +469,7 @@ public final class RSACipher extends CipherSpi {
boolean isTlsRsaPremasterSecret = boolean isTlsRsaPremasterSecret =
algorithm.equals("TlsRsaPremasterSecret"); algorithm.equals("TlsRsaPremasterSecret");
byte[] encoded = null; byte[] encoded;
update(wrappedKey, 0, wrappedKey.length); update(wrappedKey, 0, wrappedKey.length);
try { try {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2009, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -26,11 +26,10 @@
package com.sun.crypto.provider; package com.sun.crypto.provider;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import javax.crypto.MacSpi;
import javax.crypto.SecretKey;
import java.security.*; import java.security.*;
import java.security.spec.AlgorithmParameterSpec; import java.security.spec.AlgorithmParameterSpec;
import javax.crypto.MacSpi;
import javax.crypto.SecretKey;
import static com.sun.crypto.provider.TlsPrfGenerator.genPad; import static com.sun.crypto.provider.TlsPrfGenerator.genPad;
@ -109,7 +108,7 @@ final class SslMacCore {
* @param input the input byte to be processed. * @param input the input byte to be processed.
*/ */
void update(byte input) { void update(byte input) {
if (first == true) { if (first) {
// compute digest for 1st pass; start with inner pad // compute digest for 1st pass; start with inner pad
md.update(secret); md.update(secret);
md.update(pad1); md.update(pad1);
@ -128,8 +127,8 @@ final class SslMacCore {
* @param offset the offset in <code>input</code> where the input starts. * @param offset the offset in <code>input</code> where the input starts.
* @param len the number of bytes to process. * @param len the number of bytes to process.
*/ */
void update(byte input[], int offset, int len) { void update(byte[] input, int offset, int len) {
if (first == true) { if (first) {
// compute digest for 1st pass; start with inner pad // compute digest for 1st pass; start with inner pad
md.update(secret); md.update(secret);
md.update(pad1); md.update(pad1);
@ -141,7 +140,7 @@ final class SslMacCore {
} }
void update(ByteBuffer input) { void update(ByteBuffer input) {
if (first == true) { if (first) {
// compute digest for 1st pass; start with inner pad // compute digest for 1st pass; start with inner pad
md.update(secret); md.update(secret);
md.update(pad1); md.update(pad1);
@ -158,7 +157,7 @@ final class SslMacCore {
* @return the Mac result. * @return the Mac result.
*/ */
byte[] doFinal() { byte[] doFinal() {
if (first == true) { if (first) {
// compute digest for 1st pass; start with inner pad // compute digest for 1st pass; start with inner pad
md.update(secret); md.update(secret);
md.update(pad1); md.update(pad1);
@ -189,7 +188,7 @@ final class SslMacCore {
* Mac was initialized with. * Mac was initialized with.
*/ */
void reset() { void reset() {
if (first == false) { if (!first) {
md.reset(); md.reset();
first = true; first = true;
} }
@ -211,7 +210,7 @@ final class SslMacCore {
protected void engineUpdate(byte input) { protected void engineUpdate(byte input) {
core.update(input); core.update(input);
} }
protected void engineUpdate(byte input[], int offset, int len) { protected void engineUpdate(byte[] input, int offset, int len) {
core.update(input, offset, len); core.update(input, offset, len);
} }
protected void engineUpdate(ByteBuffer input) { protected void engineUpdate(ByteBuffer input) {
@ -244,7 +243,7 @@ final class SslMacCore {
protected void engineUpdate(byte input) { protected void engineUpdate(byte input) {
core.update(input); core.update(input);
} }
protected void engineUpdate(byte input[], int offset, int len) { protected void engineUpdate(byte[] input, int offset, int len) {
core.update(input, offset, len); core.update(input, offset, len);
} }
protected void engineUpdate(ByteBuffer input) { protected void engineUpdate(ByteBuffer input) {

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -62,11 +62,11 @@ public final class TlsKeyMaterialGenerator extends KeyGeneratorSpi {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected void engineInit(AlgorithmParameterSpec params, protected void engineInit(AlgorithmParameterSpec params,
SecureRandom random) throws InvalidAlgorithmParameterException { SecureRandom random) throws InvalidAlgorithmParameterException {
if (params instanceof TlsKeyMaterialParameterSpec == false) { if (!(params instanceof TlsKeyMaterialParameterSpec)) {
throw new InvalidAlgorithmParameterException(MSG); throw new InvalidAlgorithmParameterException(MSG);
} }
this.spec = (TlsKeyMaterialParameterSpec)params; this.spec = (TlsKeyMaterialParameterSpec)params;
if ("RAW".equals(spec.getMasterSecret().getFormat()) == false) { if (!"RAW".equals(spec.getMasterSecret().getFormat())) {
throw new InvalidAlgorithmParameterException( throw new InvalidAlgorithmParameterException(
"Key format must be RAW"); "Key format must be RAW");
} }
@ -105,8 +105,6 @@ public final class TlsKeyMaterialGenerator extends KeyGeneratorSpi {
SecretKey clientMacKey = null; SecretKey clientMacKey = null;
SecretKey serverMacKey = null; SecretKey serverMacKey = null;
SecretKey clientCipherKey = null;
SecretKey serverCipherKey = null;
IvParameterSpec clientIv = null; IvParameterSpec clientIv = null;
IvParameterSpec serverIv = null; IvParameterSpec serverIv = null;
@ -194,8 +192,10 @@ public final class TlsKeyMaterialGenerator extends KeyGeneratorSpi {
System.arraycopy(keyBlock, ofs, serverKeyBytes, 0, keyLength); System.arraycopy(keyBlock, ofs, serverKeyBytes, 0, keyLength);
ofs += keyLength; ofs += keyLength;
SecretKey clientCipherKey;
SecretKey serverCipherKey;
try { try {
if (isExportable == false) { if (!isExportable) {
// cipher keys // cipher keys
clientCipherKey = new SecretKeySpec(clientKeyBytes, alg); clientCipherKey = new SecretKeySpec(clientKeyBytes, alg);
serverCipherKey = new SecretKeySpec(serverKeyBytes, alg); serverCipherKey = new SecretKeySpec(serverKeyBytes, alg);

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2005, 2021, Oracle and/or its affiliates. All rights reserved. * Copyright (c) 2005, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
* *
* This code is free software; you can redistribute it and/or modify it * This code is free software; you can redistribute it and/or modify it
@ -132,12 +132,12 @@ abstract class TlsPrfGenerator extends KeyGeneratorSpi {
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
protected void engineInit(AlgorithmParameterSpec params, protected void engineInit(AlgorithmParameterSpec params,
SecureRandom random) throws InvalidAlgorithmParameterException { SecureRandom random) throws InvalidAlgorithmParameterException {
if (params instanceof TlsPrfParameterSpec == false) { if (!(params instanceof TlsPrfParameterSpec)) {
throw new InvalidAlgorithmParameterException(MSG); throw new InvalidAlgorithmParameterException(MSG);
} }
this.spec = (TlsPrfParameterSpec)params; this.spec = (TlsPrfParameterSpec)params;
SecretKey key = spec.getSecret(); SecretKey key = spec.getSecret();
if ((key != null) && ("RAW".equals(key.getFormat()) == false)) { if ((key != null) && (!"RAW".equals(key.getFormat()))) {
throw new InvalidAlgorithmParameterException( throw new InvalidAlgorithmParameterException(
"Key encoding format must be RAW"); "Key encoding format must be RAW");
} }
@ -378,7 +378,7 @@ abstract class TlsPrfGenerator extends KeyGeneratorSpi {
* TLS 1.2 uses a different hash algorithm than 1.0/1.1 for the PRF * TLS 1.2 uses a different hash algorithm than 1.0/1.1 for the PRF
* calculations. As of 2010, there is no PKCS11-level support for TLS * calculations. As of 2010, there is no PKCS11-level support for TLS
* 1.2 PRF calculations, and no known OS's have an internal variant * 1.2 PRF calculations, and no known OS's have an internal variant
* we could use. Therefore for TLS 1.2, we are updating JSSE to request * we could use. Therefore, for TLS 1.2, we are updating JSSE to request
* a different provider algorithm: "SunTls12Prf". If we reused the * a different provider algorithm: "SunTls12Prf". If we reused the
* name "SunTlsPrf", the PKCS11 provider would need be updated to * name "SunTlsPrf", the PKCS11 provider would need be updated to
* fail correctly when presented with the wrong version number * fail correctly when presented with the wrong version number