java.lang.Object
net.i2p.crypto.eddsa.spec.EdDSAPrivateKeySpec
All Implemented Interfaces:
KeySpec

public class EdDSAPrivateKeySpecextends Object implements KeySpec
EdDSA private key specification.
  • Field Details

    • seed

      private final byte[] seed
      The 32-byte seed the key was derived from.
    • h

      private final byte[] h
      The hash of the seed, from which the scalar and prefix come.
    • a

      private final byte[] a
      The private scalar.
    • A

      private final GroupElement A
      The matching public point.
    • spec

      private final EdDSAParameterSpec spec
      The curve parameters the key belongs to.
  • Constructor Details

    • EdDSAPrivateKeySpec

      public EdDSAPrivateKeySpec(byte[] seed, EdDSAParameterSpec spec)
      Create a new EdDSA private key specification from a seed.
      Parameters:
      seed - the private key
      spec - the parameter specification for this key
      Throws:
      IllegalArgumentException - if seed length is wrong or hash algorithm is unsupported
    • EdDSAPrivateKeySpec

      public EdDSAPrivateKeySpec(EdDSAParameterSpec spec, byte[] h)
      Initialize directly from the hash. getSeed() will return null if this constructor is used.
      Parameters:
      spec - the parameter specification for this key
      h - the private key; copied and clamped on the copy, the caller's array is never modified
      Throws:
      IllegalArgumentException - if hash length is wrong
    • EdDSAPrivateKeySpec

      public EdDSAPrivateKeySpec(byte[] a, GroupElement aPoint, EdDSAParameterSpec spec)
      No validation of any parameters other than a. getSeed() and getH() will return null if this constructor is used.
      Parameters:
      a - must be "clamped" (for Ed) or reduced mod l (for Red); it is not validated - an invalid scalar silently yields a wrong public key. The array is copied, later changes by the caller have no effect.
      aPoint - if null, will be derived from a.
      spec - the domain parameters naming the curve and cofactor this key belongs to
    • EdDSAPrivateKeySpec

      public EdDSAPrivateKeySpec(byte[] seed, byte[] h, byte[] a, GroupElement aPoint, EdDSAParameterSpec spec)
      No validation of any parameters other than a.
      Parameters:
      seed - may be null; copied
      h - may be null; copied
      a - must be "clamped" (for Ed) or reduced mod l (for Red); it is not validated - an invalid scalar silently yields a wrong public key. The array is copied, later changes by the caller have no effect.
      aPoint - if null, will be derived from a.
      spec - the domain parameters naming the curve and cofactor this key belongs to
  • Method Details

    • copy

      private static byte[] copy(byte[] b)
      Defensive copy; null passes through unchanged.
      Parameters:
      b - the array to copy, may be null
      Returns:
      a clone of b, or null if b was null
    • getSeed

      public byte[] getSeed()
      Return the seed, or null if constructed from the private key directly.
      Returns:
      a copy of the seed, or null if constructed directly from the private key
    • getH

      public byte[] getH()
      Return the clamped hash of the seed, H(k), from which the scalar a is derived.
      Returns:
      a copy of the clamped hash of the seed, 2*bd8 bytes with the low bits of the first byte cleared and bit 6 of the last byte set
    • geta

      public byte[] geta()
      Return the private key.
      Returns:
      a copy of the private key
    • getA

      public GroupElement getA()
      Return the public key.
      Returns:
      the public key
    • getParams

      public EdDSAParameterSpec getParams()
      Returns the parameter specification for this key.
      Returns:
      the parameter specification