mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8284112: Minor cleanup could be done in javax.crypto
Reviewed-by: wetmore
This commit is contained in:
parent
897d6c0dc7
commit
41fc078323
37 changed files with 204 additions and 270 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -41,7 +41,7 @@ public class DESKeySpec implements java.security.spec.KeySpec {
|
|||
*/
|
||||
public static final int DES_KEY_LEN = 8;
|
||||
|
||||
private byte[] key;
|
||||
private final byte[] key;
|
||||
|
||||
/*
|
||||
* Weak/semi-weak keys copied from FIPS 74.
|
||||
|
@ -226,13 +226,14 @@ public class DESKeySpec implements java.security.spec.KeySpec {
|
|||
}
|
||||
for (int i = 0; i < WEAK_KEYS.length; i++) {
|
||||
boolean found = true;
|
||||
for (int j = 0; j < DES_KEY_LEN && found == true; j++) {
|
||||
if (WEAK_KEYS[i][j] != key[j+offset]) {
|
||||
for (int j = 0; j < DES_KEY_LEN; j++) {
|
||||
if (WEAK_KEYS[i][j] != key[j + offset]) {
|
||||
found = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (found == true) {
|
||||
return found;
|
||||
if (found) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -41,7 +41,7 @@ public class DESedeKeySpec implements java.security.spec.KeySpec {
|
|||
*/
|
||||
public static final int DES_EDE_KEY_LEN = 24;
|
||||
|
||||
private byte[] key;
|
||||
private final byte[] key;
|
||||
|
||||
/**
|
||||
* Creates a DESedeKeySpec object using the first 24 bytes in
|
||||
|
@ -116,11 +116,8 @@ public class DESedeKeySpec implements java.security.spec.KeySpec {
|
|||
if (key.length - offset < 24) {
|
||||
throw new InvalidKeyException("Wrong key size");
|
||||
}
|
||||
if (DESKeySpec.isParityAdjusted(key, offset) == false
|
||||
|| DESKeySpec.isParityAdjusted(key, offset + 8) == false
|
||||
|| DESKeySpec.isParityAdjusted(key, offset + 16) == false) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return DESKeySpec.isParityAdjusted(key, offset)
|
||||
&& DESKeySpec.isParityAdjusted(key, offset + 8)
|
||||
&& DESKeySpec.isParityAdjusted(key, offset + 16);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -25,7 +25,6 @@
|
|||
|
||||
package javax.crypto.spec;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
|
||||
/**
|
||||
|
@ -45,10 +44,10 @@ import java.security.spec.AlgorithmParameterSpec;
|
|||
public class DHGenParameterSpec implements AlgorithmParameterSpec {
|
||||
|
||||
// The size in bits of the prime modulus
|
||||
private int primeSize;
|
||||
private final int primeSize;
|
||||
|
||||
// The size in bits of the random exponent (private value)
|
||||
private int exponentSize;
|
||||
private final int exponentSize;
|
||||
|
||||
/**
|
||||
* Constructs a parameter set for the generation of Diffie-Hellman
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -55,13 +55,13 @@ import java.security.spec.AlgorithmParameterSpec;
|
|||
public class DHParameterSpec implements AlgorithmParameterSpec {
|
||||
|
||||
// The prime modulus
|
||||
private BigInteger p;
|
||||
private final BigInteger p;
|
||||
|
||||
// The base generator
|
||||
private BigInteger g;
|
||||
private final BigInteger g;
|
||||
|
||||
// The size in bits of the random exponent (private value) (optional)
|
||||
private int l;
|
||||
private final int l;
|
||||
|
||||
/**
|
||||
* Constructs a parameter set for Diffie-Hellman, using a prime modulus
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -43,13 +43,13 @@ import java.math.BigInteger;
|
|||
public class DHPrivateKeySpec implements java.security.spec.KeySpec {
|
||||
|
||||
// The private value
|
||||
private BigInteger x;
|
||||
private final BigInteger x;
|
||||
|
||||
// The prime modulus
|
||||
private BigInteger p;
|
||||
private final BigInteger p;
|
||||
|
||||
// The base generator
|
||||
private BigInteger g;
|
||||
private final BigInteger g;
|
||||
|
||||
/**
|
||||
* Constructor that takes a private value <code>x</code>, a prime
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2007, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -43,13 +43,13 @@ import java.math.BigInteger;
|
|||
public class DHPublicKeySpec implements java.security.spec.KeySpec {
|
||||
|
||||
// The public value
|
||||
private BigInteger y;
|
||||
private final BigInteger y;
|
||||
|
||||
// The prime modulus
|
||||
private BigInteger p;
|
||||
private final BigInteger p;
|
||||
|
||||
// The base generator
|
||||
private BigInteger g;
|
||||
private final BigInteger g;
|
||||
|
||||
/**
|
||||
* Constructor that takes a public value <code>y</code>, a prime
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -39,7 +39,7 @@ import java.security.spec.AlgorithmParameterSpec;
|
|||
*/
|
||||
public class IvParameterSpec implements AlgorithmParameterSpec {
|
||||
|
||||
private byte[] iv;
|
||||
private final byte[] iv;
|
||||
|
||||
/**
|
||||
* Creates an IvParameterSpec object using the bytes in <code>iv</code>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -25,7 +25,6 @@
|
|||
|
||||
package javax.crypto.spec;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.security.spec.AlgorithmParameterSpec;
|
||||
import java.security.spec.MGF1ParameterSpec;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -39,8 +39,8 @@ import java.security.spec.AlgorithmParameterSpec;
|
|||
*/
|
||||
public class PBEParameterSpec implements AlgorithmParameterSpec {
|
||||
|
||||
private byte[] salt;
|
||||
private int iterationCount;
|
||||
private final byte[] salt;
|
||||
private final int iterationCount;
|
||||
private AlgorithmParameterSpec paramSpec = null;
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2003, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -48,7 +48,7 @@ package javax.crypto.spec;
|
|||
*/
|
||||
public class PSource {
|
||||
|
||||
private String pSrcName;
|
||||
private final String pSrcName;
|
||||
|
||||
/**
|
||||
* Constructs a source of the encoding input P for OAEP
|
||||
|
@ -82,7 +82,7 @@ public class PSource {
|
|||
*/
|
||||
public static final class PSpecified extends PSource {
|
||||
|
||||
private byte[] p = new byte[0];
|
||||
private final byte[] p;
|
||||
|
||||
/**
|
||||
* The encoding input P whose value equals byte[0].
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -45,7 +45,7 @@ import java.security.spec.AlgorithmParameterSpec;
|
|||
public class RC2ParameterSpec implements AlgorithmParameterSpec {
|
||||
|
||||
private byte[] iv = null;
|
||||
private int effectiveKeyBits;
|
||||
private final int effectiveKeyBits;
|
||||
|
||||
/**
|
||||
* Constructs a parameter set for RC2 from the given effective key size
|
||||
|
@ -135,10 +135,9 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec {
|
|||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof RC2ParameterSpec)) {
|
||||
if (!(obj instanceof RC2ParameterSpec other)) {
|
||||
return false;
|
||||
}
|
||||
RC2ParameterSpec other = (RC2ParameterSpec) obj;
|
||||
|
||||
return ((effectiveKeyBits == other.effectiveKeyBits) &&
|
||||
java.util.Arrays.equals(iv, other.iv));
|
||||
|
@ -155,6 +154,6 @@ public class RC2ParameterSpec implements AlgorithmParameterSpec {
|
|||
retval += iv[i] * i;
|
||||
}
|
||||
}
|
||||
return (retval += effectiveKeyBits);
|
||||
return retval + effectiveKeyBits;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -47,9 +47,9 @@ import java.security.spec.AlgorithmParameterSpec;
|
|||
public class RC5ParameterSpec implements AlgorithmParameterSpec {
|
||||
|
||||
private byte[] iv = null;
|
||||
private int version;
|
||||
private int rounds;
|
||||
private int wordSize; // the word size in bits
|
||||
private final int version;
|
||||
private final int rounds;
|
||||
private final int wordSize; // the word size in bits
|
||||
|
||||
/**
|
||||
* Constructs a parameter set for RC5 from the given version, number of
|
||||
|
@ -180,10 +180,9 @@ public class RC5ParameterSpec implements AlgorithmParameterSpec {
|
|||
if (obj == this) {
|
||||
return true;
|
||||
}
|
||||
if (!(obj instanceof RC5ParameterSpec)) {
|
||||
if (!(obj instanceof RC5ParameterSpec other)) {
|
||||
return false;
|
||||
}
|
||||
RC5ParameterSpec other = (RC5ParameterSpec) obj;
|
||||
|
||||
return ((version == other.version) &&
|
||||
(rounds == other.rounds) &&
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 1998, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 1998, 2022, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -25,14 +25,13 @@
|
|||
|
||||
package javax.crypto.spec;
|
||||
|
||||
import jdk.internal.access.JavaxCryptoSpecAccess;
|
||||
import jdk.internal.access.SharedSecrets;
|
||||
|
||||
import javax.crypto.SecretKey;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.spec.KeySpec;
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
import javax.crypto.SecretKey;
|
||||
|
||||
/**
|
||||
* This class specifies a secret key in a provider-independent fashion.
|
||||
|
@ -61,23 +60,18 @@ public class SecretKeySpec implements KeySpec, SecretKey {
|
|||
*
|
||||
* @serial
|
||||
*/
|
||||
private byte[] key;
|
||||
private final byte[] key;
|
||||
|
||||
/**
|
||||
* The name of the algorithm associated with this key.
|
||||
*
|
||||
* @serial
|
||||
*/
|
||||
private String algorithm;
|
||||
private final String algorithm;
|
||||
|
||||
static {
|
||||
SharedSecrets.setJavaxCryptoSpecAccess(
|
||||
new JavaxCryptoSpecAccess() {
|
||||
@Override
|
||||
public void clearSecretKeySpec(SecretKeySpec keySpec) {
|
||||
keySpec.clear();
|
||||
}
|
||||
});
|
||||
SecretKeySpec::clear);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -210,10 +204,9 @@ public class SecretKeySpec implements KeySpec, SecretKey {
|
|||
retval += this.key[i] * i;
|
||||
}
|
||||
if (this.algorithm.equalsIgnoreCase("TripleDES"))
|
||||
return (retval ^= "desede".hashCode());
|
||||
return retval ^ "desede".hashCode();
|
||||
else
|
||||
return (retval ^=
|
||||
this.algorithm.toLowerCase(Locale.ENGLISH).hashCode());
|
||||
return retval ^ this.algorithm.toLowerCase(Locale.ENGLISH).hashCode();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue