Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions cryptography-core/api/cryptography-core.api
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public final class dev/whyoleg/cryptography/algorithms/AES$CMAC$Companion : dev/
}

public abstract interface class dev/whyoleg/cryptography/algorithms/AES$CMAC$Key : dev/whyoleg/cryptography/algorithms/AES$Key {
public abstract fun cipherWithIv (Z)Ldev/whyoleg/cryptography/operations/AesCmacWithIvCipher;
public static synthetic fun cipherWithIv$default (Ldev/whyoleg/cryptography/algorithms/AES$CMAC$Key;ZILjava/lang/Object;)Ldev/whyoleg/cryptography/operations/AesCmacWithIvCipher;
public abstract fun signatureGenerator ()Ldev/whyoleg/cryptography/operations/SignatureGenerator;
public abstract fun signatureVerifier ()Ldev/whyoleg/cryptography/operations/SignatureVerifier;
}
Expand Down Expand Up @@ -741,6 +743,17 @@ public abstract interface class dev/whyoleg/cryptography/materials/key/KeyGenera
public abstract fun generateKeyBlocking ()Ldev/whyoleg/cryptography/materials/key/Key;
}

public abstract interface class dev/whyoleg/cryptography/operations/AesCmacWithIvCipher : dev/whyoleg/cryptography/operations/AesCmacWithIvEncryptor {
}

