public byte[] toByteArray() { /* oid || root || seed */ int n = params.getDigestSize(); // int oidSize = 4; int rootSize = n; int publicSeedSize = n; int totalSize = rootSize + publicSeedSize; // int totalSize = oidSize + rootSize + publicSeedSize; byte[] out = new byte[totalSize]; int position = 0; /* copy oid */ /* * XMSSUtil.intToBytesBigEndianOffset(out, oid, position); position += * oidSize; */ /* copy root */ XMSSUtil.copyBytesAtOffset(out, root, position); position += rootSize; /* copy public seed */ XMSSUtil.copyBytesAtOffset(out, publicSeed, position); return out; }
private void importState(XMSSMTPrivateKeyParameters privateKey, XMSSMTPublicKeyParameters publicKey) { /* import to xmss */ xmssParams.getWOTSPlus().importKeys(new byte[params.getDigestSize()], this.privateKey.getPublicSeed()); this.privateKey = privateKey; this.publicKey = publicKey; }
private WOTSPlusSignature wotsSign(byte[] messageDigest, OTSHashAddress otsHashAddress) { if (messageDigest.length != params.getDigestSize()) { throw new IllegalArgumentException("size of messageDigest needs to be equal to size of digest"); } if (otsHashAddress == null) { throw new NullPointerException("otsHashAddress == null"); } /* (re)initialize WOTS+ instance */ wotsPlus.importKeys(wotsPlus.getWOTSPlusSecretKey(privateKey.getSecretKeySeed(), otsHashAddress), privateKey.getPublicSeed()); /* create WOTS+ signature */ return wotsPlus.sign(messageDigest, otsHashAddress); }
private XMSSMTPrivateKeyParameters generatePrivateKey(BDSStateMap bdsState) { int n = params.getDigestSize(); byte[] secretKeySeed = new byte[n]; prng.nextBytes(secretKeySeed); byte[] secretKeyPRF = new byte[n]; prng.nextBytes(secretKeyPRF); byte[] publicSeed = new byte[n]; prng.nextBytes(publicSeed); XMSSMTPrivateKeyParameters privateKey = null; privateKey = new XMSSMTPrivateKeyParameters.Builder(params).withSecretKeySeed(secretKeySeed) .withSecretKeyPRF(secretKeyPRF).withPublicSeed(publicSeed) .withBDSState(bdsState).build(); return privateKey; } }
int n = params.getDigestSize(); byte[] publicKey = builder.publicKey; if (publicKey != null)
int n = params.getDigestSize(); byte[] signature = builder.signature; if (signature != null)
public byte[] toByteArray() int n = params.getDigestSize(); int indexSize = (params.getHeight() + 7) / 8; int secretKeySize = n;
xmssParams.getWOTSPlus().importKeys(new byte[params.getDigestSize()], xmssMTPrivateKey.getPublicSeed());
int n = params.getDigestSize(); byte[] privateKey = builder.privateKey; if (privateKey != null)
/** * XMSSMT constructor... * * @param height Height of tree. * @param layers Amount of layers. * @param digest Digest to use. */ public XMSSMTParameters(int height, int layers, Digest digest) { super(); this.height = height; this.layers = layers; this.xmssParams = new XMSSParameters(xmssTreeHeight(height, layers), digest); oid = DefaultXMSSMTOid.lookup(getDigest().getAlgorithmName(), getDigestSize(), getWinternitzParameter(), getLen(), getHeight(), layers); /* * if (oid == null) { throw new InvalidParameterException(); } */ }
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 n = keyParams.getParameters().getDigestSize(); int totalHeight = keyParams.getParameters().getHeight(); int indexSize = (totalHeight + 7) / 8;
XMSSUtil.toBytesBigEndian(sig.getIndex(), params.getDigestSize())); byte[] messageDigest = wotsPlus.getKhf().HMsg(concatenated, message); wotsPlus.importKeys(new byte[params.getDigestSize()], publicKey.getPublicSeed());
XMSSUtil.toBytesBigEndian(globalIndex, params.getDigestSize())); byte[] messageDigest = wotsPlus.getKhf().HMsg(concatenated, message); wotsPlus.importKeys(new byte[params.getDigestSize()], privateKey.getPublicSeed());
/** * Generate a new XMSSMT private key / public key pair. */ public AsymmetricCipherKeyPair generateKeyPair() { XMSSMTPrivateKeyParameters privateKey; XMSSMTPublicKeyParameters publicKey; /* generate XMSSMT private key */ privateKey = generatePrivateKey(new XMSSMTPrivateKeyParameters.Builder(params).build().getBDSState()); /* import to xmss */ xmssParams.getWOTSPlus().importKeys(new byte[params.getDigestSize()], privateKey.getPublicSeed()); /* get root */ int rootLayerIndex = params.getLayers() - 1; OTSHashAddress otsHashAddress = (OTSHashAddress)new OTSHashAddress.Builder().withLayerAddress(rootLayerIndex) .build(); /* store BDS instance of root xmss instance */ BDS bdsRoot = new BDS(xmssParams, privateKey.getPublicSeed(), privateKey.getSecretKeySeed(), otsHashAddress); XMSSNode root = bdsRoot.getRoot(); privateKey.getBDSState().put(rootLayerIndex, bdsRoot); /* set XMSS^MT root / create public key */ privateKey = new XMSSMTPrivateKeyParameters.Builder(params).withSecretKeySeed(privateKey.getSecretKeySeed()) .withSecretKeyPRF(privateKey.getSecretKeyPRF()).withPublicSeed(privateKey.getPublicSeed()) .withRoot(root.getValue()).withBDSState(privateKey.getBDSState()).build(); publicKey = new XMSSMTPublicKeyParameters.Builder(params).withRoot(root.getValue()) .withPublicSeed(privateKey.getPublicSeed()).build(); return new AsymmetricCipherKeyPair(publicKey, privateKey); }