public int getHeight() { return keyParams.getParameters().getHeight(); }
public int getHeight() { return keyParams.getParameters().getHeight(); }
/** * Place holder BDS for when state is exhausted. * * @param params tree parameters * @param index the index that has been reached. */ BDS(XMSSParameters params, int index) { this(params.getWOTSPlus(), params.getHeight(), params.getK()); this.index = index; this.used = true; }
public long getUsagesRemaining() { return (1L << this.getParameters().getHeight()) - this.getIndex(); }
/** * Set up constructor. * * @param params tree parameters * @param publicSeed public seed for tree * @param secretKeySeed secret seed for tree * @param otsHashAddress hash address */ BDS(XMSSParameters params, byte[] publicSeed, byte[] secretKeySeed, OTSHashAddress otsHashAddress) { this(params.getWOTSPlus(), params.getHeight(), params.getK()); this.initialize(publicSeed, secretKeySeed, otsHashAddress); }
/** * Set up constructor for a tree where the original BDS state was lost. * * @param params tree parameters * @param publicSeed public seed for tree * @param secretKeySeed secret seed for tree * @param otsHashAddress hash address * @param index index counter for the state to be at. */ BDS(XMSSParameters params, byte[] publicSeed, byte[] secretKeySeed, OTSHashAddress otsHashAddress, int index) { this(params.getWOTSPlus(), params.getHeight(), params.getK()); this.initialize(publicSeed, secretKeySeed, otsHashAddress); while (this.index < index) { this.nextAuthenticationPath(publicSeed, secretKeySeed, otsHashAddress); this.used = false; } }
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 height = params.getHeight(); byte[] reducedSignature = builder.reducedSignature; if (reducedSignature != null)
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; }
private static XMSSPrivateKey xmssCreateKeyStructure(XMSSPrivateKeyParameters keyParams) { byte[] keyData = keyParams.toByteArray(); int n = keyParams.getParameters().getDigestSize(); int totalHeight = keyParams.getParameters().getHeight(); int indexSize = 4; int secretKeySize = n; int secretKeyPRFSize = n; int publicSeedSize = n; int rootSize = n; int position = 0; int index = (int)XMSSUtil.bytesToXBigEndian(keyData, position, indexSize); if (!XMSSUtil.isIndexValid(totalHeight, index)) { throw new IllegalArgumentException("index out of bounds"); } position += indexSize; byte[] secretKeySeed = XMSSUtil.extractBytesAtOffset(keyData, position, secretKeySize); position += secretKeySize; byte[] secretKeyPRF = XMSSUtil.extractBytesAtOffset(keyData, position, secretKeyPRFSize); position += secretKeyPRFSize; byte[] publicSeed = XMSSUtil.extractBytesAtOffset(keyData, position, publicSeedSize); position += publicSeedSize; byte[] root = XMSSUtil.extractBytesAtOffset(keyData, position, rootSize); position += rootSize; /* import BDS state */ byte[] bdsStateBinary = XMSSUtil.extractBytesAtOffset(keyData, position, keyData.length - position); return new XMSSPrivateKey(index, secretKeySeed, secretKeyPRF, publicSeed, root, bdsStateBinary); }
int randomSize = n; int signatureSize = getParams().getWOTSPlus().getParams().getLen() * n; int authPathSize = getParams().getHeight() * n; int totalSize = indexSize + randomSize + signatureSize + authPathSize; byte[] out = new byte[totalSize];
if (!XMSSUtil.isIndexValid(params.getHeight(), index))
int xmssHeight = xmssParams.getHeight(); long indexTree = XMSSUtil.getTreeIndex(globalIndex, xmssHeight); int indexLeaf = XMSSUtil.getLeafIndex(globalIndex, xmssHeight);
public XMSSPrivateKeyParameters getNextKey() { /* prepare authentication path for next leaf */ int treeHeight = this.params.getHeight(); if (this.getIndex() < ((1 << treeHeight) - 1)) { return new XMSSPrivateKeyParameters.Builder(params) .withSecretKeySeed(secretKeySeed).withSecretKeyPRF(secretKeyPRF) .withPublicSeed(publicSeed).withRoot(root) .withBDSState(bdsState.getNextState(publicSeed, secretKeySeed, (OTSHashAddress)new OTSHashAddress.Builder().build())).build(); } else { return new XMSSPrivateKeyParameters.Builder(params) .withSecretKeySeed(secretKeySeed).withSecretKeyPRF(secretKeyPRF) .withPublicSeed(publicSeed).withRoot(root) .withBDSState(new BDS(params, getIndex() + 1)).build(); // no more nodes left. } }
public boolean verifySignature(byte[] message, byte[] signature) { /* parse signature and public key */ XMSSSignature sig = new XMSSSignature.Builder(params).withSignature(signature).build(); /* generate public key */ int index = sig.getIndex(); /* reinitialize WOTS+ object */ params.getWOTSPlus().importKeys(new byte[params.getDigestSize()], publicKey.getPublicSeed()); /* create message digest */ byte[] concatenated = Arrays.concatenate(sig.getRandom(), publicKey.getRoot(), XMSSUtil.toBytesBigEndian(index, params.getDigestSize())); byte[] messageDigest = khf.HMsg(concatenated, message); int xmssHeight = params.getHeight(); int indexLeaf = XMSSUtil.getLeafIndex(index, xmssHeight); /* get root from signature */ OTSHashAddress otsHashAddress = (OTSHashAddress)new OTSHashAddress.Builder().withOTSAddress(index).build(); XMSSNode rootNodeFromSignature = XMSSVerifierUtil.getRootNodeFromSignature(params.getWOTSPlus(), xmssHeight, messageDigest, sig, otsHashAddress, indexLeaf); return Arrays.constantTimeAreEqual(rootNodeFromSignature.getValue(), publicKey.getRoot()); }
final int xmssHeight = xmssParams.getHeight(); if (!XMSSUtil.isIndexValid(totalHeight, globalIndex))
private void updateState(XMSSMTParameters params, long globalIndex, byte[] publicSeed, byte[] secretKeySeed) int xmssHeight = xmssParams.getHeight();
new XMSSKeyParams(keyParams.getParameters().getHeight(), Utils.xmssLookupTreeAlgID(keyParams.getTreeDigest()))); return new SubjectPublicKeyInfo(algorithmIdentifier, new XMSSPublicKey(keyParams.getPublicSeed(), keyParams.getRoot()));
new XMSSKeyParams(keyParams.getParameters().getHeight(), Utils.xmssLookupTreeAlgID(keyParams.getTreeDigest())));