1
0
Fork 0
mirror of https://github.com/pgpainless/pgpainless.git synced 2024-12-22 19:08:00 +01:00

Kotlin conversion: ECDH

This commit is contained in:
Paul Schaub 2023-09-07 15:00:54 +02:00
parent 7f96272152
commit 9e7a25ffe1
Signed by: vanitasvitae
GPG key ID: 62BEE9264BF17311
3 changed files with 22 additions and 54 deletions

View file

@ -1,46 +0,0 @@
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.key.generation.type.ecc.ecdh;
import javax.annotation.Nonnull;
import java.security.spec.AlgorithmParameterSpec;
import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec;
import org.pgpainless.algorithm.PublicKeyAlgorithm;
import org.pgpainless.key.generation.type.KeyType;
import org.pgpainless.key.generation.type.ecc.EllipticCurve;
public final class ECDH implements KeyType {
private final EllipticCurve curve;
private ECDH(EllipticCurve curve) {
this.curve = curve;
}
public static ECDH fromCurve(@Nonnull EllipticCurve curve) {
return new ECDH(curve);
}
@Override
public String getName() {
return "ECDH";
}
@Override
public PublicKeyAlgorithm getAlgorithm() {
return PublicKeyAlgorithm.ECDH;
}
@Override
public int getBitStrength() {
return curve.getBitStrength();
}
@Override
public AlgorithmParameterSpec getAlgorithmSpec() {
return new ECNamedCurveGenParameterSpec(curve.getName());
}
}

View file

@ -1,8 +0,0 @@
// SPDX-FileCopyrightText: 2020 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
/**
* Classes related to ECDH.
*/
package org.pgpainless.key.generation.type.ecc.ecdh;

View file

@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: 2023 Paul Schaub <vanitasvitae@fsfe.org>
//
// SPDX-License-Identifier: Apache-2.0
package org.pgpainless.key.generation.type.ecc.ecdh
import org.bouncycastle.jce.spec.ECNamedCurveGenParameterSpec
import org.pgpainless.algorithm.PublicKeyAlgorithm
import org.pgpainless.key.generation.type.KeyType
import org.pgpainless.key.generation.type.ecc.EllipticCurve
class ECDH private constructor(val curve: EllipticCurve) : KeyType {
override val name = "ECDH"
override val algorithm = PublicKeyAlgorithm.ECDH
override val bitStrength = curve.bitStrength
override val algorithmSpec = ECNamedCurveGenParameterSpec(curve.curveName)
companion object {
@JvmStatic
fun fromCurve(curve: EllipticCurve) = ECDH(curve)
}
}