Skip to content

Commit bde12bc

Browse files
authored
Add ability to re-key Xof<Mac> (#100)
1 parent ede1faf commit bde12bc

File tree

5 files changed

+61
-10
lines changed

5 files changed

+61
-10
lines changed

library/xof/api/xof.api

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
1+
public abstract interface class org/kotlincrypto/core/xof/ReKeyableXofAlgorithm : org/kotlincrypto/core/xof/XofAlgorithm {
2+
public abstract fun reset ([B)V
3+
}
4+
15
public abstract class org/kotlincrypto/core/xof/Xof : org/kotlincrypto/core/Algorithm, org/kotlincrypto/core/Copyable, org/kotlincrypto/core/Resettable, org/kotlincrypto/core/Updatable {
6+
public static final field Companion Lorg/kotlincrypto/core/xof/Xof$Companion;
7+
protected final field delegate Lorg/kotlincrypto/core/xof/XofAlgorithm;
8+
public synthetic fun <init> (Lorg/kotlincrypto/core/xof/XofAlgorithm;Lkotlin/jvm/internal/DefaultConstructorMarker;)V
29
protected abstract fun newReader ()Lorg/kotlincrypto/core/xof/Xof$Reader;
310
public final fun reader ()Lorg/kotlincrypto/core/xof/Xof$Reader;
411
public final fun reader (Z)Lorg/kotlincrypto/core/xof/Xof$Reader;
512
public static synthetic fun reader$default (Lorg/kotlincrypto/core/xof/Xof;ZILjava/lang/Object;)Lorg/kotlincrypto/core/xof/Xof$Reader;
13+
public static final fun reset (Lorg/kotlincrypto/core/xof/Xof;[B)V
614
public final fun toString ()Ljava/lang/String;
715
public final fun use (Lkotlin/jvm/functions/Function1;)Ljava/lang/Object;
816
public final fun use (ZLkotlin/jvm/functions/Function1;)Ljava/lang/Object;
917
public static synthetic fun use$default (Lorg/kotlincrypto/core/xof/Xof;ZLkotlin/jvm/functions/Function1;ILjava/lang/Object;)Ljava/lang/Object;
1018
}
1119

20+
public final class org/kotlincrypto/core/xof/Xof$Companion {
21+
public final fun reset (Lorg/kotlincrypto/core/xof/Xof;[B)V
22+
}
23+
1224
public abstract class org/kotlincrypto/core/xof/Xof$Reader {
1325
public fun <init> (Lorg/kotlincrypto/core/xof/Xof;)V
1426
public final fun bytesRead ()J
@@ -43,7 +55,6 @@ protected abstract class org/kotlincrypto/core/xof/XofFactory$XofDelegate : org/
4355
protected fun <init> (Lorg/kotlincrypto/core/xof/XofFactory;Lorg/kotlincrypto/core/xof/XofAlgorithm;)V
4456
public fun algorithm ()Ljava/lang/String;
4557
public final fun equals (Ljava/lang/Object;)Z
46-
protected final fun getDelegate ()Lorg/kotlincrypto/core/xof/XofAlgorithm;
4758
public final fun hashCode ()I
4859
protected final fun newReader ()Lorg/kotlincrypto/core/xof/Xof$Reader;
4960
protected abstract fun newReader (Lorg/kotlincrypto/core/xof/XofAlgorithm;)Lorg/kotlincrypto/core/xof/Xof$Reader;

library/xof/api/xof.klib.api

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
// - Show declarations: true
77

88
// Library unique name: <org.kotlincrypto.core:xof>
9+
abstract interface org.kotlincrypto.core.xof/ReKeyableXofAlgorithm : org.kotlincrypto.core.xof/XofAlgorithm { // org.kotlincrypto.core.xof/ReKeyableXofAlgorithm|null[0]
10+
abstract fun reset(kotlin/ByteArray) // org.kotlincrypto.core.xof/ReKeyableXofAlgorithm.reset|reset(kotlin.ByteArray){}[0]
11+
}
12+
913
abstract interface org.kotlincrypto.core.xof/XofAlgorithm : org.kotlincrypto.core/Algorithm // org.kotlincrypto.core.xof/XofAlgorithm|null[0]
1014

1115
abstract class <#A: org.kotlincrypto.core.xof/XofAlgorithm> org.kotlincrypto.core.xof/XofFactory { // org.kotlincrypto.core.xof/XofFactory|null[0]
@@ -14,9 +18,6 @@ abstract class <#A: org.kotlincrypto.core.xof/XofAlgorithm> org.kotlincrypto.cor
1418
abstract inner class XofDelegate : org.kotlincrypto.core.xof/Xof<#A>, org.kotlincrypto.core/Algorithm, org.kotlincrypto.core/Resettable, org.kotlincrypto.core/Updatable { // org.kotlincrypto.core.xof/XofFactory.XofDelegate|null[0]
1519
constructor <init>(#A) // org.kotlincrypto.core.xof/XofFactory.XofDelegate.<init>|<init>(2:0){}[0]
1620

17-
final val delegate // org.kotlincrypto.core.xof/XofFactory.XofDelegate.delegate|{}delegate[0]
18-
final fun <get-delegate>(): #A // org.kotlincrypto.core.xof/XofFactory.XofDelegate.delegate.<get-delegate>|<get-delegate>(){}[0]
19-
2021
abstract fun newReader(#A): org.kotlincrypto.core.xof/Xof.Reader<#A> // org.kotlincrypto.core.xof/XofFactory.XofDelegate.newReader|newReader(2:0){}[0]
2122
final fun equals(kotlin/Any?): kotlin/Boolean // org.kotlincrypto.core.xof/XofFactory.XofDelegate.equals|equals(kotlin.Any?){}[0]
2223
final fun hashCode(): kotlin/Int // org.kotlincrypto.core.xof/XofFactory.XofDelegate.hashCode|hashCode(){}[0]
@@ -30,7 +31,10 @@ abstract class <#A: org.kotlincrypto.core.xof/XofAlgorithm> org.kotlincrypto.cor
3031
}
3132

3233
sealed class <#A: org.kotlincrypto.core.xof/XofAlgorithm> org.kotlincrypto.core.xof/Xof : org.kotlincrypto.core/Algorithm, org.kotlincrypto.core/Copyable<org.kotlincrypto.core.xof/Xof<#A>>, org.kotlincrypto.core/Resettable, org.kotlincrypto.core/Updatable { // org.kotlincrypto.core.xof/Xof|null[0]
33-
constructor <init>() // org.kotlincrypto.core.xof/Xof.<init>|<init>(){}[0]
34+
constructor <init>(#A) // org.kotlincrypto.core.xof/Xof.<init>|<init>(1:0){}[0]
35+
36+
final val delegate // org.kotlincrypto.core.xof/Xof.delegate|{}delegate[0]
37+
final fun <get-delegate>(): #A // org.kotlincrypto.core.xof/Xof.delegate.<get-delegate>|<get-delegate>(){}[0]
3438

3539
abstract fun newReader(): org.kotlincrypto.core.xof/Xof.Reader<#A> // org.kotlincrypto.core.xof/Xof.newReader|newReader(){}[0]
3640
final fun <#A1: kotlin/Any?> use(kotlin/Boolean =..., kotlin/Function1<org.kotlincrypto.core.xof/Xof.Reader<#A>, #A1>): #A1 // org.kotlincrypto.core.xof/Xof.use|use(kotlin.Boolean;kotlin.Function1<org.kotlincrypto.core.xof.Xof.Reader<1:0>,0:0>){0§<kotlin.Any?>}[0]
@@ -55,6 +59,10 @@ sealed class <#A: org.kotlincrypto.core.xof/XofAlgorithm> org.kotlincrypto.core.
5559
final fun toString(): kotlin/String // org.kotlincrypto.core.xof/Xof.Reader.toString|toString(){}[0]
5660
}
5761

62+
final object Companion { // org.kotlincrypto.core.xof/Xof.Companion|null[0]
63+
final fun <#A2: org.kotlincrypto.core.xof/ReKeyableXofAlgorithm> (org.kotlincrypto.core.xof/Xof<#A2>).reset(kotlin/ByteArray) // org.kotlincrypto.core.xof/Xof.Companion.reset|[email protected]<0:0>(kotlin.ByteArray){0§<org.kotlincrypto.core.xof.ReKeyableXofAlgorithm>}[0]
64+
}
65+
5866
final object Utils { // org.kotlincrypto.core.xof/Xof.Utils|null[0]
5967
final fun leftEncode(kotlin/Int): kotlin/ByteArray // org.kotlincrypto.core.xof/Xof.Utils.leftEncode|leftEncode(kotlin.Int){}[0]
6068
final fun leftEncode(kotlin/Int, kotlin/Int): kotlin/ByteArray // org.kotlincrypto.core.xof/Xof.Utils.leftEncode|leftEncode(kotlin.Int;kotlin.Int){}[0]

library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/Xof.kt

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package org.kotlincrypto.core.xof
1919

2020
import org.kotlincrypto.core.*
21+
import kotlin.jvm.JvmField
2122
import kotlin.jvm.JvmName
2223
import kotlin.jvm.JvmOverloads
2324
import kotlin.jvm.JvmStatic
@@ -52,7 +53,22 @@ import kotlin.jvm.JvmStatic
5253
* @see [reader]
5354
* @see [Reader]
5455
* */
55-
public sealed class Xof<A: XofAlgorithm>: Algorithm, Copyable<Xof<A>>, Resettable, Updatable {
56+
public sealed class Xof<A: XofAlgorithm>(
57+
@JvmField
58+
protected val delegate: A,
59+
): Algorithm, Copyable<Xof<A>>, Resettable, Updatable {
60+
61+
public companion object {
62+
63+
/**
64+
* Helper to provide access to the instance backing [Xof], if said instance
65+
* can be re-keyed (such as a [org.kotlincrypto.core.mac.Mac]).
66+
*
67+
* @throws [IllegalArgumentException] if [newKey] is unacceptable.
68+
* */
69+
@JvmStatic
70+
public fun <A: ReKeyableXofAlgorithm> Xof<A>.reset(newKey: ByteArray) { delegate.reset(newKey) }
71+
}
5672

5773
/**
5874
* Takes a snapshot of the current [Xof]'s state and produces
@@ -298,5 +314,4 @@ public sealed class Xof<A: XofAlgorithm>: Algorithm, Copyable<Xof<A>>, Resettabl
298314

299315
/** @suppress */
300316
public final override fun toString(): String = "Xof[${algorithm()}]@${hashCode()}"
301-
302317
}

library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/XofAlgorithm.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,22 @@ import org.kotlincrypto.core.Algorithm
2222
* which supports Extendable-Output Functions (XOFs).
2323
* */
2424
public interface XofAlgorithm: Algorithm
25+
26+
/**
27+
* Extended functionality, specifically for a [Xof] who's backing instance
28+
* is a [org.kotlincrypto.core.mac.Mac].
29+
*
30+
*
31+
* @see [Xof.Companion.reset]
32+
* */
33+
public interface ReKeyableXofAlgorithm: XofAlgorithm {
34+
35+
/**
36+
* Resets and re-initializes the instance with the provided [newKey]
37+
*
38+
* This is useful if wanting to clear the key before de-referencing.
39+
*
40+
* @throws [IllegalArgumentException] if [newKey] is unacceptable.
41+
* */
42+
public fun reset(newKey: ByteArray)
43+
}

library/xof/src/commonMain/kotlin/org/kotlincrypto/core/xof/XofFactory.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ public abstract class XofFactory<A: XofAlgorithm> public constructor() {
5454
* */
5555
protected abstract inner class XofDelegate
5656
@Throws(ClassCastException::class, IllegalArgumentException::class)
57-
protected constructor(
58-
protected val delegate: A,
59-
) : Xof<A>(),
57+
protected constructor(delegate: A) : Xof<A>(delegate),
6058
Algorithm by delegate,
6159
Resettable by delegate as Resettable,
6260
Updatable by delegate as Updatable

0 commit comments

Comments
 (0)