forked from bcgit/bc-java
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
265 additions
and
11 deletions.
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
pg/src/main/java/org/bouncycastle/bcpg/EdDSAPublicBCPGKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package org.bouncycastle.bcpg; | ||
|
||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
|
||
import org.bouncycastle.asn1.ASN1ObjectIdentifier; | ||
import org.bouncycastle.math.ec.ECPoint; | ||
import org.bouncycastle.util.Arrays; | ||
import org.bouncycastle.util.BigIntegers; | ||
|
||
|
||
/** | ||
* base class for an ECDSA Public Key. | ||
*/ | ||
public class EdDSAPublicBCPGKey | ||
extends ECPublicBCPGKey | ||
{ | ||
private static final ASN1ObjectIdentifier OID_Ed25519 = new ASN1ObjectIdentifier("1.3.6.1.4.1.11591.15.1"); | ||
|
||
/** | ||
* @param in the stream to read the packet from. | ||
*/ | ||
protected EdDSAPublicBCPGKey( | ||
BCPGInputStream in) | ||
throws IOException | ||
{ | ||
super(in); | ||
|
||
if (!OID_Ed25519.equals(oid)) | ||
{ | ||
throw new IOException("Invalid curve oid for EdDSA key!"); | ||
} | ||
} | ||
|
||
public EdDSAPublicBCPGKey( | ||
BigInteger encodedPoint) | ||
throws IOException | ||
{ | ||
super(OID_Ed25519, encodedPoint); | ||
} | ||
|
||
public static EdDSAPublicBCPGKey fromEdDSAEncodedPoint( | ||
byte[] eddsaEncodedPoint) | ||
throws IOException | ||
{ | ||
byte[] openpgpEncodedPoint = new byte[eddsaEncodedPoint.length + 1]; | ||
openpgpEncodedPoint[0] = 0x40; | ||
System.arraycopy(eddsaEncodedPoint, 0, openpgpEncodedPoint, 1, eddsaEncodedPoint.length); | ||
return new EdDSAPublicBCPGKey(BigIntegers.fromUnsignedByteArray(openpgpEncodedPoint)); | ||
} | ||
|
||
public byte[] getEdDSAEncodedPoint() | ||
{ | ||
BigInteger encodedPoint = getEncodedPoint(); | ||
byte[] pointData = BigIntegers.asUnsignedByteArray(encodedPoint); | ||
if (pointData[0] != 0x40) | ||
{ | ||
throw new IllegalStateException("Invalid point format in EdDSA key!"); | ||
} | ||
return Arrays.copyOfRange(pointData, 1, pointData.length); | ||
} | ||
|
||
} |
94 changes: 94 additions & 0 deletions
94
pg/src/main/java/org/bouncycastle/bcpg/EdDSASecretBCPGKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package org.bouncycastle.bcpg; | ||
|
||
import java.io.IOException; | ||
import java.math.BigInteger; | ||
|
||
import org.bouncycastle.util.BigIntegers; | ||
|
||
|
||
/** | ||
* base class for an EC Secret Key. | ||
*/ | ||
public class EdDSASecretBCPGKey | ||
extends BCPGObject | ||
implements BCPGKey | ||
{ | ||
MPInteger x; | ||
|
||
/** | ||
* @param in | ||
* @throws IOException | ||
*/ | ||
public EdDSASecretBCPGKey( | ||
BCPGInputStream in) | ||
throws IOException | ||
{ | ||
this.x = new MPInteger(in); | ||
} | ||
|
||
/** | ||
* @param x | ||
*/ | ||
public EdDSASecretBCPGKey( | ||
BigInteger x) | ||
{ | ||
this.x = new MPInteger(x); | ||
} | ||
|
||
/** | ||
* @param seed | ||
*/ | ||
public EdDSASecretBCPGKey( | ||
byte[] seed) | ||
{ | ||
BigInteger x = BigIntegers.fromUnsignedByteArray(seed); | ||
this.x = new MPInteger(x); | ||
} | ||
|
||
/** | ||
* return "PGP" | ||
* | ||
* @see BCPGKey#getFormat() | ||
*/ | ||
public String getFormat() | ||
{ | ||
return "PGP"; | ||
} | ||
|
||
/** | ||
* return the standard PGP encoding of the key. | ||
* | ||
* @see BCPGKey#getEncoded() | ||
*/ | ||
public byte[] getEncoded() | ||
{ | ||
try | ||
{ | ||
return super.getEncoded(); | ||
} | ||
catch (IOException e) | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
public void encode( | ||
BCPGOutputStream out) | ||
throws IOException | ||
{ | ||
out.writeObject(x); | ||
} | ||
|
||
/** | ||
* @return x | ||
*/ | ||
public BigInteger getX() | ||
{ | ||
return x.getValue(); | ||
} | ||
|
||
public byte[] getSeed() | ||
{ | ||
return BigIntegers.asUnsignedByteArray(x.getValue()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.