diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-20 18:40:56 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2023-04-20 18:40:56 +0700 |
commit | 758b05345c9d2f0b412f75435cb31231a7f70311 (patch) | |
tree | 5600970e299bc813a44ee48d2e3c8ba8eca9572d /crypto/src/openpgp/PgpSecretKey.cs | |
parent | BigInteger construction from little-endian (diff) | |
download | BouncyCastle.NET-ed25519-758b05345c9d2f0b412f75435cb31231a7f70311.tar.xz |
Refactoring: reduced allocations
Diffstat (limited to 'crypto/src/openpgp/PgpSecretKey.cs')
-rw-r--r-- | crypto/src/openpgp/PgpSecretKey.cs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/crypto/src/openpgp/PgpSecretKey.cs b/crypto/src/openpgp/PgpSecretKey.cs index 627b6788a..184621b5c 100644 --- a/crypto/src/openpgp/PgpSecretKey.cs +++ b/crypto/src/openpgp/PgpSecretKey.cs @@ -67,9 +67,13 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp } else { - // 'reverse' because the native format for X25519 private keys is little-endian + // The native format for X25519 private keys is little-endian X25519PrivateKeyParameters xK = (X25519PrivateKeyParameters)privKey.Key; - secKey = new ECSecretBcpgKey(new BigInteger(1, Arrays.ReverseInPlace(xK.GetEncoded()))); +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + secKey = new ECSecretBcpgKey(new BigInteger(1, xK.DataSpan, bigEndian: false)); +#else + secKey = new ECSecretBcpgKey(new BigInteger(1, xK.GetEncoded(), bigEndian: false)); +#endif } break; } @@ -81,11 +85,19 @@ namespace Org.BouncyCastle.Bcpg.OpenPgp { if (privKey.Key is Ed25519PrivateKeyParameters ed25519K) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + secKey = new EdSecretBcpgKey(new BigInteger(1, ed25519K.DataSpan)); +#else secKey = new EdSecretBcpgKey(new BigInteger(1, ed25519K.GetEncoded())); +#endif } else if (privKey.Key is Ed448PrivateKeyParameters ed448K) { +#if NETCOREAPP2_1_OR_GREATER || NETSTANDARD2_1_OR_GREATER + secKey = new EdSecretBcpgKey(new BigInteger(1, ed448K.DataSpan)); +#else secKey = new EdSecretBcpgKey(new BigInteger(1, ed448K.GetEncoded())); +#endif } else { |