Skip to content

Commit

Permalink
Use typed arrays instead of Array<N>
Browse files Browse the repository at this point in the history
  • Loading branch information
05nelsonm committed Dec 24, 2024
1 parent f704761 commit 3fae07a
Show file tree
Hide file tree
Showing 8 changed files with 149 additions and 60 deletions.
30 changes: 24 additions & 6 deletions library/keccak/api/keccak.api
Original file line number Diff line number Diff line change
Expand Up @@ -2,35 +2,55 @@ public final class org/kotlincrypto/sponges/keccak/F1600 : org/kotlincrypto/spon
public fun <init> ()V
public fun addData (IJ)V
public synthetic fun addData (ILjava/lang/Number;)V
public fun contains (J)Z
public fun containsAll (Ljava/util/Collection;)Z
public fun copy ()Lorg/kotlincrypto/sponges/keccak/F1600;
public synthetic fun copy ()Lorg/kotlincrypto/sponges/keccak/State;
public fun get (I)Ljava/lang/Long;
public synthetic fun get (I)Ljava/lang/Number;
public fun iterator ()Ljava/util/Iterator;
public fun reset ()V
}

public final class org/kotlincrypto/sponges/keccak/F200 : org/kotlincrypto/sponges/keccak/State {
public fun <init> ()V
public fun addData (IB)V
public synthetic fun addData (ILjava/lang/Number;)V
public fun contains (B)Z
public fun containsAll (Ljava/util/Collection;)Z
public fun copy ()Lorg/kotlincrypto/sponges/keccak/F200;
public synthetic fun copy ()Lorg/kotlincrypto/sponges/keccak/State;
public fun get (I)Ljava/lang/Byte;
public synthetic fun get (I)Ljava/lang/Number;
public fun iterator ()Ljava/util/Iterator;
public fun reset ()V
}

public final class org/kotlincrypto/sponges/keccak/F400 : org/kotlincrypto/sponges/keccak/State {
public fun <init> ()V
public synthetic fun addData (ILjava/lang/Number;)V
public fun addData (IS)V
public fun contains (S)Z
public fun containsAll (Ljava/util/Collection;)Z
public fun copy ()Lorg/kotlincrypto/sponges/keccak/F400;
public synthetic fun copy ()Lorg/kotlincrypto/sponges/keccak/State;
public synthetic fun get (I)Ljava/lang/Number;
public fun get (I)Ljava/lang/Short;
public fun iterator ()Ljava/util/Iterator;
public fun reset ()V
}

public final class org/kotlincrypto/sponges/keccak/F800 : org/kotlincrypto/sponges/keccak/State {
public fun <init> ()V
public fun addData (II)V
public synthetic fun addData (ILjava/lang/Number;)V
public fun contains (I)Z
public fun containsAll (Ljava/util/Collection;)Z
public fun copy ()Lorg/kotlincrypto/sponges/keccak/F800;
public synthetic fun copy ()Lorg/kotlincrypto/sponges/keccak/State;
public fun get (I)Ljava/lang/Integer;
public synthetic fun get (I)Ljava/lang/Number;
public fun iterator ()Ljava/util/Iterator;
public fun reset ()V
}

