Skip to content

Commit

Permalink
Update model (#137)
Browse files Browse the repository at this point in the history
* update model

Signed-off-by: Nicklas Körtge <[email protected]>

* apply fix

Signed-off-by: Nicklas Körtge <[email protected]>

---------

Signed-off-by: Nicklas Körtge <[email protected]>
  • Loading branch information
n1ckl0sk0rtge authored Sep 5, 2024
1 parent baa7a69 commit e876ccc
Show file tree
Hide file tree
Showing 38 changed files with 77 additions and 134 deletions.
16 changes: 6 additions & 10 deletions mapper/src/main/java/com/ibm/mapper/model/algorithms/AES.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,22 @@ public final class AES extends Algorithm implements BlockCipher, AuthenticatedEn
}

public AES(@NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this.put(new BlockSize(128, detectionLocation));
this(BlockCipher.class, detectionLocation);
}

public AES(int keyLength, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(new BlockSize(128, detectionLocation));
}

public AES(@Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this.put(new BlockSize(128, detectionLocation));
this(detectionLocation);
this.put(mode);
}

public AES(int keyLength, @Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(new BlockSize(128, detectionLocation));
this.put(mode);
}

Expand All @@ -72,9 +68,8 @@ public AES(
@Nonnull Mode mode,
@Nonnull Padding padding,
@NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(new BlockSize(128, detectionLocation));
this.put(mode);
this.put(padding);
}
Expand All @@ -87,5 +82,6 @@ public AES(
@Nonnull final Class<? extends IPrimitive> asKind,
@NotNull DetectionLocation detectionLocation) {
super(NAME, asKind, detectionLocation);
this.put(new BlockSize(128, detectionLocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,13 @@ public AESWrap(@NotNull DetectionLocation detectionLocation) {
}

public AESWrap(int keyLength, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
}

public AESWrap(
int keyLength, @Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(mode);
}
Expand All @@ -65,7 +65,7 @@ public AESWrap(
@Nonnull Mode mode,
@Nonnull Padding padding,
@NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(mode);
this.put(padding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

public class ANSIX942 extends Algorithm implements KeyDerivationFunction {
public final class ANSIX942 extends Algorithm implements KeyDerivationFunction {
// https://www.cryptsoft.com/pkcs11doc/v220/group__SEC__12__4__14__X9__42__DIFFIE__HELLMAN__KEY__DERIVATION.html

private static final String NAME = "ANSI X9.42";

public ANSIX942(@NotNull DetectionLocation detectionLocation) {
super(NAME, KeyDerivationFunction.class, detectionLocation);
this.put(new DH(detectionLocation));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import com.ibm.mapper.utils.DetectionLocation;
import org.jetbrains.annotations.NotNull;

public class ANSIX963 extends Algorithm implements KeyDerivationFunction {
public final class ANSIX963 extends Algorithm implements KeyDerivationFunction {
// https://csrc.nist.gov/CSRC/media/Events/Key-Management-Workshop-2000/documents/x963_overview.pdf

private static final String NAME = "ANSI X9.63";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.ibm.mapper.utils.DetectionLocation;
import javax.annotation.Nonnull;

public class BIKE extends Algorithm implements KeyEncapsulationMechanism {
public final class BIKE extends Algorithm implements KeyEncapsulationMechanism {
// https://hal.science/hal-01671903/document

private static final String NAME = "BIKE";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Blowfish(int keyLength, @NotNull DetectionLocation detectionLocation) {

public Blowfish(
int keyLength, @Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(mode);
}
Expand All @@ -54,7 +54,7 @@ public Blowfish(
@Nonnull Mode mode,
@Nonnull Padding padding,
@NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(mode);
this.put(padding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public Camellia(@NotNull DetectionLocation detectionLocation) {
}

public Camellia(int keyLength, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
}

public Camellia(
int keyLength, @Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(mode);
}
Expand All @@ -54,7 +54,7 @@ public Camellia(
@Nonnull Mode mode,
@Nonnull Padding padding,
@NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(mode);
this.put(padding);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public ChaCha20(@NotNull DetectionLocation detectionLocation) {
}

public ChaCha20(int keyLength, @NotNull DetectionLocation detectionLocation) {
super(NAME, StreamCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
}

public ChaCha20(
int keyLength, @Nonnull Padding padding, @NotNull DetectionLocation detectionLocation) {
super(NAME, StreamCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(padding);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.ibm.mapper.utils.DetectionLocation;
import javax.annotation.Nonnull;

public class ClassicMcEliece extends Algorithm implements KeyEncapsulationMechanism {
public final class ClassicMcEliece extends Algorithm implements KeyEncapsulationMechanism {
// https://classic.mceliece.org/index.html

private static final String NAME = "Classic McEliece"; // CMCE
Expand Down
15 changes: 5 additions & 10 deletions mapper/src/main/java/com/ibm/mapper/model/algorithms/DES.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,17 @@ public DES(@NotNull DetectionLocation detectionLocation) {
public DES(int keyLength, @NotNull DetectionLocation detectionLocation) {
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(new BlockSize(64, detectionLocation));
}

public DES(int keyLength, @Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(mode);
this.put(new BlockSize(64, detectionLocation));
}

public DES(@Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
this(detectionLocation);
this.put(mode);
}

public DES(
Expand All @@ -74,13 +77,6 @@ public DES(
this.put(new KeyLength(keyLength, detectionLocation));
this.put(mode);
this.put(padding);
this.put(new BlockSize(64, detectionLocation));
}

public DES(@Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
this(detectionLocation);
this.put(mode);
this.put(new BlockSize(64, detectionLocation));
}

public DES(
Expand All @@ -90,7 +86,6 @@ public DES(
this(detectionLocation);
this.put(mode);
this.put(padding);
this.put(new BlockSize(64, detectionLocation));
}

public DES(@Nonnull final Class<? extends IPrimitive> asKind, @NotNull DES des) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ public DESedeWrap(@NotNull DetectionLocation detectionLocation) {
}

public DESedeWrap(int keyLength, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
}

public DESedeWrap(
int keyLength, @Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(mode);
}
Expand All @@ -62,7 +62,7 @@ public DESedeWrap(
@Nonnull Mode mode,
@Nonnull Padding padding,
@NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(new KeyLength(keyLength, detectionLocation));
this.put(mode);
this.put(padding);
Expand Down
3 changes: 1 addition & 2 deletions mapper/src/main/java/com/ibm/mapper/model/algorithms/DH.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ public final class DH extends Algorithm implements Signature, KeyAgreement, Publ
}

public DH(@NotNull DetectionLocation detectionLocation) {
super(NAME, PublicKeyEncryption.class, detectionLocation);
this.put(new Oid("1.2.840.113549.1.3.1", detectionLocation));
this(PublicKeyEncryption.class, detectionLocation);
}

public DH(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.ibm.mapper.utils.DetectionLocation;
import javax.annotation.Nonnull;

public class DSTU4145 extends Algorithm implements Signature {
public final class DSTU4145 extends Algorithm implements Signature {
private static final String NAME = "DSTU 4145-2002";

public DSTU4145(@Nonnull DetectionLocation detectionLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public ECDSA(@NotNull DetectionLocation detectionLocation) {

public ECDSA(
@NotNull EllipticCurve ellipticCurve, @NotNull DetectionLocation detectionLocation) {
super(NAME, Signature.class, detectionLocation);
this(detectionLocation);
this.put(ellipticCurve);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ protected EdDSA(@Nonnull String name, @NotNull DetectionLocation detectionLocati
}

public EdDSA(@NotNull DetectionLocation detectionLocation) {
super(NAME, Signature.class, detectionLocation);
this(NAME, detectionLocation);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import com.ibm.mapper.utils.DetectionLocation;
import javax.annotation.Nonnull;

public class FrodoKEM extends Algorithm implements KeyEncapsulationMechanism {
public final class FrodoKEM extends Algorithm implements KeyEncapsulationMechanism {
// https://frodokem.org/files/FrodoKEM-specification-20210604.pdf

private static final String NAME = "FrodoKEM";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import com.ibm.mapper.utils.DetectionLocation;
import javax.annotation.Nonnull;

public class HQC extends Algorithm implements KeyEncapsulationMechanism, PublicKeyEncryption {
public final class HQC extends Algorithm implements KeyEncapsulationMechanism, PublicKeyEncryption {
// https://pqc-hqc.org/doc/hqc-specification_2023-04-30.pdf

private static final String NAME = "HQC"; // Hamming Quasi-Cyclic
Expand All @@ -46,10 +46,6 @@ public String asString() {
return builtName.toString();
}

// public HQC(@Nonnull DetectionLocation detectionLocation) {
// this(KeyEncapsulationMechanism.class, detectionLocation);
// }

public HQC(
@Nonnull final Class<? extends IPrimitive> asKind,
@Nonnull DetectionLocation detectionLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public IDEA(@NotNull DetectionLocation detectionLocation) {
}

public IDEA(@Nonnull Mode mode, @NotNull DetectionLocation detectionLocation) {
super(NAME, BlockCipher.class, detectionLocation);
this(detectionLocation);
this.put(mode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ public String asString() {

Optional<INode> parameterSetIdentifier = this.hasChildOfType(ParameterSetIdentifier.class);

if (parameterSetIdentifier.isPresent()) {
builtName.append(parameterSetIdentifier.get().asString());
}

parameterSetIdentifier.ifPresent(node -> builtName.append(node.asString()));
return builtName.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.Optional;
import javax.annotation.Nonnull;

public class Kalyna extends Algorithm implements BlockCipher, Mac {
public final class Kalyna extends Algorithm implements BlockCipher, Mac {
// https://en.wikipedia.org/wiki/Kalyna_(cipher)
// https://eprint.iacr.org/2015/650.pdf

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import com.ibm.mapper.utils.DetectionLocation;
import javax.annotation.Nonnull;

public class Keccak extends Algorithm implements MessageDigest, AuthenticatedEncryption {
public final class Keccak extends Algorithm implements MessageDigest, AuthenticatedEncryption {
// https://keccak.team/keccak.html

private static final String NAME = "Keccak";
Expand Down
14 changes: 13 additions & 1 deletion mapper/src/main/java/com/ibm/mapper/model/algorithms/LMS.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,29 @@
import com.ibm.mapper.model.Signature;
import com.ibm.mapper.utils.DetectionLocation;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

// Hash Based Signature (HBS)
public class LMS extends Algorithm implements Signature, MessageDigest {
public final class LMS extends Algorithm implements Signature, MessageDigest {
// https://eprint.iacr.org/2017/349.pdf

private static final String NAME = "LMS";

@Override
public @NotNull String asString() {
return this.hasChildOfType(MessageDigest.class)
.map(node -> node.asString() + "with" + this.name)
.orElse(this.name);
}

public LMS(@Nonnull DetectionLocation detectionLocation) {
this(Signature.class, detectionLocation);
}

public LMS(@Nonnull MessageDigest messageDigest) {
this(messageDigest.getDetectionContext());
}

public LMS(
@Nonnull final Class<? extends IPrimitive> asKind,
@Nonnull DetectionLocation detectionLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public final class MD2 extends Algorithm implements MessageDigest {
private static final String NAME = "MD2";

public MD2(@Nonnull DetectionLocation detectionLocation) {
super(NAME, MessageDigest.class, detectionLocation);
this.put(new BlockSize(128, detectionLocation));
this.put(new DigestSize(128, detectionLocation));
this(MessageDigest.class, detectionLocation);
}

public MD2(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@ public final class MD5 extends Algorithm implements MessageDigest {
private static final String NAME = "MD5";

public MD5(@Nonnull DetectionLocation detectionLocation) {
super(NAME, MessageDigest.class, detectionLocation);
this.put(new BlockSize(512, detectionLocation));
this.put(new DigestSize(128, detectionLocation));
this(MessageDigest.class, detectionLocation);
}

public MD5(
Expand Down
Loading

0 comments on commit e876ccc

Please sign in to comment.