Skip to content

Commit

Permalink
Modification to AES key implementation so that AESCounterRNG works on…
Browse files Browse the repository at this point in the history
… Android.
  • Loading branch information
dwdyer committed May 12, 2014
1 parent 3da7cfe commit b7ba13a
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.txt
@@ -1,3 +1,10 @@
Changes in version 1.2.4
------------------------

* Converted AES key implementation to implement javax.crypto.SecretKey so that
AESCounterRNG works on Android.


Changes in version 1.2.3
------------------------

Expand Down
4 changes: 2 additions & 2 deletions build.xml
@@ -1,5 +1,5 @@
<!-- =========================================================================
Copyright 2006-2012 Daniel W. Dyer
Copyright 2006-2014 Daniel W. Dyer
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -43,7 +43,7 @@
</fileset>
</path>

<property name="version" value="1.2.3"/>
<property name="version" value="1.2.4"/>
<property name="artifact.identifier" value="uncommons-maths-${version}"/>

<!-- This is the minimum coverage percentage (for both lines and
Expand Down
30 changes: 28 additions & 2 deletions core/src/java/main/org/uncommons/maths/random/AESCounterRNG.java
Expand Up @@ -16,10 +16,11 @@
package org.uncommons.maths.random;

import java.security.GeneralSecurityException;
import java.security.Key;
import java.util.Arrays;
import java.util.Random;
import java.util.concurrent.locks.ReentrantLock;
import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import org.uncommons.maths.binary.BinaryUtils;

/**
Expand Down Expand Up @@ -189,7 +190,7 @@ protected final int next(int bits)
/**
* Trivial key implementation for use with AES cipher.
*/
private static final class AESKey implements Key
private static final class AESKey implements SecretKey
{
private final byte[] keyData;

Expand All @@ -212,5 +213,30 @@ public byte[] getEncoded()
{
return keyData;
}


@Override
public boolean equals(Object other)
{
if (this == other)
{
return true;
}
else if (other == null || getClass() != other.getClass())
{
return false;
}
else
{
return Arrays.equals(keyData, ((AESKey) other).keyData);
}
}


@Override
public int hashCode()
{
return Arrays.hashCode(keyData);
}
}
}
8 changes: 1 addition & 7 deletions etc/intellij/Uncommons Maths.ipr
@@ -1,14 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AntConfiguration">
<defaultAnt bundledAnt="true" />
<buildFile url="file://$PROJECT_DIR$/../../build.xml">
<additionalClassPath />
<antReference projectDefault="true" />
<customJdkName value="" />
<maximumHeapSize value="128" />
<maximumStackSize value="32" />
<properties />
</buildFile>
</component>
<component name="BuildJarProjectSettings">
Expand Down Expand Up @@ -251,10 +245,10 @@
<inspection_tool class="UseOfPropertiesAsHashtable" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="UtilityClassWithPublicConstructor" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="UtilityClassWithoutPrivateConstructor" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoreClassesWithOnlyMain" value="false" />
<option name="ignorableAnnotations">
<value />
</option>
<option name="ignoreClassesWithOnlyMain" value="false" />
</inspection_tool>
<inspection_tool class="VolatileArrayField" enabled="true" level="WARNING" enabled_by_default="true" />
<inspection_tool class="VolatileLongOrDoubleField" enabled="true" level="WARNING" enabled_by_default="true" />
Expand Down

0 comments on commit b7ba13a

Please sign in to comment.