java.lang.Object
net.i2p.crypto.Blinding

public final class Blindingextends Object
Utilities for Blinding EdDSA keys. PRELIMINARY - Subject to change - see proposal 123.
  • Field Details

    • TYPE

      private static final SigType TYPE
      Signature type of blinded Ed25519.
    • TYPER

      private static final SigType TYPER
      Signature type of blinded RedDSA.
    • INFO

      private static final String INFO
      The HKDF info string of the blinding.
      See Also:
    • INFO_ALPHA

      private static final byte[] INFO_ALPHA
      The HKDF info string for generating alpha.
    • FLAG_TWOBYTE

      private static final byte FLAG_TWOBYTE
      Flag for a two byte blinding factor.
      See Also:
    • FLAG_SECRET

      private static final byte FLAG_SECRET
      Flag for a secret blinding factor.
      See Also:
    • FLAG_AUTH

      private static final byte FLAG_AUTH
      Flag for authenticated blinding.
      See Also:
    • FORMAT

      private static final String FORMAT
      Date format of the blinding epochs.
      See Also:
    • LENGTH

      private static final int LENGTH
      Length of the epoch date string.
    • _DATE_FMT

      private static final ThreadLocal<SimpleDateFormat> _DATE_FMT
      The date formatter, one per thread.
    • _hkdf

      private static volatile HKDF _hkdf
      Cached HKDF for generateAlpha(I2PAppContext, SigningPublicKey, String), which is called once per blinded destination. HKDF is stateless (it only holds the context, and the context's HMAC256Generator is itself thread-safe), so one instance per context is reusable and saves an allocation per call.
    • _hkdfCtx

      private static volatile I2PAppContext _hkdfCtx
      The context _hkdf was built for, so a context change forces a rebuild.
  • Constructor Details

    • Blinding

      private Blinding()
      Not called, the blinding class is never instantiated.
  • Method Details

    • hkdf

      static HKDF hkdf(I2PAppContext ctx)
      Get the shared HKDF for a context. The cached instance is rebuilt if the context differs, so a non-global context never ends up using a HKDF bound to a different one. A racy double build is harmless, as both instances are equivalent.
      Parameters:
      ctx - the app context, non-null
      Returns:
      the shared HKDF, never null
      Throws:
      NullPointerException - if ctx is null
    • blind

      public static SigningPublicKey blind(SigningPublicKey key, SigningPrivateKey alpha)
      Only for SigTypes EdDSA_SHA512_Ed25519 and RedDSA_SHA512_Ed25519.
      Parameters:
      key - must be SigType EdDSA_SHA512_Ed25519 or RedDSA_SHA512_Ed25519
      alpha - must be SigType RedDSA_SHA512_Ed25519
      Returns:
      SigType RedDSA_SHA512_Ed25519
      Throws:
      IllegalArgumentException - on bad inputs or unsupported SigTypes
    • blind

      public static SigningPrivateKey blind(SigningPrivateKey key, SigningPrivateKey alpha)
      Only for SigTypes EdDSA_SHA512_Ed25519 and RedDSA_SHA512_Ed25519.
      Parameters:
      key - must be SigType EdDSA_SHA512_Ed25519 or RedDSA_SHA512_Ed25519
      alpha - must be SigType RedDSA_SHA512_Ed25519
      Returns:
      SigType RedDSA_SHA512_Ed25519
      Throws:
      IllegalArgumentException - on bad inputs or unsupported SigTypes
    • unblind

      public static SigningPrivateKey unblind(SigningPrivateKey key, SigningPrivateKey alpha)
      Only for SigType EdDSA_SHA512_Ed25519.
      Parameters:
      key - must be SigType RedDSA_SHA512_Ed25519
      alpha - must be SigType RedDSA_SHA512_Ed25519
      Returns:
      SigType EdDSA_SHA512_Ed25519
      Throws:
      IllegalArgumentException - on bad inputs or unsupported SigTypes
    • generateAlpha

      public static SigningPrivateKey generateAlpha(I2PAppContext ctx, SigningPublicKey destspk, String secret)
      Generate alpha for current time. Only for SigType EdDSA_SHA512_Ed25519.
      Parameters:
      ctx - the application context
      destspk - must be SigType EdDSA_SHA512_Ed25519
      secret - may be null or zero-length
      Returns:
      SigType RedDSA_SHA512_Ed25519
      Throws:
      IllegalArgumentException - on bad inputs or unsupported SigTypes
    • generateAlpha

      public static SigningPrivateKey generateAlpha(I2PAppContext ctx, SigningPublicKey destspk, String secret, long now)
      Generate alpha for the given time. Only for SigType EdDSA_SHA512_Ed25519 or RedDSA_SHA512_Ed25519.
      Parameters:
      ctx - the application context
      destspk - must be SigType EdDSA_SHA512_Ed25519 or RedDSA_SHA512_Ed25519
      secret - may be null or zero-length
      now - the time in milliseconds for which to generate alpha
      Returns:
      SigType RedDSA_SHA512_Ed25519
      Throws:
      IllegalArgumentException - on bad inputs or unsupported SigTypes
    • getDefaultBlindedType

      public static SigType getDefaultBlindedType(SigType unblindedType)
      What's the default blinded type for a given unblinded type?
      Parameters:
      unblindedType - the unblinded signature type
      Returns:
      non-null
    • decode

      public static BlindData decode(I2PAppContext ctx, String address) throws IllegalArgumentException
      Decode a new-format b32 address. See proposal 149.
      Parameters:
      ctx - the application context
      address - ending with ".b32.i2p"
      Returns:
      BlindData structure, use getUnblindedPubKey() for the result
      Throws:
      IllegalArgumentException - on bad inputs or unsupported SigTypes
    • decode

      public static BlindData decode(I2PAppContext ctx, byte[] b) throws IllegalArgumentException
      Decode a new-format b32 address. See proposal 149. NOTE: Not for external use, use decode(String).
      Parameters:
      ctx - the application context
      b - 35+ bytes
      Returns:
      BlindData structure, use getUnblindedPubKey() for the result
      Throws:
      IllegalArgumentException - on bad inputs or unsupported SigTypes
    • encode

      public static String encode(SigningPublicKey key) throws IllegalArgumentException
      Encode a public key as a new-format b32 address. See proposal 149.
      Parameters:
      key - the signing public key to encode
      Returns:
      (56 chars).b32.i2p
      Throws:
      IllegalArgumentException - on bad inputs or unsupported SigTypes
    • encode

      public static String encode(SigningPublicKey key, boolean requireSecret, boolean requireAuth) throws IllegalArgumentException
      Encode a public key as a new-format b32 address. See proposal 149.
      Parameters:
      key - the signing public key to encode
      requireSecret - whether a secret is required
      requireAuth - whether authentication is required
      Returns:
      (56 chars).b32.i2p
      Throws:
      IllegalArgumentException - on bad inputs or unsupported SigTypes
    • main

      public static void main(String[] args) throws Exception
      Command-line tool for encoding/decoding b32 addresses.
      Parameters:
      args - the sole command-line argument, a b32 address to decode
      Throws:
      Exception - if the argument is not a valid b32 address