public abstract interface class dev/whyoleg/cryptography/operations/AesCmacWithIvEncryptor {
public fun encryptWithIv ([B[BLkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun encryptWithIvBlocking ([B[B)[B
public abstract fun initialize ()V
public fun process ([B[BLkotlin/coroutines/Continuation;)Ljava/lang/Object;
public abstract fun processBlocking ([B[B)[B
}

public abstract interface class dev/whyoleg/cryptography/operations/AuthenticatedCipher : dev/whyoleg/cryptography/operations/AuthenticatedDecryptor, dev/whyoleg/cryptography/operations/AuthenticatedEncryptor, dev/whyoleg/cryptography/operations/Cipher {
}

Expand Down
11 changes: 11 additions & 0 deletions cryptography-core/api/cryptography-core.klib.api
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ abstract interface <#A: dev.whyoleg.cryptography.algorithms/AES.Key> dev.whyoleg
open fun <get-id>(): dev.whyoleg.cryptography/CryptographyAlgorithmId<dev.whyoleg.cryptography.algorithms/AES.CMAC> // dev.whyoleg.cryptography.algorithms/AES.CMAC.id.<get-id>|<get-id>(){}[0]

abstract interface Key : dev.whyoleg.cryptography.algorithms/AES.Key { // dev.whyoleg.cryptography.algorithms/AES.CMAC.Key|null[0]
abstract fun cipherWithIv(kotlin/Boolean = ...): dev.whyoleg.cryptography.operations/AesCmacWithIvCipher // dev.whyoleg.cryptography.algorithms/AES.CMAC.Key.cipherWithIv|cipherWithIv(kotlin.Boolean){}[0]
abstract fun signatureGenerator(): dev.whyoleg.cryptography.operations/SignatureGenerator // dev.whyoleg.cryptography.algorithms/AES.CMAC.Key.signatureGenerator|signatureGenerator(){}[0]
abstract fun signatureVerifier(): dev.whyoleg.cryptography.operations/SignatureVerifier // dev.whyoleg.cryptography.algorithms/AES.CMAC.Key.signatureVerifier|signatureVerifier(){}[0]
}
Expand Down Expand Up @@ -606,6 +607,16 @@ abstract interface dev.whyoleg.cryptography.materials.key/KeyFormat { // dev.why
abstract fun toString(): kotlin/String // dev.whyoleg.cryptography.materials.key/KeyFormat.toString|toString(){}[0]
}

abstract interface dev.whyoleg.cryptography.operations/AesCmacWithIvCipher : dev.whyoleg.cryptography.operations/AesCmacWithIvEncryptor // dev.whyoleg.cryptography.operations/AesCmacWithIvCipher|null[0]

abstract interface dev.whyoleg.cryptography.operations/AesCmacWithIvEncryptor { // dev.whyoleg.cryptography.operations/AesCmacWithIvEncryptor|null[0]
abstract fun encryptWithIvBlocking(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AesCmacWithIvEncryptor.encryptWithIvBlocking|encryptWithIvBlocking(kotlin.ByteArray;kotlin.ByteArray){}[0]
abstract fun initialize() // dev.whyoleg.cryptography.operations/AesCmacWithIvEncryptor.initialize|initialize(){}[0]
abstract fun processBlocking(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AesCmacWithIvEncryptor.processBlocking|processBlocking(kotlin.ByteArray;kotlin.ByteArray){}[0]
open suspend fun encryptWithIv(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AesCmacWithIvEncryptor.encryptWithIv|encryptWithIv(kotlin.ByteArray;kotlin.ByteArray){}[0]
open suspend fun process(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.operations/AesCmacWithIvEncryptor.process|process(kotlin.ByteArray;kotlin.ByteArray){}[0]
}

abstract interface dev.whyoleg.cryptography.operations/AuthenticatedCipher : dev.whyoleg.cryptography.operations/AuthenticatedDecryptor, dev.whyoleg.cryptography.operations/AuthenticatedEncryptor, dev.whyoleg.cryptography.operations/Cipher // dev.whyoleg.cryptography.operations/AuthenticatedCipher|null[0]

abstract interface dev.whyoleg.cryptography.operations/AuthenticatedDecryptor : dev.whyoleg.cryptography.operations/Decryptor { // dev.whyoleg.cryptography.operations/AuthenticatedDecryptor|null[0]
Expand Down
1 change: 1 addition & 0 deletions cryptography-core/src/commonMain/kotlin/algorithms/AES.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public interface AES<K : AES.Key> : CryptographyAlgorithm {
public interface Key : AES.Key {
public fun signatureGenerator(): SignatureGenerator
public fun signatureVerifier(): SignatureVerifier
public fun cipherWithIv(padding: Boolean = true): AesCmacWithIvCipher
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.whyoleg.cryptography.operations

import dev.whyoleg.cryptography.*

@SubclassOptInRequired(CryptographyProviderApi::class)
public interface AesCmacWithIvCipher : AesCmacWithIvEncryptor

@SubclassOptInRequired(CryptographyProviderApi::class)
public interface AesCmacWithIvEncryptor {
public fun initialize()

@DelicateCryptographyApi
public suspend fun process(input: ByteArray, iv: ByteArray): ByteArray = processBlocking(input, iv)

@DelicateCryptographyApi
public fun processBlocking(input: ByteArray, iv: ByteArray): ByteArray

@DelicateCryptographyApi
public suspend fun encryptWithIv(iv: ByteArray, plaintext: ByteArray): ByteArray = encryptWithIvBlocking(iv, plaintext)

@DelicateCryptographyApi
public fun encryptWithIvBlocking(iv: ByteArray, plaintext: ByteArray): ByteArray
}
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ public abstract interface class dev/whyoleg/cryptography/providers/base/operatio
}

public abstract interface class dev/whyoleg/cryptography/providers/base/operations/CipherFunction {
public fun initialize ()V
public fun process ([B[B)[B
public abstract fun transform ([BII)[B
public static synthetic fun transform$default (Ldev/whyoleg/cryptography/providers/base/operations/CipherFunction;[BIIILjava/lang/Object;)[B
public abstract fun transformedSink (Lkotlinx/io/RawSink;)Lkotlinx/io/RawSink;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ abstract interface dev.whyoleg.cryptography.providers.base.operations/CipherFunc
abstract fun transform(kotlin/ByteArray, kotlin/Int = ..., kotlin/Int = ...): kotlin/ByteArray // dev.whyoleg.cryptography.providers.base.operations/CipherFunction.transform|transform(kotlin.ByteArray;kotlin.Int;kotlin.Int){}[0]
abstract fun transformedSink(kotlinx.io/RawSink): kotlinx.io/RawSink // dev.whyoleg.cryptography.providers.base.operations/CipherFunction.transformedSink|transformedSink(kotlinx.io.RawSink){}[0]
abstract fun transformedSource(kotlinx.io/RawSource): kotlinx.io/RawSource // dev.whyoleg.cryptography.providers.base.operations/CipherFunction.transformedSource|transformedSource(kotlinx.io.RawSource){}[0]
open fun initialize() // dev.whyoleg.cryptography.providers.base.operations/CipherFunction.initialize|initialize(){}[0]
open fun process(kotlin/ByteArray, kotlin/ByteArray): kotlin/ByteArray // dev.whyoleg.cryptography.providers.base.operations/CipherFunction.process|process(kotlin.ByteArray;kotlin.ByteArray){}[0]
}

abstract class dev.whyoleg.cryptography.providers.base.algorithms/BaseHkdf : dev.whyoleg.cryptography.algorithms/HKDF { // dev.whyoleg.cryptography.providers.base.algorithms/BaseHkdf|null[0]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ public interface CipherFunction {
public fun transform(source: ByteArray, startIndex: Int = 0, endIndex: Int = source.size): ByteArray
public fun transformedSource(source: RawSource): RawSource
public fun transformedSink(sink: RawSink): RawSink
public fun initialize() {}
public fun process(input: ByteArray, iv: ByteArray): ByteArray { return byteArrayOf() }
}

// TODO: test with different input/output sizes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ private class JdkAesCmacKey(
) : AES.CMAC.Key, JdkEncodableKey<AES.Key.Format>(key) {
private val algorithm = "AESCMAC"
private val signature = JdkMacSignature(state, key, algorithm)
private val ivCipher = JdkAesCmacWithIvCipher(state = state, key = key, ivSize = 16, "AES/CBC/NoPadding")

override fun signatureGenerator(): SignatureGenerator = signature
override fun signatureVerifier(): SignatureVerifier = signature
override fun cipherWithIv(padding: Boolean): AesCmacWithIvCipher = ivCipher

override fun encodeToByteArrayBlocking(format: AES.Key.Format): ByteArray = when (format) {
AES.Key.Format.JWK -> error("$format is not supported")
Expand Down
Loading