java.lang.Object
net.i2p.crypto.Blinding
Utilities for Blinding EdDSA keys. PRELIMINARY - Subject to change - see proposal 123.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final ThreadLocal<SimpleDateFormat> The date formatter, one per thread.private static HKDFCached HKDF forgenerateAlpha(I2PAppContext, SigningPublicKey, String), which is called once per blinded destination.private static I2PAppContextThe context_hkdfwas built for, so a context change forces a rebuild.private static final byteFlag for authenticated blinding.private static final byteFlag for a secret blinding factor.private static final byteFlag for a two byte blinding factor.private static final StringDate format of the blinding epochs.private static final StringThe HKDF info string of the blinding.private static final byte[]The HKDF info string for generating alpha.private static final intLength of the epoch date string.private static final SigTypeSignature type of blinded Ed25519.private static final SigTypeSignature type of blinded RedDSA.Constructor Summary
ConstructorsModifierConstructorDescriptionprivateBlinding()Not called, the blinding class is never instantiated.Method Summary
Public MethodsModifier and TypeMethodDescriptionstatic SigningPrivateKeyblind(SigningPrivateKey key, SigningPrivateKey alpha) Only for SigTypes EdDSA_SHA512_Ed25519 and RedDSA_SHA512_Ed25519.static SigningPublicKeyblind(SigningPublicKey key, SigningPrivateKey alpha) Only for SigTypes EdDSA_SHA512_Ed25519 and RedDSA_SHA512_Ed25519.static BlindDatadecode(I2PAppContext ctx, byte[] b) Decode a new-format b32 address.static BlindDatadecode(I2PAppContext ctx, String address) Decode a new-format b32 address.static Stringencode(SigningPublicKey key) Encode a public key as a new-format b32 address.static Stringencode(SigningPublicKey key, boolean requireSecret, boolean requireAuth) Encode a public key as a new-format b32 address.static SigningPrivateKeygenerateAlpha(I2PAppContext ctx, SigningPublicKey destspk, String secret) Generate alpha for current time.static SigningPrivateKeygenerateAlpha(I2PAppContext ctx, SigningPublicKey destspk, String secret, long now) Generate alpha for the given time.static SigTypegetDefaultBlindedType(SigType unblindedType) What's the default blinded type for a given unblinded type?(package private) static HKDFhkdf(I2PAppContext ctx) Get the shared HKDF for a context.static voidCommand-line tool for encoding/decoding b32 addresses.static SigningPrivateKeyunblind(SigningPrivateKey key, SigningPrivateKey alpha) Only for SigType EdDSA_SHA512_Ed25519.
Field Details
TYPE
Signature type of blinded Ed25519.TYPER
Signature type of blinded RedDSA.INFO
INFO_ALPHA
private static final byte[] INFO_ALPHAThe HKDF info string for generating alpha.FLAG_TWOBYTE
private static final byte FLAG_TWOBYTEFlag for a two byte blinding factor.- See Also:
FLAG_SECRET
private static final byte FLAG_SECRETFlag for a secret blinding factor.- See Also:
FLAG_AUTH
FORMAT
LENGTH
private static final int LENGTHLength of the epoch date string._DATE_FMT
The date formatter, one per thread._hkdf
Cached HKDF forgenerateAlpha(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
The context_hkdfwas 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
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
Only for SigTypes EdDSA_SHA512_Ed25519 and RedDSA_SHA512_Ed25519.- Parameters:
key- must be SigType EdDSA_SHA512_Ed25519 or RedDSA_SHA512_Ed25519alpha- must be SigType RedDSA_SHA512_Ed25519- Returns:
- SigType RedDSA_SHA512_Ed25519
- Throws:
IllegalArgumentException- on bad inputs or unsupported SigTypes
blind
Only for SigTypes EdDSA_SHA512_Ed25519 and RedDSA_SHA512_Ed25519.- Parameters:
key- must be SigType EdDSA_SHA512_Ed25519 or RedDSA_SHA512_Ed25519alpha- must be SigType RedDSA_SHA512_Ed25519- Returns:
- SigType RedDSA_SHA512_Ed25519
- Throws:
IllegalArgumentException- on bad inputs or unsupported SigTypes
unblind
Only for SigType EdDSA_SHA512_Ed25519.- Parameters:
key- must be SigType RedDSA_SHA512_Ed25519alpha- 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 contextdestspk- must be SigType EdDSA_SHA512_Ed25519secret- 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 contextdestspk- must be SigType EdDSA_SHA512_Ed25519 or RedDSA_SHA512_Ed25519secret- may be null or zero-lengthnow- the time in milliseconds for which to generate alpha- Returns:
- SigType RedDSA_SHA512_Ed25519
- Throws:
IllegalArgumentException- on bad inputs or unsupported SigTypes
getDefaultBlindedType
decode
Decode a new-format b32 address. See proposal 149.- Parameters:
ctx- the application contextaddress- ending with ".b32.i2p"- Returns:
- BlindData structure, use getUnblindedPubKey() for the result
- Throws:
IllegalArgumentException- on bad inputs or unsupported SigTypes
decode
Decode a new-format b32 address. See proposal 149. NOTE: Not for external use, use decode(String).- Parameters:
ctx- the application contextb- 35+ bytes- Returns:
- BlindData structure, use getUnblindedPubKey() for the result
- Throws:
IllegalArgumentException- on bad inputs or unsupported SigTypes
encode
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 encoderequireSecret- whether a secret is requiredrequireAuth- whether authentication is required- Returns:
- (56 chars).b32.i2p
- Throws:
IllegalArgumentException- on bad inputs or unsupported SigTypes
main