Data: Represent blinding secret as a SigningPrivateKey

This commit is contained in:
zzz
2019-02-04 16:58:41 +00:00
parent 0e029f84b0
commit ead49256c7
4 changed files with 27 additions and 31 deletions

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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);
}
/**

View File

@@ -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);
}
/**