From 944fe4794e3056008a219d12735f52b823c85cad Mon Sep 17 00:00:00 2001 From: zzz <zzz@mail.i2p> Date: Fri, 29 Mar 2019 12:54:12 +0000 Subject: [PATCH] Crypto: new SigContext (WIP) (proposal #148) --- core/java/src/net/i2p/crypto/SigContext.java | 69 ++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 core/java/src/net/i2p/crypto/SigContext.java diff --git a/core/java/src/net/i2p/crypto/SigContext.java b/core/java/src/net/i2p/crypto/SigContext.java new file mode 100644 index 0000000000..fa0d9dd989 --- /dev/null +++ b/core/java/src/net/i2p/crypto/SigContext.java @@ -0,0 +1,69 @@ +package net.i2p.crypto; + +import java.security.spec.AlgorithmParameterSpec; + +import net.i2p.data.DataHelper; + +/** + * Defines the context for signing with personalized hashes. + * See proposal 148. + * + * @since 0.9.40 + */ +public enum SigContext { + + SC_NONE (null), + SC_DATAGRAM ("sign_datagramI2P"), + SC_I2CP ("I2CP_SessionConf"), + SC_NETDB ("network_database"), + SC_NTCP ("NTCP_1_handshake"), + SC_SSU ("SSUHandshakeSign"), + SC_STREAMING("streaming_i2psig"), + SC_SU3 ("i2pSU3FileFormat"), + SC_TEST ("test1234test5678"), + + ; + + private final SigContextSpec spec; + + /** + * The 16 bytes for this type, or null for none + */ + SigContext(String p) { + spec = new SigContextSpec(p); + } + + /** + * The AlgorithmParameterSpec. + * Pass this as an argument in setParameter() + * to the Blake sign/verify engines. + */ + public SigContextSpec getSpec() { return spec; } + + /** + * The AlgorithmParameterSpec. + * Pass this as an argument in setParameter() + * to the Blake sign/verify engines. + */ + public static class SigContextSpec implements AlgorithmParameterSpec { + private final byte[] b; + + /** + * The 16 bytes for this type, or null for none + */ + public SigContextSpec(String p) { + if (p != null) { + b = DataHelper.getASCII(p); + if (b.length != 16) + throw new IllegalArgumentException(); + } else { + b = null; + } + } + + /** + * The 16 bytes for this type, or null for none + */ + public byte[] getData() { return b; } + } +} -- GitLab