summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2003-10-15 13:10:06 +0000
committerPeter Palfrader <peter@palfrader.org>2003-10-15 13:10:06 +0000
commit355c07de6d5252fe6da46f7a2bde6ac71e8c3d81 (patch)
treef0832d0f524a7f2eae82a1badb1ac9752e09fcb9 /src
parent924bcfd7059a5ffd48ffcfe1aa14db252ff38930 (diff)
Use IllegalArgumentException instead of Error
Diffstat (limited to 'src')
-rw-r--r--src/org/noreply/fancydress/crypto/CryptoPrimitives.java36
1 files changed, 18 insertions, 18 deletions
diff --git a/src/org/noreply/fancydress/crypto/CryptoPrimitives.java b/src/org/noreply/fancydress/crypto/CryptoPrimitives.java
index 1525f1d..820dbcb 100644
--- a/src/org/noreply/fancydress/crypto/CryptoPrimitives.java
+++ b/src/org/noreply/fancydress/crypto/CryptoPrimitives.java
@@ -44,11 +44,11 @@ public class CryptoPrimitives {
* @param a octet array 1
* @param b octet array 2
* @return an octet array of equal length where x[i] = a[i] XOR b[i] for all i
- * @throws Error if a and b do not have the same length
+ * @throws IllegalArgumentException if a and b do not have the same length
*/
public static byte[] xor(byte[] a, byte[] b) {
if (a.length != b.length)
- throw new Error("Arguments to xor must have the same length");
+ throw new IllegalArgumentException("Arguments to xor must have the same length");
byte[] result = new byte[a.length];
for (int i=0; i<a.length; i++)
result[i] = (byte) (a[i] ^ b[i]);
@@ -127,14 +127,14 @@ public class CryptoPrimitives {
* @param k the key for AES counter mode
* @param n number of octets requested
* @return a keystream of n octets
- * @throws Error if <code>k</code> is not KEY_LEN (=16) octets long.
+ * @throws IllegalArgumentException if <code>k</code> is not KEY_LEN (=16) octets long.
*/
public static byte[] prng(byte[] k, int n) {
byte[] result = new byte[ n ];
byte[] block = new byte[ KEY_LEN ];
byte[] encrypted = new byte[ KEY_LEN ];
if (k.length != KEY_LEN)
- throw new Error("Argument k to encrypt must be KEY_LEN bytes");
+ throw new IllegalArgumentException("Argument k to encrypt must be KEY_LEN bytes");
KeyParameter params = new KeyParameter(k);
aes_cipher.init(true, params);
for (int i=0, p=0; i<n; p++) {
@@ -158,12 +158,12 @@ public class CryptoPrimitives {
* @param k the key for AES counter mode
* @param m the message to encrypt
* @return the encrypted message. (len(e) == len(m))
- * @throws Error if <code>k</code> is not KEY_LEN (=16) octets long.
+ * @throws IllegalArgumentException if <code>k</code> is not KEY_LEN (=16) octets long.
*/
public static byte[] encrypt(byte[] k, byte[] m) {
byte[] result;
if (k.length != KEY_LEN)
- throw new Error("Argument k to encrypt must be KEY_LEN bytes");
+ throw new IllegalArgumentException("Argument k to encrypt must be KEY_LEN bytes");
result = xor(m, prng(k, m.length));
return(result);
}
@@ -179,14 +179,14 @@ public class CryptoPrimitives {
* @param k the key for our SPRP function
* @param m the message to encrypt
* @return the encrypted message. (len(e) == len(m))
- * @throws Error if <code>k</code> is not SPRP_KEY_LEN (=20) octets long
- * @throws Error if <code>m</code> is shorter than SPRP_KEY_LEN (=20) octets
+ * @throws IllegalArgumentException if <code>k</code> is not SPRP_KEY_LEN (=20) octets long
+ * @throws IllegalArgumentException if <code>m</code> is shorter than SPRP_KEY_LEN (=20) octets
*/
public static byte[] sprpEncrypt(byte[] k, byte[] m) {
if (m.length < HASH_LEN)
- throw new Error("Argument m to sprp_encrypt must be of at least HASH_LEN bytes");
+ throw new IllegalArgumentException("Argument m to sprp_encrypt must be of at least HASH_LEN bytes");
if (k.length != SPRP_KEY_LEN)
- throw new Error("Argument k to sprp_encrypt must be SPRP_KEY_LEN bytes");
+ throw new IllegalArgumentException("Argument k to sprp_encrypt must be SPRP_KEY_LEN bytes");
byte[] result;
byte[] k1 = new byte[HASH_LEN];
byte[] k2 = new byte[HASH_LEN];
@@ -219,7 +219,7 @@ public class CryptoPrimitives {
* @param p a string to build a subkey with.
* @param m the message to encrypt
* @return the encrypted message. (len(e) == len(m))
- * @throws Error if <code>m</code> is shorter than SPRP_KEY_LEN (=20) octets
+ * @throws IllegalArgumentException if <code>m</code> is shorter than SPRP_KEY_LEN (=20) octets
* @see #sprpEncrypt(byte[] k, byte[] m)
*/
public static byte[] sprpEncrypt(byte[] k, String p, byte[] m) {
@@ -234,15 +234,15 @@ public class CryptoPrimitives {
* @param k the key for our SPRP function
* @param m the message to decrypt
* @return the encrypted message. (len(e) == len(m))
- * @throws Error if <code>k</code> is not SPRP_KEY_LEN (=20) octets long
- * @throws Error if <code>m</code> is shorter than SPRP_KEY_LEN (=20) octets
+ * @throws IllegalArgumentException if <code>k</code> is not SPRP_KEY_LEN (=20) octets long
+ * @throws IllegalArgumentException if <code>m</code> is shorter than SPRP_KEY_LEN (=20) octets
* @see #sprpEncrypt(byte[] k, byte[] m)
*/
public static byte[] sprpDecrypt(byte[] k, byte[] m) {
if (m.length < HASH_LEN)
- throw new Error("Argument m to sprp_decrypt must be of at least HASH_LEN bytes");
+ throw new IllegalArgumentException("Argument m to sprp_decrypt must be of at least HASH_LEN bytes");
if (k.length != SPRP_KEY_LEN)
- throw new Error("Argument k to sprp_decrypt must be SPRP_KEY_LEN bytes");
+ throw new IllegalArgumentException("Argument k to sprp_decrypt must be SPRP_KEY_LEN bytes");
byte[] result;
byte[] k1 = new byte[HASH_LEN];
byte[] k2 = new byte[HASH_LEN];
@@ -275,7 +275,7 @@ public class CryptoPrimitives {
* @param p a string to build a subkey with.
* @param m the message to decrypt
* @return the encrypted message. (len(e) == len(m))
- * @throws Error if <code>m</code> is shorter than SPRP_KEY_LEN (=20) octets
+ * @throws IllegalArgumentException if <code>m</code> is shorter than SPRP_KEY_LEN (=20) octets
* @see #sprpEncrypt(byte[] k, byte[] m)
* @see #sprpDecrypt(byte[] k, byte[] m)
*/
@@ -290,11 +290,11 @@ public class CryptoPrimitives {
* @param k a master key
* @param p a string to build a subkey with
* @return the subkey
- * @throws Error if <code>k</code> is not KEY_LEN (=16) octets long
+ * @throws IllegalArgumentException if <code>k</code> is not KEY_LEN (=16) octets long
*/
public static byte[] subKey(byte[] k, String p) {
if (k.length != KEY_LEN)
- throw new Error("Argument k to subKey must be KEY_LEN bytes");
+ throw new IllegalArgumentException("Argument k to subKey must be KEY_LEN bytes");
return Util.slice(hash(k, Util.toOctets(p)), 0, 16);
}
}