Changeset 10bae6a for core


Ignore:
Timestamp:
Mar 5, 2019 3:43:23 PM (15 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
5b1b4ac
Parents:
bfafdd34
Message:

Data: Update Encrypted LS2 blinding and encryption to match current proposal 123
Hide b32 in console for encrypted LS2

Location:
core/java/src/net/i2p
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/Blinding.java

    rbfafdd34 r10bae6a  
    2828    private static final SigType TYPER = SigType.RedDSA_SHA512_Ed25519;
    2929    private static final String INFO = "i2pblinding1";
     30    private static final byte[] INFO_ALPHA = DataHelper.getASCII("I2PGenerateAlpha");
    3031
    3132    // following copied from RouterKeyGenerator
     
    113114     *  Only for SigType EdDSA_SHA512_Ed25519.
    114115     *
    115      *  @param dest spk must be SigType EdDSA_SHA512_Ed25519
     116     *  @param destspk must be SigType EdDSA_SHA512_Ed25519
    116117     *  @param secret may be null or zero-length
    117118     *  @return SigType RedDSA_SHA512_Ed25519
     
    120121     *  @since 0.9.39
    121122     */
    122     public static SigningPrivateKey generateAlpha(I2PAppContext ctx, Destination dest, String secret) {
     123    public static SigningPrivateKey generateAlpha(I2PAppContext ctx, SigningPublicKey destspk, String secret) {
    123124        long now = ctx.clock().now();
    124         return generateAlpha(ctx, dest, secret, now);
     125        return generateAlpha(ctx, destspk, secret, now);
    125126    }
    126127
     
    137138     *  @since 0.9.39
    138139     */
    139     public static SigningPrivateKey generateAlpha(I2PAppContext ctx, Destination dest,
     140    public static SigningPrivateKey generateAlpha(I2PAppContext ctx, SigningPublicKey destspk,
    140141                                                  String secret, long now) {
    141142        String modVal;
     
    156157        HKDF hkdf = new HKDF(ctx);
    157158        byte[] out = new byte[64];
    158         hkdf.calculate(dest.getHash().getData(), data, INFO, out, out, 32);
     159        int stoff = INFO_ALPHA.length + destspk.length();
     160        byte[] in = new byte[stoff + 4];
     161        // SHA256("I2PGenerateAlpha" || spk || sigtypein || sigtypeout)
     162        System.arraycopy(INFO_ALPHA, 0, in, 0, INFO_ALPHA.length);
     163        System.arraycopy(destspk.getData(), 0, in, INFO_ALPHA.length, destspk.length());
     164        DataHelper.toLong(in, stoff, 2, destspk.getType().getCode());
     165        DataHelper.toLong(in, stoff + 2, 2, TYPER.getCode());
     166        Hash salt = ctx.sha().calculateHash(in);
     167        hkdf.calculate(salt.getData(), data, INFO, out, out, 32);
    159168        byte[] b = EdDSABlinding.reduce(out);
    160169        return new SigningPrivateKey(TYPER, b);
  • core/java/src/net/i2p/data/EncryptedLeaseSet.java

    rbfafdd34 r10bae6a  
    130130        I2PAppContext ctx = I2PAppContext.getGlobalContext();
    131131        if (_published <= 0)
    132             _alpha = Blinding.generateAlpha(ctx, _destination, null);
     132            _alpha = Blinding.generateAlpha(ctx, _destination.getSigningPublicKey(), null);
    133133        else
    134             _alpha = Blinding.generateAlpha(ctx, _destination, null, _published);
     134            _alpha = Blinding.generateAlpha(ctx, _destination.getSigningPublicKey(), null, _published);
    135135        SigningPublicKey rv = Blinding.blind(spk, _alpha);
    136136        if (_log.shouldDebug())
     
    465465        if (_destination == null)
    466466            throw new IllegalStateException("no known destination to decrypt with");
    467         byte[] credential = hash(ctx, CREDENTIAL, _destination.toByteArray());
     467        SigningPublicKey destspk = _destination.getSigningPublicKey();
     468        int spklen = destspk.length();
     469        byte[] in = new byte[spklen + 4];
     470        // SHA256("credential" || spk || sigtypein || sigtypeout)
     471        System.arraycopy(destspk.getData(), 0, in, 0, spklen);
     472        DataHelper.toLong(in, spklen, 2, destspk.getType().getCode());
     473        DataHelper.toLong(in, spklen + 2, 2, SigType.RedDSA_SHA512_Ed25519.getCode());
     474        byte[] credential = hash(ctx, CREDENTIAL, in);
    468475        byte[] spk = _signingKey.getData();
    469476        byte[] tmp = new byte[credential.length + spk.length];
Note: See TracChangeset for help on using the changeset viewer.