Expand All @@ -54,22 +74,20 @@ public final class org/kotlincrypto/sponges/keccak/KeccakPKt {

public abstract class org/kotlincrypto/sponges/keccak/State : java/util/Collection, kotlin/jvm/internal/markers/KMappedMarker {
protected static final field Companion Lorg/kotlincrypto/sponges/keccak/State$Companion;
protected final field array [Ljava/lang/Number;
public final field roundCount B
public synthetic fun <init> (B[Ljava/lang/Number;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
public synthetic fun <init> (BLkotlin/jvm/internal/DefaultConstructorMarker;)V
public fun add (Ljava/lang/Number;)Z
public synthetic fun add (Ljava/lang/Object;)Z
public fun addAll (Ljava/util/Collection;)Z
public abstract fun addData (ILjava/lang/Number;)V
public fun clear ()V
public final fun contains (Ljava/lang/Number;)Z
public abstract fun contains (Ljava/lang/Number;)Z
public final fun contains (Ljava/lang/Object;)Z
public final fun containsAll (Ljava/util/Collection;)Z
public abstract fun copy ()Lorg/kotlincrypto/sponges/keccak/State;
public final fun get (I)Ljava/lang/Number;
public abstract fun get (I)Ljava/lang/Number;
public final fun getSize ()I
public final fun isEmpty ()Z
public final fun iterator ()Ljava/util/Iterator;
public fun iterator ()Ljava/util/Iterator;
public fun remove (Ljava/lang/Object;)Z
public fun removeAll (Ljava/util/Collection;)Z
public fun removeIf (Ljava/util/function/Predicate;)Z
Expand Down
25 changes: 18 additions & 7 deletions library/keccak/api/keccak.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,63 @@ final class org.kotlincrypto.sponges.keccak/F1600 : org.kotlincrypto.sponges.kec
constructor <init>() // org.kotlincrypto.sponges.keccak/F1600.<init>|<init>(){}[0]

final fun addData(kotlin/Int, kotlin/Long) // org.kotlincrypto.sponges.keccak/F1600.addData|addData(kotlin.Int;kotlin.Long){}[0]
final fun contains(kotlin/Long): kotlin/Boolean // org.kotlincrypto.sponges.keccak/F1600.contains|contains(kotlin.Long){}[0]
final fun containsAll(kotlin.collections/Collection<kotlin/Long>): kotlin/Boolean // org.kotlincrypto.sponges.keccak/F1600.containsAll|containsAll(kotlin.collections.Collection<kotlin.Long>){}[0]
final fun copy(): org.kotlincrypto.sponges.keccak/F1600 // org.kotlincrypto.sponges.keccak/F1600.copy|copy(){}[0]
final fun get(kotlin/Int): kotlin/Long // org.kotlincrypto.sponges.keccak/F1600.get|get(kotlin.Int){}[0]
final fun iterator(): kotlin.collections/Iterator<kotlin/Long> // org.kotlincrypto.sponges.keccak/F1600.iterator|iterator(){}[0]
final fun reset() // org.kotlincrypto.sponges.keccak/F1600.reset|reset(){}[0]
}

final class org.kotlincrypto.sponges.keccak/F200 : org.kotlincrypto.sponges.keccak/State<kotlin/Byte, org.kotlincrypto.sponges.keccak/F200> { // org.kotlincrypto.sponges.keccak/F200|null[0]
constructor <init>() // org.kotlincrypto.sponges.keccak/F200.<init>|<init>(){}[0]

final fun addData(kotlin/Int, kotlin/Byte) // org.kotlincrypto.sponges.keccak/F200.addData|addData(kotlin.Int;kotlin.Byte){}[0]
final fun contains(kotlin/Byte): kotlin/Boolean // org.kotlincrypto.sponges.keccak/F200.contains|contains(kotlin.Byte){}[0]
final fun containsAll(kotlin.collections/Collection<kotlin/Byte>): kotlin/Boolean // org.kotlincrypto.sponges.keccak/F200.containsAll|containsAll(kotlin.collections.Collection<kotlin.Byte>){}[0]
final fun copy(): org.kotlincrypto.sponges.keccak/F200 // org.kotlincrypto.sponges.keccak/F200.copy|copy(){}[0]
final fun get(kotlin/Int): kotlin/Byte // org.kotlincrypto.sponges.keccak/F200.get|get(kotlin.Int){}[0]
final fun iterator(): kotlin.collections/Iterator<kotlin/Byte> // org.kotlincrypto.sponges.keccak/F200.iterator|iterator(){}[0]
final fun reset() // org.kotlincrypto.sponges.keccak/F200.reset|reset(){}[0]
}

final class org.kotlincrypto.sponges.keccak/F400 : org.kotlincrypto.sponges.keccak/State<kotlin/Short, org.kotlincrypto.sponges.keccak/F400> { // org.kotlincrypto.sponges.keccak/F400|null[0]
constructor <init>() // org.kotlincrypto.sponges.keccak/F400.<init>|<init>(){}[0]

final fun addData(kotlin/Int, kotlin/Short) // org.kotlincrypto.sponges.keccak/F400.addData|addData(kotlin.Int;kotlin.Short){}[0]
final fun contains(kotlin/Short): kotlin/Boolean // org.kotlincrypto.sponges.keccak/F400.contains|contains(kotlin.Short){}[0]
final fun containsAll(kotlin.collections/Collection<kotlin/Short>): kotlin/Boolean // org.kotlincrypto.sponges.keccak/F400.containsAll|containsAll(kotlin.collections.Collection<kotlin.Short>){}[0]
final fun copy(): org.kotlincrypto.sponges.keccak/F400 // org.kotlincrypto.sponges.keccak/F400.copy|copy(){}[0]
final fun get(kotlin/Int): kotlin/Short // org.kotlincrypto.sponges.keccak/F400.get|get(kotlin.Int){}[0]
final fun iterator(): kotlin.collections/Iterator<kotlin/Short> // org.kotlincrypto.sponges.keccak/F400.iterator|iterator(){}[0]
final fun reset() // org.kotlincrypto.sponges.keccak/F400.reset|reset(){}[0]
}

final class org.kotlincrypto.sponges.keccak/F800 : org.kotlincrypto.sponges.keccak/State<kotlin/Int, org.kotlincrypto.sponges.keccak/F800> { // org.kotlincrypto.sponges.keccak/F800|null[0]
constructor <init>() // org.kotlincrypto.sponges.keccak/F800.<init>|<init>(){}[0]

final fun addData(kotlin/Int, kotlin/Int) // org.kotlincrypto.sponges.keccak/F800.addData|addData(kotlin.Int;kotlin.Int){}[0]
final fun contains(kotlin/Int): kotlin/Boolean // org.kotlincrypto.sponges.keccak/F800.contains|contains(kotlin.Int){}[0]
final fun containsAll(kotlin.collections/Collection<kotlin/Int>): kotlin/Boolean // org.kotlincrypto.sponges.keccak/F800.containsAll|containsAll(kotlin.collections.Collection<kotlin.Int>){}[0]
final fun copy(): org.kotlincrypto.sponges.keccak/F800 // org.kotlincrypto.sponges.keccak/F800.copy|copy(){}[0]
final fun get(kotlin/Int): kotlin/Int // org.kotlincrypto.sponges.keccak/F800.get|get(kotlin.Int){}[0]
final fun iterator(): kotlin.collections/Iterator<kotlin/Int> // org.kotlincrypto.sponges.keccak/F800.iterator|iterator(){}[0]
final fun reset() // org.kotlincrypto.sponges.keccak/F800.reset|reset(){}[0]
}

sealed class <#A: kotlin/Number, #B: org.kotlincrypto.sponges.keccak/State<#A, #B>> org.kotlincrypto.sponges.keccak/State : kotlin.collections/Collection<#A> { // org.kotlincrypto.sponges.keccak/State|null[0]
constructor <init>(kotlin/Byte, kotlin/Array<#A>) // org.kotlincrypto.sponges.keccak/State.<init>|<init>(kotlin.Byte;kotlin.Array<1:0>){}[0]
constructor <init>(kotlin/Byte) // org.kotlincrypto.sponges.keccak/State.<init>|<init>(kotlin.Byte){}[0]

final val array // org.kotlincrypto.sponges.keccak/State.array|{}array[0]
final fun <get-array>(): kotlin/Array<#A> // org.kotlincrypto.sponges.keccak/State.array.<get-array>|<get-array>(){}[0]
final val roundCount // org.kotlincrypto.sponges.keccak/State.roundCount|{}roundCount[0]
final fun <get-roundCount>(): kotlin/Byte // org.kotlincrypto.sponges.keccak/State.roundCount.<get-roundCount>|<get-roundCount>(){}[0]
final val size // org.kotlincrypto.sponges.keccak/State.size|{}size[0]
final fun <get-size>(): kotlin/Int // org.kotlincrypto.sponges.keccak/State.size.<get-size>|<get-size>(){}[0]

abstract fun addData(kotlin/Int, #A) // org.kotlincrypto.sponges.keccak/State.addData|addData(kotlin.Int;1:0){}[0]
abstract fun copy(): #B // org.kotlincrypto.sponges.keccak/State.copy|copy(){}[0]
abstract fun get(kotlin/Int): #A // org.kotlincrypto.sponges.keccak/State.get|get(kotlin.Int){}[0]
abstract fun reset() // org.kotlincrypto.sponges.keccak/State.reset|reset(){}[0]
final fun contains(#A): kotlin/Boolean // org.kotlincrypto.sponges.keccak/State.contains|contains(1:0){}[0]
final fun containsAll(kotlin.collections/Collection<#A>): kotlin/Boolean // org.kotlincrypto.sponges.keccak/State.containsAll|containsAll(kotlin.collections.Collection<1:0>){}[0]
final fun get(kotlin/Int): #A // org.kotlincrypto.sponges.keccak/State.get|get(kotlin.Int){}[0]
final fun isEmpty(): kotlin/Boolean // org.kotlincrypto.sponges.keccak/State.isEmpty|isEmpty(){}[0]
final fun iterator(): kotlin.collections/Iterator<#A> // org.kotlincrypto.sponges.keccak/State.iterator|iterator(){}[0]

final object Companion // org.kotlincrypto.sponges.keccak/State.Companion|null[0]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,39 @@
**/
package org.kotlincrypto.sponges.keccak

import kotlin.jvm.JvmSynthetic

/**
* [State] for Keccak-f[1600]
*
* @see [keccakP]
* */
public class F1600: State<Long, F1600> {
public constructor(): super(roundCount = 24, array = Array(P_LEN) { 0 })
private constructor(state: F1600): super(state.roundCount, state.array.copyOf())
public override fun copy(): F1600 = F1600(this)

@get:JvmSynthetic
internal val array: LongArray

public constructor(): super(roundCount = 24) {
array = LongArray(P_LEN) { 0 }
}
private constructor(state: F1600): super(state.roundCount) {
array = state.array.copyOf()
}

@Throws(IndexOutOfBoundsException::class)
public override operator fun get(index: Int): Long = array[index]

@Throws(IndexOutOfBoundsException::class)
public override fun addData(index: Int, data: Long) { array[index] = array[index] xor data }
public override fun copy(): F1600 = F1600(this)
public override fun reset() { array.fill(0) }

public override fun iterator(): Iterator<Long> = array.iterator()
public override fun contains(element: Long): Boolean = array.contains(element)
public override fun containsAll(elements: Collection<Long>): Boolean {
elements.forEach { n ->
if (!array.contains(n)) return false
}
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,39 @@
package org.kotlincrypto.sponges.keccak

import kotlin.experimental.xor
import kotlin.jvm.JvmSynthetic

/**
* [State] for Keccak-f[200]
*
* @see [keccakP]
* */
public class F200: State<Byte, F200> {
public constructor(): super(roundCount = 18, array = Array(P_LEN) { 0 })
private constructor(state: F200): super(state.roundCount, state.array.copyOf())
public override fun copy(): F200 = F200(this)

@get:JvmSynthetic
internal val array: ByteArray

public constructor(): super(roundCount = 18) {
array = ByteArray(P_LEN) { 0 }
}
private constructor(state: F200): super(state.roundCount) {
array = state.array.copyOf()
}

@Throws(IndexOutOfBoundsException::class)
public override operator fun get(index: Int): Byte = array[index]

@Throws(IndexOutOfBoundsException::class)
public override fun addData(index: Int, data: Byte) { array[index] = array[index] xor data }
public override fun copy(): F200 = F200(this)
public override fun reset() { array.fill(0) }

public override fun iterator(): Iterator<Byte> = array.iterator()
public override fun contains(element: Byte): Boolean = array.contains(element)
public override fun containsAll(elements: Collection<Byte>): Boolean {
elements.forEach { n ->
if (!array.contains(n)) return false
}
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,39 @@
package org.kotlincrypto.sponges.keccak

import kotlin.experimental.xor
import kotlin.jvm.JvmSynthetic

/**
* [State] for Keccak-f[400]
*
* @see [keccakP]
* */
public class F400: State<Short, F400> {
public constructor(): super(roundCount = 20, array = Array(P_LEN) { 0 })
private constructor(state: F400): super(state.roundCount, state.array.copyOf())
public override fun copy(): F400 = F400(this)

@get:JvmSynthetic
internal val array: ShortArray

public constructor(): super(roundCount = 20) {
array = ShortArray(P_LEN) { 0 }
}
private constructor(state: F400): super(state.roundCount) {
array = state.array.copyOf()
}

@Throws(IndexOutOfBoundsException::class)
public override operator fun get(index: Int): Short = array[index]

@Throws(IndexOutOfBoundsException::class)
public override fun addData(index: Int, data: Short) { array[index] = array[index] xor data }
public override fun copy(): F400 = F400(this)
public override fun reset() { array.fill(0) }

public override fun iterator(): Iterator<Short> = array.iterator()
public override fun contains(element: Short): Boolean = array.contains(element)
public override fun containsAll(elements: Collection<Short>): Boolean {
elements.forEach { n ->
if (!array.contains(n)) return false
}
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,40 @@
**/
package org.kotlincrypto.sponges.keccak

import kotlin.jvm.JvmSynthetic


/**
* [State] for Keccak-f[800]
*
* @see [keccakP]
* */
public class F800: State<Int, F800> {
public constructor(): super(roundCount = 22, array = Array(P_LEN) { 0 })
private constructor(state: F800): super(state.roundCount, state.array.copyOf())
public override fun copy(): F800 = F800(this)

@get:JvmSynthetic
internal val array: IntArray

public constructor(): super(roundCount = 22) {
array = IntArray(P_LEN) { 0 }
}
private constructor(state: F800): super(state.roundCount) {
array = state.array.copyOf()
}

@Throws(IndexOutOfBoundsException::class)
public override operator fun get(index: Int): Int = array[index]

@Throws(IndexOutOfBoundsException::class)
public override fun addData(index: Int, data: Int) { array[index] = array[index] xor data }
public override fun copy(): F800 = F800(this)
public override fun reset() { array.fill(0) }

public override fun iterator(): Iterator<Int> = array.iterator()
public override fun contains(element: Int): Boolean = array.contains(element)
public override fun containsAll(elements: Collection<Int>): Boolean {
elements.forEach { n ->
if (!array.contains(n)) return false
}
return true
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ private val RC = longArrayOf(
@Throws(IllegalArgumentException::class)
public fun F1600.keccakP(rounds: Byte = roundCount) {
checkRounds(rounds) ?: return
val A = lanes()
val A = array

var a00 = A[ 0]; var a01 = A[ 1]; var a02 = A[ 2]; var a03 = A[ 3]; var a04 = A[ 4]
var a05 = A[ 5]; var a06 = A[ 6]; var a07 = A[ 7]; var a08 = A[ 8]; var a09 = A[ 9]
Expand Down Expand Up @@ -187,7 +187,7 @@ public fun F1600.keccakP(rounds: Byte = roundCount) {
@Throws(IllegalArgumentException::class)
public fun F800.keccakP(rounds: Byte = roundCount) {
checkRounds(rounds) ?: return
val A = lanes()
val A = array

var a00 = A[ 0]; var a01 = A[ 1]; var a02 = A[ 2]; var a03 = A[ 3]; var a04 = A[ 4]
var a05 = A[ 5]; var a06 = A[ 6]; var a07 = A[ 7]; var a08 = A[ 8]; var a09 = A[ 9]
Expand Down Expand Up @@ -323,7 +323,7 @@ public fun F800.keccakP(rounds: Byte = roundCount) {
@Throws(IllegalArgumentException::class)
public fun F400.keccakP(rounds: Byte = roundCount) {
checkRounds(rounds) ?: return
val A = lanes()
val A = array

var a00 = A[ 0]; var a01 = A[ 1]; var a02 = A[ 2]; var a03 = A[ 3]; var a04 = A[ 4]
var a05 = A[ 5]; var a06 = A[ 6]; var a07 = A[ 7]; var a08 = A[ 8]; var a09 = A[ 9]
Expand Down Expand Up @@ -459,7 +459,7 @@ public fun F400.keccakP(rounds: Byte = roundCount) {
@Throws(IllegalArgumentException::class)
public fun F200.keccakP(rounds: Byte = roundCount) {
checkRounds(rounds) ?: return
val A = lanes()
val A = array

var a00 = A[ 0]; var a01 = A[ 1]; var a02 = A[ 2]; var a03 = A[ 3]; var a04 = A[ 4]
var a05 = A[ 5]; var a06 = A[ 6]; var a07 = A[ 7]; var a08 = A[ 8]; var a09 = A[ 9]
Expand Down
Loading

0 comments on commit 3fae07a

Please sign in to comment.