From ead49256c7c79805352283e7990bb8e3587d341d Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 4 Feb 2019 16:58:41 +0000 Subject: [PATCH] Data: Represent blinding secret as a SigningPrivateKey --- core/java/src/net/i2p/crypto/Blinding.java | 34 ++++++++----------- .../net/i2p/crypto/eddsa/EdDSABlinding.java | 12 +++---- .../src/net/i2p/data/SigningPrivateKey.java | 6 ++-- .../src/net/i2p/data/SigningPublicKey.java | 6 ++-- 4 files changed, 27 insertions(+), 31 deletions(-) diff --git a/core/java/src/net/i2p/crypto/Blinding.java b/core/java/src/net/i2p/crypto/Blinding.java index 061ae20cd..661ba88fe 100644 --- a/core/java/src/net/i2p/crypto/Blinding.java +++ b/core/java/src/net/i2p/crypto/Blinding.java @@ -8,7 +8,6 @@ import net.i2p.crypto.eddsa.EdDSAPublicKey; import net.i2p.data.Hash; import net.i2p.data.SigningPrivateKey; import net.i2p.data.SigningPublicKey; -import net.i2p.data.SimpleDataStructure; /** @@ -27,17 +26,16 @@ public final class Blinding { * Only for SigType EdDSA_SHA512_Ed25519. * * @param key must be SigType EdDSA_SHA512_Ed25519 - * @param h hash of secret data, same length as this key + * @param alpha the secret data * @throws UnsupportedOperationException unless supported */ - public static SigningPublicKey blind(SigningPublicKey key, SimpleDataStructure h) { - if (key.getType() != TYPE) + public static SigningPublicKey blind(SigningPublicKey key, SigningPrivateKey alpha) { + if (key.getType() != TYPE && alpha.getType() != TYPE) throw new UnsupportedOperationException(); - if (h.length() != key.length()) - throw new IllegalArgumentException(); try { EdDSAPublicKey jk = SigUtil.toJavaEdDSAKey(key); - EdDSAPublicKey bjk = EdDSABlinding.blind(jk, h.getData()); + EdDSAPrivateKey ajk = SigUtil.toJavaEdDSAKey(alpha); + EdDSAPublicKey bjk = EdDSABlinding.blind(jk, ajk); return SigUtil.fromJavaKey(bjk, TYPE); } catch (GeneralSecurityException gse) { throw new IllegalArgumentException(gse); @@ -48,17 +46,16 @@ public final class Blinding { * Only for SigType EdDSA_SHA512_Ed25519. * * @param key must be SigType EdDSA_SHA512_Ed25519 - * @param h hash of secret data, same length as this key + * @param alpha the secret data * @throws UnsupportedOperationException unless supported */ - public static SigningPrivateKey blind(SigningPrivateKey key, SimpleDataStructure h) { - if (key.getType() != TYPE) + public static SigningPrivateKey blind(SigningPrivateKey key, SigningPrivateKey alpha) { + if (key.getType() != TYPE && alpha.getType() != TYPE) throw new UnsupportedOperationException(); - if (h.length() != key.length()) - throw new IllegalArgumentException(); try { EdDSAPrivateKey jk = SigUtil.toJavaEdDSAKey(key); - EdDSAPrivateKey bjk = EdDSABlinding.blind(jk, h.getData()); + EdDSAPrivateKey ajk = SigUtil.toJavaEdDSAKey(alpha); + EdDSAPrivateKey bjk = EdDSABlinding.blind(jk, ajk); return SigUtil.fromJavaKey(bjk, TYPE); } catch (GeneralSecurityException gse) { throw new IllegalArgumentException(gse); @@ -69,17 +66,16 @@ public final class Blinding { * Only for SigType EdDSA_SHA512_Ed25519. * * @param key must be SigType EdDSA_SHA512_Ed25519 - * @param h hash of secret data, same length as this key + * @param alpha the secret data * @throws UnsupportedOperationException unless supported */ - public static SigningPrivateKey unblind(SigningPrivateKey key, SimpleDataStructure h) { - if (key.getType() != TYPE) + public static SigningPrivateKey unblind(SigningPrivateKey key, SigningPrivateKey alpha) { + if (key.getType() != TYPE && alpha.getType() != TYPE) throw new UnsupportedOperationException(); - if (h.length() != key.length()) - throw new IllegalArgumentException(); try { EdDSAPrivateKey bjk = SigUtil.toJavaEdDSAKey(key); - EdDSAPrivateKey jk = EdDSABlinding.unblind(bjk, h.getData()); + EdDSAPrivateKey ajk = SigUtil.toJavaEdDSAKey(alpha); + EdDSAPrivateKey jk = EdDSABlinding.unblind(bjk, ajk); return SigUtil.fromJavaKey(jk, TYPE); } catch (GeneralSecurityException gse) { throw new IllegalArgumentException(gse); diff --git a/core/java/src/net/i2p/crypto/eddsa/EdDSABlinding.java b/core/java/src/net/i2p/crypto/eddsa/EdDSABlinding.java index c92c8f179..5e4ccb457 100644 --- a/core/java/src/net/i2p/crypto/eddsa/EdDSABlinding.java +++ b/core/java/src/net/i2p/crypto/eddsa/EdDSABlinding.java @@ -14,10 +14,10 @@ public final class EdDSABlinding { * Only for SigType EdDSA_SHA512_Ed25519. * * @param key must be SigType EdDSA_SHA512_Ed25519 - * @param h hash of secret data, same length as this key + * @param alpha generated from hash of secret data * @throws UnsupportedOperationException unless supported */ - public static EdDSAPublicKey blind(EdDSAPublicKey key, byte[] h) { + public static EdDSAPublicKey blind(EdDSAPublicKey key, EdDSAPrivateKey alpha) { // TODO, test only return key; } @@ -26,10 +26,10 @@ public final class EdDSABlinding { * Only for SigType EdDSA_SHA512_Ed25519. * * @param key must be SigType EdDSA_SHA512_Ed25519 - * @param h hash of secret data, same length as this key + * @param alpha generated from hash of secret data * @throws UnsupportedOperationException unless supported */ - public static EdDSAPrivateKey blind(EdDSAPrivateKey key, byte[] h) { + public static EdDSAPrivateKey blind(EdDSAPrivateKey key, EdDSAPrivateKey alpha) { // TODO, test only return key; } @@ -38,10 +38,10 @@ public final class EdDSABlinding { * Only for SigType EdDSA_SHA512_Ed25519. * * @param key must be SigType EdDSA_SHA512_Ed25519 - * @param h hash of secret data, same length as this key + * @param alpha generated from hash of secret data * @throws UnsupportedOperationException unless supported */ - public static EdDSAPrivateKey unblind(EdDSAPrivateKey key, byte[] h) { + public static EdDSAPrivateKey unblind(EdDSAPrivateKey key, EdDSAPrivateKey alpha) { // TODO, test only return key; } diff --git a/core/java/src/net/i2p/data/SigningPrivateKey.java b/core/java/src/net/i2p/data/SigningPrivateKey.java index 1fef2c82f..c9f0143d0 100644 --- a/core/java/src/net/i2p/data/SigningPrivateKey.java +++ b/core/java/src/net/i2p/data/SigningPrivateKey.java @@ -92,12 +92,12 @@ public class SigningPrivateKey extends SimpleDataStructure { /** * Only for SigType EdDSA_SHA512_Ed25519 * - * @param h hash of secret data, same length as this key + * @param alpha the secret data * @throws UnsupportedOperationException unless supported * @since 0.9.38 */ - public SigningPrivateKey blind(SimpleDataStructure h) { - return Blinding.blind(this, h); + public SigningPrivateKey blind(SigningPrivateKey alpha) { + return Blinding.blind(this, alpha); } /** diff --git a/core/java/src/net/i2p/data/SigningPublicKey.java b/core/java/src/net/i2p/data/SigningPublicKey.java index 2ed9f9af5..d0dce7739 100644 --- a/core/java/src/net/i2p/data/SigningPublicKey.java +++ b/core/java/src/net/i2p/data/SigningPublicKey.java @@ -200,12 +200,12 @@ public class SigningPublicKey extends SimpleDataStructure { /** * Only for SigType EdDSA_SHA512_Ed25519 * - * @param h hash of secret data, same length as this key + * @param alpha the secret data * @throws UnsupportedOperationException unless supported * @since 0.9.38 */ - public SigningPublicKey blind(SimpleDataStructure h) { - return Blinding.blind(this, h); + public SigningPublicKey blind(SigningPrivateKey alpha) { + return Blinding.blind(this, alpha); } /**