/** * Derive private key at index from secret key seed. * * @param index Index. * @return Private key at index. */ private byte[] expandSecretKeySeed(int index) { if (index < 0 || index >= params.getLen()) { throw new IllegalArgumentException("index out of bounds"); } return khf.PRF(secretKeySeed, XMSSUtil.toBytesBigEndian(index, 32)); }
protected int getLen() { return xmssParams.getWOTSPlus().getParams().getLen(); } }
/** * Getter private key. * * @return WOTS+ private key. */ protected WOTSPlusPrivateKeyParameters getPrivateKey() { byte[][] privateKey = new byte[params.getLen()][]; for (int i = 0; i < privateKey.length; i++) { privateKey[i] = expandSecretKeySeed(i); } return new WOTSPlusPrivateKeyParameters(params, privateKey); }
protected WOTSPlusPrivateKeyParameters(WOTSPlusParameters params, byte[][] privateKey) { super(); if (params == null) { throw new NullPointerException("params == null"); } if (privateKey == null) { throw new NullPointerException("privateKey == null"); } if (XMSSUtil.hasNullPointer(privateKey)) { throw new NullPointerException("privateKey byte array == null"); } if (privateKey.length != params.getLen()) { throw new IllegalArgumentException("wrong privateKey format"); } for (int i = 0; i < privateKey.length; i++) { if (privateKey[i].length != params.getDigestSize()) { throw new IllegalArgumentException("wrong privateKey format"); } } this.privateKey = XMSSUtil.cloneArray(privateKey); }
protected WOTSPlusSignature(WOTSPlusParameters params, byte[][] signature) { super(); if (params == null) { throw new NullPointerException("params == null"); } if (signature == null) { throw new NullPointerException("signature == null"); } if (XMSSUtil.hasNullPointer(signature)) { throw new NullPointerException("signature byte array == null"); } if (signature.length != params.getLen()) { throw new IllegalArgumentException("wrong signature size"); } for (int i = 0; i < signature.length; i++) { if (signature[i].length != params.getDigestSize()) { throw new IllegalArgumentException("wrong signature format"); } } this.signature = XMSSUtil.cloneArray(signature); }
protected WOTSPlusPublicKeyParameters(WOTSPlusParameters params, byte[][] publicKey) { super(); if (params == null) { throw new NullPointerException("params == null"); } if (publicKey == null) { throw new NullPointerException("publicKey == null"); } if (XMSSUtil.hasNullPointer(publicKey)) { throw new NullPointerException("publicKey byte array == null"); } if (publicKey.length != params.getLen()) { throw new IllegalArgumentException("wrong publicKey size"); } for (int i = 0; i < publicKey.length; i++) { if (publicKey[i].length != params.getDigestSize()) { throw new IllegalArgumentException("wrong publicKey format"); } } this.publicKey = XMSSUtil.cloneArray(publicKey); }
public byte[] toByteArray() { /* signature || authentication path */ int n = params.getDigestSize(); int signatureSize = params.getWOTSPlus().getParams().getLen() * n; int authPathSize = params.getHeight() * n; int totalSize = signatureSize + authPathSize; byte[] out = new byte[totalSize]; int position = 0; /* copy signature */ byte[][] signature = this.wotsPlusSignature.toByteArray(); for (int i = 0; i < signature.length; i++) { XMSSUtil.copyBytesAtOffset(out, signature[i], position); position += n; } /* copy authentication path */ for (int i = 0; i < authPath.size(); i++) { byte[] value = authPath.get(i).getValue(); XMSSUtil.copyBytesAtOffset(out, value, position); position += n; } return out; }
int len = params.getWOTSPlus().getParams().getLen(); int height = params.getHeight(); byte[] reducedSignature = builder.reducedSignature;
public Builder withSignature(byte[] val) { if (val == null) { throw new NullPointerException("signature == null"); } int n = params.getDigestSize(); int len = params.getWOTSPlus().getParams().getLen(); int height = params.getHeight(); int indexSize = 4; int randomSize = n; int signatureSize = len * n; int authPathSize = height * n; int position = 0; /* extract index */ index = Pack.bigEndianToInt(val, position); position += indexSize; /* extract random */ random = XMSSUtil.extractBytesAtOffset(val, position, randomSize); position += randomSize; withReducedSignature(XMSSUtil.extractBytesAtOffset(val, position, signatureSize + authPathSize)); return this; }
int len = params.getWOTSPlus().getParams().getLen(); int indexSize = (int)Math.ceil(params.getHeight() / (double)8); int randomSize = n;
/** * XMSS Constructor... * * @param height Height of tree. * @param digest Digest to use. */ public XMSSParameters(int height, Digest digest) { super(); if (height < 2) { throw new IllegalArgumentException("height must be >= 2"); } if (digest == null) { throw new NullPointerException("digest == null"); } wotsPlus = new WOTSPlus(new WOTSPlusParameters(digest)); this.height = height; this.k = determineMinK(); oid = DefaultXMSSOid.lookup(getDigest().getAlgorithmName(), getDigestSize(), getWinternitzParameter(), wotsPlus.getParams().getLen(), height); /* * if (oid == null) { throw new InvalidParameterException(); } */ }
/** * Calculates a new public key based on the state of secretKeySeed, * publicSeed and otsHashAddress. * * @param otsHashAddress OTS hash address for randomization. * @return WOTS+ public key. */ protected WOTSPlusPublicKeyParameters getPublicKey(OTSHashAddress otsHashAddress) { if (otsHashAddress == null) { throw new NullPointerException("otsHashAddress == null"); } byte[][] publicKey = new byte[params.getLen()][]; /* derive public key from secretKeySeed */ for (int i = 0; i < params.getLen(); i++) { otsHashAddress = (OTSHashAddress)new OTSHashAddress.Builder() .withLayerAddress(otsHashAddress.getLayerAddress()).withTreeAddress(otsHashAddress.getTreeAddress()) .withOTSAddress(otsHashAddress.getOTSAddress()).withChainAddress(i) .withHashAddress(otsHashAddress.getHashAddress()).withKeyAndMask(otsHashAddress.getKeyAndMask()) .build(); publicKey[i] = chain(expandSecretKeySeed(i), 0, params.getWinternitzParameter() - 1, otsHashAddress); } return new WOTSPlusPublicKeyParameters(params, publicKey); } }
public byte[] toByteArray() { /* index || random || reduced signatures */ int n = params.getDigestSize(); int len = params.getWOTSPlus().getParams().getLen(); int indexSize = (int)Math.ceil(params.getHeight() / (double)8); int randomSize = n; int reducedSignatureSizeSingle = ((params.getHeight() / params.getLayers()) + len) * n; int reducedSignaturesSizeTotal = reducedSignatureSizeSingle * params.getLayers(); int totalSize = indexSize + randomSize + reducedSignaturesSizeTotal; byte[] out = new byte[totalSize]; int position = 0; /* copy index */ byte[] indexBytes = XMSSUtil.toBytesBigEndian(index, indexSize); XMSSUtil.copyBytesAtOffset(out, indexBytes, position); position += indexSize; /* copy random */ XMSSUtil.copyBytesAtOffset(out, random, position); position += randomSize; /* copy reduced signatures */ for (XMSSReducedSignature reducedSignature : reducedSignatures) { byte[] signature = reducedSignature.toByteArray(); XMSSUtil.copyBytesAtOffset(out, signature, position); position += reducedSignatureSizeSingle; } return out; }
int indexSize = 4; int randomSize = n; int signatureSize = getParams().getWOTSPlus().getParams().getLen() * n; int authPathSize = getParams().getHeight() * n; int totalSize = indexSize + randomSize + signatureSize + authPathSize;
int len = wotsPlus.getParams().getLen();