Changeset 1bb57c4 for core


Ignore:
Timestamp:
Jan 29, 2019 1:51:42 PM (16 months ago)
Author:
zzz <zzz@…>
Branches:
master
Children:
c555bb6c
Parents:
a51a6d57
Message:

EdDSA minor cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • core/java/src/net/i2p/crypto/eddsa/spec/EdDSAPrivateKeySpec.java

    ra51a6d57 r1bb57c4  
    2727     */
    2828    public EdDSAPrivateKeySpec(byte[] seed, EdDSAParameterSpec spec) {
    29         if (seed.length != spec.getCurve().getField().getb()/8)
     29        int bd8 = spec.getCurve().getField().getb() / 8;
     30        if (seed.length != bd8)
    3031            throw new IllegalArgumentException("seed length is wrong");
    3132
     
    3536        try {
    3637            MessageDigest hash = MessageDigest.getInstance(spec.getHashAlgorithm());
    37             int b = spec.getCurve().getField().getb();
    3838
    3939            // H(k)
     
    4747            // TODO: are these bitflips the same for any hash function?
    4848            h[0] &= 248;
    49             h[(b/8)-1] &= 63;
    50             h[(b/8)-1] |= 64;
    51             a = Arrays.copyOfRange(h, 0, b/8);
     49            h[bd8 - 1] &= 63;
     50            h[bd8 - 1] |= 64;
     51            a = Arrays.copyOfRange(h, 0, bd8);
    5252
    5353            A = spec.getB().scalarMultiply(a);
     
    6767     */
    6868    public EdDSAPrivateKeySpec(EdDSAParameterSpec spec, byte[] h) {
    69         if (h.length != spec.getCurve().getField().getb()/4)
     69        int bd4 = spec.getCurve().getField().getb() / 4;
     70        if (h.length != bd4)
    7071            throw new IllegalArgumentException("hash length is wrong");
     72        int bd8 = bd4 / 2;
    7173
    7274        this.seed = null;
    7375        this.h = h;
    7476        this.spec = spec;
    75         int b = spec.getCurve().getField().getb();
    7677
    7778        h[0] &= 248;
    78         h[(b/8)-1] &= 63;
    79         h[(b/8)-1] |= 64;
    80         a = Arrays.copyOfRange(h, 0, b/8);
     79        h[bd8 - 1] &= 63;
     80        h[bd8 - 1] |= 64;
     81        a = Arrays.copyOfRange(h, 0, bd8);
    8182
    8283        A = spec.getB().scalarMultiply(a);
Note: See TracChangeset for help on using the changeset viewer.