You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ml...@apache.org on 2006/07/11 13:49:40 UTC
svn commit: r420807 -
/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java
Author: mloenko
Date: Tue Jul 11 04:49:39 2006
New Revision: 420807
URL: http://svn.apache.org/viewvc?rev=420807&view=rev
Log:
implementation of javax.crypto.spec.DESKeySpec.isParityAdjusted is brought from crypto2
Modified:
incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java
Modified: incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java?rev=420807&r1=420806&r2=420807&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/crypto/src/main/java/javax/crypto/spec/DESKeySpec.java Tue Jul 11 04:49:39 2006
@@ -14,11 +14,6 @@
* limitations under the License.
*/
-/**
-* @author Alexander Y. Kleymenov
-* @version $Revision$
-*/
-
package javax.crypto.spec;
import java.security.InvalidKeyException;
@@ -129,7 +124,7 @@
* @com.intel.drl.spec_ref
*/
public static boolean isParityAdjusted(byte[] key, int offset)
- throws InvalidKeyException {
+ throws InvalidKeyException {
if (key == null) {
throw new InvalidKeyException("Key material is null.");
}
@@ -137,11 +132,17 @@
throw new InvalidKeyException(
"The key material is shorter than 8 bytes");
}
- for (int i=offset; i<DES_KEY_LEN+offset; i++) {
- int b = key[i];
- if ((((b & 1) + ((b & 2) >> 1) + ((b & 4) >> 2)
- + ((b & 8) >> 3) + ((b & 16) >> 4) + ((b & 32) >> 5)
- + ((b & 64) >> 6)) & 1) == ((b & 128) >> 7)) {
+
+ int byteKey = 0;
+
+ for (int i = offset; i < DES_KEY_LEN; i++) {
+ byteKey = key[i];
+
+ byteKey ^= byteKey >> 1;
+ byteKey ^= byteKey >> 2;
+ byteKey ^= byteKey >> 4;
+
+ if ((byteKey & 1) == 0) {
return false;
}
}