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
5 changes: 5 additions & 0 deletions crypto/src/pqc/crypto/ntru/NtruKeyGenerationParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,21 @@

namespace Org.BouncyCastle.Pqc.Crypto.Ntru
{
/// <summary>Key generation parameters for NTRU, binding a randomness source to an NTRU parameter set.</summary>
public class NtruKeyGenerationParameters : KeyGenerationParameters
{
internal NtruParameters NtruParameters { get; }

/// <summary>Creates key generation parameters for the given NTRU parameter set.</summary>
/// <param name="random">The randomness source for key generation.</param>
/// <param name="ntruParameters">The NTRU parameter set to generate keys for.</param>
// We won't be using strength as the key length differs between public & private key
public NtruKeyGenerationParameters(SecureRandom random, NtruParameters ntruParameters) : base(random, 1)
{
NtruParameters = ntruParameters;
}

/// <summary>The NTRU parameter set keys will be generated for.</summary>
public NtruParameters GetParameters()
{
return NtruParameters;
Expand Down
3 changes: 3 additions & 0 deletions crypto/src/pqc/crypto/ntru/NtruKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Org.BouncyCastle.Pqc.Crypto.Ntru
{
/// <summary>Base class for NTRU public and private keys, carrying the associated parameter set.</summary>
public abstract class NtruKeyParameters
: AsymmetricKeyParameter
{
Expand All @@ -13,8 +14,10 @@ internal NtruKeyParameters(bool privateKey, NtruParameters parameters)
m_parameters = parameters;
}

/// <summary>The NTRU parameter set this key belongs to.</summary>
public NtruParameters Parameters => m_parameters;

/// <summary>Returns a copy of the raw key encoding.</summary>
public abstract byte[] GetEncoded();
}
}
14 changes: 14 additions & 0 deletions crypto/src/pqc/crypto/ntru/NtruPublicKeyParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,21 @@

namespace Org.BouncyCastle.Pqc.Crypto.Ntru
{
/// <summary>An NTRU public (encapsulation) key, represented by its raw byte encoding.</summary>
/// <remarks>Instances are immutable. Create them via <see cref="FromEncoding(NtruParameters, byte[])"/>.</remarks>
public sealed class NtruPublicKeyParameters
: NtruKeyParameters
{
/// <summary>Creates an <see cref="NtruPublicKeyParameters"/> from its raw public key encoding.</summary>
/// <param name="parameters">The NTRU parameter set this key belongs to.</param>
/// <param name="encoding">
/// The raw public key bytes; length must equal the parameter set's public key length.
/// </param>
/// <returns>A new instance wrapping a defensive copy of <paramref name="encoding"/>.</returns>
/// <exception cref="ArgumentNullException">
/// If <paramref name="parameters"/> or <paramref name="encoding"/> is null.
/// </exception>
/// <exception cref="ArgumentException">If <paramref name="encoding"/> has the wrong length.</exception>
public static NtruPublicKeyParameters FromEncoding(NtruParameters parameters, byte[] encoding)
{
#pragma warning disable CS0618 // Type or member is obsolete
Expand All @@ -28,8 +40,10 @@ public NtruPublicKeyParameters(NtruParameters parameters, byte[] key)
m_publicKey = (byte[])key.Clone();
}

/// <summary>Returns a copy of the raw public key encoding.</summary>
public override byte[] GetEncoded() => (byte[])m_publicKey.Clone();

/// <summary>Obsolete. Use <see cref="GetEncoded"/> instead.</summary>
[Obsolete("Use 'GetEncoded' instead")]
public byte[] PublicKey
{
Expand Down